2 * Copyright (C) 2019 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.
9 package eu
.etaxonomy
.cdm
.io
.cdm2cdm
;
11 import java
.lang
.reflect
.Field
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.lang
.reflect
.Method
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
17 import java
.util
.HashSet
;
18 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.apache
.logging
.log4j
.LogManager
;
24 import org
.apache
.logging
.log4j
.Logger
;
26 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
27 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplication
;
28 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
29 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
30 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
31 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
32 import eu
.etaxonomy
.cdm
.database
.ICdmImportSource
;
33 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
34 import eu
.etaxonomy
.cdm
.io
.common
.ITaxonNodeOutStreamPartitioner
;
35 import eu
.etaxonomy
.cdm
.io
.common
.TaxonNodeOutStreamPartitioner
;
36 import eu
.etaxonomy
.cdm
.io
.common
.TaxonNodeOutStreamPartitionerConcurrent
;
37 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
38 import eu
.etaxonomy
.cdm
.model
.agent
.Contact
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
40 import eu
.etaxonomy
.cdm
.model
.agent
.InstitutionalMembership
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
44 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
45 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
46 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.Credit
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Extension
;
49 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
50 import eu
.etaxonomy
.cdm
.model
.common
.IIntextReferencable
;
51 import eu
.etaxonomy
.cdm
.model
.common
.IIntextReferenceTarget
;
52 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
53 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
54 import eu
.etaxonomy
.cdm
.model
.common
.Identifier
;
55 import eu
.etaxonomy
.cdm
.model
.common
.IntextReference
;
56 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
57 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
58 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
59 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
60 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
61 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
62 import eu
.etaxonomy
.cdm
.model
.common
.SingleSourcedEntityBase
;
63 import eu
.etaxonomy
.cdm
.model
.common
.SourcedEntityBase
;
64 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
65 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
66 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
67 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
68 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
69 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
70 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
71 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
72 import eu
.etaxonomy
.cdm
.model
.description
.FeatureState
;
73 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
74 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
75 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
76 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
77 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
78 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
79 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
80 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
81 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
82 import eu
.etaxonomy
.cdm
.model
.media
.ExternalLink
;
83 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
84 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
85 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
86 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
87 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
88 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
89 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
90 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalSource
;
91 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
92 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
93 import eu
.etaxonomy
.cdm
.model
.name
.Registration
;
94 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
95 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
96 import eu
.etaxonomy
.cdm
.model
.name
.TextualTypeDesignation
;
97 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
98 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
99 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
100 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
101 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
102 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSource
;
103 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSourceBase
;
104 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
105 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
106 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
107 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
108 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
109 import eu
.etaxonomy
.cdm
.model
.taxon
.SecundumSource
;
110 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
111 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
112 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
113 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
114 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNodeAgentRelation
;
115 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
116 import eu
.etaxonomy
.cdm
.model
.term
.AvailableForTermBase
;
117 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
118 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
119 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
120 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
121 import eu
.etaxonomy
.cdm
.model
.term
.TermBase
;
122 import eu
.etaxonomy
.cdm
.model
.term
.TermCollection
;
123 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
124 import eu
.etaxonomy
.cdm
.model
.term
.TermRelationBase
;
125 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
126 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
127 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
130 * Base class for migrating data from one CDM instance to another.
135 public abstract class Cdm2CdmImportBase
136 extends CdmImportBase
<Cdm2CdmImportConfigurator
, Cdm2CdmImportState
> {
138 private static final long serialVersionUID
= 1344722304369624443L;
139 private static final Logger logger
= LogManager
.getLogger();
141 protected ICdmApplication
sourceRepo(Cdm2CdmImportState state
){
142 ICdmApplication repo
= state
.getSourceRepository();
144 ICdmImportSource source
= state
.getConfig().getSource();
145 if (source
instanceof ICdmRepository
){
146 repo
= (ICdmApplication
)source
;
147 }else if (source
instanceof ICdmDataSource
){
148 System
.out
.println("start source repo");
149 boolean omitTermLoading
= true;
150 repo
= CdmApplicationController
.NewInstance((ICdmDataSource
)source
,
151 DbSchemaValidation
.VALIDATE
, omitTermLoading
);
152 state
.setSourceRepository(repo
);
153 System
.out
.println("end source repo");
155 throw new IllegalStateException("Unsupported ICdmImportSource type");
161 protected Contact
detach(Contact contact
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
162 contact
= CdmBase
.deproxy(contact
);
163 if (contact
== null){
166 return handlePersistedContact(contact
, state
);
170 protected IIntextReferencable
detach(IIntextReferencable cdmBase
, boolean onlyForDefinedSignature
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
171 return (IIntextReferencable
)detach((CdmBase
)cdmBase
, state
);
173 protected IIntextReferenceTarget
detach(IIntextReferenceTarget cdmBase
, boolean onlyForDefinedSignature
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
174 return (IIntextReferenceTarget
)detach((CdmBase
)cdmBase
, state
);
177 protected <T
extends CdmBase
> T
detach(T cdmBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
178 return detach(cdmBase
, false, state
);
181 protected <T
extends CdmBase
> T
detach(T cdmBase
, boolean notFromSource
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
182 cdmBase
= CdmBase
.deproxy(cdmBase
);
183 if (cdmBase
== null ){
185 }else if(isInCache(cdmBase
, state
)){
186 return getCached(cdmBase
, state
);
188 if (state
.getExistingObjects(cdmBase
.getClass()) == null){
189 loadExistingUuids(cdmBase
.getClass(), state
);
191 boolean exists
= state
.getExistingObjects(cdmBase
.getClass()).contains(cdmBase
.getUuid());
193 Class
<T
> clazz
= (Class
<T
>)cdmBase
.getClass();
194 T existingObj
= getCommonService().find(clazz
, cdmBase
.getUuid());
195 if (existingObj
!= null){
196 cache(existingObj
, state
);
199 logger
.warn("Object should exist already but does not exist in target. This should not happen: " + cdmBase
.getClass().getSimpleName() + "/" + cdmBase
.getUuid());
203 if ( !cdmBase
.isPersited()){
204 logger
.warn("Non persisted object not in cache and not in target DB. This should not happen: " + cdmBase
.getUuid());
205 return cdmBase
; //should not happen anymore; either in cache or in target or persisted in source
207 return notFromSource?
null : (T
)handlePersisted(cdmBase
, state
);
211 private Set
<UUID
> loadExistingUuids(Class
<?
extends CdmBase
> clazz
, Cdm2CdmImportState state
) {
212 List
<UUID
> list
= getCommonService().listUuid(clazz
);
213 Set
<UUID
> result
= new HashSet
<>(list
);
214 state
.putExistingObjects(clazz
, result
);
218 protected <A
extends CdmBase
> CdmBase
handlePersisted(A cdmBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
219 if(cdmBase
instanceof TaxonNode
){
220 return handlePersistedTaxonNode((TaxonNode
)cdmBase
, state
);
221 }else if(cdmBase
instanceof Taxon
){
222 return handlePersistedTaxon((Taxon
)cdmBase
, state
);
223 }else if(cdmBase
instanceof Synonym
){
224 return handlePersistedSynonym((Synonym
)cdmBase
, state
);
225 }else if(cdmBase
instanceof TaxonName
){
226 return handlePersistedTaxonName((TaxonName
)cdmBase
, state
);
227 }else if(cdmBase
instanceof Team
){
228 return handlePersistedTeam((Team
)cdmBase
, state
);
229 }else if(cdmBase
instanceof Person
){
230 return handlePersistedPerson((Person
)cdmBase
, state
);
231 }else if(cdmBase
instanceof Classification
){
232 return handlePersistedClassification((Classification
)cdmBase
, state
);
233 }else if(cdmBase
instanceof Reference
){
234 return handlePersistedReference((Reference
)cdmBase
, state
);
235 }else if(cdmBase
instanceof SpecimenOrObservationBase
){
236 return handlePersistedSpecimenOrObservationBase((SpecimenOrObservationBase
)cdmBase
, state
);
237 }else if(cdmBase
instanceof IdentifiableSource
){
238 return handlePersistedIdentifiableSource((IdentifiableSource
)cdmBase
, state
);
239 }else if(cdmBase
instanceof DescriptionElementSource
){
240 return handlePersistedDescriptionElementSource((DescriptionElementSource
)cdmBase
, state
);
241 }else if(cdmBase
instanceof NomenclaturalSource
){
242 return handlePersistedNomenclaturalSource((NomenclaturalSource
)cdmBase
, state
);
243 }else if(cdmBase
instanceof NamedSource
){
244 return handlePersistedNamedSource((NamedSource
)cdmBase
, state
);
245 }else if(cdmBase
instanceof SecundumSource
){
246 return handlePersistedSecundumSource((SecundumSource
)cdmBase
, state
);
247 }else if(cdmBase
instanceof CommonTaxonName
){
248 return handlePersistedCommonTaxonName((CommonTaxonName
)cdmBase
, state
);
249 }else if(cdmBase
instanceof Distribution
){
250 return handlePersistedDistribution((Distribution
)cdmBase
, state
);
251 }else if(cdmBase
instanceof TextData
){
252 return handlePersistedTextData((TextData
)cdmBase
, state
);
253 }else if(cdmBase
instanceof TaxonInteraction
){
254 return handlePersistedTaxonInteraction((TaxonInteraction
)cdmBase
, state
);
255 }else if(cdmBase
instanceof HomotypicalGroup
){
256 return handlePersistedHomotypicalGroup((HomotypicalGroup
)cdmBase
, state
);
257 }else if(cdmBase
instanceof SpecimenTypeDesignation
){
258 return handlePersistedSpecimenTypeDesignation((SpecimenTypeDesignation
)cdmBase
, state
);
259 }else if(cdmBase
instanceof NameTypeDesignation
){
260 return handlePersistedNameTypeDesignation((NameTypeDesignation
)cdmBase
, state
);
261 }else if(cdmBase
instanceof TextualTypeDesignation
){
262 return handlePersistedTextualTypeDesignation((TextualTypeDesignation
)cdmBase
, state
);
263 }else if(cdmBase
instanceof TaxonDescription
){
264 return handlePersistedTaxonDescription((TaxonDescription
)cdmBase
, state
);
265 }else if(cdmBase
instanceof NomenclaturalStatus
){
266 return handlePersistedNomenclaturalStatus((NomenclaturalStatus
)cdmBase
, state
);
267 }else if(cdmBase
instanceof TaxonNameDescription
){
268 return handlePersistedTaxonNameDescription((TaxonNameDescription
)cdmBase
, state
);
269 }else if(cdmBase
instanceof TaxonRelationship
){
270 return handlePersistedTaxonRelationship((TaxonRelationship
)cdmBase
, state
);
271 }else if(cdmBase
instanceof HybridRelationship
){
272 return handlePersistedHybridRelationship((HybridRelationship
)cdmBase
, state
);
273 }else if(cdmBase
instanceof NameRelationship
){
274 return handlePersistedNameRelationship((NameRelationship
)cdmBase
, state
);
275 }else if(cdmBase
instanceof TaxonNodeAgentRelation
){
276 return handlePersistedTaxonNodeAgentRelation((TaxonNodeAgentRelation
)cdmBase
, state
);
277 }else if(cdmBase
instanceof User
){
278 return handlePersistedUser((User
)cdmBase
, state
);
279 }else if(cdmBase
instanceof Extension
){
280 return handlePersistedExtension((Extension
)cdmBase
, state
);
281 }else if(cdmBase
instanceof Marker
){
282 return handlePersistedMarker((Marker
)cdmBase
, state
);
283 }else if(cdmBase
instanceof Annotation
){
284 return handlePersistedAnnotation((Annotation
)cdmBase
, state
);
285 }else if(cdmBase
instanceof LanguageString
){
286 return handlePersistedLanguageString((LanguageString
)cdmBase
, state
);
287 }else if(cdmBase
instanceof TermVocabulary
){
288 return handlePersistedVocabulary((TermVocabulary
<?
>)cdmBase
, state
);
289 }else if(cdmBase
instanceof TermTree
){
290 return handlePersistedTermTree((TermTree
<?
>)cdmBase
, state
);
291 }else if(cdmBase
instanceof NamedArea
){
292 return handlePersistedNamedArea((NamedArea
)cdmBase
, state
);
293 }else if(cdmBase
instanceof TermNode
){
294 return handlePersistedTermNode((TermNode
)cdmBase
, state
);
295 }else if(cdmBase
instanceof Representation
){
296 return handlePersistedRepresentation((Representation
)cdmBase
, state
);
297 }else if(cdmBase
instanceof InstitutionalMembership
){
298 return handlePersistedInstitutionalMembership((InstitutionalMembership
)cdmBase
, state
);
299 }else if(cdmBase
instanceof Institution
){
300 return handlePersistedInstitution((Institution
)cdmBase
, state
);
301 }else if(cdmBase
instanceof IntextReference
){
302 return handlePersistedIntextReference((IntextReference
)cdmBase
, state
);
303 }else if(cdmBase
instanceof ExtensionType
){
304 return handlePersistedExtensionType((ExtensionType
)cdmBase
, state
);
305 }else if(cdmBase
instanceof NomenclaturalStatusType
){
306 return handlePersistedNomenclaturalStatusType((NomenclaturalStatusType
)cdmBase
, state
);
307 }else if(cdmBase
instanceof MarkerType
){
308 return handlePersistedMarkerType((MarkerType
)cdmBase
, state
);
309 }else if(cdmBase
instanceof Rights
){
310 return handlePersistedRights((Rights
)cdmBase
, state
);
311 }else if(cdmBase
instanceof DefinedTerm
){
312 return handlePersistedDefinedTerm((DefinedTerm
)cdmBase
, state
);
313 }else if(cdmBase
instanceof Feature
){
314 return handlePersistedFeature((Feature
)cdmBase
, state
);
315 }else if(cdmBase
instanceof DefinedTermBase
){
316 return handlePersistedTerm((DefinedTermBase
<?
>)cdmBase
, state
);
317 }else if(cdmBase
instanceof ExternalLink
){
318 return handlePersistedExternalLink((ExternalLink
)cdmBase
, state
);
320 throw new RuntimeException("Type not yet supported: " + cdmBase
.getClass().getCanonicalName());
325 protected TaxonNode
handlePersistedTaxonNode(TaxonNode node
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
327 TaxonNode result
= handlePersisted((AnnotatableEntity
)node
, state
);
332 handleCollection(result
, TaxonNode
.class, "agentRelations", TaxonNodeAgentRelation
.class, state
);
333 result
.setTaxon(detach(result
.getTaxon(), state
));
334 result
.setSource(detach(node
.getSource(), state
));
335 result
.setSynonymToBeUsed(detach(result
.getSynonymToBeUsed(), state
));
336 handleMap(result
, TaxonNode
.class, "statusNote", Language
.class, LanguageString
.class, state
);
337 //classification, parent, children
338 this.setInvisible(node
, "classification", detach(node
.getClassification(), state
));
339 handleParentTaxonNode(result
, state
);
340 setNewCollection(node
, TaxonNode
.class, "childNodes", TaxonNode
.class);
344 private void handleParentTaxonNode(TaxonNode childNode
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
345 TaxonNode parent
= detach(childNode
.getParent(), true, state
);
347 String microReference
= null;
348 Reference reference
= null;
349 if (parent
== null && childNode
.getClassification().getRootNode().equals(childNode
)){
351 }else if (parent
== null ){
352 childNode
.getClassification().addChildNode(childNode
, reference
, microReference
) ;
354 parent
.addChildNode(childNode
, reference
, microReference
);
358 protected Taxon
handlePersistedTaxon(Taxon taxon
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
359 Taxon result
= handlePersisted((TaxonBase
)taxon
, state
);
361 handleCollection(result
, Taxon
.class, "synonyms", Synonym
.class, state
);
362 // handleCollection(result, Taxon.class, "taxonNodes", TaxonNode.class);
363 setNewCollection(result
, Taxon
.class, "taxonNodes", TaxonNode
.class);
364 handleCollection(result
, Taxon
.class, "relationsFromThisTaxon", TaxonRelationship
.class, state
);
365 handleCollection(result
, Taxon
.class, "relationsToThisTaxon", TaxonRelationship
.class, state
);
366 if (this.doDescriptions(state
)){
367 handleCollection(result
, Taxon
.class, "descriptions", TaxonDescription
.class, state
);
369 setNewCollection(result
, Taxon
.class, "descriptions", TaxonDescription
.class);
374 protected boolean doDescriptions(Cdm2CdmImportState state
) {
378 protected Synonym
handlePersistedSynonym(Synonym synonym
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
379 Synonym result
= handlePersisted((TaxonBase
)synonym
, state
);
381 setInvisible(result
, "acceptedTaxon", detach(result
.getAcceptedTaxon(), state
));
382 result
.setType(detach(result
.getType(), state
));
386 protected TaxonRelationship
handlePersistedTaxonRelationship(TaxonRelationship taxRel
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
387 TaxonRelationship result
= handlePersisted((RelationshipBase
)taxRel
, state
);
389 result
.setFromTaxon(detach(result
.getFromTaxon(), state
));
390 result
.setToTaxon(detach(result
.getToTaxon(), state
));
391 result
.setType(detach(result
.getType(), state
));
395 protected NameRelationship
handlePersistedNameRelationship(NameRelationship rel
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
396 NameRelationship result
= handlePersisted((RelationshipBase
)rel
, state
);
398 setInvisible(result
, "relatedFrom", detach(result
.getFromName(), state
));
399 setInvisible(result
, "relatedTo", detach(result
.getToName(), state
));
400 // result.setFromName(detache(result.getFromName(), state));
401 // result.setToName(detache(result.getToName(), state));
402 result
.setType(detach(result
.getType(), state
));
406 protected HybridRelationship
handlePersistedHybridRelationship(HybridRelationship rel
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
407 HybridRelationship result
= handlePersisted((RelationshipBase
)rel
, state
);
409 setInvisible(result
, "relatedFrom", detach(result
.getParentName(), state
));
410 setInvisible(result
, "relatedTo", detach(result
.getHybridName(), state
));
411 // result.setFromName(detache(result.getFromName()));
412 // result.setToName(detache(result.getToName()));
413 result
.setType(detach(result
.getType(), state
));
417 protected NomenclaturalStatus
handlePersistedNomenclaturalStatus(NomenclaturalStatus status
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
418 NomenclaturalStatus result
= handlePersisted((SingleSourcedEntityBase
)status
, state
);
420 result
.setType(detach(result
.getType(), state
));
424 protected TypeDesignationBase
handlePersisted(TypeDesignationBase designation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
425 TypeDesignationBase result
= handlePersisted((SourcedEntityBase
)designation
, state
);
427 handleCollection(result
, TypeDesignationBase
.class, "registrations", Registration
.class, state
);
428 handleCollection(result
, TypeDesignationBase
.class, "typifiedNames", TaxonName
.class, state
);
432 protected <T
extends TypeDesignationBase
> T
handlePersistedNameOrSpecimenTypeDesignation(T designation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
433 T result
= (T
)handlePersisted(designation
, state
);
435 result
.setDesignationSource(detach(result
.getDesignationSource(), state
));
436 result
.setTypeStatus(detach(result
.getTypeStatus(), state
));
440 protected NameTypeDesignation
handlePersistedNameTypeDesignation(NameTypeDesignation designation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
441 NameTypeDesignation result
= handlePersistedNameOrSpecimenTypeDesignation(designation
, state
);
443 result
.setTypeName(detach(result
.getTypeName(), state
));
447 protected SpecimenTypeDesignation
handlePersistedSpecimenTypeDesignation(SpecimenTypeDesignation designation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
448 SpecimenTypeDesignation result
= handlePersistedNameOrSpecimenTypeDesignation(designation
, state
);
450 result
.setTypeSpecimen(detach(result
.getTypeSpecimen(), state
));
454 protected TextualTypeDesignation
handlePersistedTextualTypeDesignation(TextualTypeDesignation designation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
455 TextualTypeDesignation result
= (TextualTypeDesignation
)handlePersisted(designation
, state
);
457 handleMap(result
, TextualTypeDesignation
.class, "text", Language
.class, LanguageString
.class, state
);
461 protected InstitutionalMembership
handlePersistedInstitutionalMembership(InstitutionalMembership institutionalMembership
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
462 InstitutionalMembership result
= handlePersisted((VersionableEntity
)institutionalMembership
, state
);
464 // result.setPerson(detache(result.getPerson()));
465 setInvisible(result
, "person", detach(result
.getPerson(), state
));
466 result
.setInstitute(detach(result
.getInstitute(), state
));
470 protected Institution
handlePersistedInstitution(Institution institution
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
471 Institution result
= handlePersisted((AgentBase
)institution
, state
);
473 result
.setIsPartOf(detach(result
.getIsPartOf(), state
));
474 handleCollection(result
, Institution
.class, "types", DefinedTerm
.class, state
);
478 protected TaxonNodeAgentRelation
handlePersistedTaxonNodeAgentRelation(TaxonNodeAgentRelation nodeAgentRel
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
479 TaxonNodeAgentRelation result
= handlePersisted((AnnotatableEntity
)nodeAgentRel
, state
);
481 result
.setAgent(detach(result
.getAgent(), state
));
482 result
.setType(detach(result
.getType(), state
));
483 setInvisible(result
, "taxonNode", detach(result
.getTaxonNode(), state
));
488 protected TaxonName
handlePersistedTaxonName(TaxonName taxonName
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
489 @SuppressWarnings("rawtypes")
490 TaxonName result
= handlePersisted((IdentifiableEntity
)taxonName
, state
);
492 result
.setRank(detach(result
.getRank(), state
));
493 result
.setCombinationAuthorship(detach(result
.getCombinationAuthorship(), state
));
494 result
.setExCombinationAuthorship(detach(result
.getExCombinationAuthorship(), state
));
495 result
.setBasionymAuthorship(detach(result
.getBasionymAuthorship(), state
));
496 result
.setExBasionymAuthorship(detach(result
.getExBasionymAuthorship(), state
));
497 result
.setInBasionymAuthorship(detach(result
.getInBasionymAuthorship(), state
));
498 result
.setInCombinationAuthorship(detach(result
.getInCombinationAuthorship(), state
));
500 // result.setNomenclaturalReference(detach(result.getNomenclaturalReference(), state));
501 result
.setNomenclaturalSource(detach(result
.getNomenclaturalSource(), state
));
502 result
.setHomotypicalGroup(detach(result
.getHomotypicalGroup(), state
));
503 handleCollection(result
, TaxonName
.class, "descriptions", TaxonNameDescription
.class, state
);
504 handleCollection(result
, TaxonName
.class, "hybridChildRelations", HybridRelationship
.class, state
);
505 handleCollection(result
, TaxonName
.class, "hybridParentRelations", HybridRelationship
.class, state
);
506 handleCollection(result
, TaxonName
.class, "relationsFromThisName", NameRelationship
.class, state
);
507 handleCollection(result
, TaxonName
.class, "relationsToThisName", NameRelationship
.class, state
);
508 handleCollection(result
, TaxonName
.class, "status", NomenclaturalStatus
.class, state
);
510 handleCollection(result
, TaxonName
.class, "registrations", Registration
.class, state
);
511 handleCollection(result
, TaxonName
.class, "typeDesignations", TypeDesignationBase
.class, state
);
513 handleCollection(result
, TaxonName
.class, "taxonBases", TaxonBase
.class, state
);
518 protected HomotypicalGroup
handlePersistedHomotypicalGroup(HomotypicalGroup group
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
519 HomotypicalGroup result
= handlePersisted((AnnotatableEntity
)group
, state
);
521 handleCollection(result
, HomotypicalGroup
.class, "typifiedNames", TaxonName
.class, state
);
525 protected Annotation
handlePersistedAnnotation(Annotation annotation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
526 Annotation result
= handlePersisted((AnnotatableEntity
)annotation
, state
);
528 result
.setAnnotationType(detach(annotation
.getAnnotationType(), state
));
529 result
.setCommentator(detach(result
.getCommentator(), state
));
530 handleCollection(result
, Annotation
.class, "intextReferences", IntextReference
.class, state
);
534 protected Extension
handlePersistedExtension(Extension extension
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
535 Extension result
= handlePersisted((VersionableEntity
)extension
, state
);
537 result
.setType(detach(extension
.getType(), state
));
541 protected Marker
handlePersistedMarker(Marker marker
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
542 Marker result
= handlePersisted((VersionableEntity
)marker
, state
);
544 result
.setMarkerType(detach(marker
.getMarkerType(), state
));
548 protected Team
handlePersistedTeam(Team team
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
549 Team result
= handlePersisted((TeamOrPersonBase
)team
, state
);
551 handleCollection(result
, Team
.class, "teamMembers", Person
.class, state
);
555 protected Contact
handlePersistedContact(Contact contact
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
556 Contact result
= contact
; // getTarget(contact);
560 if (!contact
.getAddresses().isEmpty() || !contact
.getEmailAddresses().isEmpty()
561 || !contact
.getFaxNumbers().isEmpty() ||!contact
.getPhoneNumbers().isEmpty()
562 ||!contact
.getUrls().isEmpty()){
563 logger
.warn("Addresses not yet implemented");
565 setInvisible(result
, "addresses", new HashSet
<>());
566 // handleCollection(result, Contact.class, "", Address.class);
567 setInvisible(result
, "faxNumbers", new ArrayList
<>());
568 setInvisible(result
, "phoneNumbers", new ArrayList
<>());
569 setInvisible(result
, "emailAddresses", new ArrayList
<>());
570 setInvisible(result
, "urls", new ArrayList
<>());
574 protected Person
handlePersistedPerson(Person person
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
575 Person result
= handlePersisted((TeamOrPersonBase
)person
, state
);
577 handleCollection(result
, Person
.class, "institutionalMemberships", InstitutionalMembership
.class, state
);
581 protected NamedArea
handlePersistedNamedArea(NamedArea area
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
582 NamedArea result
= handlePersisted((OrderedTermBase
)area
, state
);
584 handleCollection(result
, NamedArea
.class, "countries", Country
.class, state
);
585 result
.setLevel(detach(result
.getLevel(), state
));
586 result
.setType(detach(result
.getType(), state
));
587 result
.setShape(detach(result
.getShape(), state
));
591 protected Classification
handlePersistedClassification(Classification classification
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
592 Classification result
= handlePersisted((IdentifiableEntity
)classification
, state
);
594 result
.setName(detach(classification
.getName(), state
));
595 result
.setSource(detach(classification
.getSource(), state
));
596 result
.setRootNode(detach(classification
.getRootNode(), state
));
597 handleCollection(result
, Classification
.class, "geoScopes", NamedArea
.class, state
);
598 handleMap(result
, Classification
.class, "description", Language
.class, LanguageString
.class, state
);
602 protected Reference
handlePersistedReference(Reference reference
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
603 Reference result
= handlePersisted((IdentifiableMediaEntity
)reference
, state
);
604 result
.setAuthorship(detach(result
.getAuthorship(), state
));
605 result
.setInstitution(detach(result
.getInstitution(), state
));
606 result
.setSchool(detach(result
.getSchool(), state
));
607 result
.setInReference(detach(result
.getInReference(), state
));
611 protected SpecimenOrObservationBase
<?
> handlePersistedSpecimenOrObservationBase(SpecimenOrObservationBase specimen
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
612 //TODO implement for classes
613 SpecimenOrObservationBase
<?
> result
= handlePersisted((IdentifiableEntity
)specimen
, state
);
615 result
.setSex(detach(result
.getSex(), state
));
616 result
.setLifeStage(detach(result
.getLifeStage(), state
));
617 result
.setKindOfUnit(detach(result
.getKindOfUnit(), state
));
618 handleCollection(result
, SpecimenOrObservationBase
.class, "determinations", DeterminationEvent
.class, state
);
619 handleCollection(result
, SpecimenOrObservationBase
.class, "descriptions", SpecimenDescription
.class, state
);
620 handleCollection(result
, SpecimenOrObservationBase
.class, "derivationEvents", DerivationEvent
.class, state
);
621 handleMap(result
, SpecimenOrObservationBase
.class, "definition", Language
.class, LanguageString
.class, state
);
625 protected IdentifiableSource
handlePersistedIdentifiableSource(IdentifiableSource source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
626 IdentifiableSource result
= handlePersisted((OriginalSourceBase
)source
, state
);
631 protected <T
extends NamedSourceBase
> T
handlePersisted(NamedSourceBase source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
632 T result
= handlePersisted((OriginalSourceBase
)source
, state
);
634 result
.setNameUsedInSource(detach(result
.getNameUsedInSource(), state
));
638 protected NamedSource
handlePersistedNamedSource(NamedSource source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
639 NamedSource result
= handlePersisted((NamedSourceBase
)source
, state
);
644 protected NomenclaturalSource
handlePersistedNomenclaturalSource(NomenclaturalSource source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
645 NomenclaturalSource result
= handlePersisted((NamedSourceBase
)source
, state
);
647 result
.setSourcedName(detach(result
.getSourcedName(), state
));
651 protected SecundumSource
handlePersistedSecundumSource(SecundumSource source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
652 SecundumSource result
= handlePersisted((NamedSourceBase
)source
, state
);
654 result
.setSourcedTaxon(detach(result
.getSourcedTaxon(), state
));
658 protected DescriptionElementSource
handlePersistedDescriptionElementSource(DescriptionElementSource source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
659 DescriptionElementSource result
= handlePersisted((NamedSourceBase
)source
, state
);
661 detach(result
.getSourcedElement(), state
).addSource(result
);
665 protected <T
extends CommonTaxonName
> T
handlePersistedCommonTaxonName(CommonTaxonName element
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
666 T result
= handlePersisted((DescriptionElementBase
)element
, state
);
668 result
.setLanguage(detach(result
.getLanguage(), state
));
669 result
.setArea(detach(result
.getArea(), state
));
673 protected <T
extends TextData
> T
handlePersistedTextData(TextData element
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
674 T result
= handlePersisted((DescriptionElementBase
)element
, state
);
676 result
.setFormat(detach(result
.getFormat(), state
));
677 handleMap(result
, TextData
.class, "multilanguageText", Language
.class, LanguageString
.class, state
);
681 protected <T
extends Distribution
> T
handlePersistedDistribution(Distribution element
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
682 T result
= handlePersisted((DescriptionElementBase
)element
, state
);
684 result
.setArea(detach(result
.getArea(), state
));
685 result
.setStatus(detach(result
.getStatus(), state
));
689 protected <T
extends TaxonInteraction
> T
handlePersistedTaxonInteraction(TaxonInteraction element
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
690 T result
= handlePersisted((DescriptionElementBase
)element
, state
);
692 handleMap(result
, TaxonInteraction
.class, "description", Language
.class, LanguageString
.class, state
);
693 result
.setTaxon2(detach(result
.getTaxon2(), state
));
697 protected ExternalLink
handlePersistedExternalLink(ExternalLink externalLink
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
698 ExternalLink result
= handlePersisted((VersionableEntity
)externalLink
, state
);
700 handleMap(result
, ExternalLink
.class, "description", Language
.class, LanguageString
.class, state
);
704 protected Feature
handlePersistedFeature(Feature term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
705 Feature result
= handlePersisted((DefinedTermBase
)term
, state
);
707 handleCollection(result
, Feature
.class, "inverseRepresentations", Representation
.class, state
);
708 handleCollection(result
, Feature
.class, "recommendedMeasurementUnits", MeasurementUnit
.class, state
);
709 handleCollection(result
, Feature
.class, "recommendedModifierEnumeration", TermVocabulary
.class, state
);
710 handleCollection(result
, Feature
.class, "recommendedStatisticalMeasures", StatisticalMeasure
.class, state
);
711 handleCollection(result
, Feature
.class, "supportedCategoricalEnumerations", TermVocabulary
.class, state
);
715 protected ExtensionType
handlePersistedExtensionType(ExtensionType term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
716 ExtensionType result
= handlePersisted((DefinedTermBase
)term
, state
);
721 protected MarkerType
handlePersistedMarkerType(MarkerType term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
722 MarkerType result
= handlePersisted((DefinedTermBase
)term
, state
);
727 protected NomenclaturalStatusType
handlePersistedNomenclaturalStatusType(NomenclaturalStatusType term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
728 NomenclaturalStatusType result
= handlePersisted((OrderedTermBase
)term
, state
);
733 protected DefinedTerm
handlePersistedDefinedTerm(DefinedTerm term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
734 DefinedTerm result
= handlePersisted((DefinedTermBase
)term
, state
);
739 //placeholder for not implemented methods for subclasses
740 protected DefinedTermBase
<?
> handlePersistedTerm(DefinedTermBase term
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
741 DefinedTermBase
<?
> result
= handlePersisted(term
, state
);
742 logger
.warn("Class not yet handled: " + term
.getClass().getSimpleName());
746 protected TermVocabulary
<?
> handlePersistedVocabulary(TermVocabulary voc
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
747 TermVocabulary
<?
> result
= (TermVocabulary
<?
>)handlePersisted((TermCollection
)voc
, state
);
748 handleCollection(result
, TermVocabulary
.class, "terms", DefinedTermBase
.class, state
);
752 protected TermTree
<?
> handlePersistedTermTree(TermTree tree
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
753 //TODO TermGraphBase is still missing
754 TermTree
<?
> result
= (TermTree
<?
>)handlePersisted((TermCollection
)tree
, state
);
756 result
.getRoot().setUuid(tree
.getRoot().getUuid());
760 protected TermNode
<?
> handlePersistedTermNode(TermNode node
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
761 TermNode
<?
> result
= (TermNode
<?
>)handlePersisted((TermRelationBase
)node
, state
);
763 setInvisible(result
, "parent", detach(result
.getParent(), state
));
764 handleCollection(result
, TermNode
.class, "inapplicableIf", FeatureState
.class, state
);
765 handleCollection(result
, TermNode
.class, "onlyApplicableIf", FeatureState
.class, state
);
766 handleCollection(result
, TermNode
.class, "children", TermNode
.class, state
);
771 protected Representation
handlePersistedRepresentation(Representation representation
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
772 Representation result
= (Representation
)handlePersisted((LanguageStringBase
)representation
, state
);
776 protected <T
extends TermBase
> T
handlePersisted(TermBase termBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
777 T result
= handlePersisted((IdentifiableEntity
)termBase
, state
);
779 handleCollection(result
, TermBase
.class, "representations", Representation
.class, state
);
783 protected <T
extends TermCollection
> T
handlePersisted(TermCollection termCollection
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
784 T result
= handlePersisted((TermBase
)termCollection
, state
);
786 handleCollection(result
, TermCollection
.class, "termRelations", TermRelationBase
.class, state
);
790 protected <T
extends TermRelationBase
> T
handlePersisted(TermRelationBase termRelationBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
791 T result
= handlePersisted((VersionableEntity
)termRelationBase
, state
);
792 result
.setTerm(detach(result
.getTerm(), state
));
793 setInvisible(result
, TermRelationBase
.class, "graph", detach(result
.getGraph(), state
));
797 protected User
handlePersistedUser(User user
, Cdm2CdmImportState state
) throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
, InvocationTargetException
, NoSuchMethodException
{
798 User result
= (User
)handlePersistedCdmBase(user
, state
);
799 if (result
.getUsername().equals("admin")){
800 //TODO why only admin, is this not a problem for all duplicated usernames? Was this a preliminary decision?
801 result
= getUserService().listByUsername("admin", MatchMode
.EXACT
, null, null, null, null, null).iterator().next();
802 state
.putPermanent(user
.getUuid(), result
);
803 cache(result
, state
); //necessary?
804 state
.addToSave(result
);
805 state
.removeToSave(user
);
807 if (!result
.isPersited()){
808 result
.setAuthorities(new HashSet
<>());
809 result
.setGrantedAuthorities(new HashSet
<>());
810 setInvisible(result
, "groups", new HashSet
<>());
812 result
.setPerson(detach(user
.getPerson(), state
));
817 protected LanguageString
handlePersistedLanguageString(LanguageString languageString
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
818 LanguageString result
= handlePersisted((LanguageStringBase
)languageString
, state
);
820 handleCollection(result
, LanguageString
.class, "intextReferences", IntextReference
.class, state
);
824 protected Rights
handlePersistedRights(Rights rights
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
825 Rights result
= handlePersisted((LanguageStringBase
)rights
, state
);
826 result
.setAgent(detach(rights
.getAgent(), state
));
827 result
.setType(detach(rights
.getType(), state
));
832 protected IntextReference
handlePersistedIntextReference(IntextReference intextReference
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
833 IntextReference result
= handlePersisted((VersionableEntity
)intextReference
, state
);
834 result
.setReferencedEntity(detach(result
.getReferencedEntity(), false, state
));
835 Method targetMethod
= IntextReference
.class.getDeclaredMethod("setTarget", IIntextReferenceTarget
.class);
836 targetMethod
.setAccessible(true);
837 targetMethod
.invoke(result
, detach(result
.getTarget(), false, state
));
841 protected <T
extends TaxonDescription
> T
handlePersistedTaxonDescription(TaxonDescription taxDescription
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
842 T result
= handlePersisted((DescriptionBase
)taxDescription
, state
);
844 setInvisible(taxDescription
, "taxon", detach(taxDescription
.getTaxon(), state
));
845 handleCollection(taxDescription
, TaxonDescription
.class, "geoScopes", NamedArea
.class, state
);
846 handleCollection(taxDescription
, TaxonDescription
.class, "scopes", DefinedTerm
.class, state
);
850 protected <T
extends TaxonDescription
> T
handlePersistedTaxonNameDescription(TaxonNameDescription nameDescription
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
851 T result
= handlePersisted((DescriptionBase
)nameDescription
, state
);
853 setInvisible(nameDescription
, "taxonName", detach(nameDescription
.getTaxonName(), state
));
858 // ***************************** BASE CLASSES ********************************************/
860 protected <T
extends CdmBase
> T
handlePersistedCdmBase(CdmBase cdmBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
861 @SuppressWarnings("unchecked")
862 T result
= (T
)getTarget(cdmBase
, state
);
864 cdmBase
.setCreatedBy(makeCreatedUpdatedBy(cdmBase
.getCreatedBy(), state
, false));
868 protected <T
extends VersionableEntity
> T
handlePersisted(VersionableEntity entity
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
869 @SuppressWarnings("unchecked")
870 T result
= (T
)handlePersistedCdmBase((CdmBase
)entity
, state
);
872 entity
.setUpdatedBy(makeCreatedUpdatedBy(entity
.getUpdatedBy(), state
, true));
876 protected <T
extends AnnotatableEntity
> T
handlePersisted(AnnotatableEntity entity
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
877 T result
= handlePersisted((VersionableEntity
)entity
, state
);
879 handleCollection(result
, AnnotatableEntity
.class, "annotations", Annotation
.class, state
);
880 handleCollection(result
, AnnotatableEntity
.class, "markers", Marker
.class, state
);
884 protected <T
extends SourcedEntityBase
<?
>> T
handlePersisted(SourcedEntityBase sourcedEntity
,
885 Cdm2CdmImportState state
)
886 throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
887 int originalId
= sourcedEntity
.getId();
888 T result
= handlePersisted((AnnotatableEntity
)sourcedEntity
, state
);
890 handleCollection(result
, SourcedEntityBase
.class, "sources", OriginalSourceBase
.class, state
);
891 if (!result
.isPersited()){
892 if(state
.getConfig().isRemoveImportSources()){
893 filterImportSources(result
.getSources());
895 if (state
.getConfig().isAddSources()){
896 Reference sourceRef
= getSourceReference(state
);
897 OriginalSourceBase newSource
= result
.addImportSource(String
.valueOf(originalId
), sourcedEntity
.getClass().getSimpleName(),
899 getCommonService().save(newSource
);
900 addExistingObject(newSource
, state
);
909 private void filterImportSources(Set
<?
extends OriginalSourceBase
> sources
) {
910 Set
<OriginalSourceBase
> toDelete
= new HashSet
<>();
911 for (OriginalSourceBase osb
: sources
){
912 if (osb
.getType() == OriginalSourceType
.Import
){
916 for (OriginalSourceBase osb
: toDelete
){
921 protected <T
extends IdentifiableEntity
> T
handlePersisted(IdentifiableEntity identifiableEntity
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
922 T result
= handlePersisted((SourcedEntityBase
)identifiableEntity
, state
);
924 handleCollection(result
, IdentifiableEntity
.class, "credits", Credit
.class, state
);
925 handleCollection(result
, IdentifiableEntity
.class, "extensions", Extension
.class, state
);
926 handleCollection(result
, IdentifiableEntity
.class, "identifiers", Identifier
.class, state
);
927 handleCollection(result
, IdentifiableEntity
.class, "rights", Rights
.class, state
);
928 handleCollection(result
, IdentifiableEntity
.class, "links", ExternalLink
.class, state
);
933 protected <T
extends DefinedTermBase
> T
handlePersisted(DefinedTermBase definedTermBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
934 T result
= handlePersisted((TermBase
)definedTermBase
, state
);
936 handleCollection(result
, DefinedTermBase
.class, "media", Media
.class, state
);
937 handleCollection(result
, DefinedTermBase
.class, "generalizationOf", DefinedTermBase
.class, state
);
938 handleCollection(result
, DefinedTermBase
.class, "includes", DefinedTermBase
.class, state
);
939 result
.setKindOf(detach(result
.getKindOf(), state
));
940 result
.setPartOf(detach(result
.getPartOf(), state
));
941 setInvisible(result
, DefinedTermBase
.class, "vocabulary", detach(result
.getVocabulary(), state
));
946 protected <T
extends AvailableForTermBase
> T
handlePersisted(AvailableForTermBase availableForTermBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
947 T result
= handlePersisted((DefinedTermBase
)availableForTermBase
, state
);
952 protected <T
extends OriginalSourceBase
> T
handlePersisted(OriginalSourceBase source
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
953 T result
= handlePersisted((AnnotatableEntity
)source
, state
);
955 result
.setCitation(detach(result
.getCitation(), state
));
956 handleCollection(result
, OriginalSourceBase
.class, "links", ExternalLink
.class, state
);
960 protected <T
extends LanguageStringBase
> T
handlePersisted(LanguageStringBase lsBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
961 T result
= handlePersisted((AnnotatableEntity
)lsBase
, state
);
963 result
.setLanguage(detach(lsBase
.getLanguage(), state
));
967 protected <T
extends TeamOrPersonBase
> T
handlePersisted(TeamOrPersonBase teamOrPerson
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
968 T result
= handlePersisted((AgentBase
)teamOrPerson
, state
);
973 protected <T
extends AgentBase
> T
handlePersisted(AgentBase agent
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
974 T result
= handlePersisted((IdentifiableMediaEntity
)agent
, state
);
975 result
.setContact(detach(result
.getContact(), state
));
980 protected <T
extends TaxonBase
> T
handlePersisted(TaxonBase taxonBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
981 T result
= handlePersisted((IdentifiableEntity
)taxonBase
, state
);
983 result
.setName(detach(taxonBase
.getName(), state
));
984 result
.setSecSource(detach(taxonBase
.getSecSource(), state
));
988 protected <T
extends IdentifiableMediaEntity
> T
handlePersisted(IdentifiableMediaEntity mediaEntity
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
989 T result
= handlePersisted((IdentifiableEntity
)mediaEntity
, state
);
991 handleCollection(result
, IdentifiableMediaEntity
.class, "media", Media
.class, state
);
995 protected <T
extends SingleSourcedEntityBase
> T
handlePersisted(SingleSourcedEntityBase referencedEntity
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
996 T result
= handlePersisted((AnnotatableEntity
)referencedEntity
, state
);
998 result
.setSource(detach(result
.getSource(), state
));
1002 protected <T
extends DescriptionBase
> T
handlePersisted(DescriptionBase descriptionBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1003 T result
= handlePersisted((IdentifiableEntity
)descriptionBase
, state
);
1005 handleCollection(result
, DescriptionBase
.class, "descriptionElements", DescriptionElementBase
.class, state
);
1006 handleCollection(result
, DescriptionBase
.class, "descriptiveDataSets", DescriptiveDataSet
.class, state
);
1007 handleCollection(result
, DescriptionBase
.class, "descriptionSources", Reference
.class, state
);
1008 result
.setDescribedSpecimenOrObservation(detach(descriptionBase
.getDescribedSpecimenOrObservation(), state
));
1012 protected <T
extends DescriptionElementBase
> T
handlePersisted(DescriptionElementBase element
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1013 T result
= handlePersisted((AnnotatableEntity
)element
, state
);
1015 result
.setFeature(detach(result
.getFeature(), state
));
1016 setInvisible(result
, DescriptionElementBase
.class, "inDescription", detach(result
.getInDescription(), state
));
1017 handleCollection(result
, DescriptionElementBase
.class, "sources", DescriptionElementSource
.class, state
);
1018 handleCollection(result
, DescriptionElementBase
.class, "media", Media
.class, state
);
1019 handleCollection(result
, DescriptionElementBase
.class, "modifiers", DefinedTerm
.class, state
);
1020 handleMap(result
, DescriptionElementBase
.class, "modifyingText", Language
.class, LanguageString
.class, state
);
1025 protected <T
extends RelationshipBase
> T
handlePersisted(RelationshipBase relBase
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1026 T result
= handlePersisted((SingleSourcedEntityBase
)relBase
, state
);
1031 //************************** COLLECTIONS / MAPS ****************************************/
1033 protected <HOLDER
extends CdmBase
, ITEM
extends CdmBase
> void handleCollection(
1034 HOLDER holder
, Class
<?
super HOLDER
> declaringClass
, String parameter
, Class
<ITEM
> itemClass
,
1035 Cdm2CdmImportState state
)
1036 throws NoSuchFieldException
, IllegalAccessException
, InvocationTargetException
, NoSuchMethodException
{
1038 Collection
<ITEM
> oldCollection
= setNewCollection(holder
, declaringClass
, parameter
, itemClass
);
1039 Collection
<ITEM
> newCollection
= getTargetCollection(itemClass
, oldCollection
, state
);
1040 Field field
= declaringClass
.getDeclaredField(parameter
);
1041 field
.setAccessible(true);
1042 field
.set(holder
, newCollection
);
1045 protected <HOLDER
extends CdmBase
, KEY
extends CdmBase
, ITEM
extends CdmBase
>
1047 HOLDER holder
, Class
<?
super HOLDER
> declaringClass
, String parameter
,
1048 Class
<KEY
> keyClass
, Class
<ITEM
> itemClass
, Cdm2CdmImportState state
)
1049 throws NoSuchFieldException
, IllegalAccessException
, InvocationTargetException
, NoSuchMethodException
{
1051 //TODO we do not need to set the new map 2x
1052 Map
<KEY
,ITEM
> oldMap
= setNewMap(holder
, declaringClass
, parameter
, keyClass
, itemClass
);
1053 Map
<KEY
,ITEM
> newMap
= getTargetMap(oldMap
, state
);
1054 Field field
= declaringClass
.getDeclaredField(parameter
);
1055 field
.setAccessible(true);
1056 field
.set(holder
, newMap
);
1059 protected <T
extends CdmBase
> Collection
<T
> setNewCollection(CdmBase obj
, Class
<?
> holderClass
,
1060 String parameter
, Class
<T
> entityClass
) throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
1061 Field field
= holderClass
.getDeclaredField(parameter
);
1062 field
.setAccessible(true);
1063 Collection
<T
> oldValue
= (Collection
<T
>)field
.get(obj
);
1064 Collection
<T
> newValue
= null;
1065 if (Set
.class.isAssignableFrom(field
.getType())){
1066 newValue
= new HashSet
<>();
1067 }else if (List
.class.isAssignableFrom(field
.getType())){
1068 newValue
= new ArrayList
<>();
1070 throw new RuntimeException("Unsupported collection type: " + field
.getType().getCanonicalName());
1072 field
.set(obj
, newValue
);
1076 protected <KEY
extends CdmBase
, ITEM
extends CdmBase
> Map
<KEY
,ITEM
> setNewMap(CdmBase obj
, Class
<?
> holderClass
,
1077 String parameter
, Class
<KEY
> keyClass
, Class
<ITEM
> itemClass
) throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
1078 Field field
= holderClass
.getDeclaredField(parameter
);
1079 field
.setAccessible(true);
1080 Map
<KEY
,ITEM
> oldValue
= (Map
<KEY
,ITEM
>)field
.get(obj
);
1081 Map
<KEY
,ITEM
> newValue
= null;
1082 if (Map
.class.isAssignableFrom(field
.getType())){
1083 newValue
= new HashMap
<>();
1085 throw new RuntimeException("Unsupported map type: " + field
.getType().getCanonicalName());
1087 field
.set(obj
, newValue
);
1092 private <T
extends Collection
<S
>, S
extends CdmBase
> Collection
<S
> getTargetCollection(
1093 Class
<S
> clazz
, T sourceCollection
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1094 Collection
<S
> result
= new ArrayList
<>();
1095 if (Set
.class.isAssignableFrom(sourceCollection
.getClass())){
1096 result
= new HashSet
<>();
1098 for (S entity
: sourceCollection
){
1099 S target
= detach(entity
, state
);
1105 private <K
extends CdmBase
, V
extends CdmBase
> Map
<K
,V
> getTargetMap(Map
<K
,V
> sourceMap
, Cdm2CdmImportState state
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1106 Map
<K
,V
> result
= new HashMap
<>();
1107 for (K key
: sourceMap
.keySet()){
1108 K targetKey
= detach(key
, state
);
1109 V targetValue
= detach(sourceMap
.get(key
), state
);
1110 result
.put(targetKey
, targetValue
);
1115 // ****************************** USER HANDLING
1117 private User
makeCreatedUpdatedBy(User createdByOriginal
, Cdm2CdmImportState state
, boolean isUpdatedBy
) throws IllegalAccessException
, InvocationTargetException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, NoSuchMethodException
{
1118 UserImportMode mode
= isUpdatedBy? state
.getConfig().getUpdatedByMode() : state
.getConfig().getCreatedByMode();
1124 return detach(createdByOriginal
, state
);
1126 logger
.warn("Mode not yet supported: " + mode
);
1132 // ****************************** INVISIBLE **************************************/
1134 protected void setInvisible(Object holder
, String fieldName
, Object value
) throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
1135 setInvisible(holder
, holder
.getClass(), fieldName
, value
);
1137 protected void setInvisible(Object holder
, Class
<?
> holderClazz
, String fieldName
, Object value
) throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
1138 Field field
= holderClazz
.getDeclaredField(fieldName
);
1139 field
.setAccessible(true);
1140 field
.set(holder
, value
);
1143 // ************************* GET TARGET ******************************************/
1146 //TODO this should be cached for partition
1147 private <T
extends CdmBase
> T
getTarget(T source
, Cdm2CdmImportState state
) {
1148 if (source
== null){
1151 T result
= getCached(source
, state
);
1152 // if (result == null){
1153 // Class<T> clazz = (Class<T>)source.getClass();
1154 // result = getCommonService().find(clazz, source.getUuid());
1156 if (result
== null){
1157 //Alternative: clone?
1158 result
= CdmBase
.deproxy(source
);
1160 cache(result
, state
);
1161 state
.addToSave(result
);
1166 // ******************* CACHE *******************************************************/
1168 protected void cache(CdmBase cdmBase
, Cdm2CdmImportState state
) {
1169 if (cdmBase
instanceof User
|| cdmBase
instanceof DefinedTermBase
){
1170 state
.putPermanent(cdmBase
.getUuid(), cdmBase
);
1172 state
.putToSessionCache(cdmBase
);
1174 addExistingObject(cdmBase
, state
);
1177 private void addExistingObject(CdmBase cdmBase
, Cdm2CdmImportState state
) {
1178 cdmBase
= CdmBase
.deproxy(cdmBase
);
1179 Set
<UUID
> set
= state
.getExistingObjects(cdmBase
.getClass());
1181 set
= loadExistingUuids(cdmBase
.getClass(), state
);
1182 // set = new HashSet<>();
1183 // existingObjects.put(cdmBase.getClass(), set);
1185 set
.add(cdmBase
.getUuid());
1188 protected boolean isInCache(CdmBase cdmBase
, Cdm2CdmImportState state
) {
1189 return getCached(cdmBase
, state
) != null;
1192 protected <T
extends CdmBase
> T
getCached(T cdmBase
, Cdm2CdmImportState state
) {
1193 T result
= (T
)state
.getFromSessionCache(cdmBase
.getUuid());
1194 if (result
== null){
1195 result
= (T
)state
.getPermanent(cdmBase
.getUuid());
1200 protected void clearCache(Cdm2CdmImportState state
) {
1201 state
.clearSessionCache();
1204 private Reference
getSourceReference(Cdm2CdmImportState state
) {
1205 UUID uuid
= state
.getConfig().getSourceRefUuid();
1206 if (uuid
== null && state
.getConfig().getSourceReference() != null){
1207 uuid
= state
.getConfig().getSourceReference().getUuid();
1208 state
.getConfig().setSourceRefUuid(uuid
);
1210 Reference result
= (Reference
)state
.getFromSessionCache(uuid
);
1211 if (result
== null){
1212 result
= (Reference
)state
.getPermanent(uuid
);
1214 if (result
== null){
1215 result
= getReferenceService().find(uuid
);
1218 if (result
== null){
1219 result
= state
.getConfig().getSourceReference();
1220 if (result
== null){
1221 result
= ReferenceFactory
.newDatabase();
1223 result
.setTitle("Cdm2Cdm Import");
1225 getReferenceService().save(result
);
1226 state
.putToSessionCache(result
);
1232 protected ITaxonNodeOutStreamPartitioner
getTaxonNodePartitioner(Cdm2CdmImportState state
, IProgressMonitor monitor
,
1233 Cdm2CdmImportConfigurator config
) {
1234 ITaxonNodeOutStreamPartitioner partitioner
= config
.getPartitioner();
1235 if (partitioner
== null){
1236 if(!config
.isConcurrent()){
1237 partitioner
= TaxonNodeOutStreamPartitioner
.NewInstance(sourceRepo(state
), state
,
1238 state
.getConfig().getTaxonNodeFilter(), 100,
1239 monitor
, 1, TaxonNodeOutStreamPartitioner
.fullPropertyPaths
);
1240 ((TaxonNodeOutStreamPartitioner
)partitioner
).setLastCommitManually(true);
1242 partitioner
= TaxonNodeOutStreamPartitionerConcurrent
1243 .NewInstance(state
.getConfig().getSource(), state
.getConfig().getTaxonNodeFilter(),
1244 1000, monitor
, 1, TaxonNodeOutStreamPartitioner
.fullPropertyPaths
);