82 |
82 |
|
83 |
83 |
private static final Logger logger = Logger.getLogger(Abcd206Import.class);
|
84 |
84 |
|
85 |
|
|
86 |
85 |
public Abcd206Import() {
|
87 |
86 |
super();
|
88 |
87 |
}
|
89 |
88 |
|
90 |
|
|
91 |
89 |
@Override
|
92 |
|
// @SuppressWarnings("rawtypes")
|
|
90 |
// @SuppressWarnings("rawtypes")
|
93 |
91 |
public void doInvoke(Abcd206ImportState state) {
|
94 |
92 |
Abcd206ImportConfigurator config = state.getConfig();
|
95 |
93 |
Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores();
|
96 |
|
MapWrapper<TeamOrPersonBase<?>> authorStore = (MapWrapper<TeamOrPersonBase<?>>)stores.get(ICdmIO.TEAM_STORE);
|
|
94 |
MapWrapper<TeamOrPersonBase<?>> authorStore = (MapWrapper<TeamOrPersonBase<?>>) stores.get(ICdmIO.TEAM_STORE);
|
97 |
95 |
state.setPersonStore(authorStore);
|
98 |
|
MapWrapper<Reference> referenceStore = (MapWrapper<Reference>)stores.get(ICdmIO.REFERENCE_STORE);
|
|
96 |
MapWrapper<Reference> referenceStore = (MapWrapper<Reference>) stores.get(ICdmIO.REFERENCE_STORE);
|
99 |
97 |
createKindOfUnitsMap(state);
|
100 |
98 |
URI sourceUri = config.getSourceUri();
|
101 |
|
try{
|
|
99 |
try {
|
102 |
100 |
state.setTx(startTransaction());
|
103 |
101 |
logger.info("INVOKE Specimen Import from ABCD2.06 XML ");
|
104 |
102 |
InputStream response = null;
|
105 |
|
//init cd repository
|
106 |
|
if(state.getCdmRepository()==null){
|
|
103 |
// init cd repository
|
|
104 |
if (state.getCdmRepository() == null) {
|
107 |
105 |
state.setCdmRepository(this);
|
108 |
106 |
}
|
109 |
|
if (config.getOccurenceQuery() != null){
|
|
107 |
if (config.getOccurenceQuery() != null) {
|
110 |
108 |
BioCaseQueryServiceWrapper queryService = new BioCaseQueryServiceWrapper();
|
111 |
109 |
try {
|
112 |
110 |
|
113 |
|
response = queryService.query(config.getOccurenceQuery(), sourceUri);
|
114 |
|
state.setActualAccessPoint(sourceUri);
|
|
111 |
response = queryService.query(config.getOccurenceQuery(), sourceUri);
|
|
112 |
state.setActualAccessPoint(sourceUri);
|
115 |
113 |
|
116 |
|
}catch(Exception e){
|
|
114 |
} catch (Exception e) {
|
117 |
115 |
logger.error("An error during ABCD import");
|
118 |
116 |
}
|
119 |
117 |
}
|
120 |
118 |
SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
|
121 |
119 |
|
122 |
|
//init import reference
|
123 |
|
// List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
|
124 |
|
// List<Reference> references = new ArrayList<Reference>();
|
125 |
|
|
126 |
|
// if (state.getConfig().isInteractWithUser()){
|
127 |
|
// Map<String,Reference> refMap = new HashMap<String, Reference>();
|
128 |
|
// for (Reference reference : references) {
|
129 |
|
// if (! StringUtils.isBlank(reference.getTitleCache())) {
|
130 |
|
// refMap.put(reference.getTitleCache(),reference);
|
131 |
|
// }
|
132 |
|
// }
|
133 |
|
// state.setRef(sui.askForReference(refMap));
|
134 |
|
//
|
135 |
|
// if (state.getRef() == null){
|
136 |
|
// String cla = sui.createNewReference();
|
137 |
|
// if (refMap.get(cla)!= null) {
|
138 |
|
// state.setRef(refMap.get(cla));
|
139 |
|
// } else {
|
140 |
|
// state.setRef(ReferenceFactory.newGeneric());
|
141 |
|
// state.getRef().setTitle(cla);
|
142 |
|
// }
|
143 |
|
// }
|
144 |
|
// else{
|
145 |
|
// state.setRef(getReferenceService().find(state.getRef().getUuid()));
|
146 |
|
// }
|
147 |
|
// }else{
|
148 |
|
if (state.getRef()==null){
|
149 |
|
String name = NB(state.getConfig().getSourceReferenceTitle());
|
150 |
|
for (Reference reference : referenceStore.getAllValues()) {
|
151 |
|
if (! StringUtils.isBlank(reference.getTitleCache())) {
|
152 |
|
if (reference.getTitleCache().equalsIgnoreCase(name)) {
|
153 |
|
state.setRef(reference);
|
154 |
|
}
|
|
120 |
// init import reference
|
|
121 |
// List<Reference> references =
|
|
122 |
// getReferenceService().list(Reference.class, null, null, null,
|
|
123 |
// null);
|
|
124 |
// List<Reference> references = new ArrayList<Reference>();
|
|
125 |
|
|
126 |
// if (state.getConfig().isInteractWithUser()){
|
|
127 |
// Map<String,Reference> refMap = new HashMap<String, Reference>();
|
|
128 |
// for (Reference reference : references) {
|
|
129 |
// if (! StringUtils.isBlank(reference.getTitleCache())) {
|
|
130 |
// refMap.put(reference.getTitleCache(),reference);
|
|
131 |
// }
|
|
132 |
// }
|
|
133 |
// state.setRef(sui.askForReference(refMap));
|
|
134 |
//
|
|
135 |
// if (state.getRef() == null){
|
|
136 |
// String cla = sui.createNewReference();
|
|
137 |
// if (refMap.get(cla)!= null) {
|
|
138 |
// state.setRef(refMap.get(cla));
|
|
139 |
// } else {
|
|
140 |
// state.setRef(ReferenceFactory.newGeneric());
|
|
141 |
// state.getRef().setTitle(cla);
|
|
142 |
// }
|
|
143 |
// }
|
|
144 |
// else{
|
|
145 |
// state.setRef(getReferenceService().find(state.getRef().getUuid()));
|
|
146 |
// }
|
|
147 |
// }else{
|
|
148 |
if (state.getRef() == null) {
|
|
149 |
String name = NB(state.getConfig().getSourceReferenceTitle());
|
|
150 |
for (Reference reference : referenceStore.getAllValues()) {
|
|
151 |
if (!StringUtils.isBlank(reference.getTitleCache())) {
|
|
152 |
if (reference.getTitleCache().equalsIgnoreCase(name)) {
|
|
153 |
state.setRef(reference);
|
155 |
154 |
}
|
156 |
155 |
}
|
157 |
|
if (state.getRef() == null){
|
158 |
|
if (state.getConfig().getSourceReference() != null){
|
159 |
|
state.setRef(state.getConfig().getSourceReference());
|
160 |
|
}else{
|
161 |
|
state.setRef(ReferenceFactory.newGeneric());
|
162 |
|
state.getRef().setUri(sourceUri);
|
|
156 |
}
|
|
157 |
if (state.getRef() == null) {
|
|
158 |
if (state.getConfig().getSourceReference() != null) {
|
|
159 |
state.setRef(state.getConfig().getSourceReference());
|
|
160 |
} else {
|
|
161 |
state.setRef(ReferenceFactory.newGeneric());
|
|
162 |
state.getRef().setUri(sourceUri);
|
|
163 |
if (sourceUri != null){
|
163 |
164 |
state.getRef().setTitle(StringUtils.substringAfter(sourceUri.toString(), "dsa="));
|
164 |
|
|
165 |
|
if (!StringUtils.isBlank(state.getConfig().getSourceReferenceTitle())){
|
166 |
|
state.getRef().setTitle(state.getConfig().getSourceReferenceTitle());
|
167 |
|
}
|
168 |
165 |
}
|
169 |
166 |
|
|
167 |
if (!StringUtils.isBlank(state.getConfig().getSourceReferenceTitle())) {
|
|
168 |
state.getRef().setTitle(state.getConfig().getSourceReferenceTitle());
|
|
169 |
}
|
170 |
170 |
}
|
|
171 |
|
171 |
172 |
}
|
172 |
|
//}
|
|
173 |
}
|
|
174 |
// }
|
173 |
175 |
|
174 |
176 |
save(state.getRef(), state);
|
175 |
177 |
state.getConfig().setSourceReference(state.getRef());
|
176 |
178 |
|
177 |
|
if(state.getConfig().getClassificationUuid()!=null){
|
178 |
|
//load classification from config if it exists
|
|
179 |
if (state.getConfig().getClassificationUuid() != null) {
|
|
180 |
// load classification from config if it exists
|
179 |
181 |
state.setClassification(getClassificationService().load(state.getConfig().getClassificationUuid()));
|
180 |
182 |
}
|
181 |
|
if(state.getClassification()==null){//no existing classification was set in config
|
182 |
|
List<Classification> classificationList = getClassificationService().list(Classification.class, null, null, null, null);
|
183 |
|
//get classification via user interaction
|
184 |
|
if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()){
|
185 |
|
Map<String,Classification> classMap = new HashMap<>();
|
|
183 |
if (state.getClassification() == null) {// no existing
|
|
184 |
// classification was set in
|
|
185 |
// config
|
|
186 |
List<Classification> classificationList = getClassificationService().list(Classification.class, null,
|
|
187 |
null, null, null);
|
|
188 |
// get classification via user interaction
|
|
189 |
if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()) {
|
|
190 |
Map<String, Classification> classMap = new HashMap<>();
|
186 |
191 |
for (Classification tree : classificationList) {
|
187 |
|
if (! StringUtils.isBlank(tree.getTitleCache())) {
|
188 |
|
classMap.put(tree.getTitleCache(),tree);
|
|
192 |
if (!StringUtils.isBlank(tree.getTitleCache())) {
|
|
193 |
classMap.put(tree.getTitleCache(), tree);
|
189 |
194 |
}
|
190 |
195 |
}
|
191 |
196 |
state.setClassification(sui.askForClassification(classMap));
|
192 |
|
if (state.getClassification() == null){
|
|
197 |
if (state.getClassification() == null) {
|
193 |
198 |
String cla = sui.createNewClassification();
|
194 |
|
if (classMap.get(cla)!= null) {
|
|
199 |
if (classMap.get(cla) != null) {
|
195 |
200 |
state.setClassification(classMap.get(cla));
|
196 |
201 |
} else {
|
197 |
|
state.setClassification(Classification.NewInstance(cla, state.getRef(), Language.DEFAULT()));
|
|
202 |
state.setClassification(
|
|
203 |
Classification.NewInstance(cla, state.getRef(), Language.DEFAULT()));
|
198 |
204 |
}
|
199 |
205 |
}
|
200 |
206 |
save(state.getClassification(), state);
|
201 |
207 |
}
|
202 |
|
// use default classification as the classification to import into
|
|
208 |
// use default classification as the classification to import
|
|
209 |
// into
|
203 |
210 |
if (state.getClassification() == null) {
|
204 |
211 |
String name = NB(state.getConfig().getClassificationName());
|
205 |
|
for (Classification classif : classificationList){
|
|
212 |
for (Classification classif : classificationList) {
|
206 |
213 |
if (classif.getTitleCache() != null && classif.getTitleCache().equalsIgnoreCase(name)) {
|
207 |
214 |
state.setClassification(classif);
|
208 |
215 |
}
|
209 |
216 |
}
|
210 |
|
if (state.getClassification() == null){
|
|
217 |
if (state.getClassification() == null) {
|
211 |
218 |
state.setClassification(Classification.NewInstance(name, state.getRef(), Language.DEFAULT()));
|
212 |
|
//we do not need a default classification when creating an empty new one
|
|
219 |
// we do not need a default classification when creating
|
|
220 |
// an empty new one
|
213 |
221 |
state.setDefaultClassification(state.getClassification());
|
214 |
222 |
save(state.getDefaultClassification(false), state);
|
215 |
223 |
}
|
... | ... | |
217 |
225 |
}
|
218 |
226 |
}
|
219 |
227 |
|
220 |
|
if (response == null){
|
221 |
|
response =state.getConfig().getSource();
|
|
228 |
if (response == null) {
|
|
229 |
response = state.getConfig().getSource();
|
222 |
230 |
}
|
223 |
|
UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(response, state.getReport());
|
|
231 |
UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(response,
|
|
232 |
state.getReport());
|
224 |
233 |
NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
|
225 |
234 |
state.setPrefix(unitAssociationWrapper.getPrefix());
|
226 |
235 |
|
... | ... | |
233 |
242 |
state.setDataHolder(new Abcd206DataHolder());
|
234 |
243 |
state.getDataHolder().reset();
|
235 |
244 |
|
236 |
|
Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix());
|
237 |
|
if (config.getNomenclaturalCode() != null){
|
|
245 |
Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(state.getDataHolder(),
|
|
246 |
state.getPrefix());
|
|
247 |
if (config.getNomenclaturalCode() != null) {
|
238 |
248 |
state.getDataHolder().setNomenclatureCode(config.getNomenclaturalCode().getKey());
|
239 |
249 |
}
|
240 |
250 |
prepareCollectors(state, unitsList, abcdFieldGetter);
|
241 |
251 |
|
242 |
|
|
243 |
252 |
// save authors
|
244 |
|
getAgentService().saveOrUpdate((java.util.Collection)state.getPersonStore().objects());
|
|
253 |
getAgentService().saveOrUpdate((java.util.Collection) state.getPersonStore().objects());
|
245 |
254 |
|
246 |
255 |
commitTransaction(state.getTx());
|
247 |
256 |
state.setTx(startTransaction());
|
248 |
|
if (state.getDefaultClassification(false) != null){
|
249 |
|
state.setDefaultClassification(getClassificationService().load(state.getDefaultClassification(false).getUuid()));
|
|
257 |
if (state.getDefaultClassification(false) != null) {
|
|
258 |
state.setDefaultClassification(
|
|
259 |
getClassificationService().load(state.getDefaultClassification(false).getUuid()));
|
250 |
260 |
}
|
251 |
|
if (state.getClassification() != null){
|
|
261 |
if (state.getClassification() != null) {
|
252 |
262 |
state.setClassification(getClassificationService().load(state.getClassification().getUuid()));
|
253 |
263 |
}
|
254 |
264 |
state.setAssociationRefs(new ArrayList<>());
|
255 |
265 |
state.setDescriptionRefs(new ArrayList<>());
|
256 |
266 |
state.setDerivedUnitSources(new ArrayList<>());
|
257 |
267 |
for (int i = 0; i < unitsList.getLength(); i++) {
|
258 |
|
if(state.getConfig().getProgressMonitor().isCanceled()){
|
|
268 |
if (state.getConfig().getProgressMonitor().isCanceled()) {
|
259 |
269 |
break;
|
260 |
270 |
}
|
261 |
271 |
|
262 |
272 |
state.reset();
|
263 |
273 |
|
264 |
274 |
Element item = (Element) unitsList.item(i);
|
265 |
|
Abcd206ImportParser.setUnitPropertiesXML( item, abcdFieldGetter, state);
|
266 |
|
updateProgress(state, "Importing data for unit "+state.getDataHolder().getUnitID()+" ("+i+"/"+unitsList.getLength()+")");
|
|
275 |
Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
|
|
276 |
updateProgress(state, "Importing data for unit " + state.getDataHolder().getUnitID() + " (" + i
|
|
277 |
+ "/" + unitsList.getLength() + ")");
|
267 |
278 |
|
268 |
|
//import unit + field unit data
|
|
279 |
// import unit + field unit data
|
269 |
280 |
state.setAssociatedUnitIds(state.getDataHolder().getAssociatedUnitIds());
|
270 |
281 |
this.handleSingleUnit(state, item, true);
|
271 |
282 |
|
272 |
283 |
}
|
273 |
|
if(state.getConfig().isDeduplicateReferences()){
|
|
284 |
if (state.getConfig().isDeduplicateReferences()) {
|
274 |
285 |
getReferenceService().deduplicate(Reference.class, null, null);
|
275 |
286 |
}
|
276 |
|
if(state.getConfig().isDeduplicateClassifications()){
|
|
287 |
if (state.getConfig().isDeduplicateClassifications()) {
|
277 |
288 |
getClassificationService().deduplicate(Classification.class, null, null);
|
278 |
289 |
}
|
279 |
290 |
}
|
280 |
291 |
commitTransaction(state.getTx());
|
281 |
|
}
|
282 |
|
catch(Exception e){
|
|
292 |
} catch (Exception e) {
|
283 |
293 |
String errorDuringImport = "Exception during import!";
|
284 |
294 |
logger.error(errorDuringImport, e);
|
285 |
295 |
state.getReport().addException(errorDuringImport, e);
|
286 |
|
}
|
287 |
|
finally{
|
|
296 |
} finally {
|
288 |
297 |
state.getReport().printReport(state.getConfig().getReportUri());
|
289 |
298 |
}
|
290 |
299 |
|
291 |
|
if (state.getConfig().isDownloadSequenceData()){
|
292 |
|
//download fasta files for imported sequences
|
293 |
|
//TODO: where to store the files and how to create the new Blast DB
|
|
300 |
if (state.getConfig().isDownloadSequenceData()) {
|
|
301 |
// download fasta files for imported sequences
|
|
302 |
// TODO: where to store the files and how to create the new Blast DB
|
294 |
303 |
}
|
295 |
304 |
return;
|
296 |
305 |
}
|
297 |
306 |
|
298 |
|
|
299 |
307 |
/**
|
300 |
308 |
*
|
301 |
309 |
*/
|
302 |
310 |
private void createKindOfUnitsMap(Abcd206ImportState state) {
|
303 |
311 |
|
304 |
312 |
ICdmRepository cdmRepository = state.getConfig().getCdmAppController();
|
305 |
|
if (cdmRepository == null){
|
|
313 |
if (cdmRepository == null) {
|
306 |
314 |
cdmRepository = this;
|
307 |
315 |
}
|
308 |
316 |
|
309 |
|
List<DefinedTerm> terms = cdmRepository.getTermService().listByTermType(TermType.KindOfUnit, null, 0, null, null);
|
|
317 |
List<DefinedTerm> terms = cdmRepository.getTermService().listByTermType(TermType.KindOfUnit, null, 0, null,
|
|
318 |
null);
|
310 |
319 |
kindOfUnitsMap = new HashMap<>();
|
311 |
|
for (DefinedTerm kindOfUnit:terms) {
|
|
320 |
for (DefinedTerm kindOfUnit : terms) {
|
|
321 |
String kindOfUnitLabel = kindOfUnit.getLabel().toLowerCase();
|
312 |
322 |
kindOfUnitsMap.put(kindOfUnit.getLabel().toLowerCase(), kindOfUnit);
|
313 |
323 |
}
|
314 |
324 |
}
|
315 |
325 |
|
316 |
|
|
317 |
326 |
/**
|
318 |
327 |
* @param state
|
319 |
328 |
* @param item
|
320 |
329 |
*/
|
321 |
330 |
private void getSiblings(Abcd206ImportState state, Object item, DerivedUnitFacade facade) {
|
322 |
331 |
String unitId = facade.getCatalogNumber();
|
323 |
|
if (unitId == null){
|
|
332 |
if (unitId == null) {
|
324 |
333 |
unitId = facade.getAccessionNumber();
|
325 |
334 |
}
|
326 |
335 |
|
327 |
|
UnitAssociationParser unitParser = new UnitAssociationParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
|
|
336 |
UnitAssociationParser unitParser = new UnitAssociationParser(state.getPrefix(), state.getReport(),
|
|
337 |
state.getCdmRepository());
|
328 |
338 |
UnitAssociationWrapper unitAssociationWrapper = null;
|
329 |
|
for (URI accessPoint: state.getActualAccesPoint()){
|
|
339 |
for (URI accessPoint : state.getActualAccesPoint()) {
|
330 |
340 |
unitAssociationWrapper = unitParser.parseSiblings(unitId, accessPoint);
|
331 |
|
if (unitAssociationWrapper != null && unitAssociationWrapper.getAssociatedUnits() != null){
|
|
341 |
if (unitAssociationWrapper != null && unitAssociationWrapper.getAssociatedUnits() != null) {
|
332 |
342 |
break;
|
333 |
343 |
}
|
334 |
344 |
}
|
335 |
345 |
|
336 |
|
DerivedUnit currentUnit = state.getDerivedUnitBase();
|
337 |
|
// DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
|
338 |
|
FieldUnit currentFieldUnit = facade.getFieldUnit(false);
|
339 |
|
if(unitAssociationWrapper!=null){
|
|
346 |
DerivedUnit currentUnit = state.getDerivedUnitBase();
|
|
347 |
// DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
|
|
348 |
FieldUnit currentFieldUnit = facade.getFieldUnit(false);
|
|
349 |
if (unitAssociationWrapper != null) {
|
340 |
350 |
NodeList associatedUnits = unitAssociationWrapper.getAssociatedUnits();
|
341 |
|
if(associatedUnits!=null){
|
342 |
|
for(int m=0;m<associatedUnits.getLength();m++){
|
343 |
|
if(associatedUnits.item(m) instanceof Element){
|
|
351 |
if (associatedUnits != null) {
|
|
352 |
for (int m = 0; m < associatedUnits.getLength(); m++) {
|
|
353 |
if (associatedUnits.item(m) instanceof Element) {
|
344 |
354 |
state.reset();
|
345 |
|
String associationType = AbcdParseUtility.parseFirstTextContent(((Element) associatedUnits.item(m)).getElementsByTagName(state.getPrefix()+"AssociationType"));
|
346 |
|
|
347 |
|
Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), unitAssociationWrapper.getPrefix()), state);
|
348 |
|
// logger.debug("derived unit: " + state.getDerivedUnitBase().toString() + " associated unit: " +state.getDataHolder().getKindOfUnit() + ", " + state.getDataHolder().accessionNumber + ", " + state.getDataHolder().getRecordBasis() + ", " + state.getDataHolder().getUnitID());
|
|
355 |
String associationType = AbcdParseUtility
|
|
356 |
.parseFirstTextContent(((Element) associatedUnits.item(m))
|
|
357 |
.getElementsByTagName(state.getPrefix() + "AssociationType"));
|
|
358 |
|
|
359 |
Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m),
|
|
360 |
new Abcd206XMLFieldGetter(state.getDataHolder(), unitAssociationWrapper.getPrefix()),
|
|
361 |
state);
|
|
362 |
// logger.debug("derived unit: " +
|
|
363 |
// state.getDerivedUnitBase().toString() + " associated
|
|
364 |
// unit: " +state.getDataHolder().getKindOfUnit() + ", "
|
|
365 |
// + state.getDataHolder().accessionNumber + ", " +
|
|
366 |
// state.getDataHolder().getRecordBasis() + ", " +
|
|
367 |
// state.getDataHolder().getUnitID());
|
349 |
368 |
|
350 |
369 |
handleSingleUnit(state, associatedUnits.item(m), false);
|
351 |
370 |
|
352 |
371 |
DerivedUnit associatedUnit = state.getDerivedUnitBase();
|
353 |
372 |
FieldUnit associatedFieldUnit = null;
|
354 |
|
java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid(), null);
|
355 |
|
//ignore field unit if associated unit has more than one
|
356 |
|
if(associatedFieldUnits.size()>1){
|
357 |
|
state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
|
358 |
|
}
|
359 |
|
else if(associatedFieldUnits.size()==1){
|
|
373 |
java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository()
|
|
374 |
.getOccurrenceService().findFieldUnits(associatedUnit.getUuid(), null);
|
|
375 |
// ignore field unit if associated unit has more than
|
|
376 |
// one
|
|
377 |
if (associatedFieldUnits.size() > 1) {
|
|
378 |
state.getReport()
|
|
379 |
.addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
|
|
380 |
} else if (associatedFieldUnits.size() == 1) {
|
360 |
381 |
associatedFieldUnit = associatedFieldUnits.iterator().next();
|
361 |
382 |
}
|
362 |
|
//parent-child relation:
|
363 |
|
if(associationType.contains("individual") || associationType.contains("culture") || associationType.contains("sample")){
|
364 |
|
DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit, associatedUnit, DerivationEventType.ACCESSIONING());
|
365 |
|
if(associatedFieldUnit!=null && associatedFieldUnit != currentFieldUnit){
|
|
383 |
// parent-child relation:
|
|
384 |
if (associationType.contains("individual") || associationType.contains("culture")
|
|
385 |
|| associationType.contains("sample")) {
|
|
386 |
DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit,
|
|
387 |
associatedUnit, DerivationEventType.ACCESSIONING());
|
|
388 |
|
|
389 |
updatedDerivationEvent.setDescription(associationType);
|
|
390 |
if (associatedFieldUnit != null && associatedFieldUnit != currentFieldUnit) {
|
366 |
391 |
associatedFieldUnit.removeDerivationEvent(updatedDerivationEvent);
|
367 |
392 |
state.getCdmRepository().getOccurrenceService().delete(associatedFieldUnit);
|
368 |
393 |
}
|
... | ... | |
381 |
406 |
|
382 |
407 |
/**
|
383 |
408 |
* Handle a single unit
|
|
409 |
*
|
384 |
410 |
* @param state
|
385 |
411 |
* @param item
|
386 |
412 |
*/
|
387 |
413 |
@Override
|
388 |
|
public void handleSingleUnit(Abcd206ImportState state, Object itemObject){
|
|
414 |
public void handleSingleUnit(Abcd206ImportState state, Object itemObject) {
|
389 |
415 |
handleSingleUnit(state, itemObject, true);
|
390 |
416 |
}
|
391 |
417 |
|
392 |
|
|
393 |
418 |
@SuppressWarnings("rawtypes")
|
394 |
419 |
public void handleSingleUnit(Abcd206ImportState state, Object itemObject, boolean handleAssociatedUnits) {
|
395 |
420 |
Element item = (Element) itemObject;
|
396 |
421 |
|
397 |
422 |
Abcd206ImportConfigurator config = state.getConfig();
|
398 |
423 |
if (logger.isDebugEnabled()) {
|
399 |
|
logger.info("handleSingleUnit "+state.getRef());
|
|
424 |
logger.info("handleSingleUnit " + state.getRef());
|
400 |
425 |
}
|
401 |
426 |
try {
|
402 |
427 |
ICdmRepository cdmAppController = state.getConfig().getCdmAppController();
|
403 |
|
if(cdmAppController==null){
|
|
428 |
if (cdmAppController == null) {
|
404 |
429 |
cdmAppController = this;
|
405 |
430 |
}
|
406 |
|
//check if unit already exists
|
|
431 |
// check if unit already exists
|
407 |
432 |
DerivedUnitFacade derivedUnitFacade = null;
|
408 |
|
if(state.getConfig().isIgnoreImportOfExistingSpecimen()){
|
409 |
|
SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(state.getDataHolder().getUnitID(), state);
|
410 |
|
if(existingSpecimen!=null && existingSpecimen.isInstanceOf(DerivedUnit.class)){
|
|
433 |
if (state.getConfig().isIgnoreImportOfExistingSpecimen()) {
|
|
434 |
SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(state.getDataHolder().getUnitID(),
|
|
435 |
state);
|
|
436 |
if (existingSpecimen != null && existingSpecimen.isInstanceOf(DerivedUnit.class)) {
|
411 |
437 |
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(existingSpecimen, DerivedUnit.class);
|
412 |
438 |
state.setDerivedUnitBase(derivedUnit);
|
413 |
439 |
derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
|
414 |
|
if (handleAssociatedUnits){
|
|
440 |
if (handleAssociatedUnits) {
|
415 |
441 |
importAssociatedUnits(state, item, derivedUnitFacade);
|
416 |
442 |
}
|
417 |
443 |
|
418 |
|
state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, config), derivedUnit);
|
|
444 |
state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, config),
|
|
445 |
derivedUnit);
|
419 |
446 |
|
420 |
447 |
return;
|
421 |
448 |
}
|
422 |
449 |
}
|
423 |
450 |
// TODO: implement overwrite/merge specimen
|
424 |
|
// else if(state.getConfig().isOverwriteExistingSpecimens()){
|
425 |
|
// Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
|
426 |
|
// if(!existingSpecimens.getRecords().isEmpty()){
|
427 |
|
// derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit);
|
428 |
|
// derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
|
429 |
|
// fieldUnit = derivedUnitFacade.getFieldUnit(true);
|
430 |
|
// }
|
431 |
|
// }
|
432 |
|
//import new specimen
|
|
451 |
// else if(state.getConfig().isOverwriteExistingSpecimens()){
|
|
452 |
// Pager<SpecimenOrObservationBase> existingSpecimens =
|
|
453 |
// cdmAppController.getOccurrenceService().findByTitle(config);
|
|
454 |
// if(!existingSpecimens.getRecords().isEmpty()){
|
|
455 |
// derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit);
|
|
456 |
// derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
|
|
457 |
// fieldUnit = derivedUnitFacade.getFieldUnit(true);
|
|
458 |
// }
|
|
459 |
// }
|
|
460 |
// import new specimen
|
433 |
461 |
|
434 |
462 |
// import DNA unit
|
435 |
|
if(state.getDataHolder().getKindOfUnit() !=null && state.getDataHolder().getKindOfUnit().equalsIgnoreCase("dna")){
|
436 |
|
AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
|
|
463 |
if (state.getDataHolder().getKindOfUnit() != null
|
|
464 |
&& state.getDataHolder().getKindOfUnit().equalsIgnoreCase("dna")) {
|
|
465 |
AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(),
|
|
466 |
state.getCdmRepository());
|
437 |
467 |
DnaSample dnaSample = dnaParser.parse(item, state);
|
438 |
468 |
save(dnaSample, state);
|
439 |
|
//set dna as derived unit to avoid creating an extra specimen for this dna sample (instead just the field unit will be created)
|
|
469 |
// set dna as derived unit to avoid creating an extra specimen
|
|
470 |
// for this dna sample (instead just the field unit will be
|
|
471 |
// created)
|
440 |
472 |
state.setDerivedUnitBase(dnaSample);
|
441 |
473 |
derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
|
442 |
|
}
|
443 |
|
else{
|
|
474 |
} else {
|
444 |
475 |
// create facade
|
445 |
476 |
derivedUnitFacade = getFacade(state);
|
446 |
477 |
state.setDerivedUnitBase(derivedUnitFacade.innerDerivedUnit());
|
... | ... | |
451 |
482 |
* GATHERING EVENT
|
452 |
483 |
*/
|
453 |
484 |
|
454 |
|
//look for existing fieldUnit
|
|
485 |
// look for existing fieldUnit
|
455 |
486 |
|
456 |
487 |
FieldUnit fieldUnit = state.getFieldUnit(state.getDataHolder().getFieldNumber());
|
457 |
488 |
|
|
489 |
// gathering event
|
|
490 |
UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(cdmAppController.getTermService(),
|
|
491 |
state.getDataHolder().locality, state.getDataHolder().languageIso, state.getDataHolder().longitude,
|
|
492 |
state.getDataHolder().latitude, state.getDataHolder().getGatheringElevationText(),
|
|
493 |
state.getDataHolder().getGatheringElevationMin(), state.getDataHolder().getGatheringElevationMax(),
|
|
494 |
state.getDataHolder().getGatheringElevationUnit(), state.getDataHolder().getGatheringDateText(),
|
|
495 |
state.getDataHolder().getGatheringNotes(), state.getDataHolder().getGatheringMethod(),
|
|
496 |
state.getTransformer().getReferenceSystemByKey(state.getDataHolder().getGatheringSpatialDatum()),
|
|
497 |
state.getConfig());
|
|
498 |
|
|
499 |
unitsGatheringEvent.setGatheringDepth(state.getDataHolder().getGatheringDepthText(),
|
|
500 |
state.getDataHolder().getGatheringDepthMin(), state.getDataHolder().getGatheringDepthMax(),
|
|
501 |
state.getDataHolder().getGatheringDepthUnit());
|
|
502 |
// unitsGatheringEvent.setHeight(heightText, heightMin, heightMax,
|
|
503 |
// heightUnit);
|
|
504 |
if (state.getDataHolder().gatheringAgentsList.isEmpty()) {
|
|
505 |
unitsGatheringEvent.setCollector(state.getPersonStore().get(state.getDataHolder().gatheringAgentsText),
|
|
506 |
config);
|
|
507 |
} else {
|
|
508 |
unitsGatheringEvent.setCollector(
|
|
509 |
state.getPersonStore().get(state.getDataHolder().gatheringAgentsList.toString()), config);
|
|
510 |
}
|
|
511 |
// count
|
|
512 |
UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
|
|
513 |
// unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),
|
|
514 |
// getTermService());
|
|
515 |
unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country,
|
|
516 |
(state.getConfig()), cdmAppController.getTermService(), cdmAppController.getOccurrenceService(),
|
|
517 |
cdmAppController.getVocabularyService());
|
|
518 |
|
|
519 |
DefinedTermBase<?> areaCountry = unitsGatheringArea.getCountry();
|
|
520 |
|
|
521 |
// other areas
|
|
522 |
unitsGatheringArea = new UnitsGatheringArea();
|
|
523 |
// unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
|
|
524 |
|
|
525 |
unitsGatheringArea.setAreas(state.getDataHolder().getNamedAreaList(), (state.getConfig()),
|
|
526 |
cdmAppController.getTermService(), cdmAppController.getVocabularyService());
|
|
527 |
|
|
528 |
ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();
|
|
529 |
for (DefinedTermBase namedArea : nas) {
|
|
530 |
unitsGatheringEvent.addArea(namedArea);
|
|
531 |
}
|
458 |
532 |
|
459 |
|
// gathering event
|
460 |
|
UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(cdmAppController.getTermService(),
|
461 |
|
state.getDataHolder().locality, state.getDataHolder().languageIso, state.getDataHolder().longitude,
|
462 |
|
state.getDataHolder().latitude, state.getDataHolder().getGatheringElevationText(),
|
463 |
|
state.getDataHolder().getGatheringElevationMin(), state.getDataHolder().getGatheringElevationMax(),
|
464 |
|
state.getDataHolder().getGatheringElevationUnit(), state.getDataHolder().getGatheringDateText(),
|
465 |
|
state.getDataHolder().getGatheringNotes(), state.getDataHolder().getGatheringMethod(), state.getTransformer().getReferenceSystemByKey(
|
466 |
|
state.getDataHolder().getGatheringSpatialDatum()),
|
467 |
|
state.getConfig());
|
468 |
|
|
469 |
|
unitsGatheringEvent.setGatheringDepth(state.getDataHolder().getGatheringDepthText(),state.getDataHolder().getGatheringDepthMin(), state.getDataHolder().getGatheringDepthMax(), state.getDataHolder().getGatheringDepthUnit());
|
470 |
|
//unitsGatheringEvent.setHeight(heightText, heightMin, heightMax, heightUnit);
|
471 |
|
if(state.getDataHolder().gatheringAgentsList.isEmpty()) {
|
472 |
|
unitsGatheringEvent.setCollector(state.getPersonStore().get(state.getDataHolder().gatheringAgentsText), config);
|
473 |
|
}else{
|
474 |
|
unitsGatheringEvent.setCollector(state.getPersonStore().get(state.getDataHolder().gatheringAgentsList.toString()), config);
|
475 |
|
}
|
476 |
|
// count
|
477 |
|
UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
|
478 |
|
// unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());
|
479 |
|
unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, (state.getConfig()), cdmAppController.getTermService(), cdmAppController.getOccurrenceService(), cdmAppController.getVocabularyService());
|
480 |
|
|
481 |
|
DefinedTermBase<?> areaCountry = unitsGatheringArea.getCountry();
|
482 |
|
|
483 |
|
// other areas
|
484 |
|
unitsGatheringArea = new UnitsGatheringArea();
|
485 |
|
// unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
|
486 |
|
|
487 |
|
unitsGatheringArea.setAreas(state.getDataHolder().getNamedAreaList(),(state.getConfig()), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
|
488 |
|
|
489 |
|
ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();
|
490 |
|
for (DefinedTermBase namedArea : nas) {
|
491 |
|
unitsGatheringEvent.addArea(namedArea);
|
492 |
|
}
|
493 |
|
|
494 |
|
// copy gathering event to facade
|
495 |
|
GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
|
496 |
|
if (fieldUnit != null){
|
497 |
|
derivedUnitFacade.setFieldUnit(fieldUnit);
|
498 |
|
}
|
|
533 |
// copy gathering event to facade
|
|
534 |
GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
|
|
535 |
if (fieldUnit != null) {
|
|
536 |
derivedUnitFacade.setFieldUnit(fieldUnit);
|
|
537 |
}
|
499 |
538 |
|
500 |
|
derivedUnitFacade.setLocality(gatheringEvent.getLocality());
|
501 |
|
derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
|
502 |
|
derivedUnitFacade.setCollector(gatheringEvent.getCollector());
|
503 |
|
derivedUnitFacade.setCountry((NamedArea)areaCountry);
|
504 |
|
derivedUnitFacade.setAbsoluteElevationText(gatheringEvent.getAbsoluteElevationText());
|
505 |
|
derivedUnitFacade.setAbsoluteElevation(gatheringEvent.getAbsoluteElevation());
|
506 |
|
derivedUnitFacade.setAbsoluteElevationMax(gatheringEvent.getAbsoluteElevationMax());
|
507 |
|
derivedUnitFacade.setDistanceToGroundText(gatheringEvent.getDistanceToGroundText());
|
508 |
|
derivedUnitFacade.setDistanceToGroundMax(gatheringEvent.getDistanceToGroundMax());
|
509 |
|
derivedUnitFacade.setDistanceToGround(gatheringEvent.getDistanceToGround());
|
510 |
|
derivedUnitFacade.setDistanceToWaterSurfaceText(gatheringEvent.getDistanceToWaterSurfaceText());
|
511 |
|
derivedUnitFacade.setDistanceToWaterSurfaceMax(gatheringEvent.getDistanceToWaterSurfaceMax());
|
512 |
|
derivedUnitFacade.setDistanceToWaterSurface(gatheringEvent.getDistanceToWaterSurface());
|
513 |
|
derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());
|
514 |
|
derivedUnitFacade.setCollectingMethod(gatheringEvent.getCollectingMethod());
|
515 |
|
|
516 |
|
for(DefinedTermBase<?> area:unitsGatheringArea.getAreas()){
|
517 |
|
derivedUnitFacade.addCollectingArea((NamedArea) area);
|
518 |
|
}
|
519 |
|
// derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
|
520 |
|
// TODO exsiccatum
|
|
539 |
derivedUnitFacade.setLocality(gatheringEvent.getLocality());
|
|
540 |
derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
|
|
541 |
derivedUnitFacade.setCollector(gatheringEvent.getCollector());
|
|
542 |
derivedUnitFacade.setCountry((NamedArea) areaCountry);
|
|
543 |
derivedUnitFacade.setAbsoluteElevationText(gatheringEvent.getAbsoluteElevationText());
|
|
544 |
derivedUnitFacade.setAbsoluteElevation(gatheringEvent.getAbsoluteElevation());
|
|
545 |
derivedUnitFacade.setAbsoluteElevationMax(gatheringEvent.getAbsoluteElevationMax());
|
|
546 |
derivedUnitFacade.setDistanceToGroundText(gatheringEvent.getDistanceToGroundText());
|
|
547 |
derivedUnitFacade.setDistanceToGroundMax(gatheringEvent.getDistanceToGroundMax());
|
|
548 |
derivedUnitFacade.setDistanceToGround(gatheringEvent.getDistanceToGround());
|
|
549 |
derivedUnitFacade.setDistanceToWaterSurfaceText(gatheringEvent.getDistanceToWaterSurfaceText());
|
|
550 |
derivedUnitFacade.setDistanceToWaterSurfaceMax(gatheringEvent.getDistanceToWaterSurfaceMax());
|
|
551 |
derivedUnitFacade.setDistanceToWaterSurface(gatheringEvent.getDistanceToWaterSurface());
|
|
552 |
derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());
|
|
553 |
derivedUnitFacade.setCollectingMethod(gatheringEvent.getCollectingMethod());
|
|
554 |
|
|
555 |
for (DefinedTermBase<?> area : unitsGatheringArea.getAreas()) {
|
|
556 |
derivedUnitFacade.addCollectingArea((NamedArea) area);
|
|
557 |
}
|
|
558 |
// derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
|
|
559 |
// TODO exsiccatum
|
521 |
560 |
|
522 |
|
// add fieldNumber
|
523 |
|
derivedUnitFacade.setFieldNumber(NB(state.getDataHolder().getFieldNumber()));
|
524 |
|
save(unitsGatheringEvent.getLocality(), state);
|
|
561 |
// add fieldNumber
|
|
562 |
derivedUnitFacade.setFieldNumber(NB(state.getDataHolder().getFieldNumber()));
|
|
563 |
save(unitsGatheringEvent.getLocality(), state);
|
525 |
564 |
|
526 |
565 |
// add unitNotes
|
527 |
|
if (state.getDataHolder().getUnitNotes() != null){
|
528 |
|
derivedUnitFacade.addAnnotation(Annotation.NewDefaultLanguageInstance(NB(state.getDataHolder().getUnitNotes())));
|
|
566 |
if (state.getDataHolder().getUnitNotes() != null) {
|
|
567 |
derivedUnitFacade
|
|
568 |
.addAnnotation(Annotation.NewDefaultLanguageInstance(NB(state.getDataHolder().getUnitNotes())));
|
|
569 |
}
|
|
570 |
if (gatheringEvent.getAnnotations() != null) {
|
|
571 |
for (Annotation annotation: gatheringEvent.getAnnotations()){
|
|
572 |
derivedUnitFacade.getGatheringEvent(true).
|
|
573 |
addAnnotation(annotation );
|
|
574 |
}
|
529 |
575 |
}
|
530 |
|
|
531 |
|
|
532 |
576 |
|
533 |
577 |
// //add Multimedia URLs
|
534 |
578 |
if (state.getDataHolder().getMultimediaObjects().size() != -1) {
|
... | ... | |
536 |
580 |
Media media;
|
537 |
581 |
try {
|
538 |
582 |
media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
|
539 |
|
Map<String, String> attributes = state.getDataHolder().getMultimediaObjects().get(multimediaObject);
|
540 |
|
if (attributes.containsKey("Context")){
|
541 |
|
LanguageString description = LanguageString.NewInstance(attributes.get("Context"), Language.ENGLISH());
|
|
583 |
Map<String, String> attributes = state.getDataHolder().getMultimediaObjects()
|
|
584 |
.get(multimediaObject);
|
|
585 |
if (attributes.containsKey("Context")) {
|
|
586 |
LanguageString description = LanguageString.NewInstance(attributes.get("Context"),
|
|
587 |
Language.ENGLISH());
|
542 |
588 |
media.addDescription(description);
|
543 |
589 |
}
|
544 |
|
if (attributes.containsKey("Comment")){
|
545 |
|
LanguageString description = LanguageString.NewInstance(attributes.get("Comment"), Language.ENGLISH());
|
|
590 |
if (attributes.containsKey("Comment")) {
|
|
591 |
LanguageString description = LanguageString.NewInstance(attributes.get("Comment"),
|
|
592 |
Language.ENGLISH());
|
546 |
593 |
media.addDescription(description);
|
547 |
594 |
}
|
548 |
|
if (attributes.containsKey("Creators")){
|
|
595 |
if (attributes.containsKey("Creators")) {
|
549 |
596 |
String creators = attributes.get("Creators");
|
550 |
597 |
Person artist;
|
551 |
598 |
Team artistTeam;
|
552 |
599 |
String[] artists;
|
553 |
|
if (creators != null){
|
554 |
|
if (creators.contains("&")){
|
|
600 |
if (creators != null) {
|
|
601 |
if (creators.contains("&")) {
|
555 |
602 |
artists = creators.split("&");
|
556 |
603 |
artistTeam = new Team();
|
557 |
|
for (String creator:artists){
|
|
604 |
for (String creator : artists) {
|
558 |
605 |
artist = Person.NewTitledInstance(creator);
|
559 |
606 |
artistTeam.addTeamMember(artist);
|
560 |
607 |
}
|
561 |
608 |
media.setArtist(artistTeam);
|
562 |
|
} else{
|
|
609 |
} else {
|
563 |
610 |
|
564 |
611 |
artist = Person.NewTitledInstance(creators);
|
565 |
612 |
media.setArtist(artist);
|
566 |
613 |
}
|
567 |
614 |
}
|
568 |
615 |
|
569 |
|
|
570 |
|
|
571 |
616 |
}
|
572 |
617 |
|
573 |
618 |
derivedUnitFacade.addDerivedUnitMedia(media);
|
574 |
|
if(state.getConfig().isAddMediaAsMediaSpecimen()){
|
575 |
|
//add media also as specimen scan
|
576 |
|
MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
|
|
619 |
if (state.getConfig().isAddMediaAsMediaSpecimen()) {
|
|
620 |
// add media also as specimen scan
|
|
621 |
MediaSpecimen mediaSpecimen = MediaSpecimen
|
|
622 |
.NewInstance(SpecimenOrObservationType.StillImage);
|
577 |
623 |
mediaSpecimen.setMediaSpecimen(media);
|
578 |
|
//do it only once!!
|
|
624 |
// do it only once!!
|
579 |
625 |
DefinedTermBase specimenScanTerm = getTermService().load(SPECIMEN_SCAN_TERM);
|
580 |
|
if(specimenScanTerm instanceof DefinedTerm){
|
|
626 |
if (specimenScanTerm instanceof DefinedTerm) {
|
581 |
627 |
mediaSpecimen.setKindOfUnit((DefinedTerm) specimenScanTerm);
|
582 |
628 |
}
|
583 |
|
DerivationEvent derivationEvent = DerivationEvent.NewInstance(DerivationEventType.PREPARATION());
|
|
629 |
DerivationEvent derivationEvent = DerivationEvent
|
|
630 |
.NewInstance(DerivationEventType.PREPARATION());
|
584 |
631 |
derivationEvent.addDerivative(mediaSpecimen);
|
585 |
632 |
derivedUnitFacade.innerDerivedUnit().addDerivationEvent(derivationEvent);
|
586 |
633 |
}
|
... | ... | |
592 |
639 |
|
593 |
640 |
}
|
594 |
641 |
}
|
595 |
|
//multimedia for fieldUnit
|
|
642 |
// multimedia for fieldUnit
|
596 |
643 |
if (state.getDataHolder().getGatheringMultimediaObjects().size() != -1) {
|
597 |
644 |
for (String multimediaObject : state.getDataHolder().getGatheringMultimediaObjects().keySet()) {
|
598 |
645 |
Media media;
|
599 |
646 |
try {
|
600 |
647 |
media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
|
601 |
|
Map<String, String> attributes = state.getDataHolder().getGatheringMultimediaObjects().get(multimediaObject);
|
602 |
|
if (attributes.containsKey("Context")){
|
603 |
|
LanguageString description = LanguageString.NewInstance(attributes.get("Context"), Language.ENGLISH());
|
|
648 |
Map<String, String> attributes = state.getDataHolder().getGatheringMultimediaObjects()
|
|
649 |
.get(multimediaObject);
|
|
650 |
if (attributes.containsKey("Context")) {
|
|
651 |
LanguageString description = LanguageString.NewInstance(attributes.get("Context"),
|
|
652 |
Language.ENGLISH());
|
604 |
653 |
media.addDescription(description);
|
605 |
654 |
}
|
606 |
|
if (attributes.containsKey("Comment")){
|
607 |
|
LanguageString description = LanguageString.NewInstance(attributes.get("Comment"), Language.ENGLISH());
|
|
655 |
if (attributes.containsKey("Comment")) {
|
|
656 |
LanguageString description = LanguageString.NewInstance(attributes.get("Comment"),
|
|
657 |
Language.ENGLISH());
|
608 |
658 |
media.addDescription(description);
|
609 |
659 |
}
|
610 |
|
if (attributes.containsKey("Creators")){
|
|
660 |
if (attributes.containsKey("Creators")) {
|
611 |
661 |
String creators = attributes.get("Creators");
|
612 |
662 |
Person artist;
|
613 |
663 |
Team artistTeam;
|
614 |
664 |
String[] artists;
|
615 |
|
if (creators != null){
|
616 |
|
if (creators.contains("&")){
|
|
665 |
if (creators != null) {
|
|
666 |
if (creators.contains("&")) {
|
617 |
667 |
artists = creators.split("&");
|
618 |
668 |
artistTeam = new Team();
|
619 |
|
for (String creator:artists){
|
|
669 |
for (String creator : artists) {
|
620 |
670 |
artist = Person.NewTitledInstance(creator);
|
621 |
671 |
artistTeam.addTeamMember(artist);
|
622 |
672 |
}
|
623 |
673 |
media.setArtist(artistTeam);
|
624 |
|
} else{
|
|
674 |
} else {
|
625 |
675 |
|
626 |
676 |
artist = Person.NewTitledInstance(creators);
|
627 |
677 |
media.setArtist(artist);
|
628 |
678 |
}
|
629 |
679 |
}
|
630 |
680 |
|
631 |
|
|
632 |
|
|
633 |
681 |
}
|
634 |
682 |
|
635 |
683 |
derivedUnitFacade.addFieldObjectMedia(media);
|
636 |
684 |
|
637 |
|
|
638 |
685 |
} catch (MalformedURLException e) {
|
639 |
686 |
// TODO Auto-generated catch block
|
640 |
687 |
e.printStackTrace();
|
... | ... | |
643 |
690 |
}
|
644 |
691 |
}
|
645 |
692 |
|
646 |
|
// /*
|
647 |
|
// * merge AND STORE DATA
|
648 |
|
// */
|
649 |
|
// getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
|
|
693 |
// /*
|
|
694 |
// * merge AND STORE DATA
|
|
695 |
// */
|
|
696 |
// getTermService().saveOrUpdate(areaCountry);// TODO save area
|
|
697 |
// sooner
|
650 |
698 |
//
|
651 |
|
// for (NamedArea area : otherAreas) {
|
652 |
|
// getTermService().saveOrUpdate(area);// merge it sooner (foreach area)
|
653 |
|
// }
|
654 |
|
// save(derivedUnitFacade.getFieldUnit(false), state);
|
655 |
|
if (derivedUnitFacade.getFieldUnit(false) != null){
|
656 |
|
state.setFieldUnit(derivedUnitFacade.getFieldUnit(false));
|
657 |
|
}
|
|
699 |
// for (NamedArea area : otherAreas) {
|
|
700 |
// getTermService().saveOrUpdate(area);// merge it sooner (foreach
|
|
701 |
// area)
|
|
702 |
// }
|
|
703 |
// save(derivedUnitFacade.getFieldUnit(false), state);
|
|
704 |
if (derivedUnitFacade.getFieldUnit(false) != null) {
|
|
705 |
state.setFieldUnit(derivedUnitFacade.getFieldUnit(false));
|
|
706 |
}
|
658 |
707 |
|
659 |
708 |
// handle collection data
|
660 |
709 |
setCollectionData(state, derivedUnitFacade);
|
661 |
710 |
|
662 |
|
//Reference stuff
|
|
711 |
// Reference stuff
|
663 |
712 |
SpecimenUserInteraction sui = config.getSpecimenUserInteraction();
|
664 |
|
Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<>();
|
|
713 |
Map<String, OriginalSourceBase<?>> sourceMap = new HashMap<>();
|
665 |
714 |
|
666 |
715 |
state.getDataHolder().setDocSources(new ArrayList<>());
|
667 |
716 |
for (String[] fullReference : state.getDataHolder().getReferenceList()) {
|
668 |
|
String strReference=fullReference[0];
|
|
717 |
String strReference = fullReference[0];
|
669 |
718 |
String citationDetail = fullReference[1];
|
670 |
719 |
String citationURL = fullReference[2];
|
671 |
720 |
|
672 |
721 |
if (!citationURL.isEmpty()) {
|
673 |
|
citationDetail+=", "+citationURL;
|
|
722 |
citationDetail += ", " + citationURL;
|
674 |
723 |
}
|
675 |
724 |
|
676 |
725 |
Reference reference;
|
677 |
|
if(strReference.equals(state.getRef().getTitleCache())){
|
|
726 |
if (strReference.equals(state.getRef().getTitleCache())) {
|
678 |
727 |
reference = state.getRef();
|
679 |
|
}
|
680 |
|
else{
|
|
728 |
} else {
|
681 |
729 |
reference = ReferenceFactory.newGeneric();
|
682 |
730 |
reference.setTitle(strReference);
|
683 |
731 |
}
|
684 |
732 |
|
685 |
|
|
686 |
733 |
save(reference, state);
|
687 |
734 |
IdentifiableSource sour = getIdentifiableSource(reference, citationDetail);
|
688 |
735 |
sour.getCitation().setUri(state.getActualAccessPoint());
|
689 |
736 |
sour.setType(OriginalSourceType.PrimaryTaxonomicSource);
|
690 |
|
try{
|
691 |
|
if (sour.getCitation() != null){
|
692 |
|
if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
|
693 |
|
state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
|
|
737 |
try {
|
|
738 |
if (sour.getCitation() != null) {
|
|
739 |
if (StringUtils.isNotBlank(sour.getCitationMicroReference())) {
|
|
740 |
state.getDataHolder().getDocSources()
|
|
741 |
.add(sour.getCitation().getTitleCache() + "---" + sour.getCitationMicroReference());
|
694 |
742 |
} else {
|
695 |
743 |
state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache());
|
696 |
744 |
}
|
697 |
745 |
}
|
698 |
|
}catch(Exception e){
|
|
746 |
} catch (Exception e) {
|
699 |
747 |
logger.warn("oups");
|
700 |
748 |
}
|
701 |
749 |
derivedUnitFacade.addSource(sour);
|
702 |
750 |
|
703 |
751 |
}
|
704 |
|
// List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
|
705 |
|
// List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
|
706 |
|
//
|
707 |
|
// Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
|
708 |
|
// if(issTmp2!=null) {
|
709 |
|
// osbSet.addAll(issTmp2);
|
710 |
|
// }
|
711 |
|
// if(issTmp!=null) {
|
712 |
|
// osbSet.addAll(issTmp);
|
713 |
|
// }
|
714 |
|
|
715 |
|
IdentifiableSource sour = getIdentifiableSource(state.getRef(),null);
|
716 |
|
String idInSource = derivedUnitFacade.getAccessionNumber() != null? derivedUnitFacade.getAccessionNumber():derivedUnitFacade.getCatalogNumber();
|
|
752 |
// List<IdentifiableSource> issTmp = new
|
|
753 |
// ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class,
|
|
754 |
// null, null, null, null);
|
|
755 |
// List<DescriptionElementSource> issTmp2 = new
|
|
756 |
// ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class,
|
|
757 |
// null, null, null, null);
|
|
758 |
//
|
|
759 |
// Set<OriginalSourceBase> osbSet = new
|
|
760 |
// HashSet<OriginalSourceBase>();
|
|
761 |
// if(issTmp2!=null) {
|
|
762 |
// osbSet.addAll(issTmp2);
|
|
763 |
// }
|
|
764 |
// if(issTmp!=null) {
|
|
765 |
// osbSet.addAll(issTmp);
|
|
766 |
// }
|
|
767 |
|
|
768 |
IdentifiableSource sour = getIdentifiableSource(state.getRef(), null);
|
|
769 |
String idInSource = derivedUnitFacade.getAccessionNumber() != null ? derivedUnitFacade.getAccessionNumber()
|
|
770 |
: derivedUnitFacade.getCatalogNumber();
|
717 |
771 |
sour.getCitation().setUri(state.getActualAccessPoint());
|
718 |
772 |
sour.setIdInSource(idInSource);
|
719 |
|
try{
|
720 |
|
if (sour.getCitation() != null){
|
721 |
|
if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
|
722 |
|
state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
|
|
773 |
try {
|
|
774 |
if (sour.getCitation() != null) {
|
|
775 |
if (StringUtils.isNotBlank(sour.getCitationMicroReference())) {
|
|
776 |
state.getDataHolder().getDocSources()
|
|
777 |
.add(sour.getCitation().getTitleCache() + "---" + sour.getCitationMicroReference());
|
723 |
778 |
} else {
|
724 |
779 |
state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache());
|
725 |
780 |
}
|
726 |
781 |
}
|
727 |
|
}catch(Exception e){
|
|
782 |
} catch (Exception e) {
|
728 |
783 |
logger.warn("oups");
|
729 |
784 |
}
|
730 |
785 |
|
731 |
|
derivedUnitFacade.addSource(sour);
|
732 |
|
// sourceMap.put(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference(),sour);
|
733 |
|
|
734 |
|
// if( state.getConfig().isInteractWithUser()){
|
735 |
|
// List<OriginalSourceBase<?>>sources=null;
|
736 |
|
// if(!state.isDerivedUnitSourcesSet()){
|
737 |
|
// sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().getDocSources());
|
738 |
|
// state.setDerivedUnitSources(sources);
|
739 |
|
// state.setDerivedUnitSourcesSet(true);
|
740 |
|
// }
|
741 |
|
// else{
|
742 |
|
// sources=state.getDerivedUnitSources();
|
743 |
|
// }
|
744 |
|
//// for (OriginalSourceBase<?> source:sources){
|
745 |
|
//// if(source.isInstanceOf(IdentifiableSource.class)){
|
746 |
|
//// if(sourceNotLinkedToElement(derivedUnitFacade,source)) {
|
747 |
|
//// derivedUnitFacade.addSource((IdentifiableSource)source.clone());
|
748 |
|
//// }
|
749 |
|
//// }else{
|
750 |
|
//// if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
|
751 |
|
//// derivedUnitFacade.addSource(OriginalSourceType.Import,source.getCitation(),source.getCitationMicroReference(), ioName);
|
752 |
|
//// }
|
753 |
|
//// }
|
754 |
|
//// }
|
755 |
|
// }else{
|
756 |
|
// for (OriginalSourceBase<?> sr : sourceMap.values()){
|
757 |
|
// if(sr.isInstanceOf(IdentifiableSource.class)){
|
758 |
|
// if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
|
759 |
|
// derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
|
760 |
|
// }
|
761 |
|
// }else{
|
762 |
|
// if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
|
763 |
|
// derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);
|
764 |
|
// }
|
765 |
|
// }
|
766 |
|
// }
|
767 |
|
// }
|
|
786 |
derivedUnitFacade.addSource(sour);
|
|
787 |
// sourceMap.put(sour.getCitation().getTitleCache()+
|
|
788 |
// "---"+sour.getCitationMicroReference(),sour);
|
|
789 |
|
|
790 |
// if( state.getConfig().isInteractWithUser()){
|
|
791 |
// List<OriginalSourceBase<?>>sources=null;
|
|
792 |
// if(!state.isDerivedUnitSourcesSet()){
|
|
793 |
// sources= sui.askForSource(sourceMap, "the unit
|
|
794 |
// itself","",getReferenceService(),
|
|
795 |
// state.getDataHolder().getDocSources());
|
|
796 |
// state.setDerivedUnitSources(sources);
|
|
797 |
// state.setDerivedUnitSourcesSet(true);
|
|
798 |
// }
|
|
799 |
// else{
|
|
800 |
// sources=state.getDerivedUnitSources();
|
|
801 |
// }
|
|
802 |
//// for (OriginalSourceBase<?> source:sources){
|
|
803 |
//// if(source.isInstanceOf(IdentifiableSource.class)){
|
|
804 |
//// if(sourceNotLinkedToElement(derivedUnitFacade,source)) {
|
|
805 |
//// derivedUnitFacade.addSource((IdentifiableSource)source.clone());
|
|
806 |
//// }
|
|
807 |
//// }else{
|
|
808 |
//// if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
|
|
809 |
//// derivedUnitFacade.addSource(OriginalSourceType.Import,source.getCitation(),source.getCitationMicroReference(),
|
|
810 |
// ioName);
|
|
811 |
//// }
|
|
812 |
//// }
|
|
813 |
//// }
|
|
814 |
// }else{
|
|
815 |
// for (OriginalSourceBase<?> sr : sourceMap.values()){
|
|
816 |
// if(sr.isInstanceOf(IdentifiableSource.class)){
|
|
817 |
// if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
|
|
818 |
// derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
|
|
819 |
// }
|
|
820 |
// }else{
|
|
821 |
// if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
|
|
822 |
// derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(),
|
|
823 |
// ioName);
|
|
824 |
// }
|
|
825 |
// }
|
|
826 |
// }
|
|
827 |
// }
|
768 |
828 |
|
769 |
829 |
save(state.getDerivedUnitBase(), state);
|
770 |
830 |
|
771 |
|
if(logger.isDebugEnabled()) {
|
|
831 |
if (logger.isDebugEnabled()) {
|
772 |
832 |
logger.info("saved ABCD specimen ...");
|
773 |
833 |
}
|
774 |
834 |
|
775 |
835 |
// handle identifications
|
776 |
836 |
handleIdentifications(state, derivedUnitFacade);
|
777 |
837 |
|
778 |
|
//associatedUnits
|
779 |
|
if (handleAssociatedUnits){
|
|
838 |
// associatedUnits
|
|
839 |
if (handleAssociatedUnits) {
|
780 |
840 |
importAssociatedUnits(state, item, derivedUnitFacade);
|
781 |
841 |
}
|
782 |
|
//siblings/ other children
|
783 |
|
if (derivedUnitFacade.getType() != null && (derivedUnitFacade.getType().equals(SpecimenOrObservationType.LivingSpecimen) || derivedUnitFacade.getType().equals(SpecimenOrObservationType.TissueSample) || derivedUnitFacade.getType().equals(SpecimenOrObservationType.OtherSpecimen)) &&state.getConfig().isGetSiblings()){
|
|
842 |
// siblings/ other children
|
|
843 |
if (derivedUnitFacade.getType() != null
|
|
844 |
&& (derivedUnitFacade.getType().equals(SpecimenOrObservationType.LivingSpecimen)
|
|
845 |
|| derivedUnitFacade.getType().equals(SpecimenOrObservationType.TissueSample)
|
|
846 |
|| derivedUnitFacade.getType().equals(SpecimenOrObservationType.OtherSpecimen))
|
|
847 |
&& state.getConfig().isGetSiblings()) {
|
784 |
848 |
getSiblings(state, item, derivedUnitFacade);
|
785 |
849 |
}
|
786 |
850 |
|
787 |
|
|
788 |
851 |
} catch (Exception e) {
|
789 |
852 |
String message = "Error when reading record!";
|
790 |
853 |
logger.warn(message);
|
... | ... | |
797 |
860 |
}
|
798 |
861 |
|
799 |
862 |
@Override
|
800 |
|
protected void importAssociatedUnits(Abcd206ImportState state, Object itemObject, DerivedUnitFacade derivedUnitFacade) {
|
|
863 |
protected void importAssociatedUnits(Abcd206ImportState state, Object itemObject,
|
|
864 |
DerivedUnitFacade derivedUnitFacade) {
|
801 |
865 |
|
802 |
866 |
Abcd206ImportConfigurator config = state.getConfig();
|
803 |
|
//import associated units
|
|
867 |
// import associated units
|
804 |
868 |
FieldUnit currentFieldUnit = derivedUnitFacade.innerFieldUnit();
|
805 |
|
//TODO: push state (think of implementing stack architecture for state
|
|
869 |
// TODO: push state (think of implementing stack architecture for state
|
806 |
870 |
DerivedUnit currentUnit = state.getDerivedUnitBase();
|
807 |
871 |
DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
|
808 |
872 |
URI currentAccessPoint = state.getActualAccessPoint();
|
809 |
873 |
String currentPrefix = state.getPrefix();
|
810 |
874 |
Element item = null;
|
811 |
|
if (itemObject instanceof Element){
|
812 |
|
item = (Element)itemObject;
|
|
875 |
if (itemObject instanceof Element) {
|
|
876 |
item = (Element) itemObject;
|
813 |
877 |
}
|
814 |
878 |
NodeList unitAssociationList = null;
|
815 |
|
if (item != null){
|
816 |
|
unitAssociationList = item.getElementsByTagName(currentPrefix+"UnitAssociation");
|
817 |
|
for(int k=0;k<unitAssociationList.getLength();k++){
|
818 |
|
if(unitAssociationList.item(k) instanceof Element){
|
819 |
|
Element unitAssociation = (Element)unitAssociationList.item(k);
|
820 |
|
UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
|
|
879 |
if (item != null) {
|
|
880 |
unitAssociationList = item.getElementsByTagName(currentPrefix + "UnitAssociation");
|
|
881 |
for (int k = 0; k < unitAssociationList.getLength(); k++) {
|
|
882 |
if (unitAssociationList.item(k) instanceof Element) {
|
|
883 |
Element unitAssociation = (Element) unitAssociationList.item(k);
|
|
884 |
UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix,
|
|
885 |
state.getReport(), state.getCdmRepository());
|
821 |
886 |
UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
|
822 |
887 |
|
823 |
888 |
state.setActualAccessPoint(associationWrapper.getAccesPoint());
|
824 |
|
if(associationWrapper!=null){
|
|
889 |
if (associationWrapper != null) {
|
825 |
890 |
NodeList associatedUnits = associationWrapper.getAssociatedUnits();
|
826 |
|
if(associatedUnits!=null){
|
827 |
|
for(int m=0;m<associatedUnits.getLength();m++){
|
828 |
|
if(associatedUnits.item(m) instanceof Element){
|
|
891 |
if (associatedUnits != null) {
|
|
892 |
for (int m = 0; m < associatedUnits.getLength(); m++) {
|
|
893 |
if (associatedUnits.item(m) instanceof Element) {
|
829 |
894 |
state.reset();
|
830 |
895 |
state.setPrefix(associationWrapper.getPrefix());
|
831 |
|
Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);
|
832 |
|
logger.debug("derived unit: " + state.getDerivedUnitBase().toString() + " associated unit: " +state.getDataHolder().getKindOfUnit() + ", " + state.getDataHolder().accessionNumber + ", " + state.getDataHolder().getRecordBasis() + ", " + state.getDataHolder().getUnitID());
|
|
896 |
Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m),
|
|
897 |
new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);
|
|
898 |
logger.debug("derived unit: " + state.getDerivedUnitBase().toString()
|
|
899 |
+ " associated unit: " + state.getDataHolder().getKindOfUnit() + ", "
|
|
900 |
+ state.getDataHolder().accessionNumber + ", "
|
|
901 |
+ state.getDataHolder().getRecordBasis() + ", "
|
|
902 |
+ state.getDataHolder().getUnitID());
|
833 |
903 |
handleSingleUnit(state, associatedUnits.item(m), true);
|
834 |
904 |
|
835 |
905 |
DerivedUnit associatedUnit = state.getDerivedUnitBase();
|
836 |
906 |
FieldUnit associatedFieldUnit = null;
|
837 |
|
java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid(), null);
|
838 |
|
//ignore field unit if associated unit has more than one
|
839 |
|
if(associatedFieldUnits.size()>1){
|
840 |
|
state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
|
841 |
|
}
|
842 |
|
else if(associatedFieldUnits.size()==1){
|
|
907 |
java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository()
|
|
908 |
.getOccurrenceService().findFieldUnits(associatedUnit.getUuid(), null);
|
|
909 |
// ignore field unit if associated unit has
|
|
910 |
// more than one
|
|
911 |
if (associatedFieldUnits.size() > 1) {
|
|
912 |
state.getReport().addInfoMessage(
|
|
913 |
String.format("%s has more than one field unit.", associatedUnit));
|
|
914 |
} else if (associatedFieldUnits.size() == 1) {
|
843 |
915 |
associatedFieldUnit = associatedFieldUnits.iterator().next();
|
844 |
916 |
}
|
845 |
917 |
|
846 |
|
//attach current unit and associated unit depending on association type
|
847 |
|
|
848 |
|
//parent-child relation:
|
849 |
|
//copy derivation event and connect parent and sub derivative
|
850 |
|
// if(associationWrapper.getAssociationType().contains("individual") || associationWrapper.getAssociationType().contains("culture") || associationWrapper.getAssociationType().contains("sample") || associationWrapper.getAssociationType().contains("same in situ")){
|
851 |
|
if(currentDerivedFrom==null){
|
852 |
|
state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",SpecimenImportUtility.getUnitID(currentUnit, config)));
|
853 |
|
DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());
|
854 |
|
}
|
855 |
|
else{
|
856 |
|
DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, currentDerivedFrom.getType());
|
857 |
|
updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
|
858 |
|
updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
|
859 |
|
updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
|
860 |
|
updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
|
861 |
|
|
862 |
|
}
|
863 |
|
state.getReport().addDerivate(associatedUnit, currentUnit, config);
|
864 |
|
// }
|
865 |
|
//siblings relation
|
866 |
|
//connect current unit to field unit of associated unit
|
867 |
|
// else if(associationWrapper.getAssociationType().contains("population")|| associationWrapper.getAssociationType().contains("sample")){
|
868 |
|
// //no associated field unit -> using current one
|
869 |
|
// if(associatedFieldUnit==null){
|
870 |
|
// if(currentFieldUnit!=null){
|
871 |
|
// DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());
|
872 |
|
// }
|
873 |
|
// }
|
874 |
|
// else{
|
875 |
|
// if(currentDerivedFrom==null){
|
876 |
|
// state.getReport().addInfoMessage("No derivation event found for unit "+SpecimenImportUtility.getUnitID(currentUnit, config)+". Defaulting to ACCESIONING event.");
|
877 |
|
// DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
|
878 |
|
// }
|
879 |
|
// if(currentDerivedFrom!=null && associatedFieldUnit==currentFieldUnit){
|
880 |
|
// DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());
|
881 |
|
// updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
|
882 |
|
// updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
|
883 |
|
// updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
|
884 |
|
// updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
|
885 |
|
// }
|
886 |
|
// }
|
887 |
|
// }
|
888 |
|
|
889 |
|
//delete current field unit if replaced
|
890 |
|
if(currentFieldUnit!=null && currentDerivedFrom!=null
|
891 |
|
&& currentFieldUnit.getDerivationEvents().size()==1 && currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) //making sure that the field unit
|
892 |
|
&& currentDerivedFrom.getDerivatives().size()==1 && currentDerivedFrom.getDerivatives().contains(currentUnit) //is not attached to other derived units
|
893 |
|
&& currentDerivedFrom!=currentUnit.getDerivedFrom() // <- derivation has been replaced and can be deleted
|
894 |
|
){
|
|
918 |
// attach current unit and associated unit
|
|
919 |
// depending on association type
|
|
920 |
|
|
921 |
// parent-child relation:
|
|
922 |
// copy derivation event and connect parent
|
|
923 |
// and sub derivative
|
|
924 |
// if(associationWrapper.getAssociationType().contains("individual")
|
|
925 |
// ||
|
|
926 |
// associationWrapper.getAssociationType().contains("culture")
|
|
927 |
// ||
|
|
928 |
// associationWrapper.getAssociationType().contains("sample")
|
|
929 |
// ||
|
|
930 |
// associationWrapper.getAssociationType().contains("same
|
|
931 |
// in situ")){
|
|
932 |
if (currentDerivedFrom == null) {
|
|
933 |
state.getReport()
|
|
934 |
.addInfoMessage(String.format(
|
|
935 |
"No derivation event found for unit %s. Defaulting to ACCESSIONING event.",
|
|
936 |
SpecimenImportUtility.getUnitID(currentUnit, config)));
|
|
937 |
DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit,
|
|
938 |
DerivationEventType.ACCESSIONING());
|
|
939 |
} else {
|
|
940 |
DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(
|
|
941 |
associatedUnit, currentUnit, currentDerivedFrom.getType());
|
|
942 |
updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
|
|
943 |
updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
|
|
944 |
updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
|
|
945 |
updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
|
|
946 |
|
|
947 |
}
|
|
948 |
state.getReport().addDerivate(associatedUnit, currentUnit, config);
|
|
949 |
// }
|
|
950 |
// siblings relation
|
|
951 |
// connect current unit to field unit of
|
|
952 |
// associated unit
|
|
953 |
// else
|
|
954 |
// if(associationWrapper.getAssociationType().contains("population")||
|
|
955 |
// associationWrapper.getAssociationType().contains("sample")){
|
|
956 |
// //no associated field unit -> using
|
|
957 |
// current one
|
|
958 |
// if(associatedFieldUnit==null){
|
|
959 |
// if(currentFieldUnit!=null){
|
|
960 |
// DerivationEvent.NewSimpleInstance(currentFieldUnit,
|
|
961 |
// associatedUnit,
|
|
962 |
// DerivationEventType.ACCESSIONING());
|
|
963 |
// }
|
|
964 |
// }
|
|
965 |
// else{
|
|
966 |
// if(currentDerivedFrom==null){
|
|
967 |
// state.getReport().addInfoMessage("No
|
|
968 |
// derivation event found for unit
|
|
969 |
// "+SpecimenImportUtility.getUnitID(currentUnit,
|
|
970 |
// config)+". Defaulting to ACCESIONING
|
|
971 |
// event.");
|
|
972 |
// DerivationEvent.NewSimpleInstance(associatedFieldUnit,
|
|
973 |
// currentUnit,
|
|
974 |
// DerivationEventType.ACCESSIONING());
|
|
975 |
// }
|
|
976 |
// if(currentDerivedFrom!=null &&
|
|
977 |
// associatedFieldUnit==currentFieldUnit){
|
|
978 |
// DerivationEvent updatedDerivationEvent =
|
|
979 |
// DerivationEvent.NewSimpleInstance(associatedFieldUnit,
|
|
980 |
// currentUnit,
|
|
981 |
// currentDerivedFrom.getType());
|
|
982 |
// updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
|
|
983 |
// updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
|
|
984 |
// updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
|
|
985 |
// updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
|
|
986 |
// }
|
|
987 |
// }
|
|
988 |
// }
|
|
989 |
|
|
990 |
// delete current field unit if replaced
|
|
991 |
if (currentFieldUnit != null && currentDerivedFrom != null
|
|
992 |
&& currentFieldUnit.getDerivationEvents().size() == 1
|
|
993 |
&& currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) // making
|
|
994 |
// sure
|
|
995 |
// that
|
|
996 |
// the
|
|
997 |
// field
|
|
998 |
// unit
|
|
999 |
&& currentDerivedFrom.getDerivatives().size() == 1
|
|
1000 |
&& currentDerivedFrom.getDerivatives().contains(currentUnit) // is
|
|
1001 |
// not
|
|
1002 |
// attached
|
|
1003 |
// to
|
|
1004 |
// other
|
|
1005 |
// derived
|
|
1006 |
// units
|
|
1007 |
&& currentDerivedFrom != currentUnit.getDerivedFrom() // <-
|
|
1008 |
// derivation
|
|
1009 |
// has
|
|
1010 |
// been
|
|
1011 |
// replaced
|
|
1012 |
// and
|
|
1013 |
// can
|
|
1014 |
// be
|
|
1015 |
// deleted
|
|
1016 |
) {
|
895 |
1017 |
currentFieldUnit.removeDerivationEvent(currentDerivedFrom);
|
896 |
1018 |
state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);
|
897 |
|
}
|
|
1019 |
}
|
898 |
1020 |
|
899 |
1021 |
save(associatedUnit, state);
|
900 |
1022 |
}
|
... | ... | |
904 |
1026 |
}
|
905 |
1027 |
}
|
906 |
1028 |
}
|
907 |
|
//TODO: pop state
|
|
1029 |
// TODO: pop state
|
908 |
1030 |
state.reset();
|
909 |
1031 |
state.setDerivedUnitBase(currentUnit);
|
910 |
1032 |
state.setActualAccessPoint(currentAccessPoint);
|
911 |
1033 |
state.setPrefix(currentPrefix);
|
912 |
1034 |
}
|
913 |
1035 |
|
914 |
|
|
915 |
|
|
916 |
|
|
917 |
1036 |
/**
|
918 |
1037 |
* @param derivedUnitFacade
|
919 |
1038 |
* @param sour
|
... | ... | |
921 |
1040 |
*/
|
922 |
1041 |
private boolean sourceNotLinkedToElement(DerivedUnitFacade derivedUnitFacade, OriginalSourceBase<?> source) {
|
923 |
1042 |
Set<IdentifiableSource> linkedSources = derivedUnitFacade.getSources();
|
924 |
|
for (IdentifiableSource is:linkedSources){
|
925 |
|
if (is.getCitation()!=null && source.getCitation()!=null &&
|
926 |
|
is.getCitation().getTitleCache().equalsIgnoreCase(source.getCitation().getTitleCache())){
|
927 |
|
String isDetail = is.getCitationMicroReference();
|
|
1043 |
for (IdentifiableSource is : linkedSources) {
|
|
1044 |
if (is.getCitation() != null && source.getCitation() != null
|
|
1045 |
&& is.getCitation().getTitleCache().equalsIgnoreCase(source.getCitation().getTitleCache())) {
|
|
1046 |
String isDetail = is.getCitationMicroReference();
|
928 |
1047 |
if ((StringUtils.isBlank(isDetail) && StringUtils.isBlank(source.getCitationMicroReference()))
|
929 |
|
|| (isDetail != null && isDetail.equalsIgnoreCase(source.getCitationMicroReference())) ) {
|
|
1048 |
|| (isDetail != null && isDetail.equalsIgnoreCase(source.getCitationMicroReference()))) {
|
930 |
1049 |
return false;
|
931 |
1050 |
}
|
932 |
1051 |
}
|
... | ... | |
934 |
1053 |
return true;
|
935 |
1054 |
}
|
936 |
1055 |
|
937 |
|
|
938 |
|
|
939 |
|
// /**
|
940 |
|
// * @param reference
|
941 |
|
// * @param citationDetail
|
942 |
|
// * @return
|
943 |
|
// */
|
944 |
|
// private DescriptionElementSource getDescriptionSource(Reference reference, String citationDetail) {
|
|
1056 |
// /**
|
|
1057 |
// * @param reference
|
|
1058 |
// * @param citationDetail
|
|
1059 |
// * @return
|
|
1060 |
// */
|
|
1061 |
// private DescriptionElementSource getDescriptionSource(Reference
|
|
1062 |
// reference, String citationDetail) {
|
945 |
1063 |
//
|
946 |
|
// List<OriginalSourceBase> issTmp2 = getCommonService().list(DescriptionElementSource.class, null, null, null, null);
|
|
1064 |
// List<OriginalSourceBase> issTmp2 =
|
|
1065 |
// getCommonService().list(DescriptionElementSource.class, null, null, null,
|
|
1066 |
// null);
|
947 |
1067 |
//
|
948 |
|
// try {
|
949 |
|
// for (OriginalSourceBase<?> osb:issTmp2){
|
950 |
|
// if (osb.getCitation().equals(reference) && osb.getCitationMicroReference().equalsIgnoreCase(citationDetail)) {
|
951 |
|
// return (DescriptionElementSource) osb.clone();
|
952 |
|
// }
|
953 |
|
// }
|
954 |
|
// } catch (CloneNotSupportedException e) {
|
955 |
|
// // TODO Auto-generated catch block
|
956 |
|
// e.printStackTrace();
|
957 |
|
// }
|
|
1068 |
// try {
|
|
1069 |
// for (OriginalSourceBase<?> osb:issTmp2){
|
|
1070 |
// if (osb.getCitation().equals(reference) &&
|
|
1071 |
// osb.getCitationMicroReference().equalsIgnoreCase(citationDetail)) {
|
|
1072 |
// return (DescriptionElementSource) osb.clone();
|
|
1073 |
// }
|
|
1074 |
// }
|
|
1075 |
// } catch (CloneNotSupportedException e) {
|
|
1076 |
// // TODO Auto-generated catch block
|
|
1077 |
// e.printStackTrace();
|
|
1078 |
// }
|
958 |
1079 |
//
|
smaller changes in ABCD import