42 |
42 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
43 |
43 |
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
44 |
44 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
|
45 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
45 |
46 |
import eu.etaxonomy.cdm.model.reference.Reference;
|
46 |
47 |
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
47 |
48 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
... | ... | |
54 |
55 |
public class GreeceWillingImport
|
55 |
56 |
extends SimpleExcelTaxonImport<GreeceWillingImportConfigurator>{
|
56 |
57 |
|
57 |
|
/**
|
58 |
|
*
|
59 |
|
*/
|
|
58 |
private static final String HERBARIUM_ID_NAMESPACE = "HerbariumID";
|
60 |
59 |
private static final String RDF_ID_NAMESPACE = "rdfID";
|
61 |
60 |
|
62 |
61 |
private static final long serialVersionUID = 8258914747643501550L;
|
... | ... | |
100 |
99 |
String longitude = record.get("Longitude");
|
101 |
100 |
|
102 |
101 |
String rdfId = record.get(RDF_ID_NAMESPACE);
|
|
102 |
String herbariumId = record.get(HERBARIUM_ID_NAMESPACE);
|
|
103 |
|
|
104 |
String baseOfRecords = record.get("BaseOfRecords");
|
|
105 |
String collectionCode = record.get("CollectionCode");
|
|
106 |
String institutionCode = record.get("InstitutionCode");
|
103 |
107 |
|
104 |
108 |
TimePeriod date = TimePeriodParser.parseString(collectionDate);
|
105 |
109 |
if (date.getFreeText() != null){
|
106 |
110 |
System.out.println("Date could not be parsed: " + collectionDate + "; row: " + state.getCurrentLine());
|
107 |
111 |
}
|
108 |
112 |
|
109 |
|
validate(state, "BaseOfRecords", "Specimen");
|
110 |
|
validate(state, "InstitutionCode", "BGBM");
|
111 |
|
validate(state, "CollectionCode", "B");
|
|
113 |
// validate(state, "BaseOfRecords", "Specimen");
|
|
114 |
// validate(state, "InstitutionCode", "BGBM");
|
|
115 |
// validate(state, "CollectionCode", "B");
|
112 |
116 |
validate(state, "HigherGeography", "Greece");
|
113 |
117 |
validate(state, "Country", "Greece");
|
114 |
118 |
validate(state, "CountryCode", "GR");
|
115 |
119 |
|
116 |
120 |
//not used, but validate just in case
|
117 |
121 |
validate(state, "HUH_PURL", "NULL");
|
118 |
|
validate(state, "DB", "JACQ");
|
|
122 |
// validate(state, "DB", "JACQ");
|
119 |
123 |
validate(state, "CollDateISO", collectionDate);
|
120 |
124 |
|
121 |
125 |
// validate(state, "HerbariumID", collectionDate);
|
... | ... | |
125 |
129 |
// HTML_URI
|
126 |
130 |
|
127 |
131 |
|
128 |
|
DerivedUnit lastDerivedUnit = null;
|
129 |
|
if (collectorNumber.equals(lastCollectorNumber)){
|
130 |
|
lastDerivedUnit = (DerivedUnit)getOccurrenceService().find(lastDerivedUnitUuid);
|
131 |
|
}
|
132 |
|
|
133 |
|
|
134 |
132 |
Reference sourceReference = getSourceReference(state);
|
135 |
133 |
|
136 |
134 |
Taxon taxon = getTaxonByName(state, scientificName);
|
137 |
135 |
verifyTaxon(state, taxon, record);
|
138 |
136 |
if (taxon == null){
|
139 |
137 |
System.out.println("Taxon not found for " + scientificName + "; row: " + state.getCurrentLine());
|
140 |
|
// return;
|
141 |
|
taxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), getSourceReference(state));
|
142 |
|
taxon.getName().setTitleCache(title, true);
|
|
138 |
if (!state.getConfig().isH2()){
|
|
139 |
return;
|
|
140 |
}else{
|
|
141 |
taxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), getSourceReference(state));
|
|
142 |
taxon.getName().setTitleCache(title, true);
|
|
143 |
}
|
|
144 |
}
|
|
145 |
if (state.getConfig().isCheckNamesOnly()){
|
|
146 |
return;
|
143 |
147 |
}
|
|
148 |
|
|
149 |
DerivedUnit lastDerivedUnit = null;
|
|
150 |
if (collectorNumber.equals(lastCollectorNumber)){
|
|
151 |
lastDerivedUnit = (DerivedUnit)getOccurrenceService().find(lastDerivedUnitUuid);
|
|
152 |
}
|
|
153 |
|
144 |
154 |
DerivedUnitFacade facade;
|
145 |
155 |
String sourceId = rdfId;
|
|
156 |
String sourceNamespace = RDF_ID_NAMESPACE;
|
|
157 |
if (rdfId.equalsIgnoreCase("NULL")){
|
|
158 |
sourceId = herbariumId;
|
|
159 |
sourceNamespace = HERBARIUM_ID_NAMESPACE;
|
|
160 |
}
|
|
161 |
|
146 |
162 |
if (lastDerivedUnit == null){
|
147 |
|
facade = DerivedUnitFacade.NewPreservedSpecimenInstance();
|
|
163 |
if (baseOfRecords.equals("Specimen")){
|
|
164 |
facade = DerivedUnitFacade.NewPreservedSpecimenInstance();
|
|
165 |
}else if (baseOfRecords.equals("HumanObservation")){
|
|
166 |
facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.Observation, null);
|
|
167 |
}else {
|
|
168 |
System.out.println("baseOfRecords of records not recognized: " + baseOfRecords + "; use preserved specimen as default");
|
|
169 |
facade = DerivedUnitFacade.NewPreservedSpecimenInstance();
|
|
170 |
}
|
148 |
171 |
facade.setFieldNumber(collectorNumber);
|
149 |
172 |
facade.setCountry(Country.GREECEHELLENICREPUBLIC());
|
150 |
173 |
facade.setLocality(locality);
|
... | ... | |
156 |
179 |
facade.setCollector(getCollector(state, collector));
|
157 |
180 |
facade.getGatheringEvent(true).setTimeperiod(date);
|
158 |
181 |
facade.setPreferredStableUri(URI.create(stableIdentifier));
|
159 |
|
facade.setBarcode(catalogNumber);
|
160 |
|
facade.setCollection(getCollection(state));
|
161 |
|
this.addOriginalSource(facade.innerFieldUnit(), sourceId, RDF_ID_NAMESPACE, sourceReference);
|
162 |
|
this.addOriginalSource(facade.innerDerivedUnit(), sourceId, RDF_ID_NAMESPACE, sourceReference);
|
|
182 |
if (catalogNumber.startsWith("B")){
|
|
183 |
facade.setBarcode(catalogNumber);
|
|
184 |
}else{
|
|
185 |
facade.setCatalogNumber(catalogNumber);
|
|
186 |
}
|
|
187 |
facade.setCollection(getCollection(state, collectionCode, institutionCode));
|
|
188 |
this.addOriginalSource(facade.innerFieldUnit(), sourceId, sourceNamespace, sourceReference);
|
|
189 |
this.addOriginalSource(facade.innerDerivedUnit(), sourceId, sourceNamespace, sourceReference);
|
163 |
190 |
|
164 |
191 |
IndividualsAssociation specimen = IndividualsAssociation.NewInstance(facade.innerDerivedUnit());
|
|
192 |
if (baseOfRecords.equals("HumanObservation")){
|
|
193 |
specimen.setFeature(Feature.OBSERVATION());
|
|
194 |
}else if (baseOfRecords.equals("Specimen")){
|
|
195 |
specimen.setFeature(Feature.SPECIMEN());
|
|
196 |
}else{
|
|
197 |
System.out.println("Base of record not recognized for feature selection: " + baseOfRecords);
|
|
198 |
}
|
165 |
199 |
if (taxon != null ){
|
166 |
200 |
TaxonDescription description = getTaxonDescription(taxon, sourceReference, false, CREATE);
|
167 |
201 |
description.addElement(specimen);
|
... | ... | |
195 |
229 |
imageTextData.addMedia(media);
|
196 |
230 |
|
197 |
231 |
// media.addPrimaryMediaSource(citation, microCitation);
|
198 |
|
this.addOriginalSource(media, sourceId, RDF_ID_NAMESPACE, sourceReference);
|
|
232 |
this.addOriginalSource(media, sourceId, sourceNamespace, sourceReference);
|
199 |
233 |
|
200 |
234 |
|
201 |
235 |
// getDedupHelper(state).replaceAuthorNamesAndNomRef(state, name);
|
... | ... | |
250 |
284 |
* @param state
|
251 |
285 |
* @return
|
252 |
286 |
*/
|
253 |
|
private Collection getCollection(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state) {
|
|
287 |
private Collection getCollection(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state, String collectionCode, String institutionCode) {
|
254 |
288 |
if (bgbm == null){
|
255 |
|
List<Collection> results = getCollectionService().searchByCode("B");
|
|
289 |
List<Collection> results = getCollectionService().searchByCode(collectionCode);
|
256 |
290 |
if (results.size()> 1){
|
257 |
291 |
throw new RuntimeException("More then 1 collection found for 'B'");
|
258 |
292 |
}else if (results.isEmpty()){
|
259 |
293 |
Collection collection = Collection.NewInstance();
|
260 |
|
collection.setCode("B");
|
|
294 |
collection.setCode(collectionCode);
|
261 |
295 |
getCollectionService().save(collection);
|
262 |
|
System.out.println("Collection 'B' did not exist. Created new one.");
|
|
296 |
System.out.println("Collection '"+collectionCode+"' did not exist. Created new one.");
|
263 |
297 |
return collection;
|
264 |
298 |
// throw new RuntimeException("No collection found for 'B'");
|
265 |
299 |
}
|
|
300 |
if ("B".equals(collectionCode) && !"".equals(institutionCode)
|
|
301 |
|| "HWilling".equals(collectionCode) && !"JACQ".equals(institutionCode)){
|
|
302 |
System.out.println("CollectionCode and InstitutionCode do not match expected values: " + collectionCode + "; " + institutionCode);
|
|
303 |
}
|
266 |
304 |
bgbm = results.get(0);
|
267 |
305 |
}
|
268 |
306 |
return bgbm;
|
ref #7669 latest changes to Greece Willing images import, incl. no barcode import