Revision b608e320
Added by Andreas Müller over 6 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/in/BfnXmlImportFeature.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.io.redlist.bfnXml.in; |
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.Arrays; |
|
14 | 13 |
import java.util.List; |
15 | 14 |
import java.util.UUID; |
16 | 15 |
|
... | ... | |
26 | 25 |
import eu.etaxonomy.cdm.io.common.ICdmIO; |
27 | 26 |
import eu.etaxonomy.cdm.io.redlist.bfnXml.BfnXmlConstants; |
28 | 27 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
28 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
29 | 29 |
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; |
30 | 30 |
import eu.etaxonomy.cdm.model.common.TermType; |
31 | 31 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
... | ... | |
41 | 41 |
*/ |
42 | 42 |
@Component |
43 | 43 |
public class BfnXmlImportFeature extends BfnXmlImportBase implements ICdmIO<BfnXmlImportState> { |
44 |
private static final Logger logger = Logger.getLogger(BfnXmlImportFeature.class); |
|
44 |
private static final long serialVersionUID = 3545757825059662424L; |
|
45 |
private static final Logger logger = Logger.getLogger(BfnXmlImportFeature.class); |
|
45 | 46 |
|
46 | 47 |
public BfnXmlImportFeature(){ |
47 | 48 |
super(); |
48 | 49 |
} |
49 | 50 |
|
50 | 51 |
|
51 |
/** Hibernate classification vocabulary initialisation strategy */ |
|
52 |
private static final List<String> VOC_CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[] { |
|
53 |
"classification.$", |
|
54 |
"classification.rootNodes", |
|
55 |
"childNodes", |
|
56 |
"childNodes.taxon", |
|
57 |
"childNodes.taxon.name", |
|
58 |
"taxonNodes", |
|
59 |
"taxonNodes.taxon", |
|
60 |
"synonyms", |
|
61 |
"taxon.*", |
|
62 |
"taxon.sec", |
|
63 |
"taxon.name.*", |
|
64 |
"taxon.synonyms", |
|
65 |
"termVocabulary.*", |
|
66 |
"terms" |
|
67 |
|
|
68 |
}); |
|
69 |
|
|
70 | 52 |
@Override |
71 | 53 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
72 | 54 |
public void doInvoke(BfnXmlImportState state){ |
55 |
logger.info("start create Features in CDM..."); |
|
73 | 56 |
|
74 | 57 |
IVocabularyService vocabularyService = getVocabularyService(); |
75 | 58 |
|
76 |
|
|
77 |
logger.warn("start create Features in CDM..."); |
|
78 | 59 |
ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true); |
79 | 60 |
String childName; |
80 | 61 |
boolean obligatory; |
... | ... | |
186 | 167 |
e.printStackTrace(); |
187 | 168 |
} |
188 | 169 |
Feature redListCat = getFeature(state, featureUUID, strRlKat, strRlKat, strRlKat, null); |
170 |
addSource(redListCat, state); |
|
189 | 171 |
redListCat.setSupportsCategoricalData(supportsCategoricalData); |
190 | 172 |
//TODO implement German, but currently titleCache generation does not yet work correctly with another language |
191 | 173 |
// redListCat.getRepresentation(Language.DEFAULT()).setLanguage(Language.GERMAN()); |
... | ... | |
196 | 178 |
String childElementName = BfnXmlConstants.EL_LWERT; |
197 | 179 |
createOrUpdateStates(bfnNamespace, elListValues, childElementName, redListCat, state); |
198 | 180 |
} |
199 |
createOrUpdateTermVocabulary(TermType.Feature, vocabularyService, redListCat, BfnXmlConstants.VOC_REDLIST_FEATURES); |
|
181 |
TermVocabulary<?> voc = createOrUpdateTermVocabulary(TermType.Feature, vocabularyService, redListCat, BfnXmlConstants.VOC_REDLIST_FEATURES); |
|
182 |
addSource(voc, state); |
|
200 | 183 |
} |
201 | 184 |
|
202 |
@SuppressWarnings({ "rawtypes" }) |
|
185 |
/** |
|
186 |
* @param redListCat |
|
187 |
* @param state |
|
188 |
*/ |
|
189 |
private void addSource(IdentifiableEntity<?> redListCat, BfnXmlImportState state) { |
|
190 |
if (redListCat.getSources().isEmpty()){ |
|
191 |
String id = null; |
|
192 |
String idNamespace = null; |
|
193 |
String detail = null; |
|
194 |
redListCat.addImportSource(id, idNamespace, state.getCompleteSourceRef(), detail); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
@SuppressWarnings({ "rawtypes" }) |
|
203 | 200 |
private TermVocabulary createOrUpdateTermVocabulary(TermType termType, IVocabularyService vocabularyService, DefinedTermBase term, String strTermVocabulary) { |
204 | 201 |
|
205 | 202 |
//create/get red list feature vocabulary |
... | ... | |
219 | 216 |
|
220 | 217 |
List<Element> elListValueList = elListValues.getChildren(childElementName, bfnNamespace); |
221 | 218 |
|
222 |
OrderedTermVocabulary termVocabulary = null;
|
|
219 |
OrderedTermVocabulary stateVocabulary = null;
|
|
223 | 220 |
for(Element elListValue:elListValueList){ |
224 | 221 |
String listValue = elListValue.getTextNormalize(); |
225 | 222 |
String matchedListValue; |
... | ... | |
235 | 232 |
matchedListValue = BfnXmlTransformer.redListString2RedListCode(listValue); |
236 | 233 |
} catch (UnknownCdmTypeException e) { |
237 | 234 |
matchedListValue = listValue; |
238 |
logger.warn("No matched red list code found for \""+redListCat.toString()+":" + listValue + "\". Use original label instead. ");
|
|
235 |
logger.warn("No matched red list code found for \"" + redListCat.getTitleCache() + ":" + listValue + "\". Use original label instead. ");
|
|
239 | 236 |
} |
240 | 237 |
try { |
241 | 238 |
stateTermUuid = BfnXmlTransformer.getRedlistStateTermUUID(matchedListValue, redListCat.getTitleCache()); |
... | ... | |
244 | 241 |
//TODO: needs to be fixed for "eindeutiger Code" |
245 | 242 |
logger.warn("could not finde state term uuid for " + matchedListValue + " and redlist category"+ redListCat.getTitleCache()+"\n"+e); |
246 | 243 |
} |
247 |
String vocName = redListCat.toString()+" States"; |
|
248 |
termVocabulary = (OrderedTermVocabulary) getVocabulary(TermType.State, vocabularyStateUuid, vocName, vocName, vocName, null, true, null); |
|
249 |
State stateTerm = getStateTerm(state, stateTermUuid, matchedListValue, matchedListValue, matchedListValue, termVocabulary); |
|
250 |
} |
|
251 |
if(termVocabulary != null){ |
|
252 |
redListCat.addSupportedCategoricalEnumeration(termVocabulary); |
|
253 |
getTermService().saveOrUpdate(redListCat); |
|
244 |
String vocName = redListCat.getTitleCache() + " States"; |
|
245 |
stateVocabulary = (OrderedTermVocabulary) getVocabulary(TermType.State, vocabularyStateUuid, vocName, vocName, vocName, null, true, null); |
|
246 |
addSource(stateVocabulary, state); |
|
247 |
State stateTerm = getStateTerm(state, stateTermUuid, matchedListValue, matchedListValue, matchedListValue, stateVocabulary); |
|
248 |
addSource(stateTerm, state); |
|
249 |
if(stateVocabulary != null){ |
|
250 |
redListCat.addSupportedCategoricalEnumeration(stateVocabulary); |
|
251 |
getTermService().saveOrUpdate(redListCat); |
|
252 |
} |
|
253 |
stateVocabulary = null; |
|
254 | 254 |
} |
255 |
|
|
256 | 255 |
} |
257 | 256 |
|
258 | 257 |
|
259 | 258 |
@Override |
260 | 259 |
public boolean doCheck(BfnXmlImportState state){ |
261 | 260 |
boolean result = true; |
262 |
//TODO needs to be implemented |
|
263 | 261 |
return result; |
264 | 262 |
} |
265 | 263 |
|
... | ... | |
268 | 266 |
return ! state.getConfig().isDoFeature(); |
269 | 267 |
} |
270 | 268 |
|
271 |
|
|
272 | 269 |
} |
Also available in: Unified diff
ref #6986 improve redlist xml import