1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.apache.logging.log4j.LogManager;
|
19
|
import org.apache.logging.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
import org.springframework.transaction.TransactionStatus;
|
22
|
|
23
|
import eu.etaxonomy.cdm.common.URI;
|
24
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
25
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelAreaImportValidator;
|
26
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
27
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
28
|
import eu.etaxonomy.cdm.io.common.Source;
|
29
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
30
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
33
|
import eu.etaxonomy.cdm.model.common.Language;
|
34
|
import eu.etaxonomy.cdm.model.common.Marker;
|
35
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
36
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
37
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
39
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
40
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
41
|
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
|
42
|
import eu.etaxonomy.cdm.model.term.TermType;
|
43
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
44
|
|
45
|
/**
|
46
|
* @author a.mueller
|
47
|
* @since 20.03.2008
|
48
|
*/
|
49
|
@Component
|
50
|
public class BerlinModelAreaImport extends BerlinModelImportBase {
|
51
|
|
52
|
private static final long serialVersionUID = -2810052908318645219L;
|
53
|
private static final Logger logger = LogManager.getLogger();
|
54
|
|
55
|
public static final String NAMESPACE = "emArea";
|
56
|
|
57
|
private static final String pluralString = "areas";
|
58
|
private static final String dbTableName = "emArea"; //??
|
59
|
|
60
|
public BerlinModelAreaImport(){
|
61
|
super(dbTableName, pluralString);
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
protected String getIdQuery(BerlinModelImportState state) {
|
66
|
// String result =
|
67
|
// " SELECT AreaId "
|
68
|
// + " FROM " + getTableName();
|
69
|
// if (state.getConfig().isEuroMed()){
|
70
|
// result += " WHERE AreaID NOT IN (1, 21, 650, 653, 1718, 654, 646, 647) "; //#3986
|
71
|
// }
|
72
|
// return result;
|
73
|
return null; //not relevant as we have no partitioning here
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
78
|
// String strQuery =
|
79
|
// " SELECT * "
|
80
|
// + " FROM emArea a "
|
81
|
// + " WHERE (a.AreaId IN (" + ID_LIST_TOKEN + ") )"
|
82
|
// + " ORDER BY a.AreaId "
|
83
|
// ;
|
84
|
// return strQuery;
|
85
|
return null; //not relevant as we have no partitioning here
|
86
|
}
|
87
|
|
88
|
private Map<Integer, NamedArea> euroMedAreas = new HashMap<>();
|
89
|
|
90
|
@Override
|
91
|
public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
92
|
// not relevant
|
93
|
return true;
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void doInvoke(BerlinModelImportState state) {
|
98
|
TermVocabulary<?> voc = getVocabularyService().find(BerlinModelTransformer.uuidVocEuroMedAreas);
|
99
|
if (voc == null){
|
100
|
try {
|
101
|
createEuroMedAreas(state);
|
102
|
createCaucasusAreas(state);
|
103
|
} catch (SQLException e) {
|
104
|
logger.warn("Exception when creating areas: " + e.getMessage());
|
105
|
e.printStackTrace();
|
106
|
}
|
107
|
}
|
108
|
return;
|
109
|
}
|
110
|
|
111
|
private TermVocabulary<NamedArea> createEuroMedAreas(BerlinModelImportState state) throws SQLException {
|
112
|
|
113
|
logger.warn("Start creating E+M areas");
|
114
|
Source source = state.getConfig().getSource();
|
115
|
Reference sourceReference = state.getConfig().getSourceReference();
|
116
|
|
117
|
TransactionStatus txStatus = this.startTransaction();
|
118
|
|
119
|
sourceReference = getSourceReference(sourceReference);
|
120
|
|
121
|
TermVocabulary<NamedArea> euroMedAreasVoc = makeEmptyEuroMedVocabulary();
|
122
|
|
123
|
MarkerType eurMarkerType = getMarkerType(state, BerlinModelTransformer.uuidEurArea, "eur", "eur Area", "eur", getEuroMedMarkerTypeVoc(state));
|
124
|
MarkerType euroMedAreaMarkerType = getMarkerType(state, BerlinModelTransformer.uuidEurMedArea, "EuroMedArea", "EuroMedArea", "EuroMedArea", getEuroMedMarkerTypeVoc(state));
|
125
|
ExtensionType isoCodeExtType = getExtensionType(state, BerlinModelTransformer.uuidIsoCode, "IsoCode", "IsoCode", "iso");
|
126
|
ExtensionType tdwgCodeExtType = getExtensionType(state, BerlinModelTransformer.uuidTdwgAreaCode, "TDWG code", "TDWG Area code", "tdwg");
|
127
|
ExtensionType mclCodeExtType = getExtensionType(state, BerlinModelTransformer.uuidMclCode, "MCL code", "MedCheckList code", "mcl");
|
128
|
NamedAreaLevel areaLevelTop = getNamedAreaLevel(state, BerlinModelTransformer.uuidEuroMedAreaLevelTop, "Euro+Med top area level", "Euro+Med top area level. This level is only to be used for the area representing the complete Euro+Med area", "e+m top", null);
|
129
|
NamedAreaLevel areaLevelEm1 = getNamedAreaLevel(state, BerlinModelTransformer.uuidEuroMedAreaLevelFirst, "Euro+Med 1. area level", "Euro+Med 1. area level", "e+m 1.", null);
|
130
|
NamedAreaLevel areaLevelEm2 = getNamedAreaLevel(state, BerlinModelTransformer.uuidEuroMedAreaLevelSecond, "Euro+Med 2. area level", "Euro+Med 2. area level", "Euro+Med 1. area level", null);
|
131
|
|
132
|
|
133
|
String sql = "SELECT * , CASE WHEN EMCode = 'EM' THEN 'a' ELSE 'b' END as isEM " +
|
134
|
" FROM emArea " +
|
135
|
" WHERE areaId not IN (1, 14, 20, 21, 33, 646, 647, 653, 654, 1718) " +
|
136
|
" ORDER BY isEM, EMCode";
|
137
|
ResultSet rs = source.getResultSet(sql);
|
138
|
|
139
|
NamedArea euroMedArea = null;
|
140
|
NamedArea lastLevel1Area = null;
|
141
|
|
142
|
//euroMedArea (EMCode = 'EM')
|
143
|
rs.next();
|
144
|
euroMedArea = makeSingleEuroMedArea(rs, eurMarkerType, euroMedAreaMarkerType, isoCodeExtType, tdwgCodeExtType, mclCodeExtType,
|
145
|
areaLevelTop, areaLevelEm1 , areaLevelEm2, sourceReference, euroMedArea, lastLevel1Area);
|
146
|
euroMedAreasVoc.addTerm(euroMedArea);
|
147
|
|
148
|
//all other areas
|
149
|
while (rs.next()){
|
150
|
NamedArea newArea = makeSingleEuroMedArea(rs, eurMarkerType, euroMedAreaMarkerType,
|
151
|
isoCodeExtType, tdwgCodeExtType, mclCodeExtType,
|
152
|
areaLevelTop, areaLevelEm1 , areaLevelEm2, sourceReference, euroMedArea, lastLevel1Area);
|
153
|
if (newArea != null){
|
154
|
euroMedAreasVoc.addTerm(newArea);
|
155
|
if (newArea.getPartOf().equals(euroMedArea)){
|
156
|
lastLevel1Area = newArea;
|
157
|
}
|
158
|
}
|
159
|
}
|
160
|
emAreaFinetuning(euroMedAreasVoc, areaLevelEm2);
|
161
|
|
162
|
markAreasAsHidden(state, euroMedAreasVoc);
|
163
|
|
164
|
getVocabularyService().saveOrUpdate(euroMedAreasVoc);
|
165
|
|
166
|
try {
|
167
|
commitTransaction(txStatus);
|
168
|
} catch (Exception e) {
|
169
|
e.printStackTrace();
|
170
|
logger.error("An exception occurred when trying to commit E+M Areas");
|
171
|
}
|
172
|
logger.warn("Created E+M areas");
|
173
|
|
174
|
return euroMedAreasVoc;
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* @param areaLevelEm2
|
179
|
* @param euroMedAreas2
|
180
|
*/
|
181
|
private void emAreaFinetuning(TermVocabulary<NamedArea> euroMedAreas, NamedAreaLevel areaLevelEm2) {
|
182
|
//CZ
|
183
|
NamedArea oldArea = euroMedAreas.getTermByIdInvocabulary("Cz");
|
184
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Cs"), areaLevelEm2);
|
185
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Sk"), areaLevelEm2);
|
186
|
|
187
|
//Ju
|
188
|
oldArea = euroMedAreas.getTermByIdInvocabulary("Ju");
|
189
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("BH"), areaLevelEm2);
|
190
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Cg"), areaLevelEm2);
|
191
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Ct"), areaLevelEm2);
|
192
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Mk"), areaLevelEm2);
|
193
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Sl"), areaLevelEm2);
|
194
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Sr"), areaLevelEm2);
|
195
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Yu(K)"), areaLevelEm2);
|
196
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("SM"), areaLevelEm2);
|
197
|
|
198
|
//IJ
|
199
|
oldArea = euroMedAreas.getTermByIdInvocabulary("IJ");
|
200
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Ir"), areaLevelEm2);
|
201
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Jo"), areaLevelEm2);
|
202
|
|
203
|
//LS
|
204
|
oldArea = euroMedAreas.getTermByIdInvocabulary("LS");
|
205
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Le"), areaLevelEm2);
|
206
|
makeSubterm(oldArea, euroMedAreas.getTermByIdInvocabulary("Sy"), areaLevelEm2);
|
207
|
|
208
|
}
|
209
|
|
210
|
//5.Mark areas to be hidden #3979 .5
|
211
|
private void markAreasAsHidden(BerlinModelImportState state, TermVocabulary<NamedArea> euroMedAreasVoc) {
|
212
|
|
213
|
try {
|
214
|
|
215
|
MarkerType hiddenAreaMarkerType = getMarkerType(state, BerlinModelTransformer.uuidHiddenArea,
|
216
|
"Hidden Area","Used to hide distributions for the named areas in publications", null, getEuroMedMarkerTypeVoc(state));
|
217
|
|
218
|
//Add hidden area marker to Rs(C) and Rs(N)
|
219
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs);
|
220
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_B);
|
221
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_C);
|
222
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_E);
|
223
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_N);
|
224
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_K);
|
225
|
hideArea(euroMedAreasVoc, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_W);
|
226
|
} catch (Exception e) {
|
227
|
e.printStackTrace();
|
228
|
logger.error("Exception in markAreasAsHidden: " + e.getMessage());
|
229
|
}
|
230
|
|
231
|
}
|
232
|
|
233
|
private void hideArea(TermVocabulary<NamedArea> euroMedAreasVoc, MarkerType hiddenAreaMarkerType, UUID areaUuid) {
|
234
|
for (NamedArea namedArea : euroMedAreasVoc.getTerms()){
|
235
|
if (namedArea.getUuid().equals(areaUuid)){
|
236
|
namedArea.addMarker(Marker.NewInstance(hiddenAreaMarkerType, true));
|
237
|
return;
|
238
|
}
|
239
|
}
|
240
|
}
|
241
|
|
242
|
/**
|
243
|
* @param oldArea
|
244
|
* @param namedArea
|
245
|
* @param areaLevelEm2
|
246
|
*/
|
247
|
private void makeSubterm(NamedArea oldArea, NamedArea namedArea, NamedAreaLevel areaLevelEm2) {
|
248
|
namedArea.setLevel(areaLevelEm2);
|
249
|
namedArea.setPartOf(oldArea);
|
250
|
}
|
251
|
|
252
|
|
253
|
/**
|
254
|
* @param eurMarkerType
|
255
|
* @param euroMedAreaMarkerType
|
256
|
* @param isoCodeExtType
|
257
|
* @param tdwgCodeExtType
|
258
|
* @param mclCodeExtType
|
259
|
* @param rs
|
260
|
* @param areaLevelEm2
|
261
|
* @param areaLevelEm1
|
262
|
* @param areaLevelTop
|
263
|
* @throws SQLException
|
264
|
*/
|
265
|
private NamedArea makeSingleEuroMedArea(ResultSet rs, MarkerType eurMarkerType,
|
266
|
MarkerType euroMedAreaMarkerType, ExtensionType isoCodeExtType,
|
267
|
ExtensionType tdwgCodeExtType, ExtensionType mclCodeExtType,
|
268
|
NamedAreaLevel areaLevelTop, NamedAreaLevel areaLevelEm1, NamedAreaLevel areaLevelEm2,
|
269
|
Reference sourceReference, NamedArea euroMedArea, NamedArea level1Area) throws SQLException {
|
270
|
|
271
|
Integer areaId = rs.getInt("AreaId");
|
272
|
String emCode = nullSafeTrim(rs.getString("EMCode"));
|
273
|
String isoCode = nullSafeTrim(rs.getString("ISOCode"));
|
274
|
String tdwgCode = nullSafeTrim(rs.getString("TDWGCode"));
|
275
|
String unit = nullSafeTrim(rs.getString("Unit"));
|
276
|
// ,[Status]
|
277
|
// ,[OutputOrder]
|
278
|
boolean eurMarker = rs.getBoolean("eur");
|
279
|
boolean euroMedAreaMarker = rs.getBoolean("EuroMedArea");
|
280
|
String notes = nullSafeTrim(rs.getString("Notes"));
|
281
|
String mclCode = nullSafeTrim(rs.getString("MCLCode"));
|
282
|
String geoSearch = nullSafeTrim(rs.getString("NameForGeoSearch"));
|
283
|
|
284
|
|
285
|
if (isBlank(emCode)){
|
286
|
emCode = unit;
|
287
|
}
|
288
|
|
289
|
//uuid
|
290
|
UUID uuid = BerlinModelTransformer.getEMAreaUuid(emCode);
|
291
|
NamedArea area = (NamedArea)getTermService().find(uuid);
|
292
|
if (area == null){
|
293
|
//label
|
294
|
area = NamedArea.NewInstance(geoSearch, unit, emCode);
|
295
|
if (uuid != null){
|
296
|
area.setUuid(uuid);
|
297
|
}else{
|
298
|
if (areaId == 211 || areaId == 213){ //Additional Azores and Canary Is. area are merged into primary area, see also area.addSource part below
|
299
|
return null;
|
300
|
}
|
301
|
logger.warn("Uuid for emCode could not be defined: " + emCode);
|
302
|
}
|
303
|
}
|
304
|
|
305
|
|
306
|
//code
|
307
|
area.setIdInVocabulary(emCode);
|
308
|
//notes
|
309
|
if (StringUtils.isNotEmpty(notes)){
|
310
|
area.addAnnotation(Annotation.NewInstance(notes, AnnotationType.EDITORIAL(), Language.DEFAULT()));
|
311
|
}
|
312
|
//markers
|
313
|
area.addMarker(Marker.NewInstance(eurMarkerType, eurMarker));
|
314
|
area.addMarker(Marker.NewInstance(euroMedAreaMarkerType, euroMedAreaMarker));
|
315
|
|
316
|
//extensions
|
317
|
if (isNotBlank(isoCode)){
|
318
|
area.addExtension(isoCode, isoCodeExtType);
|
319
|
}
|
320
|
if (isNotBlank(tdwgCode)){
|
321
|
area.addExtension(tdwgCode, tdwgCodeExtType);
|
322
|
}
|
323
|
if (isNotBlank(mclCode)){
|
324
|
area.addExtension(mclCode, mclCodeExtType);
|
325
|
}
|
326
|
|
327
|
//type
|
328
|
area.setType(NamedAreaType.ADMINISTRATION_AREA());
|
329
|
|
330
|
//source
|
331
|
area.addSource(OriginalSourceType.Import, String.valueOf(areaId), NAMESPACE, sourceReference, null);
|
332
|
//add duplicate area ids for canary
|
333
|
if (areaId == 624){ //Canary Is.
|
334
|
area.addSource(OriginalSourceType.Import, String.valueOf(213), NAMESPACE, sourceReference, null);
|
335
|
}
|
336
|
if (areaId == 210){//Azores
|
337
|
area.addSource(OriginalSourceType.Import, String.valueOf(211), NAMESPACE, sourceReference, null);
|
338
|
}
|
339
|
|
340
|
//parent
|
341
|
if (euroMedArea != null){
|
342
|
if (emCode.contains("(") && !emCode.startsWith("Yu(K)")){
|
343
|
area.setPartOf(level1Area);
|
344
|
area.setLevel(areaLevelEm2);
|
345
|
}else{
|
346
|
area.setPartOf(euroMedArea);
|
347
|
area.setLevel(areaLevelEm1);
|
348
|
}
|
349
|
}else{
|
350
|
area.setLevel(areaLevelTop);
|
351
|
}
|
352
|
this.euroMedAreas.put(areaId, area);
|
353
|
|
354
|
//save
|
355
|
getTermService().saveOrUpdate(area);
|
356
|
|
357
|
return area;
|
358
|
}
|
359
|
|
360
|
private String nullSafeTrim(String string) {
|
361
|
if (string == null){
|
362
|
return null;
|
363
|
}else{
|
364
|
return string.trim();
|
365
|
}
|
366
|
}
|
367
|
|
368
|
/**
|
369
|
*
|
370
|
*/
|
371
|
private OrderedTermVocabulary<NamedArea> makeEmptyEuroMedVocabulary() {
|
372
|
TermType type = TermType.NamedArea;
|
373
|
String description = "Euro+Med area vocabulary";
|
374
|
String label = "E+M Areas";
|
375
|
String abbrev = null;
|
376
|
URI termSourceUri = null;
|
377
|
OrderedTermVocabulary<NamedArea> result = OrderedTermVocabulary.NewOrderedInstance(type, null, description, label, abbrev, termSourceUri);
|
378
|
|
379
|
result.setUuid(BerlinModelTransformer.uuidVocEuroMedAreas);
|
380
|
getVocabularyService().save(result);
|
381
|
return result;
|
382
|
}
|
383
|
|
384
|
|
385
|
/**
|
386
|
* @param state
|
387
|
*/
|
388
|
private void createCaucasusAreas(BerlinModelImportState state) {
|
389
|
OrderedTermVocabulary<NamedArea> voc = makeEmptyCaucasusVocabulary(state);
|
390
|
NamedArea last = null;
|
391
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc1, "Western Ciscaucasia","WCC","1","");
|
392
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc1a, "Azov-Kuban","Az.-Kub.","1","a");
|
393
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc1b, "Western Stavropol","W. Stavr.","1","b");
|
394
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc2, "Eastern Ciscaucasia","ECC","2","");
|
395
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc2a, "Eastern Stavropol","E. Stavr.","2","a");
|
396
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc2b, "Terek-Kuma","Ter.-Kuma ","2","b");
|
397
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc2c, "Terek-Sulak","Ter.-Sul.","2","c");
|
398
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc3, "Western Caucasus","WC","3","");
|
399
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc3a, "Adagum-Pshish","Adag.-Pshish","3","a");
|
400
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc3b, "Belaja-Laba","Bel.-Laba","3","b");
|
401
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc3c, "Urup-Teberda","Urup-Teb.","3","c");
|
402
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc3d, "Upper Kuban","U. Kub.","3","d");
|
403
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc4, "Central Caucasus","CC","4","");
|
404
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc4a, "Upper Kuma","U. Kuma","4","a");
|
405
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc4b, "Malka","Malka","4","b");
|
406
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc4c, "Upper Terek","U. Ter.","4","c");
|
407
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc5, "Eastern Caucasus","EC","5","");
|
408
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc5a, "Assa-Argun","Assa-Arg.","5","a");
|
409
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc5b, "Upper Sulak","U. Sulak","5","b");
|
410
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc5c, "Manas-Samur","Man.-Samur","5","c");
|
411
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc5d, "Kubinsky","Kubin.","5","d");
|
412
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc6, "North-Western Transcaucasia","NWTC","6","");
|
413
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc6a, "Anapa-Gelendzhik","Anapa-Gel.","6","a");
|
414
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc6b, "Pshada-Dzubga","Pshada-Dzhubga ","6","b");
|
415
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7, "Western Transcaucasia","WTC","7","");
|
416
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7a, "Tuapse-Adler","Tuap.-Adl.","7","a");
|
417
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7b, "Abkhasia","Abkh.","7","b");
|
418
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7c, "Inguri-Rioni","Ing.-Rioni","7","c");
|
419
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7d, "Rioni-Kvirili","Rioni-Kvir.","7","d");
|
420
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc7e, "Adzharia","Adzh.","7","e");
|
421
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc8, "Central Transcaucasia","CTC","8","");
|
422
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc8a, "Karthalinia-South Ossetia","Kart.-S. Oss.","8","a");
|
423
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc8b, "Trialetia-Lower Karthalinia","Trial.-L. Kart.","8","b");
|
424
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc8c, "Lori","Lori","8","c");
|
425
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9, "Eastern Transcaucasia","ETC","9","");
|
426
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9a, "Alazan-Agrichay","Alaz.-Agrich.","9","a");
|
427
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9b, "Shirvan","Shirv.","9","b");
|
428
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9c, "Iori-Sheki","Iori-Sheki","9","c");
|
429
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9d, "Murghuz-Murovdagh","Murgh.-Murovd.","9","d");
|
430
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9e, "Lower Kura","L. Kura","9","e");
|
431
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc9f, "Karabagh","Karab.","9","f");
|
432
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc10, "South-Western Transcaucasia","SWTC","10","");
|
433
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc10a, "Meskhetia","Meskh.","10","a");
|
434
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc10b, "Dzhavachetia-Upper Akhurjan","Dzhav.-U. Akh.","10","b");
|
435
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc10c, "Aragatz","Arag.","10","c");
|
436
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11, "Southern Transcaucasia","STC","11","");
|
437
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11a, "Erevan","Erev.","11","a");
|
438
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11b, "Sevan","Sevan","11","b");
|
439
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11c, "Daraleghiz","Dar.","11","c");
|
440
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11d, "Nakhitshevan","Nakh.","11","d");
|
441
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11e, "Zangezur","Zang.","11","e");
|
442
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11f, "Megri-Zangelan","Megri-Zan.","11","f");
|
443
|
last = makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc11g, "Southern Karabagh","S. Karab.","11","g");
|
444
|
makeSingleArea(state, voc, last, BerlinModelTransformer.uuidCauc12, "Talysch","T","12","");
|
445
|
}
|
446
|
|
447
|
/**
|
448
|
* @param state
|
449
|
* @param voc
|
450
|
* @param uuidCauc1
|
451
|
* @param string
|
452
|
* @param string2
|
453
|
* @param string3
|
454
|
* @param string4
|
455
|
* @return
|
456
|
*/
|
457
|
private NamedArea makeSingleArea(BerlinModelImportState state, OrderedTermVocabulary<NamedArea> voc, NamedArea last,
|
458
|
UUID uuid, String label, String labelAbbrev,
|
459
|
String mainLevel, String subLevel) {
|
460
|
|
461
|
NamedArea namedArea = NamedArea.NewInstance(label, label, labelAbbrev);
|
462
|
namedArea.setUuid(uuid);
|
463
|
if (isBlank(subLevel)){
|
464
|
namedArea.setLevel(getNamedAreaLevel(state, BerlinModelTransformer.uuidCaucasusAreaLevelFirst, "Caucasus main areas", "Caucasus main areas", "Cauc. I", null));
|
465
|
}else{
|
466
|
namedArea.setLevel(getNamedAreaLevel(state, BerlinModelTransformer.uuidCaucasusAreaLevelSecond, "Caucasus sub areas", "Caucasus sub areas", "Cauc. II", null));
|
467
|
if(last.getPartOf() != null){
|
468
|
namedArea.setPartOf(last.getPartOf());
|
469
|
}else{
|
470
|
namedArea.setPartOf(last);
|
471
|
}
|
472
|
}
|
473
|
String idInVoc = mainLevel + subLevel;
|
474
|
namedArea.setIdInVocabulary(idInVoc);
|
475
|
voc.addTerm(namedArea);
|
476
|
return namedArea;
|
477
|
}
|
478
|
|
479
|
/**
|
480
|
* @param state
|
481
|
*/
|
482
|
private OrderedTermVocabulary<NamedArea> makeEmptyCaucasusVocabulary(BerlinModelImportState state) {
|
483
|
TermType type = TermType.NamedArea;
|
484
|
String description = "E+M Caucasus area vocabulary";
|
485
|
String label = "E+M Caucasus Areas";
|
486
|
String abbrev = null;
|
487
|
URI termSourceUri = null;
|
488
|
OrderedTermVocabulary<NamedArea> result = OrderedTermVocabulary.NewOrderedInstance(type, null, description, label, abbrev, termSourceUri);
|
489
|
result.setUuid(BerlinModelTransformer.uuidVocCaucasusAreas);
|
490
|
getVocabularyService().save(result);
|
491
|
return result;
|
492
|
}
|
493
|
|
494
|
@Override
|
495
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
496
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
497
|
return result;
|
498
|
}
|
499
|
|
500
|
@Override
|
501
|
protected boolean doCheck(BerlinModelImportState state){
|
502
|
IOValidator<BerlinModelImportState> validator = new BerlinModelAreaImportValidator();
|
503
|
return validator.validate(state);
|
504
|
}
|
505
|
|
506
|
@Override
|
507
|
protected boolean isIgnore(BerlinModelImportState state){
|
508
|
if (state.getConfig().isDoNamedAreas()){
|
509
|
return false;
|
510
|
}else if (! (state.getConfig().isDoOccurrence() || state.getConfig().isDoCommonNames())){
|
511
|
return true;
|
512
|
}else{
|
513
|
if (!this.checkSqlServerColumnExists(state.getConfig().getSource(), "emArea", "AreaId")){
|
514
|
logger.error("emArea table or AreaId column do not exist. Must ignore area import");
|
515
|
return true;
|
516
|
}else{
|
517
|
TermVocabulary<?> voc = getVocabularyService().find(BerlinModelTransformer.uuidVocEuroMedAreas);
|
518
|
return voc != null;
|
519
|
}
|
520
|
}
|
521
|
}
|
522
|
}
|