9 |
9 |
|
10 |
10 |
package eu.etaxonomy.cdm.app.berlinModelImport;
|
11 |
11 |
|
12 |
|
import java.io.IOException;
|
13 |
|
import java.io.InputStream;
|
14 |
|
import java.io.InputStreamReader;
|
15 |
|
import java.io.Reader;
|
16 |
|
import java.util.Arrays;
|
17 |
|
import java.util.HashMap;
|
18 |
12 |
import java.util.List;
|
19 |
|
import java.util.Map;
|
20 |
13 |
import java.util.Set;
|
21 |
14 |
import java.util.UUID;
|
22 |
15 |
|
... | ... | |
27 |
20 |
import eu.etaxonomy.cdm.api.application.FirstDataInserter;
|
28 |
21 |
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
29 |
22 |
import eu.etaxonomy.cdm.api.service.IGroupService;
|
30 |
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution;
|
31 |
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution.AggregationMode;
|
32 |
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
33 |
23 |
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
34 |
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
35 |
24 |
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
36 |
25 |
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
37 |
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
38 |
26 |
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
39 |
27 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
40 |
28 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
... | ... | |
45 |
33 |
import eu.etaxonomy.cdm.model.agent.Person;
|
46 |
34 |
import eu.etaxonomy.cdm.model.common.Language;
|
47 |
35 |
import eu.etaxonomy.cdm.model.description.Feature;
|
48 |
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
49 |
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
50 |
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
51 |
36 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
52 |
37 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
53 |
38 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
... | ... | |
62 |
47 |
import eu.etaxonomy.cdm.model.term.TermTree;
|
63 |
48 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
64 |
49 |
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
65 |
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
66 |
50 |
|
67 |
51 |
|
68 |
52 |
/**
|
... | ... | |
404 |
388 |
tree.getRoot().addChild(Feature.IMAGE());
|
405 |
389 |
tree.getRoot().addChild(Feature.DISTRIBUTION(), 1);
|
406 |
390 |
tree.getRoot().addChild(Feature.COMMON_NAME(), 2);
|
407 |
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
|
391 |
app.getTermTreeService().saveOrUpdate(tree);
|
408 |
392 |
|
409 |
393 |
app.commitTransaction(tx);
|
410 |
394 |
} catch (Exception e) {
|
... | ... | |
435 |
419 |
}
|
436 |
420 |
}
|
437 |
421 |
|
438 |
|
//1. run transmission engine #3979
|
439 |
|
private void runTransmissionEngine(BerlinModelImportConfigurator config,
|
440 |
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
441 |
|
|
442 |
|
if (doRunTransmissionEngine && (config.getCheck().isImport() ) ){
|
443 |
|
try {
|
444 |
|
ICdmRepository app = bmImport.getCdmAppController();
|
445 |
|
|
446 |
|
final List<String> term_init_strategy = Arrays.asList(new String []{
|
447 |
|
"representations"
|
448 |
|
});
|
449 |
|
|
450 |
|
UUID uuidSuperAreaLevel = BerlinModelTransformer.uuidEuroMedAreaLevelFirst;
|
451 |
|
NamedAreaLevel euroMedLevel1 = (NamedAreaLevel)app.getTermService().find(uuidSuperAreaLevel);
|
452 |
|
|
453 |
|
Pager<NamedArea> areaPager = app.getTermService().list(
|
454 |
|
euroMedLevel1,
|
455 |
|
(NamedAreaType) null,
|
456 |
|
null,
|
457 |
|
null,
|
458 |
|
(List<OrderHint>) null,
|
459 |
|
term_init_strategy);
|
460 |
|
TransmissionEngineDistribution transmissionEngineDistribution = (TransmissionEngineDistribution)app.getBean("transmissionEngineDistribution");
|
461 |
|
transmissionEngineDistribution.accumulate(
|
462 |
|
AggregationMode.byAreasAndRanks,
|
463 |
|
areaPager.getRecords(),
|
464 |
|
Rank.UNRANKED_INFRASPECIFIC(), //or do we even want to start from lower (UNKNOWN?)
|
465 |
|
Rank.GENUS(),
|
466 |
|
null,
|
467 |
|
DefaultProgressMonitor.NewInstance());
|
468 |
|
} catch (Exception e) {
|
469 |
|
e.printStackTrace();
|
470 |
|
logger.error("Exception in markAreasAsHidden: " + e.getMessage());
|
471 |
|
}
|
472 |
|
}
|
473 |
|
}
|
474 |
422 |
|
475 |
423 |
// //5.Mark areas to be hidden #3979 .5
|
476 |
424 |
// private void markAreasAsHidden(BerlinModelImportConfigurator config,
|
... | ... | |
516 |
464 |
// app.getTermService().saveOrUpdate(area);
|
517 |
465 |
// }
|
518 |
466 |
|
519 |
|
//2. import shapefile attributes #3979 .2
|
520 |
|
private void importShapefile(BerlinModelImportConfigurator config,
|
521 |
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
522 |
|
|
523 |
|
if (config.isDoOccurrence() && (config.getCheck().isImport())){
|
524 |
|
|
525 |
|
try {
|
526 |
|
UUID areaVocabularyUuid = BerlinModelTransformer.uuidVocEuroMedAreas;
|
527 |
|
List<String> idSearchFields = Arrays.asList(new String[]{"EMAREA","PARENT"});
|
528 |
|
String wmsLayerName = "euromed_2013";
|
529 |
|
Set<UUID> areaUuidSet = null;
|
530 |
|
|
531 |
|
ICdmRepository app = bmImport.getCdmAppController();
|
532 |
|
IEditGeoService geoService = (IEditGeoService)app.getBean("editGeoService");
|
533 |
|
|
534 |
|
Map<NamedArea, String> resultMap;
|
535 |
|
try {
|
536 |
|
InputStream in = CaucasusEuroMedActivator.class.getResourceAsStream("/euromed/euromed_2013.csv");
|
537 |
|
Reader reader = new InputStreamReader(in, "UTF-8");
|
538 |
|
|
539 |
|
resultMap = geoService.mapShapeFileToNamedAreas(
|
540 |
|
reader, idSearchFields , wmsLayerName , areaVocabularyUuid, areaUuidSet);
|
541 |
|
Map<String, String> flatResultMap = new HashMap<>(resultMap.size());
|
542 |
|
for(NamedArea area : resultMap.keySet()){
|
543 |
|
flatResultMap.put(area.getTitleCache() + " [" + area.getUuid() + "]", resultMap.get(area));
|
544 |
|
}
|
545 |
|
} catch (IOException e) {
|
546 |
|
String message = "IOException when reading from mapping file or creating result map.";
|
547 |
|
logger.error(message);
|
548 |
|
System.out.println(message);
|
549 |
|
}
|
550 |
|
} catch (Exception e) {
|
551 |
|
e.printStackTrace();
|
552 |
|
logger.error("Exception in importShapefile: " + e.getMessage());
|
553 |
|
}
|
554 |
|
}
|
555 |
|
}
|
556 |
467 |
|
557 |
468 |
//4. Create users and assign roles #3979
|
558 |
469 |
private void createUsersAndRoles(BerlinModelImportConfigurator config,
|
cleanup