2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
;
12 import java
.io
.InputStream
;
13 import java
.net
.MalformedURLException
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.HashSet
;
18 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import javax
.xml
.parsers
.DocumentBuilder
;
24 import javax
.xml
.parsers
.DocumentBuilderFactory
;
26 import org
.apache
.commons
.lang
.StringUtils
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.springframework
.stereotype
.Component
;
29 import org
.w3c
.dom
.Document
;
30 import org
.w3c
.dom
.Element
;
31 import org
.w3c
.dom
.NodeList
;
33 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
34 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
35 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
36 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenImportBase
;
37 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenUserInteraction
;
38 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringArea
;
39 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringEvent
;
40 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
44 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
45 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
46 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
47 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
51 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
52 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
53 //>>>>>>> .fusion-droit.r19057
54 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
55 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
56 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
57 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
58 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
59 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
60 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
61 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
62 import eu
.etaxonomy
.cdm
.model
.name
.BacterialName
;
63 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
64 import eu
.etaxonomy
.cdm
.model
.name
.CultivarPlantName
;
65 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
66 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
67 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
68 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
69 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
70 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
71 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
72 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
73 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
74 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
75 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
76 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
77 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
78 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
79 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
80 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
81 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
82 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
83 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
84 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
85 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
92 public class Abcd206Import
extends SpecimenImportBase
<Abcd206ImportConfigurator
, Abcd206ImportState
> {
93 private static final Logger logger
= Logger
.getLogger(Abcd206Import
.class);
96 private final boolean DEBUG
= true;
98 private static final String PREFERRED
= "_preferred_";
99 private static final String CODE
= "_code_";
100 private static final String COLON
= ":";
101 private static final String SPLITTER
= "--";
104 private static String prefix
= "";
106 //TODO make all fields ABCD206ImportState variables
107 private Classification classification
= null;
108 private Reference
<?
> ref
= null;
110 private Abcd206DataHolder dataHolder
;
111 private DerivedUnit derivedUnitBase
;
113 private List
<OriginalSourceBase
<?
>> associationRefs
= new ArrayList
<OriginalSourceBase
<?
>>();
114 boolean associationSourcesSet
=false;
115 private List
<OriginalSourceBase
<?
>> descriptionRefs
= new ArrayList
<OriginalSourceBase
<?
>>();
116 boolean descriptionSourcesSet
=false;
117 private List
<OriginalSourceBase
<?
>> derivedUnitSources
= new ArrayList
<OriginalSourceBase
<?
>>();
118 boolean derivedUnitSourcesSet
=false;
120 public Abcd206Import() {
125 protected boolean doCheck(Abcd206ImportState state
) {
126 logger
.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
132 @SuppressWarnings("rawtypes")
133 public void doInvoke(Abcd206ImportState state
) {
134 state
.setTx(startTransaction());
135 logger
.info("INVOKE Specimen Import from ABCD2.06 XML ");
137 SpecimenUserInteraction sui
= state
.getConfig().getSpecimenUserInteraction();
139 List
<Reference
> references
= getReferenceService().list(Reference
.class, null, null, null, null);
141 if (state
.getConfig().isInteractWithUser()){
142 Map
<String
,Reference
> refMap
= new HashMap
<String
, Reference
>();
143 for (Reference tree
: references
) {
144 if (! StringUtils
.isBlank(tree
.getTitleCache())) {
145 refMap
.put(tree
.getTitleCache(),tree
);
148 ref
= sui
.askForReference(refMap
);
151 String cla
= sui
.createNewReference();
152 if (refMap
.get(cla
)!= null) {
153 ref
= refMap
.get(cla
);
155 ref
= ReferenceFactory
.newGeneric();
160 ref
= getReferenceService().find(ref
.getUuid());
164 String name
= NB(state
.getConfig().getSourceReferenceTitle());
165 for (Reference tree
: references
) {
166 if (! StringUtils
.isBlank(tree
.getTitleCache())) {
167 if (tree
.getTitleCache().equalsIgnoreCase(name
)) {
169 System
.out
.println("FIND SAME REFERENCE");
174 ref
= ReferenceFactory
.newGeneric();
175 ref
.setTitle("ABCD classic");
180 state
.getConfig().setSourceReference(ref
);
182 List
<Classification
> classificationList
= getClassificationService().list(Classification
.class, null, null, null, null);
183 if (state
.getConfig().isUseClassification() && state
.getConfig().isInteractWithUser()){
184 Map
<String
,Classification
> classMap
= new HashMap
<String
, Classification
>();
185 for (Classification tree
: classificationList
) {
186 if (! StringUtils
.isBlank(tree
.getTitleCache())) {
187 classMap
.put(tree
.getTitleCache(),tree
);
190 classification
= sui
.askForClassification(classMap
);
191 if (classification
== null){
192 String cla
= sui
.createNewClassification();
193 if (classMap
.get(cla
)!= null) {
194 classification
= classMap
.get(cla
);
196 classification
= Classification
.NewInstance(cla
, ref
, Language
.DEFAULT());
199 save(classification
, state
);
202 if (classification
== null) {
203 String name
= NB(state
.getConfig().getClassificationName());
204 for (Classification classif
: classificationList
){
205 if (classif
.getTitleCache().equalsIgnoreCase(name
) && classif
.getCitation().equals(ref
)) {
206 classification
=classif
;
207 System
.out
.println("FIND SAME CLASSIF");
210 if (classification
== null){
211 classification
= Classification
.NewInstance(name
, ref
, Language
.DEFAULT());
213 // if (state.getConfig().getClassificationUuid() != null) {
214 // classification.setUuid(state.getConfig().getClassificationUuid());
216 save(classification
, state
);
220 InputStream source
= state
.getConfig().getSource();
221 NodeList unitsList
= getUnitsNodeList(source
);
223 if (unitsList
!= null) {
224 String message
= "nb units to insert: " + unitsList
.getLength();
225 logger
.info(message
);
226 updateProgress(state
, message
);
228 dataHolder
= new Abcd206DataHolder();
230 Abcd206XMLFieldGetter abcdFieldGetter
= new Abcd206XMLFieldGetter(dataHolder
, prefix
);
232 prepareCollectors(state
, unitsList
, abcdFieldGetter
);
234 for (int i
= 0; i
< unitsList
.getLength(); i
++) {
235 System
.out
.println("------------------------------------------------------------------------------------------");
236 associationRefs
= new ArrayList
<OriginalSourceBase
<?
>>();
237 descriptionRefs
= new ArrayList
<OriginalSourceBase
<?
>>();
238 derivedUnitSources
= new ArrayList
<OriginalSourceBase
<?
>>();
240 this.setUnitPropertiesXML( (Element
) unitsList
.item(i
), abcdFieldGetter
);
241 // refreshTransaction(state);
242 this.handleSingleUnit(state
);
244 // compare the ABCD elements added in to the CDM and the
245 // unhandled ABCD elements
246 //compareABCDtoCDM(sourceName, dataHolder.knownABCDelements, abcdFieldGetter);
248 // reset the ABCD elements added in CDM
249 // knownABCDelements = new ArrayList<String>();
250 dataHolder
.allABCDelements
= new HashMap
<String
, String
>();
252 getReferenceService().deduplicate(Reference
.class, null, null);
253 getClassificationService().deduplicate(Classification
.class, null, null);
255 commitTransaction(state
.getTx());
261 protected NodeList
getUnitsNodeList(URI source
) {
263 InputStream is
= UriUtils
.getInputStream(source
);
264 return getUnitsNodeList(is
);
265 } catch (Exception e
) {
267 throw new RuntimeException(e
);
272 * Return the list of root nodes for an ABCD 2.06 XML file
273 * @param fileName: the file's location
274 * @return the list of root nodes ("Unit")
276 protected NodeList
getUnitsNodeList(InputStream inputStream
) {
277 NodeList unitList
= null;
279 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
280 DocumentBuilder builder
= factory
.newDocumentBuilder();
282 Document document
= builder
.parse(inputStream
);
283 Element root
= document
.getDocumentElement();
284 unitList
= root
.getElementsByTagName("Unit");
285 if (unitList
.getLength() == 0) {
286 unitList
= root
.getElementsByTagName("abcd:Unit");
289 } catch (Exception e
) {
296 * Handle a single unit
299 @SuppressWarnings("rawtypes")
300 private void handleSingleUnit(Abcd206ImportState state
) {
302 logger
.info("handleSingleUnit "+ref
);
305 updateProgress(state
, "Importing data for unit: " + dataHolder
.unitID
);
308 DerivedUnitFacade derivedUnitFacade
= getFacade();
309 derivedUnitBase
= derivedUnitFacade
.innerDerivedUnit();
315 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(getTermService(), dataHolder
.locality
, dataHolder
.languageIso
,
316 dataHolder
.longitude
, dataHolder
.latitude
, dataHolder
.gatheringAgentList
, dataHolder
.gatheringTeamList
,state
.getConfig());
319 UnitsGatheringArea unitsGatheringArea
= new UnitsGatheringArea();
320 // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());
321 unitsGatheringArea
.setParams(dataHolder
.isocountry
, dataHolder
.country
, state
.getConfig(), getTermService(), getOccurrenceService());
323 DefinedTermBase
<?
> areaCountry
= unitsGatheringArea
.getCountry();
326 unitsGatheringArea
= new UnitsGatheringArea();
327 // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
328 unitsGatheringArea
.setAreas(dataHolder
.namedAreaList
,state
.getConfig(), getTermService());
329 ArrayList
<DefinedTermBase
> nas
= unitsGatheringArea
.getAreas();
330 for (DefinedTermBase namedArea
: nas
) {
331 unitsGatheringEvent
.addArea(namedArea
);
334 // copy gathering event to facade
335 GatheringEvent gatheringEvent
= unitsGatheringEvent
.getGatheringEvent();
336 derivedUnitFacade
.setLocality(gatheringEvent
.getLocality());
337 derivedUnitFacade
.setExactLocation(gatheringEvent
.getExactLocation());
338 derivedUnitFacade
.setCollector(gatheringEvent
.getCollector());
339 derivedUnitFacade
.setCountry((NamedArea
)areaCountry
);
341 for(DefinedTermBase
<?
> area
:unitsGatheringArea
.getAreas()){
342 derivedUnitFacade
.addCollectingArea((NamedArea
) area
);
344 // derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
348 derivedUnitFacade
.setFieldNumber(NB(dataHolder
.fieldNumber
));
350 // //add Multimedia URLs
351 if (dataHolder
.multimediaObjects
.size() != -1) {
352 for (String multimediaObject
: dataHolder
.multimediaObjects
) {
355 media
= getImageMedia(multimediaObject
, READ_MEDIA_DATA
, false);
356 derivedUnitFacade
.addDerivedUnitMedia(media
);
357 } catch (MalformedURLException e
) {
358 // TODO Auto-generated catch block
366 // * merge AND STORE DATA
368 // getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
370 // for (NamedArea area : otherAreas) {
371 // getTermService().saveOrUpdate(area);// merge it sooner (foreach area)
374 save(unitsGatheringEvent
.getLocality(), state
);
376 // handle collection data
377 setCollectionData(state
, derivedUnitFacade
);
380 SpecimenUserInteraction sui
= state
.getConfig().getSpecimenUserInteraction();
381 Map
<String
,OriginalSourceBase
<?
>> sourceMap
= new HashMap
<String
, OriginalSourceBase
<?
>>();
383 dataHolder
.docSources
= new ArrayList
<String
>();
384 for (String
[] fullReference
: dataHolder
.referenceList
) {
385 System
.out
.println("referenceFullList "+fullReference
);
386 String strReference
=fullReference
[0];
387 String citationDetail
= fullReference
[1];
388 String citationURL
= fullReference
[2];
390 if (!citationURL
.isEmpty()) {
391 citationDetail
+=", "+citationURL
;
394 Reference
<?
> reference
= ReferenceFactory
.newGeneric();
395 reference
.setTitleCache(strReference
);
396 System
.out
.println("reference has problem?" +reference
.hasProblem());
399 IdentifiableSource sour
= getIdentifiableSource(reference
,citationDetail
);
402 if (sour
.getCitation() != null){
403 if(StringUtils
.isNotBlank(sour
.getCitationMicroReference())) {
404 dataHolder
.docSources
.add(sour
.getCitation().getTitleCache()+ "---"+sour
.getCitationMicroReference());
406 dataHolder
.docSources
.add(sour
.getCitation().getTitleCache());
412 //TODO what do we need tmp for?
413 String tmp
= sour
.getCitation().getTitleCache();
414 if (StringUtils
.isNotBlank(sour
.getCitationMicroReference())) {
415 tmp
+=" ("+sour
.getCitationMicroReference()+")";
417 reference
.addSource(sour
);
418 getReferenceService().saveOrUpdate(reference
);
422 List
<OriginalSourceBase
> issTmp
= getCommonService().list(IdentifiableSource
.class, null, null, null, null);
423 List
<OriginalSourceBase
> issTmp2
= getCommonService().list(DescriptionElementSource
.class, null, null, null, null);
425 Set
<OriginalSourceBase
> osbSet
= new HashSet
<OriginalSourceBase
>();
427 osbSet
.addAll(issTmp2
);
430 osbSet
.addAll(issTmp
);
434 for( OriginalSourceBase
<?
> osb
:osbSet
) {
435 if(osb
.getCitationMicroReference() !=null && !osb
.getCitationMicroReference().isEmpty()) {
437 sourceMap
.put(osb
.getCitation().getTitleCache()+ "---"+osb
.getCitationMicroReference(),osb
);
438 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
441 sourceMap
.put(osb
.getCitation().getTitleCache(),osb
);
442 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
446 if( state
.getConfig().isInteractWithUser()){
447 List
<OriginalSourceBase
<?
>>sources
=null;
448 if(!derivedUnitSourcesSet
){
449 sources
= sui
.askForSource(sourceMap
, "the unit itself","",getReferenceService(), dataHolder
.docSources
);
450 derivedUnitSources
=sources
;
451 derivedUnitSourcesSet
=true;
454 sources
=derivedUnitSources
;
456 for (OriginalSourceBase
<?
> sour
:sources
){
457 if(sour
.isInstanceOf(IdentifiableSource
.class)){
458 if(sourceNotLinkedToElement(derivedUnitFacade
,sour
)) {
459 derivedUnitFacade
.addSource((IdentifiableSource
)sour
.clone());
462 if(sourceNotLinkedToElement(derivedUnitFacade
,sour
)) {
463 derivedUnitFacade
.addSource(OriginalSourceType
.Import
,sour
.getCitation(),sour
.getCitationMicroReference(), ioName
);
468 for (OriginalSourceBase
<?
> sr
: sourceMap
.values()){
469 if(sr
.isInstanceOf(IdentifiableSource
.class)){
470 if(sourceNotLinkedToElement(derivedUnitFacade
,sr
)) {
471 derivedUnitFacade
.addSource((IdentifiableSource
)sr
.clone());
474 if(sourceNotLinkedToElement(derivedUnitFacade
,sr
)) {
475 derivedUnitFacade
.addSource(OriginalSourceType
.Import
,sr
.getCitation(),sr
.getCitationMicroReference(), ioName
);
481 getOccurrenceService().saveOrUpdate(derivedUnitBase
);
484 save(derivedUnitBase
, state
);
486 // handle identifications
487 handleIdentifications(state
, derivedUnitFacade
);
490 logger
.info("saved ABCD specimen ...");
493 } catch (Exception e
) {
494 logger
.warn("Error when reading record!!");
496 state
.setUnsuccessfull();
503 * @param derivedUnitFacade
507 private boolean sourceNotLinkedToElement(DerivedUnitFacade derivedUnitFacade
, OriginalSourceBase
<?
> source
) {
508 Set
<IdentifiableSource
> linkedSources
= derivedUnitFacade
.getSources();
509 for (IdentifiableSource is
:linkedSources
){
512 if (is
.getCitation()!=null && is
.getCitation().getTitleCache().equalsIgnoreCase(source
.getCitation().getTitleCache())){
513 String isDetail
= is
.getCitationMicroReference();
514 if (StringUtils
.isBlank(isDetail
) && StringUtils
.isBlank(source
.getCitationMicroReference())
515 || isDetail
!= null && isDetail
.equalsIgnoreCase(source
.getCitationMicroReference()) ) {
525 * @param citationDetail
528 //FIXME this method is highly critical, because
529 // * it will have serious performance and memory problems with large databases
530 // (databases may easily have >1 Mio source records)
531 // * it does not make sense to search for existing sources and then clone them
532 // we need to search for existing references instead and use them (if exist)
533 // for our new source.
534 private IdentifiableSource
getIdentifiableSource(Reference
<?
> reference
, String citationDetail
) {
536 List
<OriginalSourceBase
> issTmp
= getCommonService().list(IdentifiableSource
.class, null, null, null, null);
539 if (reference
!= null){
541 for (OriginalSourceBase
<?
> osb
: issTmp
){
542 if (osb
.getCitation() != null && osb
.getCitation().getTitleCache().equalsIgnoreCase(reference
.getTitleCache())){
543 String osbDetail
= osb
.getCitationMicroReference();
544 if (StringUtils
.isBlank(osbDetail
) && StringUtils
.isBlank(citationDetail
)
545 || osbDetail
!= null && osbDetail
.equalsIgnoreCase(citationDetail
) ) {
546 System
.out
.println("REFERENCE FOUND RETURN EXISTING SOURCE");
547 return (IdentifiableSource
) osb
.clone();
551 } catch (CloneNotSupportedException e
) {
552 throw new RuntimeException(e
);
553 } catch (Exception e1
){
554 e1
.printStackTrace();
558 IdentifiableSource sour
= IdentifiableSource
.NewInstance(OriginalSourceType
.Import
,null,null, reference
,citationDetail
);
564 * @param citationDetail
567 private DescriptionElementSource
getDescriptionSource(Reference
<?
> reference
, String citationDetail
) {
569 List
<OriginalSourceBase
> issTmp2
= getCommonService().list(DescriptionElementSource
.class, null, null, null, null);
572 for (OriginalSourceBase
<?
> osb
:issTmp2
){
573 if (osb
.getCitation().equals(reference
) && osb
.getCitationMicroReference().equalsIgnoreCase(citationDetail
)) {
574 return (DescriptionElementSource
) osb
.clone();
577 } catch (CloneNotSupportedException e
) {
578 // TODO Auto-generated catch block
582 DescriptionElementSource sour
= DescriptionElementSource
.NewInstance(OriginalSourceType
.Import
,null,null, reference
,citationDetail
);
588 * Very fast and dirty implementation to allow handling of transient objects as described in
589 * https://dev.e-taxonomy.eu/trac/ticket/3726
596 private void save(CdmBase cdmBase
, Abcd206ImportState state
) {
597 ICdmApplicationConfiguration cdmRepository
= state
.getConfig().getCdmAppController();
598 if (cdmRepository
== null){
599 cdmRepository
= this;
602 if (cdmBase
.isInstanceOf(LanguageString
.class)){
603 cdmRepository
.getTermService().saveLanguageData(CdmBase
.deproxy(cdmBase
, LanguageString
.class));
604 }else if (cdmBase
.isInstanceOf(SpecimenOrObservationBase
.class)){
605 cdmRepository
.getOccurrenceService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, SpecimenOrObservationBase
.class));
606 }else if (cdmBase
.isInstanceOf(Reference
.class)){
607 cdmRepository
.getReferenceService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, Reference
.class));
608 }else if (cdmBase
.isInstanceOf(Classification
.class)){
609 cdmRepository
.getClassificationService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, Classification
.class));
610 }else if (cdmBase
.isInstanceOf(AgentBase
.class)){
611 cdmRepository
.getAgentService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, AgentBase
.class));
612 }else if (cdmBase
.isInstanceOf(Collection
.class)){
613 cdmRepository
.getCollectionService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, Collection
.class));
614 }else if (cdmBase
.isInstanceOf(DescriptionBase
.class)){
615 cdmRepository
.getDescriptionService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, DescriptionBase
.class));
616 }else if (cdmBase
.isInstanceOf(TaxonBase
.class)){
617 cdmRepository
.getTaxonService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, TaxonBase
.class));
618 }else if (cdmBase
.isInstanceOf(TaxonNameBase
.class)){
619 cdmRepository
.getNameService().saveOrUpdate(CdmBase
.deproxy(cdmBase
, TaxonNameBase
.class));
621 throw new IllegalArgumentException("Class not supported in save method: " + CdmBase
.deproxy(cdmBase
, CdmBase
.class).getClass().getSimpleName());
627 * setCollectionData : store the collection object into the
632 private void setCollectionData(Abcd206ImportState state
, DerivedUnitFacade derivedUnitFacade
) {
633 // set catalogue number (unitID)
634 derivedUnitFacade
.setCatalogNumber(NB(dataHolder
.unitID
));
635 derivedUnitFacade
.setAccessionNumber(NB(dataHolder
.accessionNumber
));
636 // derivedUnitFacade.setCollectorsNumber(NB(dataHolder.collectorsNumber));
639 * INSTITUTION & COLLECTION
641 // manage institution
642 Institution institution
= this.getInstitution(NB(dataHolder
.institutionCode
), state
);
644 Collection collection
= this.getCollection(institution
, NB(dataHolder
.collectionCode
), state
);
645 // link specimen & collection
646 derivedUnitFacade
.setCollection(collection
);
650 * getFacade : get the DerivedUnitFacade based on the recordBasis
652 * @return DerivedUnitFacade
654 private DerivedUnitFacade
getFacade() {
656 logger
.info("getFacade()");
658 SpecimenOrObservationType type
= null;
661 if (NB((dataHolder
.recordBasis
)) != null) {
662 if (dataHolder
.recordBasis
.toLowerCase().startsWith("s") || dataHolder
.recordBasis
.toLowerCase().contains("specimen")) {// specimen
663 type
= SpecimenOrObservationType
.PreservedSpecimen
;
665 if (dataHolder
.recordBasis
.toLowerCase().startsWith("o")) {
666 type
= SpecimenOrObservationType
.Observation
;
668 if (dataHolder
.recordBasis
.toLowerCase().contains("fossil")){
669 type
= SpecimenOrObservationType
.Fossil
;
671 if (dataHolder
.recordBasis
.toLowerCase().startsWith("l")) {
672 type
= SpecimenOrObservationType
.LivingSpecimen
;
675 logger
.info("The basis of record does not seem to be known: " + dataHolder
.recordBasis
);
676 type
= SpecimenOrObservationType
.DerivedUnit
;
680 logger
.info("The basis of record is null");
681 type
= SpecimenOrObservationType
.DerivedUnit
;
683 DerivedUnitFacade derivedUnitFacade
= DerivedUnitFacade
.NewInstance(type
);
684 return derivedUnitFacade
;
687 private void getCollectorsFromXML(Element root
, Abcd206XMLFieldGetter abcdFieldGetter
) {
690 group
= root
.getChildNodes();
691 for (int i
= 0; i
< group
.getLength(); i
++) {
692 if (group
.item(i
).getNodeName().equals(prefix
+ "Identifications")) {
693 group
= group
.item(i
).getChildNodes();
697 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
698 dataHolder
.gatheringTeamList
= new ArrayList
<String
>();
699 abcdFieldGetter
.getType(root
);
700 abcdFieldGetter
.getGatheringPeople(root
);
704 * Store the unit's properties into variables Look which unit is the
705 * preferred one Look what kind of name it is supposed to be, for the
706 * parsing (Botanical, Zoological)
708 * @param racine: the root node for a single unit
710 private void setUnitPropertiesXML(Element root
, Abcd206XMLFieldGetter abcdFieldGetter
) {
714 group
= root
.getChildNodes();
715 for (int i
= 0; i
< group
.getLength(); i
++) {
716 if (group
.item(i
).getNodeName().equals(prefix
+ "Identifications")) {
717 group
= group
.item(i
).getChildNodes();
721 dataHolder
.identificationList
= new ArrayList
<String
>();
722 dataHolder
.statusList
= new ArrayList
<SpecimenTypeDesignationStatus
>();
723 dataHolder
.atomisedIdentificationList
= new ArrayList
<HashMap
<String
, String
>>();
724 dataHolder
.referenceList
= new ArrayList
<String
[]>();
725 dataHolder
.multimediaObjects
= new ArrayList
<String
>();
727 abcdFieldGetter
.getScientificNames(group
);
728 abcdFieldGetter
.getType(root
);
731 logger
.info("this.identificationList "+dataHolder
.identificationList
.toString());
733 abcdFieldGetter
.getIDs(root
);
734 abcdFieldGetter
.getRecordBasis(root
);
735 abcdFieldGetter
.getMultimedia(root
);
736 abcdFieldGetter
.getNumbers(root
);
737 abcdFieldGetter
.getGeolocation(root
);
738 abcdFieldGetter
.getGatheringPeople(root
);
739 boolean referencefound
= abcdFieldGetter
.getReferences(root
);
740 if (!referencefound
) {
741 String
[]a
= {ref
.getTitleCache(),"",""};
742 dataHolder
.referenceList
.add(a
);
745 } catch (Exception e
) {
746 logger
.info("Error occured while parsing XML file" + e
);
751 * Look if the Institution does already exist
752 * @param institutionCode: a string with the institutioncode
753 * @param config : the configurator
754 * @return the Institution (existing or new)
756 @SuppressWarnings("rawtypes")
757 private Institution
getInstitution(String institutionCode
, Abcd206ImportState state
) {
758 Institution institution
=null;
759 List
<AgentBase
> institutions
;
761 institutions
= getAgentService().list(Institution
.class, null, null, null, null);
762 } catch (Exception e
) {
763 institutions
= new ArrayList
<AgentBase
>();
766 if (institutions
.size() > 0 && state
.getConfig().isReUseExistingMetadata()) {
767 for (AgentBase inst
:institutions
){
768 Institution institut
= (Institution
)inst
;
770 if (institut
.getCode().equalsIgnoreCase(institutionCode
)) {
771 institution
=institut
;
773 }catch(Exception e
){logger
.warn("no institution code in the db");}
777 if(institution
!=null) {
778 logger
.info("getinstitution " + institution
.toString());
781 if (institution
== null){
782 // create institution
783 institution
= Institution
.NewInstance();
784 institution
.setCode(institutionCode
);
785 institution
.setTitleCache(institutionCode
);
787 save(institution
, state
);
792 * Look if the Collection does already exist
793 * @param collectionCode
794 * @param collectionCode: a string
795 * @param config : the configurator
796 * @return the Collection (existing or new)
798 private Collection
getCollection(Institution institution
, String collectionCode
, Abcd206ImportState state
) {
799 Collection collection
= null;
800 List
<Collection
> collections
;
802 collections
= getCollectionService().list(Collection
.class, null, null, null, null);
803 } catch (Exception e
) {
804 collections
= new ArrayList
<Collection
>();
806 if (collections
.size() > 0 && state
.getConfig().isReUseExistingMetadata()) {
807 for (Collection coll
:collections
){
808 if (coll
.getInstitute() != null) {
809 if (coll
.getCode().equalsIgnoreCase(collectionCode
) && coll
.getInstitute().equals(institution
)) {
816 if(collection
== null){
817 collection
=Collection
.NewInstance();
818 collection
.setCode(collectionCode
);
819 collection
.setInstitute(institution
);
820 collection
.setTitleCache(collectionCode
);
822 save(collection
, state
);
828 * join DeterminationEvent to the Taxon Object
829 * @param state : the ABCD import state
830 * @param taxon: the current Taxon
831 * @param preferredFlag :if the current name is preferred
832 * @param derivedFacade : the derived Unit Facade
834 @SuppressWarnings("rawtypes")
835 private void linkDeterminationEvent(Abcd206ImportState state
, Taxon taxon
, boolean preferredFlag
, DerivedUnitFacade derivedFacade
) {
836 Abcd206ImportConfigurator config
= state
.getConfig();
838 logger
.info("start linkdetermination with taxon:" + taxon
.getUuid()+", "+taxon
);
841 DeterminationEvent determinationEvent
= DeterminationEvent
.NewInstance();
842 determinationEvent
.setTaxon(taxon
);
843 determinationEvent
.setPreferredFlag(preferredFlag
);
845 determinationEvent
.setIdentifiedUnit(derivedUnitBase
);
846 derivedUnitBase
.addDetermination(determinationEvent
);
850 logger
.info("NB TYPES INFO: "+ dataHolder
.statusList
.size());
852 for (SpecimenTypeDesignationStatus specimenTypeDesignationstatus
: dataHolder
.statusList
) {
853 if (specimenTypeDesignationstatus
!= null) {
855 logger
.info("specimenTypeDesignationstatus :"+ specimenTypeDesignationstatus
);
858 specimenTypeDesignationstatus
= (SpecimenTypeDesignationStatus
) getTermService().find(specimenTypeDesignationstatus
.getUuid());
860 TaxonNameBase
<?
,?
> name
= taxon
.getName();
861 SpecimenTypeDesignation designation
= SpecimenTypeDesignation
.NewInstance();
863 designation
.setTypeStatus(specimenTypeDesignationstatus
);
864 designation
.setTypeSpecimen(derivedUnitBase
);
865 name
.addTypeDesignation(designation
, true);
868 } catch (Exception e
) {
869 logger
.warn("PB addding SpecimenType " + e
);
872 for (String
[] fullReference
: dataHolder
.referenceList
) {
874 System
.out
.println(fullReference
);
875 List
<Reference
> references
= getReferenceService().list(Reference
.class, null, null, null, null);
877 String strReference
=fullReference
[0];
878 String citationDetail
= fullReference
[1];
879 String citationURL
= fullReference
[2];
881 if (isNotBlank(strReference
)){
882 Reference
<?
> reference
= null;
883 for (Reference
<?
> refe
: references
) {
884 if (refe
.getTitleCache().equalsIgnoreCase(strReference
)) {
888 if (reference
==null){
889 reference
= ReferenceFactory
.newGeneric();
891 reference.setTitleCache(strReference);
892 System.out.println("reference hasproblem2 "+reference.hasProblem());
893 IdentifiableSource sour = IdentifiableSource.NewInstance(reference,citationDetail);
894 getReferenceService().saveOrUpdate(sour.getCitation());
896 reference
.setTitleCache(strReference
, true);
897 save(reference
, state
);
899 determinationEvent
.addReference(reference
);
901 }catch(Exception e
){logger
.warn("pv getReferenceList "+e
);}
903 save(derivedUnitBase
, state
);
905 if (config
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations()) {
907 logger
.info("isDoCreateIndividualsAssociations");
910 makeIndividualsAssociation(state
, taxon
, determinationEvent
);
911 save(derivedUnitBase
, state
);
916 * create and link each association (specimen, observation..) to the accepted taxon
917 * @param state : the ABCD import state
918 * @param taxon: the current Taxon
919 * @param determinationEvent:the determinationevent
921 @SuppressWarnings("unused")
922 private void makeIndividualsAssociation(Abcd206ImportState state
, Taxon taxon
, DeterminationEvent determinationEvent
) {
923 SpecimenUserInteraction sui
= state
.getConfig().getSpecimenUserInteraction();
926 System
.out
.println("MAKE INDIVIDUALS ASSOCIATION");
929 TaxonDescription taxonDescription
= null;
930 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
931 if (state
.getConfig().isInteractWithUser()){
932 taxonDescription
= sui
.askForDescriptionGroup(descriptions
);
934 for (TaxonDescription description
: descriptions
){
935 Set
<IdentifiableSource
> sources
= description
.getTaxon().getSources();
936 sources
.addAll(description
.getSources());
937 for (IdentifiableSource source
:sources
){
938 if(ref
.equals(source
.getCitation())) {
939 taxonDescription
= description
;
944 if (taxonDescription
== null){
945 taxonDescription
= TaxonDescription
.NewInstance(taxon
, false);
946 if(sourceNotLinkedToElement(taxonDescription
,ref
,null)) {
947 taxonDescription
.addSource(OriginalSourceType
.Import
, null, null, ref
, null);
949 taxon
.addDescription(taxonDescription
);
952 //PREPARE REFERENCE QUESTIONS
954 Map
<String
,OriginalSourceBase
<?
>> sourceMap
= new HashMap
<String
, OriginalSourceBase
<?
>>();
956 List
<OriginalSourceBase
> issTmp
= getCommonService().list(IdentifiableSource
.class, null, null, null, null);
957 List
<OriginalSourceBase
> issTmp2
= getCommonService().list(DescriptionElementSource
.class, null, null, null, null);
959 Set
<OriginalSourceBase
> osbSet
= new HashSet
<OriginalSourceBase
>();
961 osbSet
.addAll(issTmp2
);
964 osbSet
.addAll(issTmp
);
968 for( OriginalSourceBase
<?
> osb
:osbSet
) {
969 if(osb
.getCitationMicroReference() !=null && !osb
.getCitationMicroReference().isEmpty()) {
971 sourceMap
.put(osb
.getCitation().getTitleCache()+ "---"+osb
.getCitationMicroReference(),osb
);
972 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
975 sourceMap
.put(osb
.getCitation().getTitleCache(),osb
);
976 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
980 if (state
.getConfig().isInteractWithUser()){
981 List
<OriginalSourceBase
<?
>> res
= null;
982 if(!descriptionSourcesSet
){
983 res
= sui
.askForSource(sourceMap
, "the description group ("+taxon
+")",
984 "The current reference is "+ref
.getTitleCache(),getReferenceService(), dataHolder
.docSources
);
986 descriptionSourcesSet
=true;
992 for (OriginalSourceBase
<?
> sour
:res
){
993 if(sour
.isInstanceOf(IdentifiableSource
.class)){
995 if(sourceNotLinkedToElement(taxonDescription
,sour
)) {
996 taxonDescription
.addSource((IdentifiableSource
)sour
.clone());
998 } catch (CloneNotSupportedException e
) {
999 logger
.warn("no cloning?");
1002 if(sourceNotLinkedToElement(taxonDescription
,sour
)) {
1003 taxonDescription
.addSource(OriginalSourceType
.Import
,null, null, sour
.getCitation(),sour
.getCitationMicroReference());
1010 if(sourceNotLinkedToElement(taxonDescription
,ref
,null)) {
1011 taxonDescription
.addSource(OriginalSourceType
.Import
,null, null, ref
, null);
1015 IndividualsAssociation indAssociation
= IndividualsAssociation
.NewInstance();
1016 Feature feature
= makeFeature(derivedUnitBase
);
1017 indAssociation
.setAssociatedSpecimenOrObservation(derivedUnitBase
);
1018 indAssociation
.setFeature(feature
);
1021 if (state
.getConfig().isInteractWithUser()){
1022 sourceMap
= new HashMap
<String
, OriginalSourceBase
<?
>>();
1024 issTmp
= getCommonService().list(IdentifiableSource
.class, null, null, null, null);
1025 issTmp2
= getCommonService().list(DescriptionElementSource
.class, null, null, null, null);
1027 osbSet
= new HashSet
<OriginalSourceBase
>();
1029 osbSet
.addAll(issTmp2
);
1032 osbSet
.addAll(issTmp
);
1036 for( OriginalSourceBase
<?
> osb
:osbSet
) {
1037 if(osb
.getCitationMicroReference() !=null && !osb
.getCitationMicroReference().isEmpty()) {
1039 sourceMap
.put(osb
.getCitation().getTitleCache()+ "---"+osb
.getCitationMicroReference(),osb
);
1040 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
1043 sourceMap
.put(osb
.getCitation().getTitleCache(),osb
);
1044 }catch(NullPointerException e
){logger
.warn("null pointer problem (no ref?) with "+osb
);}
1048 List
<OriginalSourceBase
<?
>> sources
=null;
1049 if(!associationSourcesSet
) {
1050 sources
= sui
.askForSource(sourceMap
, "descriptive element (association) ",taxon
.toString(),
1051 getReferenceService(),dataHolder
.docSources
);
1052 associationRefs
=sources
;
1053 associationSourcesSet
=true;
1056 sources
=associationRefs
;
1058 if(sources
!=null) {
1059 for (OriginalSourceBase
<?
> source
: sources
) {
1061 if(source
.isInstanceOf(DescriptionElementSource
.class)){
1063 if(sourceNotLinkedToElement(indAssociation
,source
)) {
1064 indAssociation
.addSource((DescriptionElementSource
)source
.clone());
1066 } catch (CloneNotSupportedException e
) {
1067 logger
.warn("clone forbidden?");
1070 if(sourceNotLinkedToElement(indAssociation
,source
)) {
1071 indAssociation
.addSource(OriginalSourceType
.Import
,null, null, source
.getCitation(),source
.getCitationMicroReference());
1074 if(sourceNotLinkedToElement(derivedUnitBase
, source
)) {
1075 derivedUnitBase
.addSource((IdentifiableSource
) source
.clone());
1077 } catch (CloneNotSupportedException e
) {
1078 // TODO Auto-generated catch block
1079 e
.printStackTrace();
1087 if(sourceNotLinkedToElement(indAssociation
,ref
,null)) {
1088 indAssociation
.addSource(OriginalSourceType
.Import
,null, null, ref
, null);
1090 if(sourceNotLinkedToElement(derivedUnitBase
, ref
,null)) {
1091 derivedUnitBase
.addSource(OriginalSourceType
.Import
,null, null, ref
, null);
1093 for (Reference
<?
> citation
: determinationEvent
.getReferences()) {
1094 if(sourceNotLinkedToElement(indAssociation
,citation
,null))
1096 indAssociation
.addSource(DescriptionElementSource
.NewInstance(OriginalSourceType
.Import
, null, null, citation
, null));
1098 if(sourceNotLinkedToElement(derivedUnitBase
, ref
,null)) {
1099 derivedUnitBase
.addSource(OriginalSourceType
.Import
,null, null, ref
, null);
1104 taxonDescription
.addElement(indAssociation
);
1105 taxonDescription
.setTaxon(taxon
);
1107 save(taxonDescription
, state
);
1114 * @param derivedUnitBase2
1119 private boolean sourceNotLinkedToElement(DerivedUnit derivedUnitBase2
, Reference
<?
> b
, String d
) {
1120 Set
<IdentifiableSource
> linkedSources
= derivedUnitBase2
.getSources();
1121 for (IdentifiableSource is
:linkedSources
){
1122 Reference a
= is
.getCitation();
1123 String c
= is
.getCitationMicroReference();
1125 boolean refMatch
=false;
1126 boolean microMatch
=false;
1129 if (a
==null && b
==null) {
1132 if (a
!=null && b
!=null) {
1133 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1137 }catch(Exception e
){}
1141 if (c
==null && d
==null) {
1144 if(c
!=null && d
!=null) {
1145 if(c
.equalsIgnoreCase(d
)) {
1150 catch(Exception e
){}
1152 if (microMatch
&& refMatch
) {
1162 * @param derivedUnitBase2
1166 private boolean sourceNotLinkedToElement(DerivedUnit derivedUnitBase2
, OriginalSourceBase
<?
> source
) {
1167 Set
<IdentifiableSource
> linkedSources
= derivedUnitBase2
.getSources();
1168 for (IdentifiableSource is
:linkedSources
){
1169 Reference a
= is
.getCitation();
1170 Reference b
= source
.getCitation();
1171 String c
= is
.getCitationMicroReference();
1172 String d
= source
.getCitationMicroReference();
1174 boolean refMatch
=false;
1175 boolean microMatch
=false;
1178 if (a
==null && b
==null) {
1181 if (a
!=null && b
!=null) {
1182 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1186 }catch(Exception e
){}
1190 if (c
==null && d
==null) {
1193 if(c
!=null && d
!=null) {
1194 if(c
.equalsIgnoreCase(d
)) {
1199 catch(Exception e
){}
1201 if (microMatch
&& refMatch
) {
1211 * @param indAssociation
1216 private boolean sourceNotLinkedToElement(IndividualsAssociation indAssociation
, Reference
<?
> a
, String d
) {
1217 Set
<DescriptionElementSource
> linkedSources
= indAssociation
.getSources();
1218 for (DescriptionElementSource is
:linkedSources
){
1219 Reference b
= is
.getCitation();
1220 String c
= is
.getCitationMicroReference();
1222 boolean refMatch
=false;
1223 boolean microMatch
=false;
1226 if (a
==null && b
==null) {
1229 if (a
!=null && b
!=null) {
1230 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1234 }catch(Exception e
){}
1238 if (c
==null && d
==null) {
1241 if(c
!=null && d
!=null) {
1242 if(c
.equalsIgnoreCase(d
)) {
1247 catch(Exception e
){}
1249 if (microMatch
&& refMatch
) {
1257 * @param taxonDescription
1262 private boolean sourceNotLinkedToElement(TaxonDescription taxonDescription
, Reference
<?
> a
, String d
) {
1263 Set
<IdentifiableSource
> linkedSources
= taxonDescription
.getSources();
1264 for (IdentifiableSource is
:linkedSources
){
1265 Reference b
= is
.getCitation();
1266 String c
= is
.getCitationMicroReference();
1268 boolean refMatch
=false;
1269 boolean microMatch
=false;
1272 if (a
==null && b
==null) {
1275 if (a
!=null && b
!=null) {
1276 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1280 }catch(Exception e
){}
1284 if (c
==null && d
==null) {
1287 if(c
!=null && d
!=null) {
1288 if(c
.equalsIgnoreCase(d
)) {
1293 catch(Exception e
){}
1295 if (microMatch
&& refMatch
) {
1303 * @param indAssociation
1307 private boolean sourceNotLinkedToElement(IndividualsAssociation indAssociation
, OriginalSourceBase
<?
> source
) {
1308 Set
<DescriptionElementSource
> linkedSources
= indAssociation
.getSources();
1309 for (DescriptionElementSource is
:linkedSources
){
1310 Reference a
= is
.getCitation();
1311 Reference b
= source
.getCitation();
1312 String c
= is
.getCitationMicroReference();
1313 String d
= source
.getCitationMicroReference();
1315 boolean refMatch
=false;
1316 boolean microMatch
=false;
1319 if (a
==null && b
==null) {
1322 if (a
!=null && b
!=null) {
1323 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1327 }catch(Exception e
){}
1331 if (c
==null && d
==null) {
1334 if(c
!=null && d
!=null) {
1335 if(c
.equalsIgnoreCase(d
)) {
1340 catch(Exception e
){}
1342 if (microMatch
&& refMatch
) {
1350 * @param taxonDescription
1354 private boolean sourceNotLinkedToElement(TaxonDescription taxonDescription
, OriginalSourceBase
<?
> sour
) {
1355 Set
<IdentifiableSource
> linkedSources
= taxonDescription
.getSources();
1356 for (IdentifiableSource is
:linkedSources
){
1357 Reference a
= is
.getCitation();
1358 Reference b
= sour
.getCitation();
1359 String c
= is
.getCitationMicroReference();
1360 String d
= sour
.getCitationMicroReference();
1362 boolean refMatch
=false;
1363 boolean microMatch
=false;
1366 if (a
==null && b
==null) {
1369 if (a
!=null && b
!=null) {
1370 if (a
.getTitleCache().equalsIgnoreCase(b
.getTitleCache())) {
1374 }catch(Exception e
){}
1378 if (c
==null && d
==null) {
1381 if(c
!=null && d
!=null) {
1382 if(c
.equalsIgnoreCase(d
)) {
1387 catch(Exception e
){}
1389 if (microMatch
&& refMatch
) {
1399 * look for the Feature object (FieldObs, Specimen,...)
1400 * @param unit : a specimen or obersvation base
1401 * @return the corresponding Feature
1403 private Feature
makeFeature(SpecimenOrObservationBase
<?
> unit
) {
1404 SpecimenOrObservationType type
= unit
.getRecordBasis();
1405 if (type
.isFeatureObservation()){
1406 return Feature
.OBSERVATION();
1407 }else if (type
.isFeatureSpecimen()){
1408 return Feature
.SPECIMEN();
1409 }else if (type
== SpecimenOrObservationType
.DerivedUnit
){
1410 return Feature
.INDIVIDUALS_ASSOCIATION();
1412 String message
= "Unhandled record basis '%s' for defining individuals association feature type. Use default.";
1413 logger
.warn(String
.format(message
, type
.getMessage()));
1414 return Feature
.INDIVIDUALS_ASSOCIATION();
1419 * getTaxon : search for an existing taxon in the database
1420 * @param state : the ABCD import state
1421 * @param scientificName : the name (string)
1422 * @param i : the current unit position in the abcd file
1423 * @param rank : the rank for the taxon
1426 @SuppressWarnings("rawtypes")
1427 private Taxon
getTaxon(Abcd206ImportState state
, String scientificName
, int i
, Rank rank
) {
1428 System
.out
.println("GETTAXON "+scientificName
);
1429 Abcd206ImportConfigurator config
= state
.getConfig();
1431 NonViralName
<?
> taxonName
= null;
1433 SpecimenUserInteraction sui
= state
.getConfig().getSpecimenUserInteraction();
1435 System
.out
.println("config.isReuseExistingTaxaWhenPossible() :"+config
.isReuseExistingTaxaWhenPossible());
1436 if (config
.isReuseExistingTaxaWhenPossible()){
1437 List
<TaxonBase
> c
= null;
1439 List
<TaxonBase
> taxonbaseList
= getTaxonService().listByTitle(Taxon
.class, scientificName
+" sec", MatchMode
.BEGINNING
, null, null, null, null, null);
1440 if (taxonbaseList
.size()>0){
1441 if(config
.isInteractWithUser() && config
.isAllowReuseOtherClassifications()){
1442 taxon
= sui
.askWhereToFixData(scientificName
,taxonbaseList
, classification
);
1444 taxon
= sui
.lookForTaxaIntoCurrentClassification(taxonbaseList
, classification
);
1448 c
= getTaxonService().searchTaxaByName(scientificName
, ref
);
1449 if(config
.isInteractWithUser() && config
.isAllowReuseOtherClassifications()){
1450 taxon
= sui
.askWhereToFixData(scientificName
,c
, classification
);
1453 taxon
= sui
.lookForTaxaIntoCurrentClassification(c
, classification
);
1456 } catch (Exception e
) {
1457 logger
.info("Searchtaxabyname failed" + e
);
1461 if (!config
.isReuseExistingTaxaWhenPossible() || taxon
== null){
1462 System
.out
.println("create new taxonName instance "+i
+", "+config
.isParseNameAutomatically());
1463 if (config
.isParseNameAutomatically()){
1464 taxonName
= parseScientificName(scientificName
);
1467 if (i
>=0 && (dataHolder
.atomisedIdentificationList
!= null || dataHolder
.atomisedIdentificationList
.size() > 0)) {
1468 taxonName
= setTaxonNameByType(dataHolder
.atomisedIdentificationList
.get(i
), scientificName
);
1473 // if (taxonName != null) {
1474 // System.out.println(taxonName.getTitleCache());
1476 // System.out.println("taxonname: "+taxonName);
1478 if(taxonName
== null){
1479 taxonName
= NonViralName
.NewInstance(rank
);
1480 taxonName
.setFullTitleCache(scientificName
,true);
1481 taxonName
.setTitleCache(scientificName
, true);
1483 System
.out
.println("ADD NEW TAXON *"+taxonName
.getRank()+"*"+taxonName
.getTitleCache());
1484 if (rank
!= null && (taxonName
.getRank() ==null || taxonName
.getRank().toString().trim().isEmpty())) {
1485 taxonName
.setRank(rank
);
1487 save(taxonName
, state
);
1488 taxon
= Taxon
.NewInstance(taxonName
, ref
); //sec set null
1501 * HandleIdentifications : get the scientific names present in the ABCD
1502 * document and store link them with the observation/specimen data
1503 * @param state: the current ABCD import state
1504 * @param derivedUnitFacade : the current derivedunitfacade
1506 private void handleIdentifications(Abcd206ImportState state
, DerivedUnitFacade derivedUnitFacade
) {
1507 System
.out
.println("The reference from handleidentification "+ref
);
1508 Abcd206ImportConfigurator config
= state
.getConfig();
1510 String fullScientificNameString
;
1515 String scientificName
= "";
1516 boolean preferredFlag
= false;
1518 List
<String
> scientificNames
= new ArrayList
<String
>();
1519 if (dataHolder
.nomenclatureCode
== ""){
1520 dataHolder
.nomenclatureCode
= config
.getNomenclaturalCode().toString();
1523 for (int i
= 0; i
< dataHolder
.identificationList
.size(); i
++) {
1525 fullScientificNameString
= dataHolder
.identificationList
.get(i
);
1526 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
1528 if (fullScientificNameString
.indexOf(PREFERRED
) != -1) {
1529 scientificName
= fullScientificNameString
.split(PREFERRED
)[0];
1530 String pTmp
= fullScientificNameString
.split(PREFERRED
)[1].split(CODE
)[0];
1531 if (pTmp
.equals("1") || pTmp
.toLowerCase().indexOf("true") != -1) {
1532 preferredFlag
= true;
1535 preferredFlag
= false;
1539 scientificName
= fullScientificNameString
;
1542 logger
.info("fullscientificname " + fullScientificNameString
+ ", *" + dataHolder
.nomenclatureCode
+ "*");
1544 if (fullScientificNameString
.indexOf(CODE
) != -1) {
1545 if (fullScientificNameString
.indexOf(':') != -1) {
1546 dataHolder
.nomenclatureCode
= fullScientificNameString
.split(CODE
)[1].split(COLON
)[1];
1549 dataHolder
.nomenclatureCode
= fullScientificNameString
.split(CODE
)[1];
1552 scientificNames
.add(scientificName
+SPLITTER
+preferredFlag
+SPLITTER
+i
);
1554 for (String name
:scientificNames
) {
1555 scientificName
= name
.split(SPLITTER
)[0];
1556 String pref
= name
.split(SPLITTER
)[1];
1557 String index
= name
.split(SPLITTER
)[2];
1558 if (pref
.equalsIgnoreCase("true") || scientificNames
.size()==1) {
1559 preferredFlag
= true;
1561 preferredFlag
=false;
1563 taxon
= getTaxon(state
, scientificName
,Integer
.parseInt(index
),null);
1564 addTaxonNode(taxon
, state
,preferredFlag
);
1565 linkDeterminationEvent(state
, taxon
, preferredFlag
, derivedUnitFacade
);
1570 * @param taxon : a taxon to add as a node
1571 * @param state : the ABCD import state
1573 private void addTaxonNode(Taxon taxon
, Abcd206ImportState state
, boolean preferredFlag
) {
1574 logger
.info("link taxon to a taxonNode "+taxon
.getTitleCache());
1575 boolean exist
= false;
1576 for (TaxonNode p
: classification
.getAllNodes()){
1578 if(p
.getTaxon().equals(taxon
)) {
1581 }catch(Exception e
){logger
.warn("TaxonNode does'nt seem to have a taxon");}
1584 addParentTaxon(taxon
, state
, preferredFlag
);
1589 * Add the hierarchy for a Taxon(add higher taxa)
1590 * @param taxon: a taxon to add as a node
1591 * @param state: the ABCD import state
1593 private void addParentTaxon(Taxon taxon
, Abcd206ImportState state
, boolean preferredFlag
){
1594 System
.out
.println("addParentTaxon " + taxon
.getTitleCache());
1596 NonViralName
<?
> nvname
= CdmBase
.deproxy(taxon
.getName(), NonViralName
.class);
1597 Rank rank
= nvname
.getRank();
1599 Taxon subgenus
=null;
1600 Taxon species
= null;
1601 Taxon subspecies
= null;
1602 Taxon parent
= null;
1603 if (rank
.isLower(Rank
.GENUS() )){
1604 String prefix
= nvname
.getGenusOrUninomial();
1605 genus
= getTaxon(state
, prefix
, -1, Rank
.GENUS());
1606 if (preferredFlag
) {
1607 parent
= saveOrUpdateClassification(null, genus
, state
);
1611 if (rank
.isLower(Rank
.SUBGENUS())){
1612 String prefix
= nvname
.getGenusOrUninomial();
1613 String name
= nvname
.getInfraGenericEpithet();
1615 subgenus
= getTaxon(state
, prefix
+" "+name
, -1, Rank
.SUBGENUS());
1616 if (preferredFlag
) {
1617 parent
= saveOrUpdateClassification(genus
, subgenus
, state
);
1620 if (rank
.isLower(Rank
.SPECIES())){
1621 if (subgenus
!=null){
1622 String prefix
= nvname
.getGenusOrUninomial();
1623 String name
= nvname
.getInfraGenericEpithet();
1624 String spe
= nvname
.getSpecificEpithet();
1626 species
= getTaxon(state
, prefix
+" "+name
+" "+spe
, -1, Rank
.SPECIES());
1627 if (preferredFlag
) {
1628 parent
= saveOrUpdateClassification(subgenus
, species
, state
);
1633 String prefix
= nvname
.getGenusOrUninomial();
1634 String name
= nvname
.getSpecificEpithet();
1636 species
= getTaxon(state
, prefix
+" "+name
, -1, Rank
.SPECIES());
1637 if (preferredFlag
) {
1638 parent
= saveOrUpdateClassification(genus
, species
, state
);
1643 if (rank
.isInfraSpecific()){
1644 subspecies
= getTaxon(state
, nvname
.getFullTitleCache(), -1, Rank
.SUBSPECIES());
1645 if (preferredFlag
) {
1646 parent
= saveOrUpdateClassification(species
, subspecies
, state
);
1649 if (preferredFlag
) {
1650 saveOrUpdateClassification(parent
, taxon
, state
);
1655 * Link a parent to a child and save it in the current classification
1656 * @param parent: the higher Taxon
1657 * @param child : the lower (or current) Taxon
1658 * return the Taxon from the new created Node
1661 private Taxon
saveOrUpdateClassification(Taxon parent
, Taxon child
, Abcd206ImportState state
) {
1662 System
.out
.println("ADD CLASSIFICATION parent child "+parent
+"," +child
);
1663 TaxonNode node
=null;
1664 if (parent
!= null) {
1665 parent
= (Taxon
) getTaxonService().find(parent
.getUuid());
1666 child
= (Taxon
) getTaxonService().find(child
.getUuid());
1667 node
= classification
.addParentChild(parent
, child
, ref
, "");
1669 if (parent
== null) {
1670 child
= (Taxon
) getTaxonService().find(child
.getUuid());
1671 node
=classification
.addChildTaxon(child
, ref
, null);
1673 save(classification
, state
);
1674 return node
.getTaxon();
1678 * Parse automatically the scientific name
1679 * @param scientificName: the scientific name to parse
1680 * @return a parsed name
1682 private NonViralName
<?
> parseScientificName(String scientificName
) {
1683 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
1684 NonViralName
<?
> taxonName
= null;
1685 boolean problem
= false;
1688 logger
.info("parseScientificName " + dataHolder
.nomenclatureCode
.toString());
1691 if (dataHolder
.nomenclatureCode
.toString().equals("Zoological") || dataHolder
.nomenclatureCode
.toString().contains("ICZN")) {
1692 taxonName
= nvnpi
.parseFullName(scientificName
, NomenclaturalCode
.ICZN
, null);
1693 if (taxonName
.hasProblem()) {
1697 if (dataHolder
.nomenclatureCode
.toString().equals("Botanical") || dataHolder
.nomenclatureCode
.toString().contains("ICBN")) {
1698 taxonName
= nvnpi
.parseFullName(scientificName
, NomenclaturalCode
.ICNAFP
, null);
1699 if (taxonName
.hasProblem()) {
1703 if (dataHolder
.nomenclatureCode
.toString().equals("Bacterial") || dataHolder
.nomenclatureCode
.toString().contains("ICBN")) {
1704 taxonName
= nvnpi
.parseFullName(scientificName
, NomenclaturalCode
.ICNB
, null);
1705 if (taxonName
.hasProblem()) {
1709 if (dataHolder
.nomenclatureCode
.toString().equals("Cultivar") || dataHolder
.nomenclatureCode
.toString().contains("ICNCP")) {
1710 taxonName
= nvnpi
.parseFullName(scientificName
, NomenclaturalCode
.ICNCP
, null);
1711 if (taxonName
.hasProblem()) {
1716 logger
.info("Parsing with problem in parseScientificName " + scientificName
);
1724 * Create the name without automatic parsing, either because it failed, or because the user deactivated it.
1725 * The name is built upon the ABCD fields
1726 * @param atomisedMap : the ABCD atomised fields
1727 * @param fullName : the full scientific name
1728 * @return the corresponding Botanical or Zoological or... name
1730 private NonViralName
<?
> setTaxonNameByType(
1731 HashMap
<String
, String
> atomisedMap
, String fullName
) {
1732 boolean problem
= false;
1734 logger
.info("settaxonnamebytype " + dataHolder
.nomenclatureCode
.toString());
1737 if (dataHolder
.nomenclatureCode
.equals("Zoological")) {
1738 NonViralName
<ZoologicalName
> taxonName
= ZoologicalName
.NewInstance(null);
1739 taxonName
.setFullTitleCache(fullName
, true);
1740 taxonName
.setGenusOrUninomial(NB(getFromMap(atomisedMap
, "Genus")));
1741 taxonName
.setInfraGenericEpithet(NB(getFromMap(atomisedMap
, "SubGenus")));
1742 taxonName
.setSpecificEpithet(NB(getFromMap(atomisedMap
,"SpeciesEpithet")));
1743 taxonName
.setInfraSpecificEpithet(NB(getFromMap(atomisedMap
,"SubspeciesEpithet")));
1745 if (taxonName
.getGenusOrUninomial() != null){
1746 taxonName
.setRank(Rank
.GENUS());
1749 if (taxonName
.getInfraGenericEpithet() != null){
1750 taxonName
.setRank(Rank
.SUBGENUS());
1753 if (taxonName
.getSpecificEpithet() != null){
1754 taxonName
.setRank(Rank
.SPECIES());
1757 if (taxonName
.getInfraSpecificEpithet() != null){
1758 taxonName
.setRank(Rank
.SUBSPECIES());
1762 if (getFromMap(atomisedMap
, "AuthorTeamParenthesis") != null) {
1763 team
= Team
.NewInstance();
1764 team
.setTitleCache(getFromMap(atomisedMap
, "AuthorTeamParenthesis"), true);
1767 if (getFromMap(atomisedMap
, "AuthorTeamAndYear") != null) {
1768 team
= Team
.NewInstance();
1769 team
.setTitleCache(getFromMap(atomisedMap
, "AuthorTeamAndYear"), true);
1773 taxonName
.setBasionymAuthorTeam(team
);
1776 if (getFromMap(atomisedMap
, "AuthorTeamParenthesis") != null) {
1777 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
, "AuthorTeamParenthesis"));
1779 else if (getFromMap(atomisedMap
, "AuthorTeamAndYear") != null) {
1780 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
, "AuthorTeamAndYear"));
1783 if (getFromMap(atomisedMap
, "CombinationAuthorTeamAndYear") != null) {
1784 team
= Team
.NewInstance();
1785 team
.setTitleCache(getFromMap(atomisedMap
, "CombinationAuthorTeamAndYear"), true);
1786 taxonName
.setCombinationAuthorTeam(team
);
1788 if (taxonName
.hasProblem()) {
1789 logger
.info("pb ICZN");
1796 else if (dataHolder
.nomenclatureCode
.equals("Botanical")) {
1797 BotanicalName taxonName
= (BotanicalName
) parseScientificName(fullName
);
1798 if (taxonName
!= null){
1802 taxonName
= BotanicalName
.NewInstance(null);
1804 taxonName
.setFullTitleCache(fullName
, true);
1805 taxonName
.setGenusOrUninomial(NB(getFromMap(atomisedMap
, "Genus")));
1806 taxonName
.setInfraGenericEpithet(NB(getFromMap(atomisedMap
, "FirstEpithet")));
1807 taxonName
.setInfraSpecificEpithet(NB(getFromMap(atomisedMap
, "InfraSpeEpithet")));
1809 taxonName
.setRank(Rank
.getRankByName(getFromMap(atomisedMap
, "Rank")));
1810 } catch (Exception e
) {
1811 if (taxonName
.getGenusOrUninomial() != null){
1812 taxonName
.setRank(Rank
.GENUS());
1814 else if (taxonName
.getInfraGenericEpithet() != null){
1815 taxonName
.setRank(Rank
.SUBGENUS());
1817 else if (taxonName
.getSpecificEpithet() != null){
1818 taxonName
.setRank(Rank
.SPECIES());
1820 else if (taxonName
.getInfraSpecificEpithet() != null){
1821 taxonName
.setRank(Rank
.SUBSPECIES());
1825 if (getFromMap(atomisedMap
, "AuthorTeamParenthesis") != null) {
1826 team
= Team
.NewInstance();
1827 team
.setTitleCache(getFromMap(atomisedMap
, "AuthorTeamParenthesis"), true);
1828 taxonName
.setBasionymAuthorTeam(team
);
1830 if (getFromMap(atomisedMap
, "AuthorTeam") != null) {
1831 team
= Team
.NewInstance();
1832 team
.setTitleCache(getFromMap(atomisedMap
, "AuthorTeam"), true);
1833 taxonName
.setCombinationAuthorTeam(team
);
1836 if (getFromMap(atomisedMap
, "AuthorTeamParenthesis") != null) {
1837 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
, "AuthorTeamParenthesis"));
1839 else if (getFromMap(atomisedMap
, "AuthorTeam") != null) {
1840 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
, "AuthorTeam"));
1843 if (getFromMap(atomisedMap
, "CombinationAuthorTeamAndYear") != null) {
1844 team
= Team
.NewInstance();
1845 team
.setTitleCache(getFromMap(atomisedMap
, "CombinationAuthorTeamAndYear"), true);
1846 taxonName
.setCombinationAuthorTeam(team
);
1848 if (taxonName
.hasProblem()) {
1849 logger
.info("pb ICBN");
1856 else if (dataHolder
.nomenclatureCode
.equals("Bacterial")) {
1857 NonViralName
<BacterialName
> taxonName
= BacterialName
.NewInstance(null);
1858 taxonName
.setFullTitleCache(fullName
, true);
1859 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
, "Genus"));
1860 taxonName
.setInfraGenericEpithet(NB(getFromMap(atomisedMap
, "SubGenus")));
1861 taxonName
.setSpecificEpithet(NB(getFromMap(atomisedMap
, "Species")));
1862 taxonName
.setInfraSpecificEpithet(NB(getFromMap(atomisedMap
, "SubspeciesEpithet")));
1864 if (taxonName
.getGenusOrUninomial() != null){
1865 taxonName
.setRank(Rank
.GENUS());
1867 else if (taxonName
.getInfraGenericEpithet() != null){
1868 taxonName
.setRank(Rank
.SUBGENUS());
1870 else if (taxonName
.getSpecificEpithet() != null){
1871 taxonName
.setRank(Rank
.SPECIES());
1873 else if (taxonName
.getInfraSpecificEpithet() != null){
1874 taxonName
.setRank(Rank
.SUBSPECIES());
1877 if (getFromMap(atomisedMap
, "AuthorTeamAndYear") != null) {
1878 Team team
= Team
.NewInstance();
1879 team
.setTitleCache(getFromMap(atomisedMap
, "AuthorTeamAndYear"), true);
1880 taxonName
.setCombinationAuthorTeam(team
);
1882 if (getFromMap(atomisedMap
, "ParentheticalAuthorTeamAndYear") != null) {
1883 Team team
= Team
.NewInstance();
1884 team
.setTitleCache(getFromMap(atomisedMap
, "ParentheticalAuthorTeamAndYear"), true);
1885 taxonName
.setBasionymAuthorTeam(team
);
1887 if (taxonName
.hasProblem()) {
1888 logger
.info("pb ICNB");
1895 else if (dataHolder
.nomenclatureCode
.equals("Cultivar")) {
1896 CultivarPlantName taxonName
= CultivarPlantName
.NewInstance(null);
1898 if (taxonName
.hasProblem()) {
1899 logger
.info("pb ICNCP");
1909 logger
.info("Problem im setTaxonNameByType ");
1910 NonViralName
<?
> taxonName
= NonViralName
.NewInstance(null);
1911 taxonName
.setFullTitleCache(fullName
, true);
1914 NonViralName
<?
> tn
= NonViralName
.NewInstance(null);
1920 * Get a formated string from a hashmap
1921 * @param atomisedMap
1925 private String
getFromMap(HashMap
<String
, String
> atomisedMap
, String key
) {
1926 String value
= null;
1927 if (atomisedMap
.containsKey(key
)) {
1928 value
= atomisedMap
.get(key
);
1932 if (value
!= null && key
.matches(".*Year.*")) {
1933 value
= value
.trim();
1934 if (value
.matches("[a-z A-Z ]*[0-9]{4}$")) {
1935 String tmp
= value
.split("[0-9]{4}$")[0];
1936 int year
= Integer
.parseInt(value
.split(tmp
)[1]);
1949 catch (Exception e
) {
1955 // private void compareABCDtoCDM(URI urlFileName, List<String> knownElts, Abcd206XMLFieldGetter abcdFieldGetter) {
1957 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
1958 // DocumentBuilder constructeur = factory.newDocumentBuilder();
1959 // URL url = urlFileName.toURL();
1960 // Object o = url.getContent();
1961 // InputStream is = (InputStream) o;
1962 // Document document = constructeur.parse(is);
1963 // Element root = document.getDocumentElement();
1964 // abcdFieldGetter.traverse(root);
1966 // catch (ParserConfigurationException e){
1967 // e.printStackTrace();
1969 // catch (SAXException e) {
1970 // e.printStackTrace();
1972 // catch (IOException e) {
1973 // e.printStackTrace();
1975 // Set<String> elts = dataHolder.allABCDelements.keySet();
1976 // Iterator<String> it = elts.iterator();
1978 // while (it.hasNext()) {
1980 // if (knownElts.indexOf(elt) == -1) {
1982 // logger.info("Unmerged ABCD element: " + elt + " - "+ dataHolder.allABCDelements.get(elt));
1989 * Load the list of names from the ABCD file and save them
1990 * @param state : the current ABCD import state
1991 * @param unitsList : the unit list from the ABCD file
1992 * @param abcdFieldGetter : the ABCD parser
1994 private void prepareCollectors(Abcd206ImportState state
, NodeList unitsList
, Abcd206XMLFieldGetter abcdFieldGetter
) {
1995 List
<String
> collectors
= new ArrayList
<String
>();
1996 List
<String
> teams
= new ArrayList
<String
>();
1997 List
<List
<String
>> collectorinteams
= new ArrayList
<List
<String
>>();
1999 for (int i
= 0; i
< unitsList
.getLength(); i
++) {
2000 this.getCollectorsFromXML((Element
) unitsList
.item(i
), abcdFieldGetter
);
2001 for (String agent
: dataHolder
.gatheringAgentList
) {
2002 collectors
.add(agent
);
2004 List
<String
> tmpTeam
= new ArrayList
<String
>(new HashSet
<String
>(dataHolder
.gatheringTeamList
));
2005 if(!tmpTeam
.isEmpty()) {
2006 teams
.add(StringUtils
.join(tmpTeam
.toArray()," & "));
2008 for (String agent
:tmpTeam
) {
2009 collectors
.add(agent
);
2013 List
<String
> collectorsU
= new ArrayList
<String
>(new HashSet
<String
>(collectors
));
2014 List
<String
> teamsU
= new ArrayList
<String
>(new HashSet
<String
>(teams
));
2017 //existing teams in DB
2018 Map
<String
,Team
> titleCacheTeam
= new HashMap
<String
, Team
>();
2019 List
<UuidAndTitleCache
<Team
>> hiberTeam
= getAgentService().getTeamUuidAndTitleCache();
2021 Set
<UUID
> uuids
= new HashSet
<UUID
>();
2022 for (UuidAndTitleCache
<Team
> hibernateT
:hiberTeam
){
2023 uuids
.add(hibernateT
.getUuid());
2025 if (!uuids
.isEmpty()){
2026 List
<AgentBase
> existingTeams
= getAgentService().find(uuids
);
2027 for (AgentBase
<?
> existingP
:existingTeams
){
2028 titleCacheTeam
.put(existingP
.getTitleCache(),CdmBase
.deproxy(existingP
,Team
.class));
2033 Map
<String
,UUID
> teamMap
= new HashMap
<String
, UUID
>();
2034 for (UuidAndTitleCache
<Team
> uuidt
:hiberTeam
){
2035 teamMap
.put(uuidt
.getTitleCache(), uuidt
.getUuid());
2038 //existing persons in DB
2039 List
<UuidAndTitleCache
<Person
>> hiberPersons
= getAgentService().getPersonUuidAndTitleCache();
2040 Map
<String
,Person
> titleCachePerson
= new HashMap
<String
, Person
>();
2041 uuids
= new HashSet
<UUID
>();
2042 for (UuidAndTitleCache
<Person
> hibernateP
:hiberPersons
){
2043 uuids
.add(hibernateP
.getUuid());
2046 if (!uuids
.isEmpty()){
2047 List
<AgentBase
> existingPersons
= getAgentService().find(uuids
);
2048 for (AgentBase
<?
> existingP
:existingPersons
){
2049 titleCachePerson
.put(existingP
.getTitleCache(),CdmBase
.deproxy(existingP
,Person
.class));
2053 Map
<String
,UUID
> personMap
= new HashMap
<String
, UUID
>();
2054 for (UuidAndTitleCache
<Person
> person
:hiberPersons
){
2055 personMap
.put(person
.getTitleCache(), person
.getUuid());
2058 java
.util
.Collection
<Person
> personToadd
= new ArrayList
<Person
>();
2059 java
.util
.Collection
<Team
> teamToAdd
= new ArrayList
<Team
>();
2061 for (String collector
:collectorsU
){
2062 Person p
= Person
.NewInstance();
2063 p
.setTitleCache(collector
,true);
2064 if (!personMap
.containsKey(p
.getTitleCache())){
2068 for (String team
:teamsU
){
2069 Team p
= Team
.NewInstance();
2070 p
.setTitleCache(team
,true);
2071 if (!teamMap
.containsKey(p
.getTitleCache())){
2076 if(!personToadd
.isEmpty()){
2077 for (Person agent
: personToadd
){
2079 titleCachePerson
.put(agent
.getTitleCache(),CdmBase
.deproxy(agent
, Person
.class) );
2084 Map
<String
,Integer
>teamdone
= new HashMap
<String
, Integer
>();
2085 for (List
<String
> collteam
: collectorinteams
){
2086 if (!teamdone
.containsKey(StringUtils
.join(collteam
.toArray(),"-"))){
2087 Team team
= new Team();
2089 for (String collector
:collteam
){
2090 ptmp
= Person
.NewInstance();
2091 ptmp
.setTitleCache(collector
,true);
2092 Person p2
= titleCachePerson
.get(ptmp
.getTitleCache());
2093 team
.addTeamMember(p2
);
2097 teamToAdd
.add(team
);
2099 teamdone
.put(StringUtils
.join(collteam
.toArray(),"-"),0);
2103 if(!teamToAdd
.isEmpty()){
2104 for (Team agent
: teamToAdd
){
2106 titleCacheTeam
.put(agent
.getTitleCache(), CdmBase
.deproxy( agent
,Team
.class) );
2110 state
.getConfig().setTeams(titleCacheTeam
);
2111 state
.getConfig().setPersons(titleCachePerson
);
2115 protected boolean isIgnore(Abcd206ImportState state
) {