Revision 38672714
Added by Andreas Müller over 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/FauEu2CdmActivator.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.app.pesi; |
10 | 10 |
|
11 |
import java.util.Calendar; |
|
11 | 12 |
import java.util.UUID; |
12 | 13 |
|
13 | 14 |
import org.apache.log4j.Logger; |
... | ... | |
23 | 24 |
import eu.etaxonomy.cdm.io.common.TaxonNodeOutStreamPartitioner; |
24 | 25 |
import eu.etaxonomy.cdm.io.common.TaxonNodeOutStreamPartitionerConcurrent; |
25 | 26 |
import eu.etaxonomy.cdm.io.pesi.fauEu2Cdm.FauEu2CdmImportConfigurator; |
27 |
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod; |
|
28 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
29 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
26 | 30 |
|
27 | 31 |
/** |
28 | 32 |
* @author a.mueller |
... | ... | |
34 | 38 |
private static final Logger logger = Logger.getLogger(FauEu2CdmActivator.class); |
35 | 39 |
|
36 | 40 |
static final ICdmDataSource fauEuSource = CdmDestinations.test_cdm_pesi_fauna_europaea(); |
37 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_pesi_leer2(); |
|
41 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_pesi_leer(); |
|
42 |
|
|
43 |
static final String sourceRefTitle = "Fauna Europaea PESI import."; |
|
44 |
static final UUID sourceRefUuid = UUID.fromString("f27a5e67-d065-4b79-8d41-eabd3ae0edd0"); |
|
38 | 45 |
|
39 | 46 |
//check - import |
40 | 47 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
... | ... | |
67 | 74 |
config.setConcurrent(doConcurrent); |
68 | 75 |
config.setDoTaxa(doTaxa); |
69 | 76 |
config.setDoDescriptions(doDescriptions); |
77 |
config.setSourceReference(getSourceRef()); |
|
70 | 78 |
|
71 | 79 |
IProgressMonitor monitor = config.getProgressMonitor(); |
72 | 80 |
|
... | ... | |
93 | 101 |
System.out.println("End" + importFrom); |
94 | 102 |
} |
95 | 103 |
|
104 |
private Reference getSourceRef() { |
|
105 |
Reference ref = ReferenceFactory.newDatabase(); |
|
106 |
ref.setTitle(sourceRefTitle); |
|
107 |
ref.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(Calendar.getInstance())); |
|
108 |
ref.setUuid(sourceRefUuid); |
|
109 |
return ref; |
|
110 |
} |
|
111 |
|
|
96 | 112 |
public static void main(String[] args) { |
97 | 113 |
ICdmDataSource cdmDB = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination; |
98 | 114 |
FauEu2CdmActivator myImport = new FauEu2CdmActivator(); |
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/fauEu2Cdm/FauEu2CdmImportBase.java | ||
---|---|---|
747 | 747 |
} |
748 | 748 |
|
749 | 749 |
protected <T extends SourcedEntityBase> T handlePersisted(SourcedEntityBase sourcedEntity) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException { |
750 |
int originalId = sourcedEntity.getId(); |
|
750 | 751 |
T result = handlePersisted((AnnotatableEntity)sourcedEntity); |
752 |
if (!result.isPersited() && getState().getConfig().isAddSources()){ |
|
753 |
result.addImportSource(String.valueOf(originalId), sourcedEntity.getClass().getSimpleName(), |
|
754 |
getSourceReference(getState()), null); |
|
755 |
} |
|
751 | 756 |
//complete |
752 | 757 |
handleCollection(result, SourcedEntityBase.class, "sources", OriginalSourceBase.class); |
753 | 758 |
return result; |
... | ... | |
1010 | 1015 |
sessionCache.clear(); |
1011 | 1016 |
} |
1012 | 1017 |
|
1018 |
private Reference getSourceReference(FauEu2CdmImportState state) { |
|
1019 |
UUID uuid = state.getConfig().getSourceRefUuid(); |
|
1020 |
if (uuid == null){ |
|
1021 |
uuid = state.getConfig().getSourceReference().getUuid(); |
|
1022 |
state.getConfig().setSourceRefUuid(uuid); |
|
1023 |
} |
|
1024 |
Reference result = (Reference)sessionCache.get(uuid); |
|
1025 |
if (result == null){ |
|
1026 |
result = (Reference)getState().getPermanent(uuid); |
|
1027 |
} |
|
1028 |
if (result == null){ |
|
1029 |
result = getReferenceService().find(uuid); |
|
1030 |
} |
|
1031 |
if (result == null){ |
|
1032 |
result = state.getConfig().getSourceReference(); |
|
1033 |
getReferenceService().save(result); |
|
1034 |
sessionCache.put(result.getUuid(), result); |
|
1035 |
} |
|
1036 |
return result; |
|
1037 |
} |
|
1038 |
|
|
1013 | 1039 |
public FauEu2CdmImportState getState() { |
1014 | 1040 |
return state; |
1015 | 1041 |
} |
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/fauEu2Cdm/FauEu2CdmImportConfigurator.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
private boolean doTaxa = true; |
34 | 34 |
private boolean doDescriptions = true; |
35 |
private boolean addSources = true; |
|
35 | 36 |
|
36 | 37 |
public static FauEu2CdmImportConfigurator NewInstance(ICdmDataSource source, ICdmDataSource destination) { |
37 | 38 |
return new FauEu2CdmImportConfigurator(source, destination); |
... | ... | |
60 | 61 |
@Override |
61 | 62 |
@Deprecated |
62 | 63 |
public Reference getSourceReference() { |
63 |
return null;
|
|
64 |
return sourceReference;
|
|
64 | 65 |
} |
65 | 66 |
|
66 | 67 |
|
... | ... | |
99 | 100 |
this.doTaxa = doTaxa; |
100 | 101 |
} |
101 | 102 |
|
102 |
|
|
103 |
public boolean isAddSources() { |
|
104 |
return addSources; |
|
105 |
} |
|
106 |
public void setAddSources(boolean addSources) { |
|
107 |
this.addSources = addSources; |
|
108 |
} |
|
103 | 109 |
} |
Also available in: Unified diff
ref #8479 add import source to FauEu2CDM/CDM-2-CDM import