Revision 64367d00
Added by Katja Luther over 8 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmApplicationAwareDefaultImport.java | ||
---|---|---|
128 | 128 |
state.initialize(config); |
129 | 129 |
|
130 | 130 |
//do check for each class |
131 |
for (Class<ICdmImport> ioClass: config.getIoClassList()){
|
|
131 |
for (Class<ICdmIO> ioClass: config.getIoClassList()){
|
|
132 | 132 |
try { |
133 | 133 |
String ioBeanName = getComponentBeanName(ioClass); |
134 | 134 |
ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class); |
... | ... | |
197 | 197 |
|
198 | 198 |
state.setSuccess(true); |
199 | 199 |
//do invoke for each class |
200 |
for (Class<ICdmImport> ioClass: config.getIoClassList()){
|
|
200 |
for (Class<ICdmIO> ioClass: config.getIoClassList()){
|
|
201 | 201 |
try { |
202 | 202 |
String ioBeanName = getComponentBeanName(ioClass); |
203 |
ICdmImport cdmIo = applicationContext.getBean(ioBeanName, ICdmImport.class);
|
|
203 |
ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class);
|
|
204 | 204 |
if (cdmIo != null){ |
205 | 205 |
registerObservers(config, cdmIo); |
206 | 206 |
state.setCurrentIO(cdmIo); |
207 | 207 |
result &= cdmIo.invoke(state); |
208 |
importResult.addReport(cdmIo.getByteArray()); |
|
208 |
//importResult.addReport(cdmIo.getByteArray());
|
|
209 | 209 |
unRegisterObservers(config, cdmIo); |
210 | 210 |
}else{ |
211 | 211 |
logger.error("cdmIO was null"); |
... | ... | |
250 | 250 |
* @return |
251 | 251 |
* @throws IllegalArgumentException if the class does not have a "Component" annotation |
252 | 252 |
*/ |
253 |
public static String getComponentBeanName(Class<ICdmImport> ioClass) throws IllegalArgumentException {
|
|
253 |
public static String getComponentBeanName(Class<ICdmIO> ioClass) throws IllegalArgumentException {
|
|
254 | 254 |
Component component = ioClass.getAnnotation(Component.class); |
255 | 255 |
if (component == null){ |
256 | 256 |
throw new IllegalArgumentException("Class " + ioClass.getName() + " is missing a @Component annotation." ); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/DeleteNonReferencedReferencesConfigurator.java | ||
---|---|---|
10 | 10 |
public class DeleteNonReferencedReferencesConfigurator extends ImportConfiguratorBase<DefaultImportState<DeleteNonReferencedReferencesConfigurator>, Object> implements IImportConfigurator{ |
11 | 11 |
|
12 | 12 |
private boolean doReferences = true; |
13 |
private boolean doAuthors = true;
|
|
14 |
|
|
13 |
private boolean doAuthors = true; |
|
14 |
|
|
15 | 15 |
public boolean isDoReferences() { |
16 | 16 |
return doReferences; |
17 | 17 |
} |
... | ... | |
43 | 43 |
this.setSource(destination); |
44 | 44 |
this.setDestination(destination); |
45 | 45 |
this.setDbSchemaValidation(DbSchemaValidation.UPDATE); |
46 |
|
|
46 |
|
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
@SuppressWarnings("unused") |
... | ... | |
53 | 53 |
DeleteNonReferencedReferencesConfigurator result = new DeleteNonReferencedReferencesConfigurator(destination); |
54 | 54 |
return result; |
55 | 55 |
} |
56 |
|
|
57 |
|
|
58 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 | 59 |
@Override |
60 | 60 |
public <STATE extends ImportStateBase> STATE getNewState() { |
61 | 61 |
return (STATE) new DefaultImportState(this); |
... | ... | |
65 | 65 |
protected void makeIoClassList() { |
66 | 66 |
ioClassList = new Class[]{ |
67 | 67 |
DeleteNonReferencedreferencesUpdater.class |
68 |
};
|
|
68 |
}; |
|
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
@Override |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/IImportConfigurator.java | ||
---|---|---|
164 | 164 |
|
165 | 165 |
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode); |
166 | 166 |
|
167 |
public Class<ICdmImport>[] getIoClassList();
|
|
167 |
public Class<ICdmIO>[] getIoClassList();
|
|
168 | 168 |
|
169 | 169 |
// public String[] getIoBeans(); |
170 | 170 |
// public void setIoBeans(String[] ioBeans); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/ImportConfiguratorBase.java | ||
---|---|---|
76 | 76 |
private ICdmDataSource destination; |
77 | 77 |
private Person commentator = Person.NewTitledInstance("automatic CDM importer"); |
78 | 78 |
|
79 |
protected Class<ICdmImport>[] ioClassList;
|
|
79 |
protected Class<ICdmIO>[] ioClassList;
|
|
80 | 80 |
|
81 | 81 |
protected ICdmIO[] ioList; |
82 | 82 |
|
... | ... | |
148 | 148 |
} |
149 | 149 |
|
150 | 150 |
@Override |
151 |
public Class<ICdmImport>[] getIoClassList(){
|
|
151 |
public Class<ICdmIO>[] getIoClassList(){
|
|
152 | 152 |
if (ioClassList == null){ |
153 | 153 |
makeIoClassList(); |
154 | 154 |
} |
... | ... | |
158 | 158 |
/** |
159 | 159 |
* @param ioClassList |
160 | 160 |
*/ |
161 |
public void setIoClassList(Class<ICdmImport>[] ioClassList){
|
|
161 |
public void setIoClassList(Class<ICdmIO>[] ioClassList){
|
|
162 | 162 |
this.ioClassList = ioClassList; |
163 | 163 |
} |
164 | 164 |
|
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfTaxonNameImport.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.io.tcsrdf; |
11 | 11 |
|
12 |
import java.io.IOException; |
|
13 | 12 |
import java.io.InputStream; |
14 |
import java.util.List; |
|
15 | 13 |
import java.util.Set; |
16 | 14 |
|
17 | 15 |
import org.apache.log4j.Logger; |
... | ... | |
22 | 20 |
|
23 | 21 |
import com.hp.hpl.jena.rdf.model.Model; |
24 | 22 |
import com.hp.hpl.jena.rdf.model.ModelFactory; |
23 |
import com.hp.hpl.jena.rdf.model.Property; |
|
25 | 24 |
import com.hp.hpl.jena.rdf.model.RDFNode; |
26 | 25 |
import com.hp.hpl.jena.rdf.model.ResIterator; |
27 | 26 |
import com.hp.hpl.jena.rdf.model.Resource; |
28 | 27 |
import com.hp.hpl.jena.rdf.model.Statement; |
29 | 28 |
import com.hp.hpl.jena.rdf.model.StmtIterator; |
30 |
import com.hp.hpl.jena.rdf.model.Property; |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 | 29 |
|
35 | 30 |
import eu.etaxonomy.cdm.common.XmlHelp; |
36 | 31 |
import eu.etaxonomy.cdm.io.common.ICdmIO; |
... | ... | |
49 | 44 |
import eu.etaxonomy.cdm.model.reference.Reference; |
50 | 45 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
51 | 46 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
47 |
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser; |
|
48 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
52 | 49 |
|
53 | 50 |
/** |
54 | 51 |
* @author a.mueller |
... | ... | |
60 | 57 |
private static final Logger logger = Logger.getLogger(TcsRdfTaxonNameImport.class); |
61 | 58 |
|
62 | 59 |
private static int modCount = 5000; |
60 |
INonViralNameParser nameParser = new NonViralNameParserImpl(); |
|
63 | 61 |
|
64 | 62 |
public TcsRdfTaxonNameImport(){ |
65 | 63 |
super(); |
... | ... | |
127 | 125 |
Resource elTaxonName = root.getResource(taxonNameNamespace); |
128 | 126 |
|
129 | 127 |
int i = 0; |
130 |
|
|
128 |
|
|
131 | 129 |
TaxonNameBase name; |
132 | 130 |
Property property = root.getProperty(taxonNameNamespace+"authorship"); |
133 |
|
|
131 |
|
|
134 | 132 |
ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null); |
135 | 133 |
String id ; |
136 | 134 |
while (iterator.hasNext()){ |
137 |
|
|
135 |
|
|
138 | 136 |
Resource resource = iterator.next(); |
139 |
|
|
137 |
|
|
140 | 138 |
name = handleNameResource(resource, config); |
141 | 139 |
id = resource.getNameSpace(); |
142 | 140 |
taxonNameMap.put(id, name); |
143 | 141 |
} |
144 |
|
|
142 |
|
|
145 | 143 |
logger.info(i + " names handled"); |
146 | 144 |
getNameService().save(taxonNameMap.objects()); |
147 | 145 |
// makeNameSpecificData(nameMap); |
... | ... | |
156 | 154 |
protected boolean isIgnore(TcsRdfImportState state){ |
157 | 155 |
return ! state.getConfig().isDoTaxonNames(); |
158 | 156 |
} |
159 |
|
|
157 |
|
|
160 | 158 |
protected TaxonNameBase handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){ |
161 | 159 |
Resource nameAbout = model.getResource(uri); |
162 | 160 |
TaxonNameBase result = handleNameResource(nameAbout, config); |
163 | 161 |
taxonNameMap.put(uri, result); |
164 | 162 |
return result; |
165 |
|
|
163 |
|
|
166 | 164 |
} |
167 |
|
|
165 |
|
|
168 | 166 |
private TaxonNameBase handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){ |
169 | 167 |
String idNamespace = "TaxonName"; |
170 |
|
|
168 |
|
|
171 | 169 |
StmtIterator stmts = nameAbout.listProperties(); |
172 | 170 |
while(stmts.hasNext()){ |
173 | 171 |
System.out.println(stmts.next().getPredicate().toString()); |
174 | 172 |
} |
175 |
|
|
173 |
|
|
176 | 174 |
Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode"); |
177 | 175 |
Statement stateNomenclaturalCode = nameAbout.getProperty(prop); |
178 | 176 |
String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString(); |
179 | 177 |
//Rank |
180 | 178 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString"); |
181 | 179 |
String strRank = nameAbout.getProperty(prop).getString(); |
182 |
|
|
183 |
|
|
184 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
185 | 183 |
try { |
186 |
|
|
184 |
|
|
187 | 185 |
Rank rank = TcsRdfTransformer.rankString2Rank(strRank); |
188 | 186 |
NomenclaturalCode nomCode; |
189 | 187 |
if (strNomenclaturalCode != null){ |
... | ... | |
191 | 189 |
}else{ |
192 | 190 |
nomCode = NomenclaturalCode.ICNAFP; |
193 | 191 |
} |
194 |
|
|
192 |
|
|
195 | 193 |
TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank); |
196 | 194 |
|
197 | 195 |
Set<String> omitAttributes = null; |
198 | 196 |
//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers); |
199 |
|
|
197 |
|
|
200 | 198 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete"); |
201 | 199 |
String strNameComplete = nameAbout.getProperty(prop).getString(); |
202 | 200 |
nameBase.setTitleCache(strNameComplete, true); |
203 |
|
|
201 |
|
|
204 | 202 |
prop = nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn"); |
205 | 203 |
String strPublishedIn = nameAbout.getProperty(prop).getString(); |
206 | 204 |
if (strPublishedIn != null && strPublishedIn != ""){ |
... | ... | |
226 | 224 |
((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false)); |
227 | 225 |
} |
228 | 226 |
} |
229 |
|
|
227 |
|
|
230 | 228 |
if (nameBase instanceof NonViralName){ |
231 | 229 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
232 | 230 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart"); |
... | ... | |
237 | 235 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial"); |
238 | 236 |
strGenusPart = nameAbout.getProperty(prop).getString(); |
239 | 237 |
} |
240 |
|
|
238 |
|
|
241 | 239 |
nonViralName.setGenusOrUninomial(strGenusPart); |
242 |
|
|
240 |
|
|
243 | 241 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet"); |
244 | 242 |
try{ |
245 | 243 |
String strInfragenericEpithet = nameAbout.getProperty(prop).getString(); |
246 | 244 |
nonViralName.setInfraGenericEpithet(strInfragenericEpithet); |
247 | 245 |
}catch(NullPointerException e){ |
248 |
|
|
246 |
|
|
249 | 247 |
} |
250 | 248 |
try { |
251 | 249 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet"); |
252 | 250 |
String strSpecificEpithet = nameAbout.getProperty(prop).getString(); |
253 | 251 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
254 | 252 |
}catch(NullPointerException e){ |
255 |
|
|
253 |
|
|
256 | 254 |
} |
257 | 255 |
try{ |
258 | 256 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet"); |
259 | 257 |
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString(); |
260 | 258 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
261 | 259 |
}catch(NullPointerException e){ |
262 |
|
|
260 |
|
|
263 | 261 |
} |
264 | 262 |
//Authorships |
265 | 263 |
//TODO |
... | ... | |
270 | 268 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1" |
271 | 269 |
tm:index="1" |
272 | 270 |
tm:role="Combination Author"/> |
273 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
|
|
271 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1" |
|
274 | 272 |
tm:index="1" |
275 | 273 |
tm:role="Basionym Author"/> |
276 | 274 |
</tm:Team> |
... | ... | |
290 | 288 |
try{ |
291 | 289 |
stateAutorTeamTeam = stateAuthorTeam.getProperty(prop); |
292 | 290 |
}catch(Exception e){ |
293 |
|
|
291 |
|
|
294 | 292 |
} |
295 | 293 |
try{ |
296 | 294 |
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"name"); |
297 | 295 |
stateAutorTeamName = stateAuthorTeam.getProperty(prop); |
298 | 296 |
}catch(Exception e){ |
299 |
|
|
297 |
|
|
300 | 298 |
} |
301 | 299 |
try{ |
302 | 300 |
prop = nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember"); |
303 | 301 |
stateTeamMember = ((Resource)stateAuthorTeam.getObject()).listProperties(prop); |
304 | 302 |
String memberString = null; |
305 | 303 |
Person person; |
306 |
for (Statement statement :stateTeamMember.toList()){ |
|
304 |
if (stateTeamMember.toList().size() ==1){ |
|
305 |
person = Person.NewTitledInstance(authorTeam.getTitleCache()); |
|
306 |
}else { |
|
307 |
nameParser.parseAuthors(nonViralName, authorTeam.getTitleCache()); |
|
308 |
} |
|
309 |
/* for (Statement statement :stateTeamMember.toList()){ |
|
307 | 310 |
memberString =statement.getObject().toString(); |
308 | 311 |
if (memberString != null){ |
309 | 312 |
person = Person.NewTitledInstance(memberString); |
310 | 313 |
authorTeam.addTeamMember(person); |
311 | 314 |
} |
312 |
} |
|
315 |
}*/
|
|
313 | 316 |
}catch(Exception e){ |
314 | 317 |
System.err.println(e.getMessage()); |
315 | 318 |
} |
316 | 319 |
} |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
320 | 323 |
nonViralName.setCombinationAuthorship(authorTeam); |
321 |
|
|
324 |
|
|
322 | 325 |
//Annotations: |
323 | 326 |
/* |
324 | 327 |
* <tn:hasAnnotation> |
... | ... | |
326 | 329 |
<tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/> |
327 | 330 |
<tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/> |
328 | 331 |
</tn:NomenclaturalNote> |
329 |
</tn:hasAnnotation>
|
|
332 |
</tn:hasAnnotation> |
|
330 | 333 |
*/ |
331 | 334 |
/* |
332 | 335 |
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString(); |
... | ... | |
370 | 373 |
//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace); |
371 | 374 |
|
372 | 375 |
//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers); |
373 |
|
|
376 |
|
|
374 | 377 |
return nameBase; |
375 |
|
|
378 |
|
|
376 | 379 |
}catch(Exception e){ |
377 | 380 |
e.printStackTrace(); |
378 | 381 |
return null; |
... | ... | |
381 | 384 |
//name |
382 | 385 |
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace); |
383 | 386 |
nameBase.setTitleCache(strNameComplete, true); |
384 |
|
|
387 |
|
|
385 | 388 |
//Reference |
386 | 389 |
//TODO |
387 | 390 |
String tcsElementName = "publishedIn"; |
... | ... | |
439 | 442 |
if (nameBase instanceof NonViralName){ |
440 | 443 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
441 | 444 |
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace); |
442 |
|
|
445 |
|
|
443 | 446 |
//for names of rank genus the uninomial property should be used |
444 | 447 |
if (strGenusPart == null){ |
445 | 448 |
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace); |
446 | 449 |
} |
447 | 450 |
nonViralName.setGenusOrUninomial(strGenusPart); |
448 |
|
|
451 |
|
|
449 | 452 |
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace); |
450 | 453 |
nonViralName.setGenusOrUninomial(strInfragenericEpithet); |
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
454 | 457 |
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace); |
455 | 458 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
456 |
|
|
459 |
|
|
457 | 460 |
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace); |
458 | 461 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
459 | 462 |
//AuthorTeams |
... | ... | |
509 | 512 |
} |
510 | 513 |
return null;*/ |
511 | 514 |
} |
512 |
|
|
515 |
|
|
513 | 516 |
protected TaxonNameBase handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap){ |
514 | 517 |
String idNamespace = "TaxonName"; |
515 | 518 |
Attribute about = elTaxonName.getAttribute("about", rdfNamespace); |
516 |
|
|
519 |
|
|
517 | 520 |
//create TaxonName element |
518 |
|
|
519 |
|
|
521 |
|
|
522 |
|
|
520 | 523 |
String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace); |
521 | 524 |
if (nameAbout == null){ |
522 | 525 |
nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace); |
523 | 526 |
} |
524 |
|
|
525 |
|
|
527 |
|
|
528 |
|
|
526 | 529 |
String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rankString", taxonNameNamespace, "rankString", rdfNamespace); |
527 | 530 |
if (strRank == null){ |
528 | 531 |
strRank = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "rankString", rdfNamespace); |
529 |
|
|
532 |
|
|
530 | 533 |
} |
531 |
|
|
534 |
|
|
532 | 535 |
if (strRank == null){ |
533 | 536 |
strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace); |
534 |
|
|
537 |
|
|
535 | 538 |
} |
536 |
|
|
539 |
|
|
537 | 540 |
String strNomenclaturalCode = XmlHelp.getChildContentAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "nomenclaturalCode", rdfNamespace); |
538 | 541 |
if (strNomenclaturalCode == null){ |
539 | 542 |
strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace); |
540 |
|
|
543 |
|
|
541 | 544 |
} |
542 | 545 |
try { |
543 |
|
|
546 |
|
|
544 | 547 |
Rank rank = TcsRdfTransformer.rankString2Rank(strRank); |
545 | 548 |
NomenclaturalCode nomCode; |
546 | 549 |
if (strNomenclaturalCode != null){ |
... | ... | |
548 | 551 |
}else{ |
549 | 552 |
nomCode = NomenclaturalCode.ICNAFP; |
550 | 553 |
} |
551 |
|
|
554 |
|
|
552 | 555 |
TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank); |
553 | 556 |
|
554 | 557 |
Set<String> omitAttributes = null; |
555 | 558 |
//makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers); |
556 |
|
|
559 |
|
|
557 | 560 |
//name |
558 | 561 |
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace); |
559 | 562 |
nameBase.setTitleCache(strNameComplete, true); |
560 |
|
|
563 |
|
|
561 | 564 |
//Reference |
562 | 565 |
//TODO |
563 | 566 |
String tcsElementName = "publishedIn"; |
... | ... | |
615 | 618 |
if (nameBase instanceof NonViralName){ |
616 | 619 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
617 | 620 |
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace); |
618 |
|
|
621 |
|
|
619 | 622 |
//for names of rank genus the uninomial property should be used |
620 | 623 |
if (strGenusPart == null){ |
621 | 624 |
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace); |
622 | 625 |
} |
623 | 626 |
nonViralName.setGenusOrUninomial(strGenusPart); |
624 |
|
|
627 |
|
|
625 | 628 |
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace); |
626 | 629 |
nonViralName.setGenusOrUninomial(strInfragenericEpithet); |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
630 | 633 |
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace); |
631 | 634 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
632 |
|
|
635 |
|
|
633 | 636 |
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace); |
634 | 637 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
635 | 638 |
//AuthorTeams |
... | ... | |
690 | 693 |
Model model = ModelFactory.createDefaultModel(); |
691 | 694 |
try{ |
692 | 695 |
model.read(is, null); |
693 |
|
|
696 |
|
|
694 | 697 |
config.makeNamespaces(model); |
695 |
|
|
698 |
|
|
696 | 699 |
String rdfNamespace = config.getRdfNamespaceURIString(); |
697 | 700 |
String taxonNameNamespace = config.getTnNamespaceURIString(); |
698 | 701 |
return handleNameModel(model, config, taxonNameMap, uri); |
699 |
|
|
700 |
|
|
702 |
|
|
703 |
|
|
701 | 704 |
}catch(Exception e){ |
702 | 705 |
logger.debug("The file was no valid rdf file"); |
703 | 706 |
} |
704 |
|
|
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
|
707 | 710 |
return null; |
708 | 711 |
} |
709 |
|
|
712 |
|
|
710 | 713 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsxml/in/TcsXmlImportBase.java | ||
---|---|---|
38 | 38 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
39 | 39 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
40 | 40 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
41 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
|
41 | 42 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
42 | 43 |
import eu.etaxonomy.cdm.model.reference.Reference; |
43 | 44 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
44 | 45 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
45 | 46 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
47 |
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException; |
|
48 |
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser; |
|
49 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
46 | 50 |
|
47 | 51 |
/** |
48 | 52 |
* @author a.mueller |
... | ... | |
62 | 66 |
@Autowired |
63 | 67 |
IpniService service; |
64 | 68 |
|
69 |
INonViralNameParser nameParser = new NonViralNameParserImpl(); |
|
70 |
|
|
65 | 71 |
@Override |
66 | 72 |
protected abstract void doInvoke(TcsXmlImportState state); |
67 | 73 |
|
... | ... | |
309 | 315 |
|
310 | 316 |
|
311 | 317 |
@SuppressWarnings("unchecked") |
312 |
protected TeamOrPersonBase<?> makeNameCitation(Element elNameCitation, MapWrapper<Person> authorMap, ResultWrapper<Boolean> success){
|
|
318 |
protected TeamOrPersonBase makeNameCitation(Element elNameCitation, MapWrapper<Person> authorMap, ResultWrapper<Boolean> success, NonViralName name,boolean isBasionymAuthor){
|
|
313 | 319 |
TeamOrPersonBase<?> result = null; |
314 | 320 |
String childName; |
315 | 321 |
boolean obligatory; |
... | ... | |
339 | 345 |
obligatory = true; |
340 | 346 |
Element elSimple = XmlHelp.getSingleChildElement(success, elNameCitation, childName, ns, obligatory); |
341 | 347 |
String simple = (elSimple == null)? "" : elSimple.getTextNormalize(); |
342 |
result = Team.NewInstance(); |
|
343 |
result.setNomenclaturalTitle(simple); |
|
348 |
result = Person.NewInstance(); |
|
349 |
try{ |
|
350 |
nameParser.parseAuthors(name, simple); |
|
351 |
}catch(StringNotParsableException e){ |
|
352 |
logger.error(e.getMessage()); |
|
353 |
} |
|
354 |
if (isBasionymAuthor){ |
|
355 |
result = name.getBasionymAuthorship(); |
|
356 |
}else{ |
|
357 |
result= name.getCombinationAuthorship(); |
|
358 |
} |
|
359 |
//result.setNomenclaturalTitle(simple); |
|
344 | 360 |
} |
345 | 361 |
} |
346 | 362 |
return result; |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsxml/in/TcsXmlTaxonNameImport.java | ||
---|---|---|
36 | 36 |
import eu.etaxonomy.cdm.model.reference.Reference; |
37 | 37 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
38 | 38 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
39 |
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser; |
|
40 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
39 | 41 |
|
40 | 42 |
@Component("tcsXmlTaxonNameIO") |
41 | 43 |
public class TcsXmlTaxonNameImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> { |
... | ... | |
43 | 45 |
|
44 | 46 |
private static int modCount = 5000; |
45 | 47 |
|
48 |
private static INonViralNameParser parser = new NonViralNameParserImpl(); |
|
49 |
|
|
46 | 50 |
public TcsXmlTaxonNameImport(){ |
47 | 51 |
super(); |
48 | 52 |
} |
... | ... | |
295 | 299 |
obligatory = true; |
296 | 300 |
Element elSimple = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory); |
297 | 301 |
String simple = (elSimple == null)? "" : elSimple.getTextNormalize(); |
298 |
nameBase.setTitleCache(simple, false);
|
|
302 |
nameBase.setTitleCache(simple, true);
|
|
299 | 303 |
elementList.add(childName.toString()); |
300 | 304 |
|
301 | 305 |
childName = "CanonicalName"; |
... | ... | |
381 | 385 |
childName = "Authorship"; |
382 | 386 |
obligatory = false; |
383 | 387 |
Element elAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory); |
384 |
TeamOrPersonBase author = makeNameCitation(elAuthorship, authorMap, success); |
|
388 |
TeamOrPersonBase author = makeNameCitation(elAuthorship, authorMap, success, nonViralName, false);
|
|
385 | 389 |
nonViralName.setCombinationAuthorship(author); |
386 | 390 |
//setCombinationAuthorship(author); |
387 | 391 |
testNoMoreElements(); |
... | ... | |
389 | 393 |
childName = "BasionymAuthorship"; |
390 | 394 |
obligatory = false; |
391 | 395 |
Element elBasionymAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory); |
392 |
TeamOrPersonBase<?> basionymAuthor = makeNameCitation(elBasionymAuthorship, authorMap, success); |
|
396 |
TeamOrPersonBase<?> basionymAuthor = makeNameCitation(elBasionymAuthorship, authorMap, success, nonViralName, true);
|
|
393 | 397 |
nonViralName.setBasionymAuthorship(basionymAuthor); |
394 | 398 |
testNoMoreElements(); |
395 | 399 |
|
396 | 400 |
childName = "CombinationAuthorship"; |
397 | 401 |
obligatory = false; |
398 | 402 |
Element elCombinationAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory); |
399 |
TeamOrPersonBase<?> combinationAuthor = makeNameCitation(elCombinationAuthorship, authorMap ,success); |
|
403 |
TeamOrPersonBase<?> combinationAuthor = makeNameCitation(elCombinationAuthorship, authorMap ,success, nonViralName, false);
|
|
400 | 404 |
if (combinationAuthor != null){ |
401 | 405 |
nonViralName.setCombinationAuthorship(combinationAuthor); |
402 | 406 |
} |
... | ... | |
546 | 550 |
private void makePublishedIn(TaxonNameBase name, Element elPublishedIn, MapWrapper<Reference> referenceMap, ResultWrapper<Boolean> success){ |
547 | 551 |
if (elPublishedIn != null && name != null){ |
548 | 552 |
Class<Reference> clazz = Reference.class; |
553 |
|
|
549 | 554 |
Reference<?> ref = makeReferenceType(elPublishedIn, clazz, referenceMap, success); |
550 | 555 |
if (ref instanceof Reference){ |
556 |
|
|
557 |
String titleCache = ref.getTitleCache(); |
|
558 |
|
|
559 |
ref.setAuthorship(((NonViralName)name).getCombinationAuthorship()); |
|
560 |
|
|
561 |
ref.setAbbrevTitleCache(titleCache, true); |
|
562 |
ref.setAbbrevTitle(titleCache); |
|
563 |
ref.setProtectedTitleCache(false); |
|
564 |
|
|
551 | 565 |
name.setNomenclaturalReference(ref); |
566 |
name.setProtectedFullTitleCache(false); |
|
567 |
name.getFullTitleCache(); |
|
568 |
name.setProtectedFullTitleCache(true); |
|
552 | 569 |
}else if (ref == null){ |
553 | 570 |
logger.warn("Nomecl. reference could not be created for '" + name.getTitleCache() + "'"); |
554 | 571 |
}else{ |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java | ||
---|---|---|
50 | 50 |
import org.hibernate.validator.constraints.NotEmpty; |
51 | 51 |
import org.springframework.util.ReflectionUtils; |
52 | 52 |
|
53 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
53 | 54 |
import eu.etaxonomy.cdm.model.common.IParsable; |
54 | 55 |
import eu.etaxonomy.cdm.model.common.IRelated; |
55 | 56 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
... | ... | |
339 | 340 |
if (protectedFullTitleCache){ |
340 | 341 |
return this.fullTitleCache; |
341 | 342 |
} |
342 |
if (fullTitleCache == null ){
|
|
343 |
// if (fullTitleCache == null ){
|
|
343 | 344 |
this.fullTitleCache = getTruncatedCache(generateFullTitle()); |
344 |
} |
|
345 |
// }
|
|
345 | 346 |
return fullTitleCache; |
346 | 347 |
} |
347 | 348 |
|
... | ... | |
844 | 845 |
if(!INomenclaturalReference.class.isAssignableFrom(nomenclaturalReference.getClass())){ |
845 | 846 |
throw new IllegalArgumentException("Parameter nomenclaturalReference is not assignable from INomenclaturalReference"); |
846 | 847 |
} |
847 |
this.nomenclaturalReference = (Reference)nomenclaturalReference;
|
|
848 |
this.nomenclaturalReference = HibernateProxyHelper.deproxy(nomenclaturalReference, Reference.class);
|
|
848 | 849 |
} else { |
849 | 850 |
this.nomenclaturalReference = null; |
850 | 851 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/NomRefDefaultCacheStrategyBase.java | ||
---|---|---|
13 | 13 |
import org.apache.log4j.Logger; |
14 | 14 |
|
15 | 15 |
import eu.etaxonomy.cdm.common.CdmUtils; |
16 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
16 | 17 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
17 | 18 |
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; |
18 | 19 |
import eu.etaxonomy.cdm.model.reference.Reference; |
... | ... | |
128 | 129 |
@Override |
129 | 130 |
public String getNomenclaturalCitation(Reference nomenclaturalReference, String microReference) { |
130 | 131 |
if (nomenclaturalReference.isProtectedAbbrevTitleCache()){ |
132 |
nomenclaturalReference = HibernateProxyHelper.deproxy(nomenclaturalReference, Reference.class); |
|
131 | 133 |
String cache = nomenclaturalReference.getAbbrevTitleCache(); |
132 | 134 |
return handleDetailAndYearForPreliminary(nomenclaturalReference, cache, microReference); |
133 | 135 |
|
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java | ||
---|---|---|
516 | 516 |
* @param year |
517 | 517 |
* @return |
518 | 518 |
*/ |
519 |
private INomenclaturalReference parseReferenceTitle(String strReference, String year, boolean isInReference){
|
|
519 |
public INomenclaturalReference parseReferenceTitle(String strReference, String year, boolean isInReference){
|
|
520 | 520 |
IBook result = null; |
521 | 521 |
|
522 | 522 |
Matcher refSineDetailMatcher = referenceSineDetailPattern.matcher(strReference); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java | ||
---|---|---|
972 | 972 |
// I think this is preferable to catching lazy initialization errors |
973 | 973 |
// as that solution only swallows and hides the exception, but doesn't |
974 | 974 |
// actually solve it. |
975 |
getSession().merge(taxonBase); |
|
975 |
//getSession().merge(taxonBase);
|
|
976 | 976 |
|
977 | 977 |
taxonBase.removeSources(); |
978 | 978 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java | ||
---|---|---|
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
|
120 |
|
|
120 | 121 |
Classification classification = oldTaxonNode.getClassification(); |
121 |
Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(oldTaxonNode.getTaxon()); |
|
122 |
Taxon newAcceptedTaxon = (Taxon)this.taxonService.load(newAcceptedTaxonNode.getTaxon().getUuid()); |
|
122 |
Taxon oldTaxon = HibernateProxyHelper.deproxy(oldTaxonNode.getTaxon(), Taxon.class); |
|
123 |
Taxon newAcceptedTaxon = HibernateProxyHelper.deproxy(this.taxonService.load(newAcceptedTaxonNode.getTaxon().getUuid()), Taxon.class); |
|
124 |
|
|
123 | 125 |
// Move oldTaxon to newTaxon |
124 | 126 |
//TaxonNameBase<?,?> synonymName = oldTaxon.getName(); |
125 | 127 |
TaxonNameBase<?,?> synonymName = (TaxonNameBase)HibernateProxyHelper.deproxy(oldTaxon.getName()); |
... | ... | |
235 | 237 |
|
236 | 238 |
TaxonDeletionConfigurator conf = new TaxonDeletionConfigurator(); |
237 | 239 |
conf.setDeleteSynonymsIfPossible(false); |
240 |
conf.setDeleteNameIfPossible(false); |
|
238 | 241 |
DeleteResult result = taxonService.isDeletable(oldTaxon, conf); |
239 | 242 |
conf.setDeleteNameIfPossible(false); |
240 | 243 |
|
... | ... | |
248 | 251 |
result.includeResult(deleteTaxonNode(oldTaxonNode, conf)); |
249 | 252 |
} |
250 | 253 |
result.addUpdatedObject(newAcceptedTaxon); |
251 |
result.addUpdatedObject(oldTaxon); |
|
254 |
//result.addUpdatedObject(oldTaxon);
|
|
252 | 255 |
|
253 | 256 |
//oldTaxonNode.delete(); |
254 | 257 |
return result; |
... | ... | |
456 | 459 |
} |
457 | 460 |
|
458 | 461 |
result.setCdmEntity(node); |
459 |
boolean success = taxon.removeTaxonNode(node); |
|
460 |
dao.save(parent); |
|
462 |
|
|
463 |
boolean success = true; |
|
464 |
if(taxon != null){ |
|
465 |
success = taxon.removeTaxonNode(node); |
|
466 |
} |
|
467 |
|
|
461 | 468 |
taxonService.saveOrUpdate(taxon); |
462 | 469 |
result.addUpdatedObject(parent); |
463 | 470 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java | ||
---|---|---|
966 | 966 |
if (config == null){ |
967 | 967 |
config = new TaxonDeletionConfigurator(); |
968 | 968 |
} |
969 |
Taxon taxon = (Taxon)dao.load(taxonUUID);
|
|
970 |
taxon = (Taxon) HibernateProxyHelper.deproxy(taxon); |
|
969 |
Taxon taxon = HibernateProxyHelper.deproxy(dao.load(taxonUUID), Taxon.class);
|
|
970 |
|
|
971 | 971 |
Classification classification = HibernateProxyHelper.deproxy(classificationDao.load(classificationUuid), Classification.class); |
972 | 972 |
DeleteResult result = isDeletable(taxon, config); |
973 | 973 |
|
... | ... | |
1144 | 1144 |
}else { |
1145 | 1145 |
taxon.setName(null); |
1146 | 1146 |
} |
1147 |
|
|
1148 |
|
|
1147 |
this.saveOrUpdate(taxon); |
|
1148 |
|
|
1149 | 1149 |
// TaxonDescription |
1150 | 1150 |
/* Set<TaxonDescription> descriptions = taxon.getDescriptions(); |
1151 | 1151 |
|
... | ... | |
1166 | 1166 |
|
1167 | 1167 |
if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0) ){ |
1168 | 1168 |
try{ |
1169 |
//taxon = HibernateProxyHelper.deproxy(taxon, Taxon.class); |
|
1169 | 1170 |
UUID uuid = dao.delete(taxon); |
1170 | 1171 |
|
1171 | 1172 |
}catch(Exception e){ |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/UpdateResult.java | ||
---|---|---|
122 | 122 |
return updatedObjects; |
123 | 123 |
} |
124 | 124 |
public void addUpdatedObject(CdmBase relatedObject) { |
125 |
this.updatedObjects.add(relatedObject); |
|
125 |
if (relatedObject != null){ |
|
126 |
this.updatedObjects.add(relatedObject); |
|
127 |
} |
|
126 | 128 |
} |
127 | 129 |
public void addUpdatedObjects(Set<? extends CdmBase> updatedObjects) { |
128 |
this.updatedObjects.addAll(updatedObjects); |
|
130 |
if (updatedObjects.size() >0){ |
|
131 |
this.updatedObjects.addAll(updatedObjects); |
|
132 |
} |
|
133 |
|
|
129 | 134 |
} |
130 | 135 |
|
131 | 136 |
// /** |
... | ... | |
182 | 187 |
public void includeResult(UpdateResult includedResult){ |
183 | 188 |
this.setMaxStatus(includedResult.getStatus()); |
184 | 189 |
this.addExceptions(includedResult.getExceptions()); |
190 |
|
|
185 | 191 |
this.addUpdatedObjects(includedResult.getUpdatedObjects()); |
192 |
|
|
193 |
|
|
186 | 194 |
} |
187 | 195 |
|
188 | 196 |
public boolean isOk(){ |
Also available in: Unified diff
minor