53 |
53 |
|
54 |
54 |
//database validation status (create, update, validate ...)
|
55 |
55 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
56 |
|
// static final URI source = cyprus_distribution();
|
57 |
56 |
static final URI source = cyprus_altitude();
|
58 |
57 |
|
59 |
58 |
|
... | ... | |
91 |
90 |
|
92 |
91 |
CdmApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, hbm2dll);
|
93 |
92 |
|
94 |
|
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
|
|
93 |
Set<TaxonBase> taxaToSave = new HashSet<>();
|
95 |
94 |
|
96 |
95 |
TransactionStatus tx = app.startTransaction();
|
97 |
96 |
|
... | ... | |
101 |
100 |
Reference mikle77 = app.getReferenceService().find(uuidMikle77);
|
102 |
101 |
Reference mikle85 = app.getReferenceService().find(uuidMikle85);
|
103 |
102 |
|
104 |
|
|
105 |
103 |
Feature altitudeFeature = (Feature) app.getTermService().find(uuidAltitudeFeature);
|
106 |
104 |
if (altitudeFeature == null){
|
107 |
|
// altitudeFeature = Feature.NewInstance("Altitude", "Altitude", "alt.");
|
108 |
|
// altitudeFeature.setUuid(uuidAltitudeFeature);
|
109 |
|
// featureVoc = app.getVocabularyService().find(UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8"));
|
110 |
|
// featureVoc.addTerm(altitudeFeature);
|
111 |
105 |
throw new RuntimeException("Could not find altitudinal range feature");
|
112 |
106 |
}
|
113 |
107 |
|
114 |
108 |
MeasurementUnit meter = (MeasurementUnit)app.getTermService().find(UUID.fromString("8bef5055-789c-41e5-bea2-8dc2ea8ecdf6"));
|
115 |
|
// NamedArea cyprus = (NamedArea)app.getTermService().find(UUID.fromString("da4cce9a-439b-4cc4-8073-85dc75bae169"));
|
116 |
109 |
|
117 |
110 |
int count =1;
|
118 |
111 |
for (HashMap<String, String> row : excel){
|
... | ... | |
121 |
114 |
UUID acceptedUuid = makeUuid(row, "acceptedNameUuid");
|
122 |
115 |
UUID parentUuid = makeUuid(row, "parentUuid");
|
123 |
116 |
|
124 |
|
// String altitude = row.get("Altitude-kumuliert");
|
125 |
|
|
126 |
117 |
String altitudeMin = row.get("Min");
|
127 |
118 |
String altitudeMax = row.get("Max");
|
128 |
119 |
String acceptedName = row.get("AcceptedName");
|
129 |
120 |
|
130 |
|
|
131 |
|
|
132 |
121 |
String source = row.get("Source");
|
133 |
122 |
|
134 |
123 |
if (StringUtils.isBlank(altitudeMin)){
|
... | ... | |
142 |
131 |
TaxonDescription desc = getDescription(taxon, sourceRef);
|
143 |
132 |
|
144 |
133 |
hasAltitude = makeAltitude(altitudeMin, altitudeMax, altitudeFeature, sourceRef, desc, meter, count);
|
145 |
|
// hasAltitude = makeAltitudeOld(altitude, altitudeFeature, sourceRef, desc, meter, count);
|
146 |
134 |
if (hasAltitude){
|
147 |
135 |
if(desc.getTaxon() == null){
|
148 |
136 |
taxon.addDescription(desc);
|
... | ... | |
158 |
146 |
|
159 |
147 |
app.getTaxonService().saveOrUpdate(taxaToSave);
|
160 |
148 |
|
161 |
|
// tx.setRollbackOnly();
|
162 |
149 |
app.commitTransaction(tx);
|
163 |
150 |
}
|
164 |
151 |
|
165 |
152 |
|
166 |
153 |
private Taxon getTaxon(CdmApplicationController app, UUID baseUuid, UUID acceptedUuid, UUID parentUuid, String acceptedName, int row) {
|
167 |
154 |
TaxonBase<?> base = app.getTaxonService().find(baseUuid);
|
168 |
|
// TaxonBase<?> parent = app.getTaxonService().find(parentUuid);
|
169 |
155 |
|
170 |
|
//TODO
|
171 |
156 |
Taxon result = null;
|
172 |
157 |
if (base.isInstanceOf(Taxon.class)){
|
173 |
158 |
Taxon t = CdmBase.deproxy(base, Taxon.class);
|
... | ... | |
227 |
212 |
TaxonNameBase<?,?> nameUsedInSource = null; //TODO
|
228 |
213 |
data.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, sourceRef, null, nameUsedInSource, null);
|
229 |
214 |
}
|
230 |
|
// //Excel //excel source not wanted by Ralf
|
231 |
|
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this
|
232 |
|
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);
|
233 |
|
|
234 |
215 |
data.setUnit(meter);
|
235 |
216 |
|
236 |
217 |
Integer min = Integer.valueOf(altitudeMin);
|
... | ... | |
245 |
226 |
return true;
|
246 |
227 |
}
|
247 |
228 |
|
248 |
|
// private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference source, TaxonDescription desc, MeasurementUnit meter, int row) {
|
249 |
|
// String altitude = altitudeOrig.trim().replace(" ", "");
|
250 |
|
// Matcher matcher = altitudePattern.matcher(altitude);
|
251 |
|
//
|
252 |
|
// if (matcher.matches()){
|
253 |
|
// QuantitativeData data = QuantitativeData.NewInstance(feature);
|
254 |
|
//
|
255 |
|
// //Meikle
|
256 |
|
// if (source != null){
|
257 |
|
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO
|
258 |
|
// data.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, source, null, nameUsedInSource, null);
|
259 |
|
// }
|
260 |
|
// //Excel
|
261 |
|
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this
|
262 |
|
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);
|
263 |
|
// data.setUnit(meter);
|
264 |
|
//
|
265 |
|
// String[] split = altitude.split("-");
|
266 |
|
//
|
267 |
|
// Integer min = Integer.valueOf(split[0]);
|
268 |
|
// StatisticalMeasurementValue minValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MIN(), min);
|
269 |
|
// data.addStatisticalValue(minValue);
|
270 |
|
//
|
271 |
|
// if (split.length > 1){
|
272 |
|
// Integer max = Integer.valueOf(split[1]);
|
273 |
|
// StatisticalMeasurementValue maxValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MAX(), max);
|
274 |
|
// data.addStatisticalValue(maxValue);
|
275 |
|
// }
|
276 |
|
// desc.addElement(data);
|
277 |
|
// return true;
|
278 |
|
// }else{
|
279 |
|
// logger.warn("Altitude does not match in row " + row + ": " + altitudeOrig);
|
280 |
|
// return false;
|
281 |
|
// }
|
282 |
|
// }
|
283 |
|
|
284 |
229 |
private TaxonDescription getDescription(Taxon taxon, Reference sourceRef) {
|
285 |
230 |
if (taxon != null){
|
286 |
231 |
//TODO Mikle existiert derzeit nicht also Source
|
... | ... | |
320 |
265 |
}
|
321 |
266 |
}
|
322 |
267 |
|
323 |
|
// private void getRowValues(HashMap<String, String> row) {
|
324 |
|
// // TODO Auto-generated method stub
|
325 |
|
// HashMap<String, Object> = new HashM
|
326 |
|
// row
|
327 |
|
//
|
328 |
|
//
|
329 |
|
// }
|
330 |
|
|
331 |
|
|
332 |
268 |
Reference sourceReference;
|
333 |
269 |
private Reference getSourceReference() {
|
334 |
270 |
if (sourceReference == null){
|
335 |
271 |
sourceReference = ReferenceFactory.newGeneric();
|
336 |
272 |
sourceReference.setTitleCache(sourceReferenceTitle, true);
|
337 |
|
|
338 |
273 |
}
|
339 |
274 |
return sourceReference;
|
340 |
275 |
|
341 |
276 |
}
|
342 |
277 |
|
343 |
|
|
344 |
278 |
//Cyprus
|
345 |
279 |
public static URI cyprus_altitude() {
|
346 |
280 |
URI sourceUrl;
|
... | ... | |
361 |
295 |
public static void main(String[] args) {
|
362 |
296 |
CyprusAltitudeActivator me = new CyprusAltitudeActivator();
|
363 |
297 |
me.doImport(cdmDestination);
|
364 |
|
me.testMatcher();
|
365 |
|
}
|
366 |
|
|
367 |
|
private void testMatcher() {
|
368 |
|
// makeAltitude("0-4400", null, null);
|
369 |
|
|
370 |
298 |
}
|
371 |
299 |
|
372 |
300 |
}
|
clean up old cyprus import activators