1 |
2d9a13f7
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
da005e87
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
2d9a13f7
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
da005e87
|
Patric Plitzner
|
*
|
6 |
2d9a13f7
|
n.hoffmann
|
* 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 |
|
|
|
10 |
|
|
package eu.etaxonomy.taxeditor.model;
|
11 |
|
|
|
12 |
a799db81
|
Andreas Müller
|
import java.lang.reflect.InvocationTargetException;
|
13 |
|
|
import java.lang.reflect.Method;
|
14 |
cfcb0ce6
|
n.hoffmann
|
import java.util.Arrays;
|
15 |
|
|
import java.util.List;
|
16 |
a799db81
|
Andreas Müller
|
import java.util.Set;
|
17 |
cfcb0ce6
|
n.hoffmann
|
|
18 |
a799db81
|
Andreas Müller
|
import org.apache.commons.lang.StringUtils;
|
19 |
3fb05254
|
n.hoffmann
|
import org.hibernate.LazyInitializationException;
|
20 |
2d9a13f7
|
n.hoffmann
|
|
21 |
bad14dbc
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
22 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;
|
23 |
|
|
import eu.etaxonomy.cdm.api.service.DefaultQuantitativeDescriptionBuilder;
|
24 |
|
|
import eu.etaxonomy.cdm.api.service.DescriptionBuilder;
|
25 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
26 |
bad14dbc
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
27 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28 |
|
|
import eu.etaxonomy.cdm.model.common.Group;
|
29 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
30 |
|
|
import eu.etaxonomy.cdm.model.common.Language;
|
31 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
32 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
|
33 |
|
|
import eu.etaxonomy.cdm.model.common.Marker;
|
34 |
a7e7d941
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
35 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
|
36 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
37 |
|
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
38 |
|
|
import eu.etaxonomy.cdm.model.common.Representation;
|
39 |
bad14dbc
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
40 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.User;
|
41 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
42 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
43 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
44 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
45 |
f6a8dc56
|
Patric Plitzner
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
46 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
47 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.Feature;
|
48 |
|
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
49 |
cd19940f
|
Katja Luther
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
50 |
da005e87
|
Patric Plitzner
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
51 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
52 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
53 |
|
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
54 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
55 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
56 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.TextData;
|
57 |
|
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
58 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.media.Media;
|
59 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
60 |
|
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
61 |
|
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
62 |
|
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
63 |
|
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
64 |
e3a4a3ff
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
65 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
66 |
|
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
67 |
d63fc1f3
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
68 |
bad14dbc
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
69 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
70 |
87d0418a
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
71 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
72 |
d63fc1f3
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
73 |
87d0418a
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
74 |
a799db81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
75 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
3be6ef3e
|
n.hoffmann
|
* <p>DescriptionHelper class.</p>
|
79 |
|
|
*
|
80 |
2d9a13f7
|
n.hoffmann
|
* @author p.ciardelli
|
81 |
cfcb0ce6
|
n.hoffmann
|
* @author n.hoffmann
|
82 |
2d9a13f7
|
n.hoffmann
|
*/
|
83 |
|
|
public class DescriptionHelper {
|
84 |
da005e87
|
Patric Plitzner
|
|
85 |
2d9a13f7
|
n.hoffmann
|
/**
|
86 |
|
|
* Returns whatever the element's title cache equivalent is,
|
87 |
|
|
* depending on its class.
|
88 |
3be6ef3e
|
n.hoffmann
|
*
|
89 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
90 |
|
|
* @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
91 |
|
|
* @return a {@link java.lang.String} object.
|
92 |
2d9a13f7
|
n.hoffmann
|
*/
|
93 |
da005e87
|
Patric Plitzner
|
public static String getCache(DescriptionElementBase element,
|
94 |
2d9a13f7
|
n.hoffmann
|
Language language) {
|
95 |
cd19940f
|
Katja Luther
|
|
96 |
a799db81
|
Andreas Müller
|
String mainElementLabel= null;
|
97 |
|
|
DescriptionBase<?> descr = element.getInDescription();
|
98 |
cd19940f
|
Katja Luther
|
descr = CdmBase.deproxy(descr, DescriptionBase.class);
|
99 |
|
|
|
100 |
a799db81
|
Andreas Müller
|
if (descr != null){
|
101 |
|
|
if (descr.isInstanceOf(TaxonDescription.class)){
|
102 |
|
|
Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
|
103 |
|
|
if (taxon != null){
|
104 |
|
|
mainElementLabel = taxon.getTitleCache();
|
105 |
|
|
}
|
106 |
|
|
}else if (descr.isInstanceOf(SpecimenDescription.class)){
|
107 |
|
|
SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(descr, SpecimenDescription.class).getDescribedSpecimenOrObservation();
|
108 |
|
|
if (specimen != null){
|
109 |
|
|
mainElementLabel = specimen.getTitleCache();
|
110 |
|
|
}
|
111 |
|
|
}else if (descr.isInstanceOf(TaxonNameDescription.class)){
|
112 |
e3a4a3ff
|
Andreas Müller
|
TaxonName name = CdmBase.deproxy(descr, TaxonNameDescription.class).getTaxonName();
|
113 |
a799db81
|
Andreas Müller
|
if (name != null){
|
114 |
|
|
mainElementLabel = name.getTitleCache();
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
cd19940f
|
Katja Luther
|
|
119 |
|
|
|
120 |
2d9a13f7
|
n.hoffmann
|
String cache = null;
|
121 |
|
|
if (element instanceof TextData) {
|
122 |
cd19940f
|
Katja Luther
|
//cache = ((TextData) element).getText(language);
|
123 |
|
|
cache = "Text Data";
|
124 |
2d9a13f7
|
n.hoffmann
|
}
|
125 |
|
|
if (element instanceof CommonTaxonName) {
|
126 |
|
|
cache = ((CommonTaxonName) element).getName();
|
127 |
|
|
}
|
128 |
|
|
if (element instanceof TaxonInteraction) {
|
129 |
|
|
Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
|
130 |
|
|
if(taxon2 != null && taxon2.getName() != null){
|
131 |
|
|
cache = taxon2.getName().getTitleCache();
|
132 |
|
|
}else{
|
133 |
|
|
cache = "No taxon chosen";
|
134 |
|
|
}
|
135 |
da005e87
|
Patric Plitzner
|
|
136 |
2d9a13f7
|
n.hoffmann
|
}
|
137 |
|
|
if (element instanceof Distribution) {
|
138 |
|
|
Distribution distribution = (Distribution) element;
|
139 |
da005e87
|
Patric Plitzner
|
|
140 |
2d9a13f7
|
n.hoffmann
|
NamedArea area = distribution.getArea();
|
141 |
|
|
if(area != null){
|
142 |
|
|
cache = area.getLabel();
|
143 |
da005e87
|
Patric Plitzner
|
|
144 |
|
|
PresenceAbsenceTerm status = distribution.getStatus();
|
145 |
2d9a13f7
|
n.hoffmann
|
if (status == null){
|
146 |
|
|
cache += ", no status";
|
147 |
|
|
}else {
|
148 |
|
|
cache += ", " + status.getLabel();
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
a799db81
|
Andreas Müller
|
String result = cache == null ? "" : cache;
|
153 |
a147c1df
|
Andreas Müller
|
if (isNotBlank(mainElementLabel)){
|
154 |
a799db81
|
Andreas Müller
|
result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
|
155 |
|
|
}
|
156 |
|
|
return result;
|
157 |
2d9a13f7
|
n.hoffmann
|
}
|
158 |
|
|
|
159 |
|
|
/**
|
160 |
|
|
* Returns whatever the element's title cache equivalent is,
|
161 |
|
|
* depending on its class, using the default language.
|
162 |
3be6ef3e
|
n.hoffmann
|
*
|
163 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
164 |
|
|
* @return a {@link java.lang.String} object.
|
165 |
2d9a13f7
|
n.hoffmann
|
*/
|
166 |
|
|
public static String getCache(DescriptionElementBase element) {
|
167 |
|
|
return getCache(element, CdmStore.getDefaultLanguage());
|
168 |
|
|
}
|
169 |
da005e87
|
Patric Plitzner
|
|
170 |
2d9a13f7
|
n.hoffmann
|
/**
|
171 |
|
|
* Set whatever the element's title cache equivalent is,
|
172 |
|
|
* depending on its class.
|
173 |
3be6ef3e
|
n.hoffmann
|
*
|
174 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
175 |
|
|
* @param value a {@link java.lang.String} object.
|
176 |
|
|
* @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
177 |
2d9a13f7
|
n.hoffmann
|
*/
|
178 |
|
|
public static void setCache(DescriptionElementBase element,
|
179 |
|
|
String value, Language language) {
|
180 |
|
|
if (element instanceof TextData) {
|
181 |
ce22246a
|
n.hoffmann
|
((TextData) element).putText(language, value);
|
182 |
2d9a13f7
|
n.hoffmann
|
return;
|
183 |
a799db81
|
Andreas Müller
|
}else if (element instanceof CommonTaxonName) {
|
184 |
2d9a13f7
|
n.hoffmann
|
((CommonTaxonName) element).setName(value);
|
185 |
|
|
return;
|
186 |
a799db81
|
Andreas Müller
|
}else if (element instanceof TaxonInteraction) {
|
187 |
da005e87
|
Patric Plitzner
|
|
188 |
a799db81
|
Andreas Müller
|
}else if(element instanceof Distribution){
|
189 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.warn(DescriptionHelper.class, "trying to set cache on distribution, don't know what to do at the moment.");
|
190 |
2d9a13f7
|
n.hoffmann
|
return;
|
191 |
a799db81
|
Andreas Müller
|
}else{
|
192 |
|
|
MessagingUtils.warn(DescriptionHelper.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
|
193 |
2d9a13f7
|
n.hoffmann
|
}
|
194 |
|
|
}
|
195 |
da005e87
|
Patric Plitzner
|
|
196 |
2d9a13f7
|
n.hoffmann
|
/**
|
197 |
|
|
* Set whatever the element's title cache equivalent is,
|
198 |
|
|
* depending on its class, using the default language.
|
199 |
3be6ef3e
|
n.hoffmann
|
*
|
200 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
201 |
|
|
* @param value a {@link java.lang.String} object.
|
202 |
|
|
*/
|
203 |
2d9a13f7
|
n.hoffmann
|
public static void setCache(DescriptionElementBase element,
|
204 |
|
|
String value) {
|
205 |
|
|
setCache(element, value, CdmStore.getDefaultLanguage());
|
206 |
|
|
}
|
207 |
da005e87
|
Patric Plitzner
|
|
208 |
a799db81
|
Andreas Müller
|
|
209 |
3be6ef3e
|
n.hoffmann
|
/**
|
210 |
|
|
* <p>getObjectDescription</p>
|
211 |
|
|
*
|
212 |
|
|
* @param element a {@link java.lang.Object} object.
|
213 |
|
|
* @return a {@link java.lang.String} object.
|
214 |
|
|
*/
|
215 |
2d9a13f7
|
n.hoffmann
|
public static String getObjectDescription(Object element) {
|
216 |
3a5a8583
|
Katja Luther
|
String resultString = null;
|
217 |
2d9a13f7
|
n.hoffmann
|
if (element instanceof IdentifiableEntity) {
|
218 |
|
|
try{
|
219 |
3a5a8583
|
Katja Luther
|
resultString = ((IdentifiableEntity) element).getTitleCache();
|
220 |
3fb05254
|
n.hoffmann
|
}catch(LazyInitializationException e){
|
221 |
|
|
String result = "No Session to initialize title cache for IdentifiableEntity";
|
222 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.error(DescriptionHelper.class, result, e);
|
223 |
3a5a8583
|
Katja Luther
|
resultString = "TODO: " + result;
|
224 |
2d9a13f7
|
n.hoffmann
|
}
|
225 |
a799db81
|
Andreas Müller
|
}else if (element instanceof OriginalSourceBase) {
|
226 |
3fb05254
|
n.hoffmann
|
try{
|
227 |
a799db81
|
Andreas Müller
|
OriginalSourceBase<?> originalSource = (OriginalSourceBase<?>) element;
|
228 |
e8633778
|
Andreas Müller
|
// ISourceable sourcedObject = originalSource.getSourcedObj();
|
229 |
cd19940f
|
Katja Luther
|
//due to #5743 the bidirectionality for sourced object had to be removed
|
230 |
e8633778
|
Andreas Müller
|
String sourceObjectTitle = "sourced object data not available (#5743)";
|
231 |
|
|
// if(sourcedObject instanceof IIdentifiableEntity){
|
232 |
|
|
// sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
|
233 |
|
|
// }else if(sourcedObject instanceof DescriptionElementBase){
|
234 |
|
|
// sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
|
235 |
|
|
// }else{
|
236 |
|
|
// throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
|
237 |
|
|
// }
|
238 |
da005e87
|
Patric Plitzner
|
|
239 |
3a5a8583
|
Katja Luther
|
resultString = CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle});
|
240 |
3fb05254
|
n.hoffmann
|
}catch(LazyInitializationException e){
|
241 |
|
|
String result = "Error initializing title cache for ISourceable of an OriginalSourceBase";
|
242 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.error(DescriptionHelper.class, result, e);
|
243 |
3a5a8583
|
Katja Luther
|
resultString = "TODO: " + result;
|
244 |
2d9a13f7
|
n.hoffmann
|
}
|
245 |
a799db81
|
Andreas Müller
|
}else if (element instanceof LanguageStringBase) {
|
246 |
3a5a8583
|
Katja Luther
|
resultString = ((LanguageStringBase) element).getText();
|
247 |
a799db81
|
Andreas Müller
|
}else if (element instanceof DescriptionElementBase) {
|
248 |
3a5a8583
|
Katja Luther
|
resultString = getCache((DescriptionElementBase) element);
|
249 |
a799db81
|
Andreas Müller
|
}else if (element instanceof RelationshipBase<?, ?, ?>) {
|
250 |
3a5a8583
|
Katja Luther
|
resultString = getCache((RelationshipBase<?, ?, ?>) element);
|
251 |
a799db81
|
Andreas Müller
|
}else if (element instanceof TypeDesignationBase<?>) {
|
252 |
3a5a8583
|
Katja Luther
|
resultString = getCache((TypeDesignationBase<?>) element);
|
253 |
a799db81
|
Andreas Müller
|
}else if (element instanceof HomotypicalGroup) {
|
254 |
3a5a8583
|
Katja Luther
|
resultString = getCache((HomotypicalGroup) element);
|
255 |
87d0418a
|
Andreas Müller
|
}else if (element instanceof TaxonNode) {
|
256 |
3a5a8583
|
Katja Luther
|
resultString = getCache((TaxonNode) element);
|
257 |
d63fc1f3
|
Andreas Müller
|
}else if (element instanceof DeterminationEvent) {
|
258 |
3a5a8583
|
Katja Luther
|
resultString = getCache((DeterminationEvent) element);
|
259 |
bad14dbc
|
Andreas Müller
|
}else if (element instanceof GatheringEvent){
|
260 |
|
|
resultString = getCache((GatheringEvent) element);
|
261 |
a799db81
|
Andreas Müller
|
}else if (element instanceof Marker) {
|
262 |
2d9a13f7
|
n.hoffmann
|
Marker marker = (Marker) element;
|
263 |
a7e7d941
|
Andreas Müller
|
MarkerType type = marker.getMarkerType();
|
264 |
3a5a8583
|
Katja Luther
|
resultString = (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
|
265 |
a799db81
|
Andreas Müller
|
}else if (element instanceof User) {
|
266 |
|
|
User user = (User) element;
|
267 |
3a5a8583
|
Katja Luther
|
resultString = user.getUsername();
|
268 |
a799db81
|
Andreas Müller
|
}else if (element instanceof Group) {
|
269 |
|
|
Group group = (Group) element;
|
270 |
3a5a8583
|
Katja Luther
|
resultString = group.getName();
|
271 |
cd19940f
|
Katja Luther
|
}else if (element instanceof KeyStatement) {
|
272 |
|
|
KeyStatement keyStatement = (KeyStatement) element;
|
273 |
3a5a8583
|
Katja Luther
|
resultString = getCache(keyStatement);
|
274 |
cd19940f
|
Katja Luther
|
}else{
|
275 |
a799db81
|
Andreas Müller
|
// TODO write return texts for HomotypicalGroup, etc.
|
276 |
3a5a8583
|
Katja Luther
|
resultString = element.toString();
|
277 |
a799db81
|
Andreas Müller
|
}
|
278 |
3a5a8583
|
Katja Luther
|
|
279 |
|
|
if (resultString == null){
|
280 |
|
|
resultString = element.toString();
|
281 |
|
|
}
|
282 |
|
|
return resultString;
|
283 |
a799db81
|
Andreas Müller
|
}
|
284 |
bad14dbc
|
Andreas Müller
|
|
285 |
|
|
private static String getCache(GatheringEvent gatheringEvent){
|
286 |
|
|
String ALTITUDE_PREFIX = "alt. ";
|
287 |
|
|
final String METER = "m";
|
288 |
|
|
|
289 |
|
|
String result = "";
|
290 |
|
|
|
291 |
|
|
//collector
|
292 |
|
|
AgentBase<?> collector = CdmBase.deproxy(gatheringEvent.getCollector());
|
293 |
|
|
String collectorStr = collector == null? null : collector.getTitleCache();
|
294 |
|
|
result = CdmUtils.concat(", ", result, collectorStr);
|
295 |
|
|
|
296 |
|
|
//gathering period
|
297 |
|
|
TimePeriod gatheringPeriod = gatheringEvent.getTimeperiod();
|
298 |
|
|
result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString()));
|
299 |
|
|
|
300 |
|
|
//country
|
301 |
|
|
String strCountry = null;
|
302 |
|
|
NamedArea country = gatheringEvent.getCountry();
|
303 |
|
|
Representation repCountry = country == null ? null : country.getRepresentation(Language.DEFAULT());
|
304 |
|
|
strCountry = repCountry == null ? null: repCountry.getLabel();
|
305 |
|
|
result = CdmUtils.concat(", ", result, strCountry);
|
306 |
|
|
|
307 |
|
|
//locality
|
308 |
|
|
LanguageString locality = gatheringEvent.getLocality();
|
309 |
|
|
if (locality != null) {
|
310 |
|
|
result = CdmUtils.concat(", ", result, locality.getText());
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
//elevation
|
314 |
|
|
String elevationStr;
|
315 |
|
|
if (isNotBlank(gatheringEvent.getAbsoluteElevationText())){
|
316 |
|
|
elevationStr = gatheringEvent.getAbsoluteElevationText();
|
317 |
|
|
}else{
|
318 |
|
|
String text = gatheringEvent.getAbsoluteElevationText();
|
319 |
|
|
Integer min = gatheringEvent.getAbsoluteElevation();
|
320 |
|
|
Integer max = gatheringEvent.getAbsoluteElevationMax();
|
321 |
|
|
elevationStr = DerivedUnitFacade.distanceString(min, max, text, METER);
|
322 |
|
|
}
|
323 |
|
|
if (isNotBlank(elevationStr)){
|
324 |
|
|
result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
|
325 |
|
|
result += elevationStr;
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
//exact locality
|
329 |
|
|
if (gatheringEvent.getExactLocation() != null){
|
330 |
|
|
String exactLocation = gatheringEvent.getExactLocation().toSexagesimalString(false, false);
|
331 |
|
|
result = CdmUtils.concat(", ", result, exactLocation);
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
return result;
|
335 |
|
|
}
|
336 |
a799db81
|
Andreas Müller
|
|
337 |
|
|
|
338 |
d63fc1f3
|
Andreas Müller
|
private static String getCache(DeterminationEvent detEvent) {
|
339 |
|
|
//taxon
|
340 |
e519dde1
|
Andreas Müller
|
String taxonStr = null;
|
341 |
e3a4a3ff
|
Andreas Müller
|
TaxonName taxonName = detEvent.getTaxonName();
|
342 |
d63fc1f3
|
Andreas Müller
|
TaxonBase<?> taxon = detEvent.getTaxon();
|
343 |
|
|
if (taxonName != null){
|
344 |
|
|
taxonStr = taxonName.getTitleCache();
|
345 |
e519dde1
|
Andreas Müller
|
}
|
346 |
a147c1df
|
Andreas Müller
|
if (isBlank(taxonStr) && taxon != null){
|
347 |
d63fc1f3
|
Andreas Müller
|
taxonStr = taxon.getTitleCache();
|
348 |
|
|
}
|
349 |
a147c1df
|
Andreas Müller
|
if (isBlank(taxonStr)){
|
350 |
e519dde1
|
Andreas Müller
|
taxonStr = "no or unlabled taxon";
|
351 |
|
|
}
|
352 |
cd19940f
|
Katja Luther
|
|
353 |
|
|
|
354 |
d63fc1f3
|
Andreas Müller
|
//unit
|
355 |
|
|
SpecimenOrObservationBase<?> unit = detEvent.getIdentifiedUnit();
|
356 |
e519dde1
|
Andreas Müller
|
String unitStr;
|
357 |
d63fc1f3
|
Andreas Müller
|
if (unit != null){
|
358 |
|
|
unitStr = unit.getTitleCache();
|
359 |
a147c1df
|
Andreas Müller
|
if (isBlank(unitStr)){
|
360 |
e519dde1
|
Andreas Müller
|
unitStr = "Unlabled unit";
|
361 |
|
|
}
|
362 |
|
|
}else{
|
363 |
|
|
unitStr = "no unit";
|
364 |
d63fc1f3
|
Andreas Müller
|
}
|
365 |
cd19940f
|
Katja Luther
|
|
366 |
d63fc1f3
|
Andreas Müller
|
String result = CdmUtils.concat(" determined as ", unitStr, taxonStr);
|
367 |
|
|
|
368 |
|
|
return result;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
87d0418a
|
Andreas Müller
|
private static String getCache(TaxonNode taxonNode) {
|
372 |
|
|
String result = "";
|
373 |
|
|
Classification classification = taxonNode.getClassification();
|
374 |
|
|
if (classification != null){
|
375 |
|
|
String classificationStr = classification.getName() == null ? "" : classification.getName().getText();
|
376 |
|
|
result = CdmUtils.concat("" , result, classificationStr);
|
377 |
a147c1df
|
Andreas Müller
|
if (isBlank(result)){
|
378 |
87d0418a
|
Andreas Müller
|
result = classification.toString();
|
379 |
|
|
}
|
380 |
|
|
}
|
381 |
|
|
String parentStr;
|
382 |
|
|
TaxonNode parentNode = taxonNode.getParent();
|
383 |
|
|
if (parentNode == null){
|
384 |
|
|
parentStr = "no parent";
|
385 |
|
|
}else{
|
386 |
|
|
Taxon parentTaxon = parentNode.getTaxon();
|
387 |
|
|
if (parentTaxon == null){
|
388 |
|
|
parentStr = "no parent taxon";
|
389 |
|
|
}else{
|
390 |
e3a4a3ff
|
Andreas Müller
|
TaxonName parentName = parentTaxon.getName();
|
391 |
87d0418a
|
Andreas Müller
|
if (parentName == null){
|
392 |
eee5ea0d
|
Andreas Müller
|
parentStr = "child of " + parentTaxon.getTitleCache();
|
393 |
87d0418a
|
Andreas Müller
|
}else{
|
394 |
eee5ea0d
|
Andreas Müller
|
parentStr = "child of " + parentName.getTitleCache();
|
395 |
87d0418a
|
Andreas Müller
|
}
|
396 |
|
|
}
|
397 |
|
|
}
|
398 |
|
|
result = CdmUtils.concat(": ", result, parentStr);
|
399 |
cd19940f
|
Katja Luther
|
|
400 |
d63fc1f3
|
Andreas Müller
|
return result;
|
401 |
87d0418a
|
Andreas Müller
|
}
|
402 |
|
|
|
403 |
a799db81
|
Andreas Müller
|
private static String getCache(TypeDesignationBase<?> designation) {
|
404 |
|
|
designation = CdmBase.deproxy(designation);
|
405 |
|
|
TypeDesignationStatusBase<?> status = designation.getTypeStatus();
|
406 |
e3a4a3ff
|
Andreas Müller
|
Set<TaxonName> from;
|
407 |
a799db81
|
Andreas Müller
|
IdentifiableEntity<?> to;
|
408 |
|
|
from = designation.getTypifiedNames();
|
409 |
|
|
if (designation.isInstanceOf(SpecimenTypeDesignation.class)){
|
410 |
|
|
to = ((SpecimenTypeDesignation)designation).getTypeSpecimen();
|
411 |
|
|
}else if (designation.isInstanceOf(NameTypeDesignation.class)){
|
412 |
cd19940f
|
Katja Luther
|
to = ((NameTypeDesignation)designation).getTypeName();
|
413 |
a799db81
|
Andreas Müller
|
}else{
|
414 |
|
|
throw new RuntimeException("Type Designation class not supported: " + designation.getClass().getName());
|
415 |
|
|
}
|
416 |
|
|
String typeLabel = null;
|
417 |
|
|
if (status != null){
|
418 |
|
|
Representation typeRepr = status.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
419 |
|
|
if (typeRepr != null){
|
420 |
|
|
typeLabel = typeRepr.getAbbreviatedLabel();
|
421 |
|
|
}
|
422 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel) && typeRepr != null){
|
423 |
a799db81
|
Andreas Müller
|
typeLabel = typeRepr.getLabel();
|
424 |
|
|
}
|
425 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel) ){
|
426 |
a799db81
|
Andreas Müller
|
typeLabel = status.getSymbol();
|
427 |
|
|
}
|
428 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel)){
|
429 |
a799db81
|
Andreas Müller
|
typeLabel = status.getTitleCache();
|
430 |
|
|
}
|
431 |
|
|
}
|
432 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel)){
|
433 |
a799db81
|
Andreas Müller
|
typeLabel = "->";
|
434 |
|
|
}
|
435 |
|
|
String fromString = "";
|
436 |
e3a4a3ff
|
Andreas Müller
|
for (TaxonName name : from){
|
437 |
a799db81
|
Andreas Müller
|
CdmUtils.concat(",", fromString, name.getTitleCache());
|
438 |
|
|
}
|
439 |
cd19940f
|
Katja Luther
|
String result = CdmUtils.concat(" ", new String[]{from == null ? null : fromString,
|
440 |
a799db81
|
Andreas Müller
|
typeLabel, to == null? null : to.getTitleCache()});
|
441 |
|
|
return result;
|
442 |
|
|
}
|
443 |
|
|
|
444 |
|
|
private static String getCache(RelationshipBase<?, ?, ?> rel) {
|
445 |
|
|
rel = CdmBase.deproxy(rel);
|
446 |
|
|
RelationshipTermBase<?> type = rel.getType();
|
447 |
|
|
IdentifiableEntity<?> from;
|
448 |
|
|
IdentifiableEntity<?> to;
|
449 |
bdd1bcf5
|
Andreas Müller
|
if (rel.isInstanceOf(NameRelationship.class)){
|
450 |
a799db81
|
Andreas Müller
|
from = ((NameRelationship)rel).getFromName();
|
451 |
|
|
to = ((NameRelationship)rel).getToName();
|
452 |
|
|
}else if (rel.isInstanceOf(HybridRelationship.class)){
|
453 |
|
|
from = ((HybridRelationship)rel).getParentName();
|
454 |
|
|
to = ((HybridRelationship)rel).getHybridName();
|
455 |
|
|
}else if (rel.isInstanceOf(TaxonRelationship.class)){
|
456 |
|
|
from = ((TaxonRelationship)rel).getFromTaxon();
|
457 |
|
|
to = ((TaxonRelationship)rel).getToTaxon();
|
458 |
|
|
}else{
|
459 |
|
|
try {
|
460 |
|
|
Method fromMethod = rel.getClass().getMethod("getRelatedFrom");
|
461 |
|
|
Method toMethod = rel.getClass().getMethod("getRelatedFrom");
|
462 |
|
|
fromMethod.setAccessible(true);
|
463 |
|
|
toMethod.setAccessible(true);
|
464 |
|
|
from = (IdentifiableEntity<?>)fromMethod.invoke(rel);
|
465 |
|
|
to = (IdentifiableEntity<?>)toMethod.invoke(rel);
|
466 |
d63fc1f3
|
Andreas Müller
|
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
|
467 |
|
|
| IllegalArgumentException | InvocationTargetException e) {
|
468 |
a799db81
|
Andreas Müller
|
throw new RuntimeException(e);
|
469 |
|
|
}
|
470 |
|
|
}
|
471 |
|
|
String typeLabel = null;
|
472 |
|
|
if (type != null){
|
473 |
|
|
Representation typeRepr = type.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
474 |
|
|
if (typeRepr != null){
|
475 |
|
|
typeLabel = typeRepr.getAbbreviatedLabel();
|
476 |
|
|
}
|
477 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel) && typeRepr != null){
|
478 |
a799db81
|
Andreas Müller
|
typeLabel = typeRepr.getLabel();
|
479 |
|
|
}
|
480 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel) ){
|
481 |
a799db81
|
Andreas Müller
|
typeLabel = type.getSymbol();
|
482 |
|
|
}
|
483 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel)){
|
484 |
a799db81
|
Andreas Müller
|
typeLabel = type.getTitleCache();
|
485 |
|
|
}
|
486 |
|
|
}
|
487 |
a147c1df
|
Andreas Müller
|
if (isBlank(typeLabel)){
|
488 |
a799db81
|
Andreas Müller
|
typeLabel = "->";
|
489 |
|
|
}
|
490 |
cd19940f
|
Katja Luther
|
String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(),
|
491 |
a799db81
|
Andreas Müller
|
typeLabel, to == null? null : to.getTitleCache()});
|
492 |
|
|
return result;
|
493 |
|
|
}
|
494 |
cd19940f
|
Katja Luther
|
|
495 |
a799db81
|
Andreas Müller
|
|
496 |
|
|
private static String getCache(HomotypicalGroup hg) {
|
497 |
|
|
String result = "";
|
498 |
e3a4a3ff
|
Andreas Müller
|
for (TaxonName tnb : hg.getTypifiedNames()){
|
499 |
a799db81
|
Andreas Müller
|
result = CdmUtils.concat(", ", result, tnb.getTitleCache());
|
500 |
|
|
}
|
501 |
a147c1df
|
Andreas Müller
|
if (isBlank(result)){
|
502 |
a799db81
|
Andreas Müller
|
result = "No typified names";
|
503 |
2d9a13f7
|
n.hoffmann
|
}
|
504 |
a799db81
|
Andreas Müller
|
return result;
|
505 |
2d9a13f7
|
n.hoffmann
|
}
|
506 |
3fb05254
|
n.hoffmann
|
|
507 |
cd19940f
|
Katja Luther
|
private static String getCache(KeyStatement ks) {
|
508 |
|
|
String result = "";
|
509 |
|
|
|
510 |
|
|
result = "KeyStatement";
|
511 |
|
|
|
512 |
|
|
return result;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
3be6ef3e
|
n.hoffmann
|
/**
|
516 |
|
|
* <p>getObjectClassname</p>
|
517 |
|
|
*
|
518 |
|
|
* @param element a {@link java.lang.Object} object.
|
519 |
|
|
* @return a {@link java.lang.String} object.
|
520 |
|
|
*/
|
521 |
3fb05254
|
n.hoffmann
|
public static String getObjectClassname(Object element) {
|
522 |
|
|
return element.getClass().getSimpleName();
|
523 |
|
|
}
|
524 |
da005e87
|
Patric Plitzner
|
|
525 |
3be6ef3e
|
n.hoffmann
|
/**
|
526 |
|
|
* <p>getFeatureNodeContainerText</p>
|
527 |
|
|
*
|
528 |
|
|
* @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
|
529 |
|
|
* @return a {@link java.lang.String} object.
|
530 |
|
|
*/
|
531 |
cfcb0ce6
|
n.hoffmann
|
public static String getFeatureNodeContainerText(FeatureNodeContainer element) {
|
532 |
69d856ba
|
Katja Luther
|
String result = null;
|
533 |
35861667
|
n.hoffmann
|
if(element.getFeatureNode() != null && element.getFeatureNode().getFeature() != null){
|
534 |
69d856ba
|
Katja Luther
|
result = element.getFeatureNode().getFeature().getLabel(CdmStore.getDefaultLanguage());
|
535 |
|
|
} else{
|
536 |
|
|
return "No label set";
|
537 |
35861667
|
n.hoffmann
|
}
|
538 |
69d856ba
|
Katja Luther
|
if (result == null){
|
539 |
|
|
result = element.getFeatureNode().getFeature().getLabel();
|
540 |
|
|
}
|
541 |
|
|
return result;
|
542 |
cfcb0ce6
|
n.hoffmann
|
}
|
543 |
|
|
|
544 |
3be6ef3e
|
n.hoffmann
|
/**
|
545 |
|
|
* <p>getQuantitativeDataText</p>
|
546 |
|
|
*
|
547 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
|
548 |
|
|
* @return a {@link java.lang.String} object.
|
549 |
|
|
*/
|
550 |
cfcb0ce6
|
n.hoffmann
|
public static String getQuantitativeDataText(QuantitativeData element) {
|
551 |
|
|
TextData textData = quantitativeDescriptionBuilder.build(element, getLanguageList());
|
552 |
da005e87
|
Patric Plitzner
|
|
553 |
cfcb0ce6
|
n.hoffmann
|
return textData.getText(CdmStore.getDefaultLanguage());
|
554 |
|
|
}
|
555 |
|
|
|
556 |
3be6ef3e
|
n.hoffmann
|
/**
|
557 |
|
|
* <p>getCategoricalDataText</p>
|
558 |
|
|
*
|
559 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
|
560 |
|
|
* @return a {@link java.lang.String} object.
|
561 |
|
|
*/
|
562 |
cfcb0ce6
|
n.hoffmann
|
public static String getCategoricalDataText(CategoricalData element) {
|
563 |
|
|
TextData textData = categoricalDescriptionBuilder.build(element, getLanguageList());
|
564 |
da005e87
|
Patric Plitzner
|
|
565 |
cfcb0ce6
|
n.hoffmann
|
return textData.getText(CdmStore.getDefaultLanguage());
|
566 |
|
|
}
|
567 |
da005e87
|
Patric Plitzner
|
|
568 |
cfcb0ce6
|
n.hoffmann
|
private static List<Language> getLanguageList(){
|
569 |
|
|
return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
570 |
|
|
}
|
571 |
da005e87
|
Patric Plitzner
|
|
572 |
cfcb0ce6
|
n.hoffmann
|
private static DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder();
|
573 |
|
|
private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
|
574 |
da005e87
|
Patric Plitzner
|
|
575 |
cfcb0ce6
|
n.hoffmann
|
|
576 |
|
|
/**
|
577 |
3be6ef3e
|
n.hoffmann
|
* <p>getDistributionText</p>
|
578 |
|
|
*
|
579 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
|
580 |
|
|
* @return a {@link java.lang.String} object.
|
581 |
cfcb0ce6
|
n.hoffmann
|
*/
|
582 |
|
|
public static String getDistributionText(Distribution element) {
|
583 |
da005e87
|
Patric Plitzner
|
|
584 |
cfcb0ce6
|
n.hoffmann
|
String text = "EMPTY";
|
585 |
da005e87
|
Patric Plitzner
|
|
586 |
|
|
Distribution distribution = element;
|
587 |
|
|
|
588 |
cfcb0ce6
|
n.hoffmann
|
NamedArea area = distribution.getArea();
|
589 |
|
|
if(area != null){
|
590 |
da005e87
|
Patric Plitzner
|
|
591 |
35861667
|
n.hoffmann
|
text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage());
|
592 |
da005e87
|
Patric Plitzner
|
|
593 |
|
|
PresenceAbsenceTerm status = distribution.getStatus();
|
594 |
|
|
|
595 |
cfcb0ce6
|
n.hoffmann
|
if (status != null) {
|
596 |
|
|
text += ", " + status.getLabel();
|
597 |
|
|
}else{
|
598 |
|
|
text += ", NO STATUS";
|
599 |
|
|
}
|
600 |
|
|
}
|
601 |
|
|
return text;
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
/**
|
605 |
3be6ef3e
|
n.hoffmann
|
* <p>getImageText</p>
|
606 |
|
|
*
|
607 |
|
|
* @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
|
608 |
|
|
* @return a {@link java.lang.String} object.
|
609 |
cfcb0ce6
|
n.hoffmann
|
*/
|
610 |
|
|
public static String getImageText(Media media) {
|
611 |
|
|
LanguageString title = media.getTitle(CdmStore.getDefaultLanguage());
|
612 |
|
|
if (title != null) {
|
613 |
|
|
return title.getText();
|
614 |
|
|
}
|
615 |
|
|
return "No title.";
|
616 |
|
|
}
|
617 |
|
|
|
618 |
da005e87
|
Patric Plitzner
|
|
619 |
|
|
|
620 |
cfcb0ce6
|
n.hoffmann
|
/**
|
621 |
3be6ef3e
|
n.hoffmann
|
* <p>getElementText</p>
|
622 |
|
|
*
|
623 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
|
624 |
|
|
* @return a {@link java.lang.String} object.
|
625 |
cfcb0ce6
|
n.hoffmann
|
*/
|
626 |
da005e87
|
Patric Plitzner
|
public static String getElementText(TextData element) {
|
627 |
cfcb0ce6
|
n.hoffmann
|
String text = null;
|
628 |
|
|
if(element.getFeature().equals(Feature.CITATION())){
|
629 |
|
|
text = "";
|
630 |
|
|
for(DescriptionElementSource source : element.getSources()){
|
631 |
c35245ae
|
n.hoffmann
|
if(source.getCitation() != null){
|
632 |
|
|
text += source.getCitation().getTitleCache();
|
633 |
|
|
}
|
634 |
|
|
if(source.getNameUsedInSource() != null){
|
635 |
|
|
text += " [ " + source.getNameUsedInSource().getTitleCache() + " ]";
|
636 |
|
|
}
|
637 |
cfcb0ce6
|
n.hoffmann
|
}
|
638 |
a147c1df
|
Andreas Müller
|
if(isBlank(text)){
|
639 |
35861667
|
n.hoffmann
|
text = "No sources provided";
|
640 |
|
|
}
|
641 |
cfcb0ce6
|
n.hoffmann
|
}else{
|
642 |
ce22246a
|
n.hoffmann
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
643 |
|
|
LanguageString languageString = element.getPreferredLanguageString(languages);
|
644 |
|
|
text = languageString != null ? languageString.getText() : null;
|
645 |
cfcb0ce6
|
n.hoffmann
|
}
|
646 |
a147c1df
|
Andreas Müller
|
return isBlank(text) ? "No text provided" : text;
|
647 |
cfcb0ce6
|
n.hoffmann
|
}
|
648 |
da005e87
|
Patric Plitzner
|
|
649 |
cfcb0ce6
|
n.hoffmann
|
/**
|
650 |
3be6ef3e
|
n.hoffmann
|
* <p>getTaxonInteractionText</p>
|
651 |
|
|
*
|
652 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
|
653 |
|
|
* @return a {@link java.lang.String} object.
|
654 |
cfcb0ce6
|
n.hoffmann
|
*/
|
655 |
|
|
public static String getTaxonInteractionText(TaxonInteraction element) {
|
656 |
|
|
String text = "";
|
657 |
da005e87
|
Patric Plitzner
|
Taxon taxon2 = element.getTaxon2();
|
658 |
cfcb0ce6
|
n.hoffmann
|
if(taxon2 != null && taxon2.getName() != null){
|
659 |
|
|
text = taxon2.getName().getTitleCache();
|
660 |
|
|
}else{
|
661 |
|
|
text = "No taxon chosen";
|
662 |
|
|
}
|
663 |
da005e87
|
Patric Plitzner
|
|
664 |
cfcb0ce6
|
n.hoffmann
|
return text;
|
665 |
|
|
}
|
666 |
|
|
|
667 |
|
|
/**
|
668 |
3be6ef3e
|
n.hoffmann
|
* <p>getCommonNameText</p>
|
669 |
|
|
*
|
670 |
|
|
* @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
|
671 |
|
|
* @return a {@link java.lang.String} object.
|
672 |
cfcb0ce6
|
n.hoffmann
|
*/
|
673 |
|
|
public static String getCommonNameText(CommonTaxonName commonName) {
|
674 |
|
|
String name = commonName.getName();
|
675 |
|
|
if (name == null || name.length() == 0) {
|
676 |
|
|
name = "No name provided";
|
677 |
|
|
}
|
678 |
|
|
Language language = commonName.getLanguage();
|
679 |
|
|
if (language == null) {
|
680 |
|
|
name += " (No language provided)";
|
681 |
|
|
} else {
|
682 |
|
|
name += " (" + language.getDescription() + ")";
|
683 |
|
|
}
|
684 |
|
|
return name;
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
/**
|
688 |
3be6ef3e
|
n.hoffmann
|
* <p>getDescriptionText</p>
|
689 |
|
|
*
|
690 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
|
691 |
|
|
* @return a {@link java.lang.String} object.
|
692 |
cfcb0ce6
|
n.hoffmann
|
*/
|
693 |
|
|
public static String getDescriptionText(DescriptionBase element) {
|
694 |
|
|
String text = element.getTitleCache();
|
695 |
|
|
if (text == null || text.length() == 0) {
|
696 |
|
|
text = "No label provided";
|
697 |
|
|
}
|
698 |
da005e87
|
Patric Plitzner
|
|
699 |
99e44b3d
|
Patrick Plitzner
|
return text;
|
700 |
cfcb0ce6
|
n.hoffmann
|
}
|
701 |
da005e87
|
Patric Plitzner
|
|
702 |
cfcb0ce6
|
n.hoffmann
|
/**
|
703 |
3be6ef3e
|
n.hoffmann
|
* <p>getIndividualsAssociationText</p>
|
704 |
|
|
*
|
705 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
|
706 |
|
|
* @return a {@link java.lang.String} object.
|
707 |
cfcb0ce6
|
n.hoffmann
|
*/
|
708 |
|
|
public static String getIndividualsAssociationText(IndividualsAssociation element) {
|
709 |
|
|
SpecimenOrObservationBase derivedUnit = element.getAssociatedSpecimenOrObservation();
|
710 |
|
|
if(derivedUnit != null){
|
711 |
|
|
return derivedUnit.getTitleCache();
|
712 |
|
|
}
|
713 |
d08c79ee
|
Patrick Plitzner
|
return "No unit chosen";
|
714 |
cfcb0ce6
|
n.hoffmann
|
}
|
715 |
|
|
|
716 |
3be6ef3e
|
n.hoffmann
|
/**
|
717 |
|
|
* <p>getLabel</p>
|
718 |
|
|
*
|
719 |
|
|
* @param element a {@link java.lang.Object} object.
|
720 |
|
|
* @return a {@link java.lang.String} object.
|
721 |
|
|
*/
|
722 |
cfcb0ce6
|
n.hoffmann
|
public static String getLabel(Object element){
|
723 |
f32fb062
|
Patric Plitzner
|
String noLabelString = "[no label]";
|
724 |
cfcb0ce6
|
n.hoffmann
|
if (element instanceof FeatureNodeContainer){
|
725 |
|
|
return getFeatureNodeContainerText((FeatureNodeContainer) element);
|
726 |
|
|
}
|
727 |
|
|
else if (element instanceof DescriptionBase) {
|
728 |
|
|
return getDescriptionText((DescriptionBase) element);
|
729 |
|
|
}
|
730 |
|
|
else if(element instanceof CategoricalData){
|
731 |
f32fb062
|
Patric Plitzner
|
String categoricalDataText = getCategoricalDataText((CategoricalData) element);
|
732 |
4a5c5357
|
Patric Plitzner
|
if(categoricalDataText==null || categoricalDataText.isEmpty()){
|
733 |
f32fb062
|
Patric Plitzner
|
categoricalDataText = noLabelString;
|
734 |
|
|
}
|
735 |
|
|
return categoricalDataText;
|
736 |
cfcb0ce6
|
n.hoffmann
|
}
|
737 |
|
|
else if (element instanceof CommonTaxonName) {
|
738 |
da005e87
|
Patric Plitzner
|
return getCommonNameText((CommonTaxonName) element);
|
739 |
cfcb0ce6
|
n.hoffmann
|
}
|
740 |
|
|
else if (element instanceof Distribution) {
|
741 |
da005e87
|
Patric Plitzner
|
return getDistributionText((Distribution) element);
|
742 |
|
|
}
|
743 |
cfcb0ce6
|
n.hoffmann
|
else if (element instanceof IndividualsAssociation) {
|
744 |
|
|
return getIndividualsAssociationText((IndividualsAssociation) element);
|
745 |
|
|
}
|
746 |
|
|
else if (element instanceof QuantitativeData) {
|
747 |
f32fb062
|
Patric Plitzner
|
String quantitativeDataText = getQuantitativeDataText((QuantitativeData) element);
|
748 |
4a5c5357
|
Patric Plitzner
|
if(quantitativeDataText==null || quantitativeDataText.isEmpty()){
|
749 |
f32fb062
|
Patric Plitzner
|
quantitativeDataText = noLabelString;
|
750 |
|
|
}
|
751 |
|
|
return quantitativeDataText;
|
752 |
cfcb0ce6
|
n.hoffmann
|
}
|
753 |
|
|
else if (element instanceof TaxonInteraction) {
|
754 |
|
|
return getTaxonInteractionText((TaxonInteraction) element);
|
755 |
|
|
}
|
756 |
|
|
else if (element instanceof TextData) {
|
757 |
|
|
return getElementText((TextData) element);
|
758 |
|
|
}
|
759 |
|
|
else{
|
760 |
|
|
return element.toString();
|
761 |
|
|
}
|
762 |
|
|
}
|
763 |
a147c1df
|
Andreas Müller
|
|
764 |
|
|
private static boolean isNotBlank(String str){
|
765 |
|
|
return StringUtils.isNotBlank(str);
|
766 |
|
|
}
|
767 |
|
|
|
768 |
|
|
private static boolean isBlank(String str){
|
769 |
|
|
return StringUtils.isBlank(str);
|
770 |
|
|
}
|
771 |
2d9a13f7
|
n.hoffmann
|
}
|