Project

General

Profile

« Previous | Next » 

Revision 4d8fb1a4

Added by Alexander Oppermann about 9 years ago

Adapted Redlist Import to new XML Schema...

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/BfnXmlImportFeature.java
72 72
public class BfnXmlImportFeature extends BfnXmlImportBase implements ICdmIO<BfnXmlImportState> {
73 73
	private static final Logger logger = Logger.getLogger(BfnXmlImportFeature.class);
74 74

  
75
	private static final String strNomenclaturalCode = "Botanical";
76
	private static int i = 0;
77
	
78 75
	public BfnXmlImportFeature(){
79 76
		super();
80 77
	}
......
90 87
	@SuppressWarnings({ "unchecked", "rawtypes" })
91 88
	public void doInvoke(BfnXmlImportState state){
92 89

  
93
		ITermService termService = getTermService();
94 90
		IVocabularyService vocabularyService = getVocabularyService();
95 91
		
96 92
		
97
		logger.info("start create Features in CDM...");
98
		MapWrapper<DefinedTermBase> featureMap = (MapWrapper<DefinedTermBase>)state.getStore(ICdmIO.TAXON_STORE);
99
		MapWrapper<StateData> stateMap = (MapWrapper<StateData>)state.getStore(ICdmIO.FEATURE_STORE);
100

  
101
		
93
		logger.warn("start create Features in CDM...");
102 94
		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
103 95
		String childName;
104 96
		boolean obligatory;
105
		String idNamespace = "Features";
106

  
107 97
		BfnXmlImportConfigurator config = state.getConfig();
108 98
		Element elDataSet = getDataSetElement(config);
109 99
		Namespace bfnNamespace = config.getBfnXmlNamespace();
......
130 120
					for (Element elFeature : elFeatureList){
131 121

  
132 122
						if(elFeature.getAttributeValue("standardname", bfnNamespace).equalsIgnoreCase("RL Kat.")){
133
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
123
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
134 124
						}
135 125
						String featureLabel = "Kat. +/-";
136 126
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase(featureLabel)){
137
							//getFeature(state, null, featureLabel, featureLabel, null, null);
138

  
139
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
127
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
140 128
						}
141 129
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("aktuelle Bestandsstituation")){
142
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
130
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
143 131
						}
144 132
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("langfristiger Bestandstrend")){
145
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
133
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
146 134
						}
147 135
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("kurzfristiger Bestandstrend")){
148
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
136
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
149 137
						}
150 138
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Risikofaktoren")){
151
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
139
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
152 140
						}
153 141
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Verantwortlichkeit")){
154
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
142
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
155 143
						}
156 144
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("alte RL- Kat.")){
157
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
145
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
158 146
						}
159 147
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Neobiota")){
160
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
148
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
161 149
						}
162 150
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Eindeutiger Code")){
163
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
151
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
164 152
						}
165 153
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Kommentar zur Taxonomie")){
166
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
154
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
167 155
						}
168 156
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Kommentar zur Gefährdung")){
169
							makeFeature(termService, vocabularyService, featureList,success, obligatory, idNamespace, config, bfnNamespace,elFeature, state);
157
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
158
						}
159
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Sonderfälle")){
160
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
161
						}
162
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Letzter Nachweis")){
163
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
164
						}
165
						if(elFeature.getAttributeValue("standardname").equalsIgnoreCase("Weitere Kommentare")){
166
							makeFeature(vocabularyService, featureList,success, obligatory, bfnNamespace,elFeature, state);
170 167
						}
171 168
					}
172 169
					createFeatureTree(featureList);
173
					//		termService.save(featureMap.objects());
174
					
175 170
					commitTransaction(tx);
176 171
					
177 172
					logger.info("end create features ...");
178 173
					
179
					
180
					
181 174
					if (!success.getValue()){
182 175
						state.setUnsuccessfull();
183 176
					}
184
					//FIXME: Only take the first RoteListeData Features
185
					
186
					
187 177
					return;
188 178
				}
189 179
			}
......
198 188
	private void createFeatureTree(List<Feature> featureList) {
199 189
		FeatureTree featureTree = FeatureTree.NewInstance(featureList);
200 190
		String featureTreeName = "RedListFeatureTree";
201
		featureTree.setTitleCache(featureTreeName);
191
		featureTree.setTitleCache(featureTreeName, true);
202 192
		getFeatureTreeService().save(featureTree);
203 193
	}
204 194

  
205 195
	/**
206
	 * @param termService
196
	 * 
207 197
	 * @param vocabularyService
208
	 * @param featureMap
198
	 * @param featureList
209 199
	 * @param success
210 200
	 * @param obligatory
211
	 * @param idNamespace
212
	 * @param config
213 201
	 * @param bfnNamespace
214 202
	 * @param elFeature
203
	 * @param state
215 204
	 */
216
	private void makeFeature(ITermService termService,
217
			IVocabularyService vocabularyService,
205
	private void makeFeature(IVocabularyService vocabularyService,
218 206
			List<Feature> featureList,
219 207
			ResultWrapper<Boolean> success, boolean obligatory,
220
			String idNamespace, BfnXmlImportConfigurator config,
221 208
			Namespace bfnNamespace, Element elFeature, BfnXmlImportState state) {
222 209
		String childName;
223 210
		String strRlKat = elFeature.getAttributeValue("standardname");
......
225 212
		try {
226 213
			featureUUID = BfnXmlTransformer.getRedlistFeatureUUID(strRlKat);
227 214
		} catch (UnknownCdmTypeException e) {
228
			// TODO Auto-generated catch block
229 215
			e.printStackTrace();
230 216
		}
231 217
		Feature redListCat = getFeature(state, featureUUID, strRlKat, strRlKat, strRlKat, null);
232 218
		featureList.add(redListCat);
233
//		Feature redListCat = Feature.NewInstance(strRlKat, strRlKat, strRlKat);
234
		//TODO save
235
//		termService.saveOrUpdate(redListCat);
236 219
		childName = "LISTENWERTE";
237 220
		Element elListValues = XmlHelp.getSingleChildElement(success, elFeature, childName, bfnNamespace, obligatory);
238 221
		if(elListValues != null && !elListValues.getContent().isEmpty()){
239 222
			String childElementName = "LWERT";
240
			createOrUpdateStates(success, idNamespace, config, bfnNamespace, elListValues, childElementName, redListCat, state);
223
			createOrUpdateStates(bfnNamespace, elListValues, childElementName, redListCat, state);
241 224
		}
242 225
		createOrUpdateTermVocabulary(TermType.Feature, vocabularyService, redListCat, "RedList Feature");
243 226
	}
......
267 250

  
268 251
	/**
269 252
	 * @param success
270
	 * @param idNamespace
271
	 * @param config
272 253
	 * @param bfnNamespace
273 254
	 * @param elListValues
274 255
	 * @param childElementName
......
276 257
	 */
277 258
	
278 259
	@SuppressWarnings({ "unchecked", "rawtypes"})
279
	private void createOrUpdateStates(ResultWrapper<Boolean> success, String idNamespace,
280
			BfnXmlImportConfigurator config, Namespace bfnNamespace,
281
			Element elListValues, String childElementName, Feature redListCat, BfnXmlImportState state) {
260
	private void createOrUpdateStates(Namespace bfnNamespace, Element elListValues, String childElementName, 
261
			Feature redListCat, BfnXmlImportState state) {
282 262

  
283 263
		List<Element> elListValueList = (List<Element>)elListValues.getChildren(childElementName, bfnNamespace);
284 264
//		List<StateData> stateList = new ArrayList<StateData>();
......
293 273
				vocabularyStateUuid = BfnXmlTransformer.getRedlistVocabularyUUID(redListCat.toString());
294 274
			} catch (UnknownCdmTypeException e1) {
295 275
				vocabularyStateUuid = UUID.randomUUID();
276
				logger.info("Element: " + listValue);
296 277
				e1.printStackTrace();
297 278
			}
298 279
			try {
......
311 292
			String vocName = redListCat.toString()+" States";
312 293
			termVocabulary = (OrderedTermVocabulary) getVocabulary(TermType.State, vocabularyStateUuid, vocName, vocName, vocName, null, true, null); 	
313 294
			State stateTerm = getStateTerm(state, stateTermUuid, matchedListValue, matchedListValue, matchedListValue, termVocabulary);
314
//			State stateTerm = State.NewInstance(matchedListValue,matchedListValue, matchedListValue);
315
					
316
//			getTermService().saveOrUpdate(stateTerm);
317
//			termVocabulary = createOrUpdateTermVocabulary(getVocabularyService(), stateTerm, redListCat.toString()+" States");
318
			
319
//			StateData stateData = StateData.NewInstance(stateTerm);
320
//			featureMap.put(i++, state);
321
//			stateList.add(stateData);
322 295
		}
323 296
		if(termVocabulary != null){
324 297
			redListCat.addSupportedCategoricalEnumeration(termVocabulary);
325 298
			getTermService().saveOrUpdate(redListCat);
326 299
		}
327 300
		
328
//		CategoricalData catData = CategoricalData.NewInstance();
329
//		catData.setFeature(redListCat);
330
//		for(StateData sd: stateList){
331
//			catData.addState(sd);
332
//		}
333
//		catData.setStatesOnly(stateList);
334
//		DescriptionElementBase descriptionElementBase = catData;
335
//		getDescriptionService().saveDescriptionElement(descriptionElementBase);
336
//		
337
//		DescriptionBase<?> descriptionBase = null; 
338
//		descriptionBase.addElement(descriptionElementBase);
339
//		
340
		//featureMap.put(i++, descriptionBase);
341 301
	}
342 302

  
343 303
	

Also available in: Unified diff