1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.app.eflora;
|
5
|
|
6
|
import java.util.Collection;
|
7
|
import java.util.HashMap;
|
8
|
import java.util.HashSet;
|
9
|
import java.util.List;
|
10
|
import java.util.Map;
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
16
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
17
|
import eu.etaxonomy.cdm.io.markup.FeatureSorter;
|
18
|
import eu.etaxonomy.cdm.io.markup.FeatureSorterInfo;
|
19
|
import eu.etaxonomy.cdm.io.markup.MarkupImportState;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
22
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
*
|
27
|
*/
|
28
|
public class EfloraActivatorBase {
|
29
|
private static final Logger logger = Logger.getLogger(EfloraActivatorBase.class);
|
30
|
|
31
|
|
32
|
protected FeatureTree makeAutomatedFeatureTree(ICdmApplicationConfiguration app,
|
33
|
MarkupImportState state, UUID featureTreeUuid, String featureTreeTitle){
|
34
|
System.out.println("Start creating automated Feature Tree");
|
35
|
FeatureTree tree = FeatureTree.NewInstance(featureTreeUuid);
|
36
|
tree.setTitleCache(featureTreeTitle, true);
|
37
|
FeatureNode root = tree.getRoot();
|
38
|
|
39
|
ITermService termService = app.getTermService();
|
40
|
FeatureSorter sorter = new FeatureSorter();
|
41
|
FeatureNode descriptionNode = null;
|
42
|
|
43
|
//general features
|
44
|
Map<String, List<FeatureSorterInfo>> generalList = state.getGeneralFeatureSorterListMap();
|
45
|
List<UUID> uuidList = sorter.getSortOrder(generalList);
|
46
|
Map<UUID, Feature> map = makeUuidMap(uuidList, termService);
|
47
|
for (UUID key : uuidList){
|
48
|
Feature feature = map.get(key);
|
49
|
FeatureNode node = FeatureNode.NewInstance(feature);
|
50
|
root.addChild(node);
|
51
|
if (feature.equals(Feature.DESCRIPTION())){
|
52
|
descriptionNode = node;
|
53
|
}
|
54
|
}
|
55
|
FeatureNode newNode = FeatureNode.NewInstance(Feature.CITATION());
|
56
|
root.addChild(newNode);
|
57
|
|
58
|
|
59
|
//description features
|
60
|
if (descriptionNode != null){
|
61
|
Map<String, List<FeatureSorterInfo>> charList = state.getCharFeatureSorterListMap();
|
62
|
uuidList = sorter.getSortOrder(charList);
|
63
|
map = makeUuidMap(uuidList, termService);
|
64
|
for (UUID key : uuidList){
|
65
|
Feature feature = map.get(key);
|
66
|
descriptionNode.addChild(FeatureNode.NewInstance(feature));
|
67
|
}
|
68
|
}else{
|
69
|
logger.warn("No description node found. Could not create feature nodes for description features.");
|
70
|
}
|
71
|
|
72
|
//save tree
|
73
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
74
|
|
75
|
System.out.println("End creating automated Feature Tree");
|
76
|
|
77
|
return tree;
|
78
|
}
|
79
|
|
80
|
private Map<UUID,Feature> makeUuidMap(Collection<UUID> uuids, ITermService termService){
|
81
|
HashSet<UUID> uuidSet = new HashSet<UUID>();
|
82
|
uuidSet.addAll(uuids);
|
83
|
List<Feature> featureSet = (List)termService.find(uuidSet);
|
84
|
|
85
|
Map<UUID,Feature> result = new HashMap<UUID, Feature>();
|
86
|
for (Feature feature : featureSet){
|
87
|
result.put(feature.getUuid(), feature);
|
88
|
}
|
89
|
return result;
|
90
|
}
|
91
|
}
|