1 |
1 |
/**
|
2 |
2 |
* Copyright (C) 2007 EDIT
|
3 |
|
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy
|
4 |
4 |
* http://www.e-taxonomy.eu
|
5 |
|
*
|
|
5 |
*
|
6 |
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
7 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
8 |
*/
|
... | ... | |
21 |
21 |
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
22 |
22 |
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
23 |
23 |
import eu.etaxonomy.cdm.io.common.Source;
|
|
24 |
import eu.etaxonomy.cdm.model.agent.Person;
|
24 |
25 |
import eu.etaxonomy.cdm.model.agent.Team;
|
25 |
26 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26 |
27 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
... | ... | |
36 |
37 |
private static final Logger logger = Logger.getLogger(FaunaEuropaeaAuthorImport.class);
|
37 |
38 |
|
38 |
39 |
private static int modCount = 1000;
|
|
40 |
private final static String authorSeparator = ", ";
|
|
41 |
private final static String lastAuthorSeparator = " & ";
|
|
42 |
|
39 |
43 |
|
40 |
|
|
41 |
44 |
/* (non-Javadoc)
|
42 |
45 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
43 |
46 |
*/
|
... | ... | |
45 |
48 |
protected boolean doCheck(FaunaEuropaeaImportState state){
|
46 |
49 |
boolean result = true;
|
47 |
50 |
logger.warn("No checking for Authors not implemented");
|
48 |
|
|
|
51 |
|
49 |
52 |
return result;
|
50 |
53 |
}
|
51 |
|
|
|
54 |
|
52 |
55 |
/* (non-Javadoc)
|
53 |
56 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
|
54 |
57 |
*/
|
55 |
58 |
@Override
|
56 |
|
protected void doInvoke(FaunaEuropaeaImportState state){
|
|
59 |
protected void doInvoke(FaunaEuropaeaImportState state){
|
57 |
60 |
/*
|
58 |
61 |
logger.warn("Start author doInvoke");
|
59 |
62 |
ProfilerController.memorySnapshot();
|
... | ... | |
62 |
65 |
return;
|
63 |
66 |
}
|
64 |
67 |
Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores();
|
65 |
|
MapWrapper<TeamOrPersonBase> authorStore = (MapWrapper<TeamOrPersonBase>)stores.get(ICdmIO.TEAM_STORE);
|
|
68 |
MapWrapper<TeamOrPersonBase<?>> authorStore = (MapWrapper<TeamOrPersonBase<?>>)stores.get(ICdmIO.TEAM_STORE);
|
66 |
69 |
TransactionStatus txStatus = null;
|
67 |
|
|
|
70 |
|
68 |
71 |
FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig();
|
69 |
72 |
Source source = fauEuConfig.getSource();
|
70 |
|
|
|
73 |
|
71 |
74 |
String namespace = "AuthorTeam";
|
72 |
|
|
|
75 |
|
73 |
76 |
if(logger.isInfoEnabled()) { logger.info("Start making Authors..."); }
|
74 |
|
|
|
77 |
|
75 |
78 |
try {
|
76 |
79 |
|
77 |
|
String strQuery =
|
|
80 |
String strQuery =
|
78 |
81 |
" SELECT * " +
|
79 |
82 |
" FROM author " ;
|
80 |
83 |
ResultSet rs = source.getResultSet(strQuery) ;
|
... | ... | |
82 |
85 |
int i = 0;
|
83 |
86 |
while (rs.next()) {
|
84 |
87 |
|
85 |
|
if ((i++ % modCount) == 0 && i!= 1 ) {
|
|
88 |
if ((i++ % modCount) == 0 && i!= 1 ) {
|
86 |
89 |
if(logger.isDebugEnabled()) {
|
87 |
|
logger.debug("Authors retrieved: " + (i-1));
|
|
90 |
logger.debug("Authors retrieved: " + (i-1));
|
88 |
91 |
}
|
89 |
92 |
}
|
90 |
93 |
|
... | ... | |
93 |
96 |
|
94 |
97 |
String auctWithNecRegEx = "\\bauct\\b\\.?.*\\bnec\\b\\.?.*";
|
95 |
98 |
String necAuctRegEx = "\\bnec\\b\\.?.*\\bauct\\b\\.?.*";
|
96 |
|
|
|
99 |
|
97 |
100 |
boolean auctWithNecFound = expressionMatches(auctWithNecRegEx, authorName);
|
98 |
101 |
boolean necAuctFound = expressionMatches(necAuctRegEx, authorName);
|
99 |
102 |
if (auctWithNecFound){
|
... | ... | |
101 |
104 |
authorName = authorName.substring(expressionEnd("nec\\.?", authorName)+1, authorName.length());
|
102 |
105 |
logger.debug("authorName after auct nec string is removed" + authorName);
|
103 |
106 |
}
|
104 |
|
|
|
107 |
|
105 |
108 |
if (necAuctFound){
|
106 |
109 |
logger.debug("authorName before nec auct string is removed" + authorName);
|
107 |
110 |
authorName = authorName.substring(0, authorName.indexOf("nec")-1);
|
108 |
111 |
logger.debug("authorName before nec auct string is removed" + authorName);
|
109 |
112 |
}
|
110 |
|
TeamOrPersonBase<Team> author = null;
|
|
113 |
TeamOrPersonBase<?> author = null;
|
111 |
114 |
|
112 |
115 |
try {
|
113 |
|
author = Team.NewInstance();
|
114 |
|
author.setTitleCache(authorName, true);
|
115 |
|
|
116 |
|
ImportHelper.setOriginalSource(author, fauEuConfig.getSourceReference(), authorId, namespace);
|
|
116 |
author = parseAuthorString(authorName);
|
|
117 |
ImportHelper.setOriginalSource(author, fauEuConfig.getSourceReference(), authorId, namespace);
|
117 |
118 |
|
118 |
119 |
if (!authorStore.containsId(authorId)) {
|
119 |
120 |
authorStore.put(authorId, author);
|
... | ... | |
125 |
126 |
logger.warn("An exception occurred when creating author with id " + authorId + ". Author could not be saved.");
|
126 |
127 |
}
|
127 |
128 |
}
|
128 |
|
|
|
129 |
|
129 |
130 |
if(logger.isInfoEnabled()) { logger.info("Saving authors ..."); }
|
130 |
131 |
|
131 |
132 |
txStatus = startTransaction();
|
... | ... | |
134 |
135 |
getAgentService().save((Collection)authorStore.objects());
|
135 |
136 |
|
136 |
137 |
commitTransaction(txStatus);
|
137 |
|
|
|
138 |
|
138 |
139 |
if(logger.isInfoEnabled()) { logger.info("End making authors ..."); }
|
139 |
140 |
|
140 |
141 |
return;
|
... | ... | |
144 |
145 |
state.setUnsuccessfull();
|
145 |
146 |
}
|
146 |
147 |
}
|
147 |
|
|
|
148 |
|
148 |
149 |
/* (non-Javadoc)
|
149 |
150 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
150 |
151 |
*/
|
151 |
|
protected boolean isIgnore(FaunaEuropaeaImportState state){
|
|
152 |
@Override
|
|
153 |
protected boolean isIgnore(FaunaEuropaeaImportState state){
|
152 |
154 |
return ! state.getConfig().isDoAuthors();
|
153 |
155 |
}
|
154 |
156 |
|
|
157 |
public static TeamOrPersonBase<?> parseAuthorString(String authorName){
|
|
158 |
TeamOrPersonBase<?> author = null;
|
|
159 |
String[] teamMembers = authorName.split(authorSeparator);
|
|
160 |
String lastMember;
|
|
161 |
String[] lastMembers;
|
|
162 |
Person teamMember;
|
|
163 |
if (teamMembers.length>1){
|
|
164 |
lastMember = teamMembers[teamMembers.length -1];
|
|
165 |
lastMembers = lastMember.split(lastAuthorSeparator);
|
|
166 |
teamMembers[teamMembers.length -1] = "";
|
|
167 |
author = Team.NewInstance();
|
|
168 |
for(String member:teamMembers){
|
|
169 |
if (!member.equals("")){
|
|
170 |
teamMember = Person.NewInstance();
|
|
171 |
teamMember.setTitleCache(member, true);
|
|
172 |
((Team)author).addTeamMember(teamMember);
|
|
173 |
}
|
|
174 |
}
|
|
175 |
if (lastMembers != null){
|
|
176 |
for(String member:lastMembers){
|
|
177 |
teamMember = Person.NewInstance();
|
|
178 |
teamMember.setTitleCache(member, true);
|
|
179 |
((Team)author).addTeamMember(teamMember);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
} else {
|
|
184 |
teamMembers = authorName.split(lastAuthorSeparator);
|
|
185 |
if (teamMembers.length>1){
|
|
186 |
author = Team.NewInstance();
|
|
187 |
for(String member:teamMembers){
|
|
188 |
teamMember = Person.NewInstance();
|
|
189 |
teamMember.setTitleCache(member, true);
|
|
190 |
((Team)author).addTeamMember(teamMember);
|
|
191 |
|
|
192 |
}
|
|
193 |
}else{
|
|
194 |
author = Person.NewInstance();
|
|
195 |
author.setTitleCache(authorName, true);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
author.getTitleCache();
|
|
199 |
return author;
|
|
200 |
}
|
|
201 |
|
155 |
202 |
}
|
improve fauna europaea author import