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
.List
;
20 import java
.util
.UUID
;
22 import org
.apache
.commons
.lang
.StringUtils
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.springframework
.stereotype
.Component
;
25 import org
.w3c
.dom
.Element
;
26 import org
.w3c
.dom
.NodeList
;
28 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
29 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
30 import eu
.etaxonomy
.cdm
.ext
.occurrence
.bioCase
.BioCaseQueryServiceWrapper
;
31 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
32 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
33 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
34 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenImportBase
;
35 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenUserInteraction
;
36 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringArea
;
37 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringEvent
;
38 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.molecular
.AbcdDnaParser
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
40 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
43 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
44 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
45 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
46 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
50 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
51 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
52 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
53 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
54 import eu
.etaxonomy
.cdm
.model
.molecular
.DnaSample
;
55 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
64 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
65 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
66 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
74 public class Abcd206Import
extends SpecimenImportBase
<Abcd206ImportConfigurator
, Abcd206ImportState
> {
76 private static final long serialVersionUID
= 3918095362150986307L;
78 private static final UUID SPECIMEN_SCAN_TERM
= UUID
.fromString("acda15be-c0e2-4ea8-8783-b9b0c4ad7f03");
80 private static final Logger logger
= Logger
.getLogger(Abcd206Import
.class);
83 public Abcd206Import() {
89 // @SuppressWarnings("rawtypes")
90 public void doInvoke(Abcd206ImportState state
) {
91 Abcd206ImportConfigurator config
= state
.getConfig();
92 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
= state
.getStores();
93 MapWrapper
<TeamOrPersonBase
<?
>> authorStore
= (MapWrapper
<TeamOrPersonBase
<?
>>)stores
.get(ICdmIO
.TEAM_STORE
);
94 state
.setPersonStore(authorStore
);
95 MapWrapper
<Reference
> referenceStore
= (MapWrapper
<Reference
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
96 URI sourceUri
= config
.getSourceUri();
98 state
.setTx(startTransaction());
99 logger
.info("INVOKE Specimen Import from ABCD2.06 XML ");
100 InputStream response
= null;
102 if(state
.getCdmRepository()==null){
103 state
.setCdmRepository(this);
105 if (config
.getOccurenceQuery() != null){
106 BioCaseQueryServiceWrapper queryService
= new BioCaseQueryServiceWrapper();
109 response
= queryService
.query(config
.getOccurenceQuery(), sourceUri
);
110 state
.setActualAccessPoint(sourceUri
);
113 logger
.error("An error during ABCD import");
116 SpecimenUserInteraction sui
= state
.getConfig().getSpecimenUserInteraction();
118 //init import reference
119 // List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
120 // List<Reference> references = new ArrayList<Reference>();
122 // if (state.getConfig().isInteractWithUser()){
123 // Map<String,Reference> refMap = new HashMap<String, Reference>();
124 // for (Reference reference : references) {
125 // if (! StringUtils.isBlank(reference.getTitleCache())) {
126 // refMap.put(reference.getTitleCache(),reference);
129 // state.setRef(sui.askForReference(refMap));
131 // if (state.getRef() == null){
132 // String cla = sui.createNewReference();
133 // if (refMap.get(cla)!= null) {
134 // state.setRef(refMap.get(cla));
136 // state.setRef(ReferenceFactory.newGeneric());
137 // state.getRef().setTitle(cla);
141 // state.setRef(getReferenceService().find(state.getRef().getUuid()));
144 if (state
.getRef()==null){
145 String name
= NB(state
.getConfig().getSourceReferenceTitle());
146 for (Reference reference
: referenceStore
.getAllValues()) {
147 if (! StringUtils
.isBlank(reference
.getTitleCache())) {
148 if (reference
.getTitleCache().equalsIgnoreCase(name
)) {
149 state
.setRef(reference
);
153 if (state
.getRef() == null){
154 if (state
.getConfig().getSourceReference() != null){
155 state
.setRef(state
.getConfig().getSourceReference());
157 state
.setRef(ReferenceFactory
.newGeneric());
159 if (state
.getConfig().getSourceReferenceTitle() != null){
160 state
.getRef().setTitle(state
.getConfig().getSourceReferenceTitle());
162 state
.getRef().setTitle("ABCD Import Source Reference");
170 save(state
.getRef(), state
);
171 state
.getConfig().setSourceReference(state
.getRef());
173 if(state
.getConfig().getClassificationUuid()!=null){
174 //load classification from config if it exists
175 state
.setClassification(getClassificationService().load(state
.getConfig().getClassificationUuid()));
177 if(state
.getClassification()==null){//no existing classification was set in config
178 List
<Classification
> classificationList
= getClassificationService().list(Classification
.class, null, null, null, null);
179 //get classification via user interaction
180 if (state
.getConfig().isUseClassification() && state
.getConfig().isInteractWithUser()){
181 Map
<String
,Classification
> classMap
= new HashMap
<>();
182 for (Classification tree
: classificationList
) {
183 if (! StringUtils
.isBlank(tree
.getTitleCache())) {
184 classMap
.put(tree
.getTitleCache(),tree
);
187 state
.setClassification(sui
.askForClassification(classMap
));
188 if (state
.getClassification() == null){
189 String cla
= sui
.createNewClassification();
190 if (classMap
.get(cla
)!= null) {
191 state
.setClassification(classMap
.get(cla
));
193 state
.setClassification(Classification
.NewInstance(cla
, state
.getRef(), Language
.DEFAULT()));
196 save(state
.getClassification(), state
);
198 // use default classification as the classification to import into
199 if (state
.getClassification() == null) {
200 String name
= NB(state
.getConfig().getClassificationName());
201 for (Classification classif
: classificationList
){
202 if (classif
.getTitleCache() != null && classif
.getTitleCache().equalsIgnoreCase(name
)) {
203 state
.setClassification(classif
);
206 if (state
.getClassification() == null){
207 state
.setClassification(Classification
.NewInstance(name
, state
.getRef(), Language
.DEFAULT()));
208 //we do not need a default classification when creating an empty new one
209 state
.setDefaultClassification(state
.getClassification());
210 save(state
.getDefaultClassification(false), state
);
212 save(state
.getClassification(), state
);
216 if (response
== null){
217 response
=state
.getConfig().getSource();
219 UnitAssociationWrapper unitAssociationWrapper
= AbcdParseUtility
.parseUnitsNodeList(response
, state
.getReport());
220 NodeList unitsList
= unitAssociationWrapper
.getAssociatedUnits();
221 state
.setPrefix(unitAssociationWrapper
.getPrefix());
223 if (unitsList
!= null) {
224 String message
= "nb units to insert: " + unitsList
.getLength();
225 logger
.info(message
);
226 state
.getConfig().getProgressMonitor().beginTask("Importing ABCD file", unitsList
.getLength() + 3);
227 updateProgress(state
, message
);
229 state
.setDataHolder(new Abcd206DataHolder());
230 state
.getDataHolder().reset();
232 Abcd206XMLFieldGetter abcdFieldGetter
= new Abcd206XMLFieldGetter(state
.getDataHolder(), state
.getPrefix());
234 prepareCollectors(state
, unitsList
, abcdFieldGetter
);
238 getAgentService().saveOrUpdate((java
.util
.Collection
)state
.getPersonStore().objects());
240 commitTransaction(state
.getTx());
241 state
.setTx(startTransaction());
242 if (state
.getDefaultClassification(false) != null){
243 state
.setDefaultClassification(getClassificationService().load(state
.getDefaultClassification(false).getUuid()));
245 if (state
.getClassification() != null){
246 state
.setClassification(getClassificationService().load(state
.getClassification().getUuid()));
248 state
.setAssociationRefs(new ArrayList
<>());
249 state
.setDescriptionRefs(new ArrayList
<>());
250 state
.setDerivedUnitSources(new ArrayList
<>());
251 for (int i
= 0; i
< unitsList
.getLength(); i
++) {
252 if(state
.getConfig().getProgressMonitor().isCanceled()){
258 Element item
= (Element
) unitsList
.item(i
);
259 Abcd206ImportParser
.setUnitPropertiesXML( item
, abcdFieldGetter
, state
);
260 updateProgress(state
, "Importing data for unit "+state
.getDataHolder().getUnitID()+" ("+i
+"/"+unitsList
.getLength()+")");
262 //import unit + field unit data
263 state
.setAssociatedUnitIds(state
.getDataHolder().getAssociatedUnitIds());
264 this.handleSingleUnit(state
, item
, true);
267 if(state
.getConfig().isDeduplicateReferences()){
268 getReferenceService().deduplicate(Reference
.class, null, null);
270 if(state
.getConfig().isDeduplicateClassifications()){
271 getClassificationService().deduplicate(Classification
.class, null, null);
274 commitTransaction(state
.getTx());
277 String errorDuringImport
= "Exception during import!";
278 logger
.error(errorDuringImport
, e
);
279 state
.getReport().addException(errorDuringImport
, e
);
282 state
.getReport().printReport(state
.getConfig().getReportUri());
292 private void getSiblings(Abcd206ImportState state
, Object item
, DerivedUnitFacade facade
) {
293 String unitId
= facade
.getCatalogNumber();
295 UnitAssociationParser unitParser
= new UnitAssociationParser(state
.getPrefix(), state
.getReport(), state
.getCdmRepository());
296 UnitAssociationWrapper unitAssociationWrapper
= null;
297 for (URI accessPoint
: state
.getActualAccesPoint()){
298 unitAssociationWrapper
= unitParser
.parseSiblings(unitId
, accessPoint
);
299 if (unitAssociationWrapper
.getAssociatedUnits() != null){
304 DerivedUnit currentUnit
= state
.getDerivedUnitBase();
305 // DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
306 FieldUnit currentFieldUnit
= facade
.getFieldUnit(false);
307 if(unitAssociationWrapper
!=null){
308 NodeList associatedUnits
= unitAssociationWrapper
.getAssociatedUnits();
309 if(associatedUnits
!=null){
310 for(int m
=0;m
<associatedUnits
.getLength();m
++){
311 if(associatedUnits
.item(m
) instanceof Element
){
313 String associationType
= AbcdParseUtility
.parseFirstTextContent(((Element
) associatedUnits
.item(m
)).getElementsByTagName(state
.getPrefix()+"AssociationType"));
315 Abcd206ImportParser
.setUnitPropertiesXML((Element
) associatedUnits
.item(m
), new Abcd206XMLFieldGetter(state
.getDataHolder(), unitAssociationWrapper
.getPrefix()), state
);
316 // logger.debug("derived unit: " + state.getDerivedUnitBase().toString() + " associated unit: " +state.getDataHolder().getKindOfUnit() + ", " + state.getDataHolder().accessionNumber + ", " + state.getDataHolder().getRecordBasis() + ", " + state.getDataHolder().getUnitID());
318 handleSingleUnit(state
, associatedUnits
.item(m
), false);
320 DerivedUnit associatedUnit
= state
.getDerivedUnitBase();
321 FieldUnit associatedFieldUnit
= null;
322 java
.util
.Collection
<FieldUnit
> associatedFieldUnits
= state
.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit
.getUuid());
323 //ignore field unit if associated unit has more than one
324 if(associatedFieldUnits
.size()>1){
325 state
.getReport().addInfoMessage(String
.format("%s has more than one field unit.", associatedUnit
));
327 else if(associatedFieldUnits
.size()==1){
328 associatedFieldUnit
= associatedFieldUnits
.iterator().next();
330 //parent-child relation:
331 if(associationType
.contains("individual") || associationType
.contains("culture") || associationType
.contains("sample")){
332 DerivationEvent updatedDerivationEvent
= DerivationEvent
.NewSimpleInstance(currentUnit
, associatedUnit
, DerivationEventType
.ACCESSIONING());
333 if(associatedFieldUnit
!=null && associatedFieldUnit
!= currentFieldUnit
){
334 associatedFieldUnit
.removeDerivationEvent(updatedDerivationEvent
);
335 state
.getCdmRepository().getOccurrenceService().delete(associatedFieldUnit
);
337 state
.getReport().addDerivate(associatedUnit
, currentUnit
, state
.getConfig());
339 save(associatedUnit
, state
);
346 state
.setDerivedUnitBase(currentUnit
);
351 * Handle a single unit
356 public void handleSingleUnit(Abcd206ImportState state
, Object itemObject
){
357 handleSingleUnit(state
, itemObject
, true);
361 @SuppressWarnings("rawtypes")
362 public void handleSingleUnit(Abcd206ImportState state
, Object itemObject
, boolean handleAssociatedUnits
) {
363 Element item
= (Element
) itemObject
;
365 Abcd206ImportConfigurator config
= state
.getConfig();
366 if (logger
.isDebugEnabled()) {
367 logger
.info("handleSingleUnit "+state
.getRef());
370 ICdmRepository cdmAppController
= state
.getConfig().getCdmAppController();
371 if(cdmAppController
==null){
372 cdmAppController
= this;
374 //check if unit already exists
375 DerivedUnitFacade derivedUnitFacade
= null;
376 if(state
.getConfig().isIgnoreImportOfExistingSpecimen()){
377 SpecimenOrObservationBase
<?
> existingSpecimen
= findExistingSpecimen(state
.getDataHolder().getUnitID(), state
);
378 if(existingSpecimen
!=null && existingSpecimen
.isInstanceOf(DerivedUnit
.class)){
379 DerivedUnit derivedUnit
= HibernateProxyHelper
.deproxy(existingSpecimen
, DerivedUnit
.class);
380 state
.setDerivedUnitBase(derivedUnit
);
381 derivedUnitFacade
= DerivedUnitFacade
.NewInstance(state
.getDerivedUnitBase());
382 if (handleAssociatedUnits
){
383 importAssociatedUnits(state
, item
, derivedUnitFacade
);
385 state
.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility
.getUnitID(derivedUnit
, config
), derivedUnit
);
389 // TODO: implement overwrite/merge specimen
390 // else if(state.getConfig().isOverwriteExistingSpecimens()){
391 // Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
392 // if(!existingSpecimens.getRecords().isEmpty()){
393 // derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit);
394 // derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
395 // fieldUnit = derivedUnitFacade.getFieldUnit(true);
398 //import new specimen
401 if(state
.getDataHolder().getKindOfUnit() !=null && state
.getDataHolder().getKindOfUnit().equalsIgnoreCase("dna")){
402 AbcdDnaParser dnaParser
= new AbcdDnaParser(state
.getPrefix(), state
.getReport(), state
.getCdmRepository());
403 DnaSample dnaSample
= dnaParser
.parse(item
, state
);
404 save(dnaSample
, state
);
405 //set dna as derived unit to avoid creating an extra specimen for this dna sample (instead just the field unit will be created)
406 state
.setDerivedUnitBase(dnaSample
);
407 derivedUnitFacade
= DerivedUnitFacade
.NewInstance(state
.getDerivedUnitBase());
411 derivedUnitFacade
= getFacade(state
);
412 state
.setDerivedUnitBase(derivedUnitFacade
.innerDerivedUnit());
420 //look for existing fieldUnit
422 FieldUnit fieldUnit
= state
.getFieldUnit(state
.getDataHolder().getFieldNumber());
426 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(cdmAppController
.getTermService(),
427 state
.getDataHolder().locality
, state
.getDataHolder().languageIso
, state
.getDataHolder().longitude
,
428 state
.getDataHolder().latitude
, state
.getDataHolder().getGatheringElevationText(),
429 state
.getDataHolder().getGatheringElevationMin(), state
.getDataHolder().getGatheringElevationMax(),
430 state
.getDataHolder().getGatheringElevationUnit(), state
.getDataHolder().getGatheringDateText(),
431 state
.getDataHolder().getGatheringNotes(), state
.getDataHolder().getGatheringMethod(), state
.getTransformer().getReferenceSystemByKey(
432 state
.getDataHolder().getGatheringSpatialDatum()),
435 unitsGatheringEvent
.setGatheringDepth(state
.getDataHolder().getGatheringDepthText(),state
.getDataHolder().getGatheringDepthMin(), state
.getDataHolder().getGatheringDepthMax(), state
.getDataHolder().getGatheringDepthUnit());
436 //unitsGatheringEvent.setHeight(heightText, heightMin, heightMax, heightUnit);
437 unitsGatheringEvent
.setCollector(state
.getPersonStore().get(state
.getDataHolder().gatheringAgents
), config
);
439 UnitsGatheringArea unitsGatheringArea
= new UnitsGatheringArea();
440 // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());
441 unitsGatheringArea
.setParams(state
.getDataHolder().isocountry
, state
.getDataHolder().country
, (state
.getConfig()), cdmAppController
.getTermService(), cdmAppController
.getOccurrenceService(), cdmAppController
.getVocabularyService());
443 DefinedTermBase
<?
> areaCountry
= unitsGatheringArea
.getCountry();
446 unitsGatheringArea
= new UnitsGatheringArea();
447 // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
449 unitsGatheringArea
.setAreas(state
.getDataHolder().getNamedAreaList(),(state
.getConfig()), cdmAppController
.getTermService(), cdmAppController
.getVocabularyService());
451 ArrayList
<DefinedTermBase
> nas
= unitsGatheringArea
.getAreas();
452 for (DefinedTermBase namedArea
: nas
) {
453 unitsGatheringEvent
.addArea(namedArea
);
456 // copy gathering event to facade
457 GatheringEvent gatheringEvent
= unitsGatheringEvent
.getGatheringEvent();
458 if (fieldUnit
!= null){
459 derivedUnitFacade
.setFieldUnit(fieldUnit
);
462 derivedUnitFacade
.setLocality(gatheringEvent
.getLocality());
463 derivedUnitFacade
.setExactLocation(gatheringEvent
.getExactLocation());
464 derivedUnitFacade
.setCollector(gatheringEvent
.getCollector());
465 derivedUnitFacade
.setCountry((NamedArea
)areaCountry
);
466 derivedUnitFacade
.setAbsoluteElevationText(gatheringEvent
.getAbsoluteElevationText());
467 derivedUnitFacade
.setAbsoluteElevation(gatheringEvent
.getAbsoluteElevation());
468 derivedUnitFacade
.setAbsoluteElevationMax(gatheringEvent
.getAbsoluteElevationMax());
469 derivedUnitFacade
.setDistanceToGroundText(gatheringEvent
.getDistanceToGroundText());
470 derivedUnitFacade
.setDistanceToGroundMax(gatheringEvent
.getDistanceToGroundMax());
471 derivedUnitFacade
.setDistanceToGround(gatheringEvent
.getDistanceToGround());
472 derivedUnitFacade
.setDistanceToWaterSurfaceText(gatheringEvent
.getDistanceToWaterSurfaceText());
473 derivedUnitFacade
.setDistanceToWaterSurfaceMax(gatheringEvent
.getDistanceToWaterSurfaceMax());
474 derivedUnitFacade
.setDistanceToWaterSurface(gatheringEvent
.getDistanceToWaterSurface());
475 derivedUnitFacade
.setGatheringPeriod(gatheringEvent
.getTimeperiod());
476 derivedUnitFacade
.setCollectingMethod(gatheringEvent
.getCollectingMethod());
478 for(DefinedTermBase
<?
> area
:unitsGatheringArea
.getAreas()){
479 derivedUnitFacade
.addCollectingArea((NamedArea
) area
);
481 // derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
485 derivedUnitFacade
.setFieldNumber(NB(state
.getDataHolder().getFieldNumber()));
486 save(unitsGatheringEvent
.getLocality(), state
);
489 if (state
.getDataHolder().getUnitNotes() != null){
490 derivedUnitFacade
.addAnnotation(Annotation
.NewDefaultLanguageInstance(NB(state
.getDataHolder().getUnitNotes())));
495 // //add Multimedia URLs
496 if (state
.getDataHolder().getMultimediaObjects().size() != -1) {
497 for (String multimediaObject
: state
.getDataHolder().getMultimediaObjects().keySet()) {
500 media
= getImageMedia(multimediaObject
, READ_MEDIA_DATA
);
501 Map
<String
, String
> attributes
= state
.getDataHolder().getMultimediaObjects().get(multimediaObject
);
502 if (attributes
.containsKey("Context")){
503 LanguageString description
= LanguageString
.NewInstance(attributes
.get("Context"), Language
.ENGLISH());
504 media
.addDescription(description
);
506 if (attributes
.containsKey("Comment")){
507 LanguageString description
= LanguageString
.NewInstance(attributes
.get("Comment"), Language
.ENGLISH());
508 media
.addDescription(description
);
510 if (attributes
.containsKey("Creators")){
511 String creators
= attributes
.get("Creators");
515 if (creators
!= null){
516 if (creators
.contains("&")){
517 artists
= creators
.split("&");
518 artistTeam
= new Team();
519 for (String creator
:artists
){
520 artist
= Person
.NewTitledInstance(creator
);
521 artistTeam
.addTeamMember(artist
);
523 media
.setArtist(artistTeam
);
526 artist
= Person
.NewTitledInstance(creators
);
527 media
.setArtist(artist
);
535 derivedUnitFacade
.addDerivedUnitMedia(media
);
536 if(state
.getConfig().isAddMediaAsMediaSpecimen()){
537 //add media also as specimen scan
538 MediaSpecimen mediaSpecimen
= MediaSpecimen
.NewInstance(SpecimenOrObservationType
.StillImage
);
539 mediaSpecimen
.setMediaSpecimen(media
);
541 DefinedTermBase specimenScanTerm
= getTermService().load(SPECIMEN_SCAN_TERM
);
542 if(specimenScanTerm
instanceof DefinedTerm
){
543 mediaSpecimen
.setKindOfUnit((DefinedTerm
) specimenScanTerm
);
545 DerivationEvent derivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.PREPARATION());
546 derivationEvent
.addDerivative(mediaSpecimen
);
547 derivedUnitFacade
.innerDerivedUnit().addDerivationEvent(derivationEvent
);
550 } catch (MalformedURLException e
) {
551 // TODO Auto-generated catch block
557 //multimedia for fieldUnit
558 if (state
.getDataHolder().getGatheringMultimediaObjects().size() != -1) {
559 for (String multimediaObject
: state
.getDataHolder().getGatheringMultimediaObjects().keySet()) {
562 media
= getImageMedia(multimediaObject
, READ_MEDIA_DATA
);
563 Map
<String
, String
> attributes
= state
.getDataHolder().getGatheringMultimediaObjects().get(multimediaObject
);
564 if (attributes
.containsKey("Context")){
565 LanguageString description
= LanguageString
.NewInstance(attributes
.get("Context"), Language
.ENGLISH());
566 media
.addDescription(description
);
568 if (attributes
.containsKey("Comment")){
569 LanguageString description
= LanguageString
.NewInstance(attributes
.get("Comment"), Language
.ENGLISH());
570 media
.addDescription(description
);
572 if (attributes
.containsKey("Creators")){
573 String creators
= attributes
.get("Creators");
577 if (creators
!= null){
578 if (creators
.contains("&")){
579 artists
= creators
.split("&");
580 artistTeam
= new Team();
581 for (String creator
:artists
){
582 artist
= Person
.NewTitledInstance(creator
);
583 artistTeam
.addTeamMember(artist
);
585 media
.setArtist(artistTeam
);
588 artist
= Person
.NewTitledInstance(creators
);
589 media
.setArtist(artist
);
597 derivedUnitFacade
.addFieldObjectMedia(media
);
600 } catch (MalformedURLException e
) {
601 // TODO Auto-generated catch block
609 // * merge AND STORE DATA
611 // getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
613 // for (NamedArea area : otherAreas) {
614 // getTermService().saveOrUpdate(area);// merge it sooner (foreach area)
616 // save(derivedUnitFacade.getFieldUnit(false), state);
617 if (derivedUnitFacade
.getFieldUnit(false) != null){
618 state
.setFieldUnit(derivedUnitFacade
.getFieldUnit(false));
621 // handle collection data
622 setCollectionData(state
, derivedUnitFacade
);
625 SpecimenUserInteraction sui
= config
.getSpecimenUserInteraction();
626 Map
<String
,OriginalSourceBase
<?
>> sourceMap
= new HashMap
<>();
628 state
.getDataHolder().setDocSources(new ArrayList
<>());
629 for (String
[] fullReference
: state
.getDataHolder().getReferenceList()) {
630 String strReference
=fullReference
[0];
631 String citationDetail
= fullReference
[1];
632 String citationURL
= fullReference
[2];
634 if (!citationURL
.isEmpty()) {
635 citationDetail
+=", "+citationURL
;
639 if(strReference
.equals(state
.getRef().getTitleCache())){
640 reference
= state
.getRef();
643 reference
= ReferenceFactory
.newGeneric();
644 reference
.setTitle(strReference
);
648 save(reference
, state
);
649 IdentifiableSource sour
= getIdentifiableSource(reference
, citationDetail
);
650 sour
.getCitation().setUri(state
.getActualAccessPoint());
651 sour
.setType(OriginalSourceType
.PrimaryTaxonomicSource
);
653 if (sour
.getCitation() != null){
654 if(StringUtils
.isNotBlank(sour
.getCitationMicroReference())) {
655 state
.getDataHolder().getDocSources().add(sour
.getCitation().getTitleCache()+ "---"+sour
.getCitationMicroReference());
657 state
.getDataHolder().getDocSources().add(sour
.getCitation().getTitleCache());
663 derivedUnitFacade
.addSource(sour
);
666 // List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
667 // List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
669 // Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
670 // if(issTmp2!=null) {
671 // osbSet.addAll(issTmp2);
673 // if(issTmp!=null) {
674 // osbSet.addAll(issTmp);
677 IdentifiableSource sour
= getIdentifiableSource(state
.getRef(),null);
678 String idInSource
= derivedUnitFacade
.getAccessionNumber() != null? derivedUnitFacade
.getAccessionNumber():derivedUnitFacade
.getCatalogNumber();
679 sour
.getCitation().setUri(state
.getActualAccessPoint());
680 sour
.setIdInSource(idInSource
);
682 if (sour
.getCitation() != null){
683 if(StringUtils
.isNotBlank(sour
.getCitationMicroReference())) {
684 state
.getDataHolder().getDocSources().add(sour
.getCitation().getTitleCache()+ "---"+sour
.getCitationMicroReference());
686 state
.getDataHolder().getDocSources().add(sour
.getCitation().getTitleCache());
693 derivedUnitFacade
.addSource(sour
);
694 // sourceMap.put(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference(),sour);
696 // if( state.getConfig().isInteractWithUser()){
697 // List<OriginalSourceBase<?>>sources=null;
698 // if(!state.isDerivedUnitSourcesSet()){
699 // sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().getDocSources());
700 // state.setDerivedUnitSources(sources);
701 // state.setDerivedUnitSourcesSet(true);
704 // sources=state.getDerivedUnitSources();
706 //// for (OriginalSourceBase<?> source:sources){
707 //// if(source.isInstanceOf(IdentifiableSource.class)){
708 //// if(sourceNotLinkedToElement(derivedUnitFacade,source)) {
709 //// derivedUnitFacade.addSource((IdentifiableSource)source.clone());
712 //// if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
713 //// derivedUnitFacade.addSource(OriginalSourceType.Import,source.getCitation(),source.getCitationMicroReference(), ioName);
718 // for (OriginalSourceBase<?> sr : sourceMap.values()){
719 // if(sr.isInstanceOf(IdentifiableSource.class)){
720 // if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
721 // derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
724 // if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
725 // derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);
731 save(state
.getDerivedUnitBase(), state
);
733 if(logger
.isDebugEnabled()) {
734 logger
.info("saved ABCD specimen ...");
737 // handle identifications
738 handleIdentifications(state
, derivedUnitFacade
);
741 if (handleAssociatedUnits
){
742 importAssociatedUnits(state
, item
, derivedUnitFacade
);
744 //siblings/ other children
745 if (derivedUnitFacade
.getType() != null && (derivedUnitFacade
.getType().equals(SpecimenOrObservationType
.LivingSpecimen
) || derivedUnitFacade
.getType().equals(SpecimenOrObservationType
.TissueSample
) || derivedUnitFacade
.getType().equals(SpecimenOrObservationType
.OtherSpecimen
)) &&state
.getConfig().isGetSiblings()){
746 getSiblings(state
, item
, derivedUnitFacade
);
750 } catch (Exception e
) {
751 String message
= "Error when reading record!";
752 logger
.warn(message
);
753 state
.getReport().addException(message
, e
);
755 state
.setUnsuccessfull();
762 protected void importAssociatedUnits(Abcd206ImportState state
, Object itemObject
, DerivedUnitFacade derivedUnitFacade
) {
764 Abcd206ImportConfigurator config
= state
.getConfig();
765 //import associated units
766 FieldUnit currentFieldUnit
= derivedUnitFacade
.innerFieldUnit();
767 //TODO: push state (think of implementing stack architecture for state
768 DerivedUnit currentUnit
= state
.getDerivedUnitBase();
769 DerivationEvent currentDerivedFrom
= currentUnit
.getDerivedFrom();
770 URI currentAccessPoint
= state
.getActualAccessPoint();
771 String currentPrefix
= state
.getPrefix();
773 if (itemObject
instanceof Element
){
774 item
= (Element
)itemObject
;
776 NodeList unitAssociationList
= null;
778 unitAssociationList
= item
.getElementsByTagName(currentPrefix
+"UnitAssociation");
779 for(int k
=0;k
<unitAssociationList
.getLength();k
++){
780 if(unitAssociationList
.item(k
) instanceof Element
){
781 Element unitAssociation
= (Element
)unitAssociationList
.item(k
);
782 UnitAssociationParser unitAssociationParser
= new UnitAssociationParser(currentPrefix
, state
.getReport(), state
.getCdmRepository());
783 UnitAssociationWrapper associationWrapper
= unitAssociationParser
.parse(unitAssociation
);
785 state
.setActualAccessPoint(associationWrapper
.getAccesPoint());
786 if(associationWrapper
!=null){
787 NodeList associatedUnits
= associationWrapper
.getAssociatedUnits();
788 if(associatedUnits
!=null){
789 for(int m
=0;m
<associatedUnits
.getLength();m
++){
790 if(associatedUnits
.item(m
) instanceof Element
){
792 state
.setPrefix(associationWrapper
.getPrefix());
793 Abcd206ImportParser
.setUnitPropertiesXML((Element
) associatedUnits
.item(m
), new Abcd206XMLFieldGetter(state
.getDataHolder(), state
.getPrefix()), state
);
794 logger
.debug("derived unit: " + state
.getDerivedUnitBase().toString() + " associated unit: " +state
.getDataHolder().getKindOfUnit() + ", " + state
.getDataHolder().accessionNumber
+ ", " + state
.getDataHolder().getRecordBasis() + ", " + state
.getDataHolder().getUnitID());
795 handleSingleUnit(state
, associatedUnits
.item(m
), true);
797 DerivedUnit associatedUnit
= state
.getDerivedUnitBase();
798 FieldUnit associatedFieldUnit
= null;
799 java
.util
.Collection
<FieldUnit
> associatedFieldUnits
= state
.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit
.getUuid());
800 //ignore field unit if associated unit has more than one
801 if(associatedFieldUnits
.size()>1){
802 state
.getReport().addInfoMessage(String
.format("%s has more than one field unit.", associatedUnit
));
804 else if(associatedFieldUnits
.size()==1){
805 associatedFieldUnit
= associatedFieldUnits
.iterator().next();
808 //attach current unit and associated unit depending on association type
810 //parent-child relation:
811 //copy derivation event and connect parent and sub derivative
812 // if(associationWrapper.getAssociationType().contains("individual") || associationWrapper.getAssociationType().contains("culture") || associationWrapper.getAssociationType().contains("sample") || associationWrapper.getAssociationType().contains("same in situ")){
813 if(currentDerivedFrom
==null){
814 state
.getReport().addInfoMessage(String
.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",SpecimenImportUtility
.getUnitID(currentUnit
, config
)));
815 DerivationEvent
.NewSimpleInstance(associatedUnit
, currentUnit
, DerivationEventType
.ACCESSIONING());
818 DerivationEvent updatedDerivationEvent
= DerivationEvent
.NewSimpleInstance(associatedUnit
, currentUnit
, currentDerivedFrom
.getType());
819 updatedDerivationEvent
.setActor(currentDerivedFrom
.getActor());
820 updatedDerivationEvent
.setDescription(currentDerivedFrom
.getDescription());
821 updatedDerivationEvent
.setInstitution(currentDerivedFrom
.getInstitution());
822 updatedDerivationEvent
.setTimeperiod(currentDerivedFrom
.getTimeperiod());
825 state
.getReport().addDerivate(associatedUnit
, currentUnit
, config
);
828 //connect current unit to field unit of associated unit
829 // else if(associationWrapper.getAssociationType().contains("population")|| associationWrapper.getAssociationType().contains("sample")){
830 // //no associated field unit -> using current one
831 // if(associatedFieldUnit==null){
832 // if(currentFieldUnit!=null){
833 // DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());
837 // if(currentDerivedFrom==null){
838 // state.getReport().addInfoMessage("No derivation event found for unit "+SpecimenImportUtility.getUnitID(currentUnit, config)+". Defaulting to ACCESIONING event.");
839 // DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
841 // if(currentDerivedFrom!=null && associatedFieldUnit==currentFieldUnit){
842 // DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());
843 // updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
844 // updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
845 // updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
846 // updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
851 //delete current field unit if replaced
852 if(currentFieldUnit
!=null && currentDerivedFrom
!=null
853 && currentFieldUnit
.getDerivationEvents().size()==1 && currentFieldUnit
.getDerivationEvents().contains(currentDerivedFrom
) //making sure that the field unit
854 && currentDerivedFrom
.getDerivatives().size()==1 && currentDerivedFrom
.getDerivatives().contains(currentUnit
) //is not attached to other derived units
855 && currentDerivedFrom
!=currentUnit
.getDerivedFrom() // <- derivation has been replaced and can be deleted
857 currentFieldUnit
.removeDerivationEvent(currentDerivedFrom
);
858 state
.getCdmRepository().getOccurrenceService().delete(currentFieldUnit
);
861 save(associatedUnit
, state
);
871 state
.setDerivedUnitBase(currentUnit
);
872 state
.setActualAccessPoint(currentAccessPoint
);
873 state
.setPrefix(currentPrefix
);
880 * @param derivedUnitFacade
884 private boolean sourceNotLinkedToElement(DerivedUnitFacade derivedUnitFacade
, OriginalSourceBase
<?
> source
) {
885 Set
<IdentifiableSource
> linkedSources
= derivedUnitFacade
.getSources();
886 for (IdentifiableSource is
:linkedSources
){
887 if (is
.getCitation()!=null && source
.getCitation()!=null &&
888 is
.getCitation().getTitleCache().equalsIgnoreCase(source
.getCitation().getTitleCache())){
889 String isDetail
= is
.getCitationMicroReference();
890 if ((StringUtils
.isBlank(isDetail
) && StringUtils
.isBlank(source
.getCitationMicroReference()))
891 || (isDetail
!= null && isDetail
.equalsIgnoreCase(source
.getCitationMicroReference())) ) {
902 // * @param reference
903 // * @param citationDetail
906 // private DescriptionElementSource getDescriptionSource(Reference reference, String citationDetail) {
908 // List<OriginalSourceBase> issTmp2 = getCommonService().list(DescriptionElementSource.class, null, null, null, null);
911 // for (OriginalSourceBase<?> osb:issTmp2){
912 // if (osb.getCitation().equals(reference) && osb.getCitationMicroReference().equalsIgnoreCase(citationDetail)) {
913 // return (DescriptionElementSource) osb.clone();
916 // } catch (CloneNotSupportedException e) {
917 // // TODO Auto-generated catch block
918 // e.printStackTrace();
921 // DescriptionElementSource sour = DescriptionElementSource.NewInstance(OriginalSourceType.Import,null,null, reference,citationDetail);
929 * setCollectionData : store the collection object into the
934 protected void setCollectionData(Abcd206ImportState state
, DerivedUnitFacade derivedUnitFacade
) {
935 Abcd206ImportConfigurator config
= state
.getConfig();
936 SpecimenImportUtility
.setUnitID(derivedUnitFacade
.innerDerivedUnit(), state
.getDataHolder().getUnitID(), config
);
937 if(!config
.isMapUnitIdToAccessionNumber()){
938 derivedUnitFacade
.setAccessionNumber(NB(state
.getDataHolder().accessionNumber
));
940 // derivedUnitFacade.setCollectorsNumber(NB(state.getDataHolder().collectorsNumber));
943 * INSTITUTION & COLLECTION
945 // manage institution
946 Institution institution
= this.getInstitution(NB(state
.getDataHolder().institutionCode
), state
);
948 Collection collection
= this.getCollection(institution
, NB(state
.getDataHolder().collectionCode
), state
);
949 // link specimen & collection
950 derivedUnitFacade
.setCollection(collection
);
954 * getFacade : get the DerivedUnitFacade based on the recordBasis
957 * @return DerivedUnitFacade
960 protected DerivedUnitFacade
getFacade(Abcd206ImportState state
) {
961 if(logger
.isDebugEnabled()) {
962 logger
.info("getFacade()");
964 SpecimenOrObservationType type
= null;
965 DefinedTerm kindOfUnit
= null;
968 if (NB((state
.getDataHolder()).getRecordBasis()) != null) {
969 if (state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("living")>-1) {
970 type
= SpecimenOrObservationType
.LivingSpecimen
;
972 else if (state
.getDataHolder().getRecordBasis().toLowerCase().startsWith("s") || state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("specimen")>-1) {// specimen
973 type
= SpecimenOrObservationType
.PreservedSpecimen
;
975 else if (state
.getDataHolder().getRecordBasis().toLowerCase().startsWith("o") ||state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("observation")>-1 ) {
976 type
= SpecimenOrObservationType
.Observation
;
978 else if (state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("fossil")>-1){
979 type
= SpecimenOrObservationType
.Fossil
;
980 }else if (state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("materialsample")>-1){
981 type
= SpecimenOrObservationType
.OtherSpecimen
;
983 else if (state
.getDataHolder().getRecordBasis().toLowerCase().indexOf("sample")>-1){
984 type
= SpecimenOrObservationType
.TissueSample
;
988 logger
.info("The basis of record does not seem to be known: " + state
.getDataHolder().getRecordBasis());
989 type
= SpecimenOrObservationType
.DerivedUnit
;
992 logger
.info("The basis of record is null");
993 type
= SpecimenOrObservationType
.DerivedUnit
;
996 if (NB((state
.getDataHolder()).getKindOfUnit()) != null) {
997 if (state
.getDataHolder().getKindOfUnit().toLowerCase().indexOf("clone")>-1) {
998 kindOfUnit
= getKindOfUnit(state
, null, "clone culture", "clone culture", "cc", null);
1000 else if (state
.getDataHolder().getKindOfUnit().toLowerCase().startsWith("live")) {
1001 kindOfUnit
= getKindOfUnit(state
, null, "live sample", "live sample", "ls", null);
1005 if (kindOfUnit
== null) {
1006 logger
.info("The kind of unit does not seem to be known: " + state
.getDataHolder().getKindOfUnit());
1010 logger
.info("The kind of unit is null");
1013 DerivedUnitFacade derivedUnitFacade
= DerivedUnitFacade
.NewInstance(type
);
1014 derivedUnitFacade
.setFieldUnit(state
.getFieldUnit(state
.getDataHolder().getFieldNumber()));
1015 derivedUnitFacade
.setKindOfUnit(kindOfUnit
);
1016 return derivedUnitFacade
;
1019 private void getCollectorsFromXML(Element root
, Abcd206XMLFieldGetter abcdFieldGetter
, Abcd206ImportState state
) {
1022 group
= root
.getChildNodes();
1023 for (int i
= 0; i
< group
.getLength(); i
++) {
1024 if (group
.item(i
).getNodeName().equals(state
.getPrefix() + "Identifications")) {
1025 group
= group
.item(i
).getChildNodes();
1029 //state.getDataHolder().gatheringAgents = "";
1031 abcdFieldGetter
.getType(root
);
1032 abcdFieldGetter
.getGatheringPeople(root
);
1037 // private void compareABCDtoCDM(URI urlFileName, List<String> knownElts, Abcd206XMLFieldGetter abcdFieldGetter) {
1039 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
1040 // DocumentBuilder constructeur = factory.newDocumentBuilder();
1041 // URL url = urlFileName.toURL();
1042 // Object o = url.getContent();
1043 // InputStream is = (InputStream) o;
1044 // Document document = constructeur.parse(is);
1045 // Element root = document.getDocumentElement();
1046 // abcdFieldGetter.traverse(root);
1048 // catch (ParserConfigurationException e){
1049 // e.printStackTrace();
1051 // catch (SAXException e) {
1052 // e.printStackTrace();
1054 // catch (IOException e) {
1055 // e.printStackTrace();
1057 // Set<String> elts = state.getDataHolder().allABCDelements.keySet();
1058 // Iterator<String> it = elts.iterator();
1060 // while (it.hasNext()) {
1062 // if (knownElts.indexOf(elt) == -1) {
1064 // logger.info("Unmerged ABCD element: " + elt + " - "+ state.getDataHolder().allABCDelements.get(elt));
1071 * Load the list of names from the ABCD file and save them
1072 * @param state : the current ABCD import state
1073 * @param unitsList : the unit list from the ABCD file
1074 * @param abcdFieldGetter : the ABCD parser
1076 private void prepareCollectors(Abcd206ImportState state
, NodeList unitsList
, Abcd206XMLFieldGetter abcdFieldGetter
) {
1078 TeamOrPersonBase
<?
> teamOrPerson
= null;
1080 //ImportHelper.setOriginalSource(teamOrPerson, state.getConfig().getSourceReference(), collector, "Collector");
1081 for (int i
= 0; i
< unitsList
.getLength(); i
++) {
1082 this.getCollectorsFromXML((Element
) unitsList
.item(i
), abcdFieldGetter
, state
);
1083 if (!StringUtils
.isBlank(state
.getDataHolder().gatheringAgents
)){
1084 teamOrPerson
= parseAuthorString(state
.getDataHolder().gatheringAgents
);
1085 if (!state
.getPersonStore().containsId(state
.getDataHolder().gatheringAgents
)) {
1086 state
.getPersonStore().put(state
.getDataHolder().gatheringAgents
, teamOrPerson
);
1087 if (logger
.isDebugEnabled()) { logger
.debug("Stored author " + state
.getDataHolder().gatheringAgents
); }
1089 logger
.warn("Not imported author with duplicated aut_id " + state
.getDataHolder().gatheringAgents
);
1098 // List<String> collectorsU = new ArrayList<String>(new HashSet<String>(collectors));
1099 // List<String> teamsU = new ArrayList<String>(new HashSet<String>(teams));
1102 // //existing teams in DB
1103 // Map<String,Team> titleCacheTeam = new HashMap<String, Team>();
1104 // List<UuidAndTitleCache<Team>> hiberTeam = new ArrayList<UuidAndTitleCache<Team>>();//getAgentService().getTeamUuidAndTitleCache();
1106 // Set<UUID> uuids = new HashSet<UUID>();
1107 // for (UuidAndTitleCache<Team> hibernateT:hiberTeam){
1108 // uuids.add(hibernateT.getUuid());
1110 // if (!uuids.isEmpty()){
1111 // List<AgentBase> existingTeams = getAgentService().find(uuids);
1112 // for (AgentBase<?> existingP:existingTeams){
1113 // titleCacheTeam.put(existingP.getTitleCache(),CdmBase.deproxy(existingP,Team.class));
1118 // Map<String,UUID> teamMap = new HashMap<String, UUID>();
1119 // for (UuidAndTitleCache<Team> uuidt:hiberTeam){
1120 // teamMap.put(uuidt.getTitleCache(), uuidt.getUuid());
1123 //existing persons in DB
1124 // List<UuidAndTitleCache<Person>> hiberPersons = new ArrayList<UuidAndTitleCache<Person>>();//getAgentService().getPersonUuidAndTitleCache();
1125 // Map<String,Person> titleCachePerson = new HashMap<String, Person>();
1126 // uuids = new HashSet<UUID>();
1127 // for (UuidAndTitleCache<Person> hibernateP:hiberPersons){
1128 // uuids.add(hibernateP.getUuid());
1131 // if (!uuids.isEmpty()){
1132 // List<AgentBase> existingPersons = getAgentService().find(uuids);
1133 // for (AgentBase<?> existingP:existingPersons){
1134 // titleCachePerson.put(existingP.getTitleCache(),CdmBase.deproxy(existingP,Person.class));
1138 // Map<String,UUID> personMap = new HashMap<String, UUID>();
1139 // for (UuidAndTitleCache<Person> person:hiberPersons){
1140 // personMap.put(person.getTitleCache(), person.getUuid());
1143 // java.util.Collection<Person> personToadd = new ArrayList<Person>();
1144 // java.util.Collection<Team> teamToAdd = new ArrayList<Team>();
1146 // for (String collector:collectorsU){
1147 // Person p = Person.NewInstance();
1148 // p.setTitleCache(collector,true);
1149 // if (!personMap.containsKey(p.getTitleCache())){
1150 // personToadd.add(p);
1153 // for (String team:teamsU){
1154 // Team p = Team.NewInstance();
1155 // p.setTitleCache(team,true);
1156 // if (!teamMap.containsKey(p.getTitleCache())){
1157 // teamToAdd.add(p);
1161 // if(!personToadd.isEmpty()){
1162 // for (Person agent: personToadd){
1163 // save(agent, state);
1164 // titleCachePerson.put(agent.getTitleCache(),CdmBase.deproxy(agent, Person.class) );
1169 // Map <String,Integer>teamdone = new HashMap<String, Integer>();
1170 // for (List<String> collteam: collectorinteams){
1171 // if (!teamdone.containsKey(StringUtils.join(collteam.toArray(),"-"))){
1172 // Team team = new Team();
1173 // boolean em =true;
1174 // for (String collector:collteam){
1175 // ptmp = Person.NewInstance();
1176 // ptmp.setTitleCache(collector,true);
1177 // Person p2 = titleCachePerson.get(ptmp.getTitleCache());
1178 // team.addTeamMember(p2);
1182 // teamToAdd.add(team);
1184 // teamdone.put(StringUtils.join(collteam.toArray(),"-"),0);
1188 // if(!teamToAdd.isEmpty()){
1189 // for (Team agent: teamToAdd){
1190 // save(agent, state);
1191 // titleCacheTeam.put(agent.getTitleCache(), CdmBase.deproxy( agent,Team.class) );
1195 // ((Abcd206ImportConfigurator) state.getConfig()).setTeams(titleCacheTeam);
1196 // ((Abcd206ImportConfigurator) state.getConfig()).setPersons(titleCachePerson);
1201 protected boolean doCheck(Abcd206ImportState state
) {
1202 logger
.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
1207 protected boolean isIgnore(Abcd206ImportState state
) {