Revision bb38665e
Added by Andreas Müller over 10 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraFactEcologyImport.java | ||
---|---|---|
22 | 22 |
import org.springframework.stereotype.Component; |
23 | 23 |
|
24 | 24 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
25 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType; |
|
26 | 25 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy; |
27 | 26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException; |
28 | 27 |
import eu.etaxonomy.cdm.common.CdmUtils; |
... | ... | |
41 | 40 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
42 | 41 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent; |
43 | 42 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
44 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase; |
|
45 | 43 |
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent; |
46 |
import eu.etaxonomy.cdm.model.occurrence.FieldObservation; |
|
47 |
import eu.etaxonomy.cdm.model.occurrence.Fossil; |
|
48 |
import eu.etaxonomy.cdm.model.occurrence.LivingBeing; |
|
49 |
import eu.etaxonomy.cdm.model.occurrence.Observation; |
|
50 |
import eu.etaxonomy.cdm.model.occurrence.Specimen; |
|
44 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
51 | 45 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
46 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
52 | 47 |
import eu.etaxonomy.cdm.model.reference.Reference; |
53 | 48 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
54 | 49 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
... | ... | |
112 | 107 |
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>(); |
113 | 108 |
|
114 | 109 |
Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE); |
115 |
Map<String, DerivedUnitBase> ecoFactDerivedUnitMap = (Map<String, DerivedUnitBase>) partitioner.getObjectMap(ECO_FACT_DERIVED_UNIT_NAMESPACE);
|
|
110 |
Map<String, DerivedUnit> ecoFactDerivedUnitMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(ECO_FACT_DERIVED_UNIT_NAMESPACE);
|
|
116 | 111 |
|
117 | 112 |
ResultSet rs = partitioner.getResultSet(); |
118 | 113 |
|
... | ... | |
136 | 131 |
//source ref |
137 | 132 |
Reference<?> sourceRef = state.getTransactionalSourceReference(); |
138 | 133 |
|
139 |
DerivedUnitBase<?> ecoFact = ecoFactDerivedUnitMap.get(String.valueOf(ecoFactId));
|
|
134 |
DerivedUnit ecoFact = ecoFactDerivedUnitMap.get(String.valueOf(ecoFactId)); |
|
140 | 135 |
if (ecoFact == null){ |
141 | 136 |
logger.warn("EcoFact is null for EcoFact: " + CdmUtils.Nz(ecoFactId) + ", taxonId: " + CdmUtils.Nz(taxonId)); |
142 | 137 |
} |
... | ... | |
146 | 141 |
Taxon taxon = getTaxon(state, taxonId, taxonMap, factId); |
147 | 142 |
|
148 | 143 |
if(taxon != null){ |
149 |
DerivedUnitBase identifiedSpecimen = makeIdentifiedSpecimen(ecoFact, recordBasis);
|
|
144 |
DerivedUnit identifiedSpecimen = makeIdentifiedSpecimen(ecoFact, recordBasis); |
|
150 | 145 |
|
151 | 146 |
makeDetermination(state, rs, taxon, identifiedSpecimen, factId, partitioner); |
152 | 147 |
|
... | ... | |
181 | 176 |
} |
182 | 177 |
} |
183 | 178 |
|
184 |
private void makeIndividualsAssociation(AlgaTerraImportState state, Taxon taxon, Reference<?> sourceRef, DerivedUnitBase<?> identifiedSpecimen){
|
|
179 |
private void makeIndividualsAssociation(AlgaTerraImportState state, Taxon taxon, Reference<?> sourceRef, DerivedUnit identifiedSpecimen){ |
|
185 | 180 |
TaxonDescription taxonDescription = getTaxonDescription(state, taxon, sourceRef); |
186 | 181 |
IndividualsAssociation indAssociation = IndividualsAssociation.NewInstance(); |
187 |
Feature feature = makeFeature(identifiedSpecimen); |
|
182 |
Feature feature = makeFeature(identifiedSpecimen.getRecordBasis());
|
|
188 | 183 |
indAssociation.setAssociatedSpecimenOrObservation(identifiedSpecimen); |
189 | 184 |
indAssociation.setFeature(feature); |
190 | 185 |
taxonDescription.addElement(indAssociation); |
191 | 186 |
} |
192 | 187 |
|
193 |
private void makeDetermination(AlgaTerraImportState state, ResultSet rs, Taxon taxon, DerivedUnitBase<?> identifiedSpecimen, int factId, ResultSetPartitioner partitioner) throws SQLException {
|
|
188 |
private void makeDetermination(AlgaTerraImportState state, ResultSet rs, Taxon taxon, DerivedUnit identifiedSpecimen, int factId, ResultSetPartitioner partitioner) throws SQLException { |
|
194 | 189 |
Date identifiedWhen = rs.getDate("IdentifiedWhen"); |
195 | 190 |
Date identifiedWhenEnd = rs.getDate("IdentiedWhenEnd"); |
196 | 191 |
boolean restrictedFlag = rs.getBoolean("RestrictedFlag"); |
... | ... | |
231 | 226 |
|
232 | 227 |
|
233 | 228 |
|
234 |
private DerivedUnitBase<?> makeIdentifiedSpecimen(DerivedUnitBase<?> ecoFact, String recordBasis) {
|
|
229 |
private DerivedUnit makeIdentifiedSpecimen(DerivedUnit ecoFact, String recordBasis) {
|
|
235 | 230 |
//TODO event type |
236 | 231 |
DerivationEvent event = DerivationEvent.NewInstance(); |
237 |
DerivedUnitType derivedUnitType = makeDerivedUnitType(recordBasis);
|
|
232 |
SpecimenOrObservationType derivedUnitType = makeDerivedUnitType(recordBasis);
|
|
238 | 233 |
if (derivedUnitType == null){ |
239 |
logger.warn("NULL"); |
|
234 |
logger.warn("derivedUnitType is NULL");
|
|
240 | 235 |
} |
241 | 236 |
|
242 |
DerivedUnitBase<?> result = derivedUnitType.getNewDerivedUnitInstance();
|
|
237 |
DerivedUnit result = DerivedUnit.NewInstance(derivedUnitType);
|
|
243 | 238 |
result.setDerivedFrom(event); |
244 | 239 |
ecoFact.addDerivationEvent(event); |
245 | 240 |
|
... | ... | |
266 | 261 |
* @param type |
267 | 262 |
* @return |
268 | 263 |
*/ |
269 |
private DerivedUnitFacade getDerivedUnit(AlgaTerraImportState state, int ecoFactId, Map<String, DerivedUnit> derivedUnitMap, DerivedUnitType type) {
|
|
264 |
private DerivedUnitFacade getDerivedUnit(AlgaTerraImportState state, int ecoFactId, Map<String, DerivedUnit> derivedUnitMap, SpecimenOrObservationType type) {
|
|
270 | 265 |
String key = String.valueOf(ecoFactId); |
271 | 266 |
DerivedUnit derivedUnit = derivedUnitMap.get(key); |
272 | 267 |
DerivedUnitFacade facade; |
... | ... | |
284 | 279 |
|
285 | 280 |
return facade; |
286 | 281 |
} |
287 |
|
|
288 |
private Feature makeFeature(SpecimenOrObservationBase unit) { |
|
289 |
if (unit.isInstanceOf(DerivedUnit.class)){ |
|
290 |
return Feature.INDIVIDUALS_ASSOCIATION(); |
|
291 |
}else if (unit.isInstanceOf(FieldObservation.class) || unit.isInstanceOf(Observation.class) ){ |
|
292 |
return Feature.OBSERVATION(); |
|
293 |
}else if (unit.isInstanceOf(Fossil.class) || unit.isInstanceOf(LivingBeing.class) || unit.isInstanceOf(Specimen.class )){ |
|
294 |
return Feature.SPECIMEN(); |
|
295 |
} |
|
296 |
logger.warn("No feature defined for derived unit class: " + unit.getClass().getSimpleName()); |
|
297 |
return null; |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
private DerivedUnitType makeDerivedUnitType(String recordBasis) { |
|
302 |
DerivedUnitType result = null; |
|
303 |
if (StringUtils.isBlank(recordBasis)){ |
|
304 |
result = DerivedUnitType.DerivedUnit; |
|
305 |
} else if (recordBasis.equalsIgnoreCase("FossileSpecimen")){ |
|
306 |
result = DerivedUnitType.Fossil; |
|
307 |
}else if (recordBasis.equalsIgnoreCase("Observation")){ |
|
308 |
result = DerivedUnitType.Observation; |
|
309 |
}else if (recordBasis.equalsIgnoreCase("HumanObservation")){ |
|
310 |
result = DerivedUnitType.Observation; |
|
311 |
}else if (recordBasis.equalsIgnoreCase("Literature")){ |
|
312 |
logger.warn("Literature record basis not yet supported"); |
|
313 |
result = DerivedUnitType.DerivedUnit; |
|
314 |
}else if (recordBasis.equalsIgnoreCase("LivingSpecimen")){ |
|
315 |
result = DerivedUnitType.LivingBeing; |
|
316 |
}else if (recordBasis.equalsIgnoreCase("LivingCulture")){ |
|
317 |
logger.warn("LivingCulture record basis not yet supported"); |
|
318 |
result = DerivedUnitType.DerivedUnit; |
|
319 |
}else if (recordBasis.equalsIgnoreCase("MachineObservation")){ |
|
320 |
logger.warn("MachineObservation record basis not yet supported"); |
|
321 |
result = DerivedUnitType.Observation; |
|
322 |
}else if (recordBasis.equalsIgnoreCase("PreservedSpecimen")){ |
|
323 |
result = DerivedUnitType.Specimen; |
|
324 |
} |
|
325 |
return result; |
|
326 |
} |
|
327 | 282 |
|
328 | 283 |
|
329 |
|
|
330 |
/* (non-Javadoc) |
|
331 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
|
332 |
*/ |
|
284 |
|
|
285 |
@Override |
|
333 | 286 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) { |
334 | 287 |
String nameSpace; |
335 | 288 |
Class cdmClass; |
... | ... | |
356 | 309 |
|
357 | 310 |
//derived unit map |
358 | 311 |
nameSpace = AlgaTerraFactEcologyImport.ECO_FACT_DERIVED_UNIT_NAMESPACE; |
359 |
cdmClass = DerivedUnitBase.class;
|
|
312 |
cdmClass = DerivedUnit.class; |
|
360 | 313 |
idSet = extensionFkSet; |
361 |
Map<String, DerivedUnitBase> derivedUnitMap = (Map<String, DerivedUnitBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
314 |
Map<String, DerivedUnit> derivedUnitMap = (Map<String, DerivedUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
362 | 315 |
result.put(nameSpace, derivedUnitMap); |
363 | 316 |
|
364 | 317 |
//nom reference map |
Also available in: Unified diff
reintegrate cdmlib-app-3.3 branch into trunk