1
|
/**
|
2
|
* Copyright (C) 2016 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.ext.geo;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.Language;
|
19
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
20
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
21
|
import eu.etaxonomy.cdm.model.term.Representation;
|
22
|
|
23
|
/**
|
24
|
* Base class for Distribution Composers
|
25
|
* @author a.mueller
|
26
|
* @since 02.06.2016
|
27
|
*
|
28
|
*/
|
29
|
public abstract class CondensedDistributionComposerBase implements ICondensedDistributionComposer{
|
30
|
|
31
|
protected static Map<UUID, String> statusSymbols;
|
32
|
|
33
|
|
34
|
|
35
|
protected String areaPreTag = "<b>";
|
36
|
|
37
|
protected String areaPostTag = "</b>";
|
38
|
|
39
|
|
40
|
protected boolean replaceCommonAreaLabelStart;
|
41
|
|
42
|
//for future use in combined DistributionComposer
|
43
|
private boolean sortByStatus;
|
44
|
|
45
|
|
46
|
/**
|
47
|
* @param langs
|
48
|
* @param area
|
49
|
* @return
|
50
|
*/
|
51
|
protected String makeAreaLabel(List<Language> langs, NamedArea area) {
|
52
|
String result = area.getIdInVocabulary() != null ? area.getIdInVocabulary() :area.getPreferredRepresentation(langs).getAbbreviatedLabel();
|
53
|
return areaPreTag + result + areaPostTag;
|
54
|
}
|
55
|
|
56
|
|
57
|
/**
|
58
|
* @param status
|
59
|
* @return
|
60
|
*/
|
61
|
protected String statusSymbol(PresenceAbsenceTerm status) {
|
62
|
if(status == null) {
|
63
|
return "";
|
64
|
}
|
65
|
String symbol = statusSymbols.get(status.getUuid());
|
66
|
if(symbol != null) {
|
67
|
return symbol;
|
68
|
}else if (status.getSymbol() != null){
|
69
|
return status.getSymbol();
|
70
|
}else if (status.getIdInVocabulary() != null){
|
71
|
return status.getIdInVocabulary();
|
72
|
}else {
|
73
|
Representation r = status.getPreferredRepresentation((Language)null);
|
74
|
if (r != null){
|
75
|
String abbrevLabel = r.getAbbreviatedLabel();
|
76
|
if (abbrevLabel != null){
|
77
|
return abbrevLabel;
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
return "n.a.";
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Searches for the parent are of the area given as parameter in
|
87
|
* the Collection of areas.
|
88
|
*
|
89
|
* @parent area
|
90
|
* The area whose parent area is to be searched
|
91
|
* @param collection
|
92
|
* The areas to search in.
|
93
|
*
|
94
|
* @return
|
95
|
* Either the parent if it has been found or null.
|
96
|
*/
|
97
|
protected NamedArea findParentIn(NamedArea area, Collection<NamedArea> areas) {
|
98
|
NamedArea parent = area.getPartOf();
|
99
|
if(parent != null && areas.contains(parent)){
|
100
|
return parent;
|
101
|
}
|
102
|
return null;
|
103
|
}
|
104
|
|
105
|
protected class AreaNode {
|
106
|
|
107
|
protected final NamedArea area;
|
108
|
protected AreaNode parent = null;
|
109
|
protected final Set<AreaNode> subAreas = new HashSet<AreaNode>();
|
110
|
|
111
|
/**
|
112
|
* @param area
|
113
|
*/
|
114
|
public AreaNode(NamedArea area) {
|
115
|
this.area = area;
|
116
|
}
|
117
|
|
118
|
public void addSubArea(AreaNode subArea) {
|
119
|
subAreas.add(subArea);
|
120
|
subArea.parent = this;
|
121
|
}
|
122
|
|
123
|
public AreaNode getParent() {
|
124
|
return parent;
|
125
|
}
|
126
|
|
127
|
public boolean hasParent() {
|
128
|
return getParent() != null;
|
129
|
}
|
130
|
|
131
|
public Collection<NamedArea> getSubareas() {
|
132
|
Collection<NamedArea> areas = new HashSet<NamedArea>();
|
133
|
for(AreaNode node : subAreas) {
|
134
|
areas.add(node.area);
|
135
|
}
|
136
|
return areas;
|
137
|
}
|
138
|
|
139
|
|
140
|
@Override
|
141
|
public String toString() {
|
142
|
return "AreaNode [area=" + area + "]";
|
143
|
}
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
* @param status
|
149
|
* @return
|
150
|
*/
|
151
|
//Keep here only in case new version does creates problems in E+M
|
152
|
//can be deleted if no problem occurs
|
153
|
private String statusSymbolEuroMedOld(PresenceAbsenceTerm status) {
|
154
|
if(status == null) {
|
155
|
return "";
|
156
|
}
|
157
|
String symbol = statusSymbols.get(status.getUuid());
|
158
|
if(symbol == null) {
|
159
|
symbol = "";
|
160
|
}
|
161
|
return symbol;
|
162
|
}
|
163
|
|
164
|
|
165
|
public String getAreaPreTag() {
|
166
|
return areaPreTag;
|
167
|
}
|
168
|
|
169
|
public void setAreaPreTag(String areaPreTag) {
|
170
|
this.areaPreTag = areaPreTag;
|
171
|
}
|
172
|
|
173
|
public String getAreaPostTag() {
|
174
|
return areaPostTag;
|
175
|
}
|
176
|
|
177
|
public void setAreaPostTag(String areaPostTag) {
|
178
|
this.areaPostTag = areaPostTag;
|
179
|
}
|
180
|
|
181
|
|
182
|
|
183
|
}
|