Revision 8422c0cd
Added by Andreas Müller almost 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/cyprus/CyprusAltitudeActivator.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
51 | 51 |
*/ |
52 | 52 |
public class CyprusAltitudeActivator { |
53 | 53 |
private static final Logger logger = Logger.getLogger(CyprusAltitudeActivator.class); |
54 |
|
|
54 |
|
|
55 | 55 |
//database validation status (create, update, validate ...) |
56 | 56 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE; |
57 | 57 |
// static final URI source = cyprus_distribution(); |
58 | 58 |
static final URI source = cyprus_altitude(); |
59 | 59 |
|
60 |
|
|
60 |
|
|
61 | 61 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
62 | 62 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test(); |
63 | 63 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev(); |
64 | 64 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_production(); |
65 | 65 |
|
66 |
|
|
66 |
|
|
67 | 67 |
//feature tree uuid |
68 | 68 |
public static final UUID featureTreeUuid = UUID.fromString("14d1e912-5ec2-4d10-878b-828788b70a87"); |
69 |
|
|
69 |
|
|
70 | 70 |
//classification |
71 | 71 |
static final UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab"); |
72 |
|
|
72 |
|
|
73 | 73 |
private static final String sourceReferenceTitle = "Cyprus Excel Altitude Import"; |
74 |
|
|
75 |
|
|
74 |
|
|
75 |
|
|
76 | 76 |
//TODO move to Feature vocabulary |
77 | 77 |
private static final UUID uuidAltitudeFeature = UUID.fromString("1a28ed59-e15f-4001-b5c2-ea89f0012671"); |
78 |
|
|
78 |
|
|
79 | 79 |
//check - import |
80 | 80 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
81 |
|
|
81 |
|
|
82 | 82 |
private void doImport(ICdmDataSource cdmDestination){ |
83 |
|
|
84 |
|
|
83 |
|
|
84 |
|
|
85 | 85 |
ArrayList<HashMap<String, String>> excel; |
86 | 86 |
try { |
87 | 87 |
excel = ExcelUtils.parseXLS(source, "coreTax"); |
... | ... | |
89 | 89 |
e.printStackTrace(); |
90 | 90 |
return; |
91 | 91 |
} |
92 |
|
|
92 |
|
|
93 | 93 |
CdmApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, hbm2dll); |
94 | 94 |
|
95 | 95 |
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>(); |
96 |
|
|
96 |
|
|
97 | 97 |
TransactionStatus tx = app.startTransaction(); |
98 |
|
|
98 |
|
|
99 | 99 |
UUID uuidMikle77 = UUID.fromString("9f5fa7ee-538b-4ae5-bd82-2a9503fea1d6"); |
100 | 100 |
UUID uuidMikle85 = UUID.fromString("994403c4-c400-413d-9a1a-8531a40bfd8c"); |
101 |
|
|
102 |
Reference<?> mikle77 = app.getReferenceService().find(uuidMikle77);
|
|
103 |
Reference<?> mikle85 = app.getReferenceService().find(uuidMikle85);
|
|
104 |
|
|
105 |
|
|
101 |
|
|
102 |
Reference mikle77 = app.getReferenceService().find(uuidMikle77); |
|
103 |
Reference mikle85 = app.getReferenceService().find(uuidMikle85); |
|
104 |
|
|
105 |
|
|
106 | 106 |
Feature altitudeFeature = (Feature) app.getTermService().find(uuidAltitudeFeature); |
107 | 107 |
if (altitudeFeature == null){ |
108 | 108 |
// altitudeFeature = Feature.NewInstance("Altitude", "Altitude", "alt."); |
... | ... | |
111 | 111 |
// featureVoc.addTerm(altitudeFeature); |
112 | 112 |
throw new RuntimeException("Could not find altitudinal range feature"); |
113 | 113 |
} |
114 |
|
|
114 |
|
|
115 | 115 |
MeasurementUnit meter = (MeasurementUnit)app.getTermService().find(UUID.fromString("8bef5055-789c-41e5-bea2-8dc2ea8ecdf6")); |
116 | 116 |
// NamedArea cyprus = (NamedArea)app.getTermService().find(UUID.fromString("da4cce9a-439b-4cc4-8073-85dc75bae169")); |
117 |
|
|
117 |
|
|
118 | 118 |
int count =1; |
119 | 119 |
for (HashMap<String, String> row : excel){ |
120 | 120 |
count++; |
121 | 121 |
UUID baseUuid = makeUuid(row, "uuid"); |
122 | 122 |
UUID acceptedUuid = makeUuid(row, "acceptedNameUuid"); |
123 | 123 |
UUID parentUuid = makeUuid(row, "parentUuid"); |
124 |
|
|
124 |
|
|
125 | 125 |
// String altitude = row.get("Altitude-kumuliert"); |
126 |
|
|
126 |
|
|
127 | 127 |
String altitudeMin = row.get("Min"); |
128 | 128 |
String altitudeMax = row.get("Max"); |
129 | 129 |
String acceptedName = row.get("AcceptedName"); |
130 |
|
|
131 |
|
|
132 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 | 133 |
String source = row.get("Source"); |
134 |
|
|
134 |
|
|
135 | 135 |
if (StringUtils.isBlank(altitudeMin)){ |
136 | 136 |
continue; |
137 | 137 |
} |
138 |
|
|
138 |
|
|
139 | 139 |
boolean hasAltitude = false; |
140 |
Reference<?> sourceRef = getSource(source, mikle77, mikle85);
|
|
140 |
Reference sourceRef = getSource(source, mikle77, mikle85); |
|
141 | 141 |
Taxon taxon = getTaxon(app, baseUuid, acceptedUuid, parentUuid, acceptedName, count); |
142 | 142 |
if (taxon != null){ |
143 | 143 |
TaxonDescription desc = getDescription(taxon, sourceRef); |
144 |
|
|
144 |
|
|
145 | 145 |
hasAltitude = makeAltitude(altitudeMin, altitudeMax, altitudeFeature, sourceRef, desc, meter, count); |
146 | 146 |
// hasAltitude = makeAltitudeOld(altitude, altitudeFeature, sourceRef, desc, meter, count); |
147 | 147 |
if (hasAltitude){ |
... | ... | |
158 | 158 |
} |
159 | 159 |
|
160 | 160 |
app.getTaxonService().saveOrUpdate(taxaToSave); |
161 |
|
|
161 |
|
|
162 | 162 |
// tx.setRollbackOnly(); |
163 | 163 |
app.commitTransaction(tx); |
164 | 164 |
} |
... | ... | |
167 | 167 |
private Taxon getTaxon(CdmApplicationController app, UUID baseUuid, UUID acceptedUuid, UUID parentUuid, String acceptedName, int row) { |
168 | 168 |
TaxonBase<?> base = app.getTaxonService().find(baseUuid); |
169 | 169 |
// TaxonBase<?> parent = app.getTaxonService().find(parentUuid); |
170 |
|
|
170 |
|
|
171 | 171 |
//TODO |
172 | 172 |
Taxon result = null; |
173 | 173 |
if (base.isInstanceOf(Taxon.class)){ |
... | ... | |
187 | 187 |
}else{ |
188 | 188 |
logger.warn("Synonym relation has changed somehow. Row: " + row + ", Taxon: " + base.getTitleCache()); |
189 | 189 |
} |
190 |
|
|
190 |
|
|
191 | 191 |
}else{ |
192 | 192 |
logger.warn("Accepted taxon not in classification. Row: " + row + ", Taxon: " + base.getTitleCache()); |
193 | 193 |
} |
194 | 194 |
} |
195 |
|
|
195 |
|
|
196 | 196 |
if (result != null){ |
197 | 197 |
if (! result.getName().getTitleCache().equals(acceptedName)){ |
198 | 198 |
logger.warn("AcceptedName and taxon name is not equal in " + row + ".\n" + |
... | ... | |
200 | 200 |
" Taxon Name: " + result.getName().getTitleCache()); |
201 | 201 |
} |
202 | 202 |
} |
203 |
|
|
203 |
|
|
204 | 204 |
return result; |
205 | 205 |
} |
206 | 206 |
|
... | ... | |
218 | 218 |
// private static final Pattern altitudePattern = Pattern.compile("\\d{1,4}(-\\d{1,4})?"); |
219 | 219 |
|
220 | 220 |
|
221 |
private boolean makeAltitude(String altitudeMin, String altitudeMax, Feature altitudeFeature,
|
|
222 |
Reference<?> sourceRef, TaxonDescription desc, MeasurementUnit meter, int row) {
|
|
223 |
|
|
221 |
private boolean makeAltitude(String altitudeMin, String altitudeMax, Feature altitudeFeature, |
|
222 |
Reference sourceRef, TaxonDescription desc, MeasurementUnit meter, int row) { |
|
223 |
|
|
224 | 224 |
QuantitativeData data = QuantitativeData.NewInstance(altitudeFeature); |
225 |
|
|
225 |
|
|
226 | 226 |
//Meikle |
227 | 227 |
if (source != null){ |
228 | 228 |
TaxonNameBase<?,?> nameUsedInSource = null; //TODO |
... | ... | |
231 | 231 |
// //Excel //excel source not wanted by Ralf |
232 | 232 |
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this |
233 | 233 |
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null); |
234 |
|
|
234 |
|
|
235 | 235 |
data.setUnit(meter); |
236 |
|
|
236 |
|
|
237 | 237 |
Integer min = Integer.valueOf(altitudeMin); |
238 | 238 |
StatisticalMeasurementValue minValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MIN(), min); |
239 | 239 |
data.addStatisticalValue(minValue); |
... | ... | |
241 | 241 |
Integer max = Integer.valueOf(altitudeMax); |
242 | 242 |
StatisticalMeasurementValue maxValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MAX(), max); |
243 | 243 |
data.addStatisticalValue(maxValue); |
244 |
|
|
244 |
|
|
245 | 245 |
desc.addElement(data); |
246 | 246 |
return true; |
247 | 247 |
} |
248 |
|
|
249 |
// private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference<?> source, TaxonDescription desc, MeasurementUnit meter, int row) {
|
|
248 |
|
|
249 |
// private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference source, TaxonDescription desc, MeasurementUnit meter, int row) { |
|
250 | 250 |
// String altitude = altitudeOrig.trim().replace(" ", ""); |
251 | 251 |
// Matcher matcher = altitudePattern.matcher(altitude); |
252 |
//
|
|
252 |
// |
|
253 | 253 |
// if (matcher.matches()){ |
254 | 254 |
// QuantitativeData data = QuantitativeData.NewInstance(feature); |
255 |
//
|
|
255 |
// |
|
256 | 256 |
// //Meikle |
257 | 257 |
// if (source != null){ |
258 | 258 |
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO |
... | ... | |
262 | 262 |
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this |
263 | 263 |
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null); |
264 | 264 |
// data.setUnit(meter); |
265 |
//
|
|
265 |
// |
|
266 | 266 |
// String[] split = altitude.split("-"); |
267 | 267 |
// |
268 | 268 |
// Integer min = Integer.valueOf(split[0]); |
... | ... | |
282 | 282 |
// } |
283 | 283 |
// } |
284 | 284 |
|
285 |
private TaxonDescription getDescription(Taxon taxon, Reference<?> sourceRef) {
|
|
285 |
private TaxonDescription getDescription(Taxon taxon, Reference sourceRef) { |
|
286 | 286 |
if (taxon != null){ |
287 | 287 |
//TODO Mikle existiert derzeit nicht also Source |
288 |
|
|
288 |
|
|
289 | 289 |
TaxonDescription desc = TaxonDescription.NewInstance(); |
290 | 290 |
desc.setTitleCache("Import from " + getSourceReference().getTitleCache(), true); |
291 | 291 |
desc.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, sourceRef,null); |
292 | 292 |
desc.addSource(OriginalSourceType.Import, null, null, getSourceReference(), null); |
293 |
|
|
293 |
|
|
294 | 294 |
return desc; |
295 | 295 |
} |
296 | 296 |
return null; |
297 | 297 |
} |
298 | 298 |
|
299 |
private Reference<?> getSource(String source, Reference<?> m77, Reference<?> m85) {
|
|
299 |
private Reference getSource(String source, Reference m77, Reference m85) {
|
|
300 | 300 |
if(StringUtils.isNotBlank(source)){ |
301 | 301 |
if (source.equals("Meikle 1977")){ |
302 | 302 |
return m77; |
... | ... | |
325 | 325 |
// // TODO Auto-generated method stub |
326 | 326 |
// HashMap<String, Object> = new HashM |
327 | 327 |
// row |
328 |
//
|
|
329 |
//
|
|
328 |
// |
|
329 |
// |
|
330 | 330 |
// } |
331 | 331 |
|
332 |
|
|
333 |
Reference<?> sourceReference;
|
|
334 |
private Reference<?> getSourceReference() {
|
|
332 |
|
|
333 |
Reference sourceReference; |
|
334 |
private Reference getSourceReference() { |
|
335 | 335 |
if (sourceReference == null){ |
336 | 336 |
sourceReference = ReferenceFactory.newGeneric(); |
337 | 337 |
sourceReference.setTitleCache(sourceReferenceTitle, true); |
338 |
|
|
338 |
|
|
339 | 339 |
} |
340 | 340 |
return sourceReference; |
341 |
|
|
341 |
|
|
342 | 342 |
} |
343 | 343 |
|
344 |
|
|
344 |
|
|
345 | 345 |
//Cyprus |
346 | 346 |
public static URI cyprus_altitude() { |
347 | 347 |
URI sourceUrl; |
... | ... | |
367 | 367 |
|
368 | 368 |
private void testMatcher() { |
369 | 369 |
// makeAltitude("0-4400", null, null); |
370 |
|
|
370 |
|
|
371 | 371 |
} |
372 |
|
|
372 |
|
|
373 | 373 |
} |
Also available in: Unified diff
Remove generics from Reference in cdmlib-app #5830