Project

General

Profile

Download (4.82 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.berlinModel;
10

    
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import java.util.List;
14
import java.util.Map;
15

    
16
import org.apache.log4j.Logger;
17
import org.springframework.stereotype.Component;
18

    
19
import eu.etaxonomy.cdm.io.common.ICdmIO;
20
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
21
import eu.etaxonomy.cdm.io.common.ImportHelper;
22
import eu.etaxonomy.cdm.io.common.MapWrapper;
23
import eu.etaxonomy.cdm.io.common.Source;
24
import eu.etaxonomy.cdm.model.agent.AgentBase;
25
import eu.etaxonomy.cdm.model.agent.Person;
26
import eu.etaxonomy.cdm.model.agent.Team;
27
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29

    
30

    
31
/**
32
 * @author a.mueller
33
 * @created 20.03.2008
34
 * @version 1.0
35
 */
36
@Component
37
public class BerlinModelAuthorExport extends BerlinModelExportBase {
38
	private static final Logger logger = Logger.getLogger(BerlinModelAuthorExport.class);
39

    
40
	private static int modCount = 1000;
41

    
42
	public BerlinModelAuthorExport(){
43
		super();
44
	}
45
	
46
	/* (non-Javadoc)
47
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
48
	 */
49
	@Override
50
	protected boolean doCheck(IExportConfigurator config){
51
		boolean result = true;
52
		logger.warn("Checking for Authors not yet implemented");
53
		//result &= checkArticlesWithoutJournal(bmiConfig);
54
		//result &= checkPartOfJournal(bmiConfig);
55
		
56
		return result;
57
	}
58
	
59
	/* (non-Javadoc)
60
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
61
	 */
62
	@Override
63
	protected boolean doInvoke(IExportConfigurator config, 
64
			Map<String, MapWrapper<? extends CdmBase>> stores){ 
65

    
66
		MapWrapper<AgentBase> teamMap = (MapWrapper<AgentBase>)stores.get(ICdmIO.AUTHOR_STORE);
67
		
68
		BerlinModelImportConfigurator bmiConfig = (BerlinModelImportConfigurator)config;
69
		Source source = bmiConfig.getSource();
70
		String dbAttrName;
71
		String cdmAttrName;
72

    
73
		logger.info("start makeAuthors ...");
74
		boolean success = true ;
75
		
76
		String sql = "";
77
		
78
		//TODO get all persons ; getAllTeams
79
		List<? extends AgentBase> persons = getAgentService().getAllAgents(0, 10);
80
		sql = "INSERT INTO author (authorID, authorCache, ...) VALUES ";  
81
		for (AgentBase agent : persons){
82
			if (agent instanceof Person){
83
				Person person = (Person)agent;
84
				sql += person.getFirstname() + ", " + ", " + person.getLastname() + ", " + person.getFirstname() + ", ";  
85
			}
86
		}
87
		
88
		//TODO get all persons ; getAllTeams
89
		List<? extends AgentBase> teams = getAgentService().getAllAgents(0, 10);
90
		sql = "INSERT INTO AuthorTeam (AuthorTeamId, AuthorTeamCache, FullAuthorTeamCache) VALUES ";  
91
		for (AgentBase agent : teams){
92
			if (agent instanceof Team){
93
				Team team = (Team)agent;
94
				sql += team.getSources()/*TODO*/ + ", " + ", " + team.getTitleCache() + ", " + team.getTeamMembers() + ", ";  
95
			}
96
		}
97
		
98
//****************** FROM IMPORT ************/		
99
		//get data from database
100
		String strQuery = 
101
				" SELECT *  " +
102
                " FROM AuthorTeam " ;
103
		ResultSet rs = source.getResultSet(strQuery) ;
104
		String namespace = "AuthorTeam";
105
		
106
		int i = 0;
107
		//for each reference
108
		try{
109
			while (rs.next()){
110
				
111
				if ((i++ % modCount ) == 0 && i!= 1 ){ logger.info("Authors handled: " + (i-1));}
112
				
113
				//create Agent element
114
				int teamId = rs.getInt("AuthorTeamId");
115
				
116
				TeamOrPersonBase team = new Team();
117
				
118
				dbAttrName = "AuthorTeamCache";
119
				cdmAttrName = "nomenclaturalTitle";
120
				success &= ImportHelper.addStringValue(rs, team, dbAttrName, cdmAttrName);
121

    
122
				dbAttrName = "AuthorTeamCache";
123
				cdmAttrName = "titleCache";
124
				success &= ImportHelper.addStringValue(rs, team, dbAttrName, cdmAttrName);
125

    
126
				//TODO
127
				//FullAuthorTeamCache
128
				//preliminaryFlag
129
				//title cache or nomenclaturalTitle?
130

    
131
				//created, notes
132
	//			doIdCreatedUpdatedNotes(config, team, rs, teamId, namespace);
133

    
134
				teamMap.put(teamId, team);
135
			} //while rs.hasNext()
136
		} catch (SQLException e) {
137
			logger.error("SQLException:" +  e);
138
			return false;
139
		}
140

    
141
			
142
		logger.info(i + " authors handled");
143
		getAgentService().saveAgentAll(teamMap.objects());
144

    
145
		logger.info("end make authors ...");
146
		return success;
147
	}
148
	
149
	/* (non-Javadoc)
150
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
151
	 */
152
	protected boolean isIgnore(IExportConfigurator config){
153
		return ! ((BerlinModelExportConfigurator)config).isDoAuthors();
154
	}
155

    
156
}
(1-1/21)