Revision 262c0177
Added by Andreas Müller almost 2 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/compare/name/NullTypeDesignationStatus.java | ||
---|---|---|
13 | 13 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
14 | 14 |
|
15 | 15 |
/** |
16 |
* NOTE: This class was moved here from TypeDesignationWorkingSet to allow to be used
|
|
16 |
* NOTE: This class was moved here from TypeDesignationSet to allow to be used |
|
17 | 17 |
* in model compare classes. |
18 | 18 |
* |
19 | 19 |
* @author a.kohlbecker |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/value/MapJSONValueProcessor.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 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.remote.json.processor.value; |
|
10 |
|
|
11 |
import java.util.Map; |
|
12 |
import java.util.Objects; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n; |
|
15 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet; |
|
16 |
import eu.etaxonomy.cdm.model.common.LanguageString; |
|
17 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
18 |
import eu.etaxonomy.cdm.ref.TypedEntityReference; |
|
19 |
import net.sf.json.JSONObject; |
|
20 |
import net.sf.json.JsonConfig; |
|
21 |
import net.sf.json.processors.JsonValueProcessor; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author a.kohlbecker |
|
25 |
* @since 23.06.2010 |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class MapJSONValueProcessor implements JsonValueProcessor { |
|
29 |
|
|
30 |
|
|
31 |
@Override |
|
32 |
public Object processArrayValue(Object value, JsonConfig jsonConfig) { |
|
33 |
|
|
34 |
if(value instanceof TypeDesignationWorkingSet){ |
|
35 |
TypeDesignationWorkingSet map = (TypeDesignationWorkingSet)value; |
|
36 |
JSONObject json = new JSONObject(); |
|
37 |
for(TypeDesignationStatusBase<?> key : map.keySet()){ |
|
38 |
TermRepresentation_L10n term_L10n = new TermRepresentation_L10n(key, false); |
|
39 |
String label = Objects.toString(term_L10n.getLabel(), "NULL"); |
|
40 |
json.element(label, map.get(key), jsonConfig); |
|
41 |
} |
|
42 |
return json; |
|
43 |
} else if(value instanceof Map){ |
|
44 |
Map<?,?> map= (Map<?,?>)value; |
|
45 |
if( ! map.isEmpty()){ |
|
46 |
JSONObject json = new JSONObject(); |
|
47 |
if(map.keySet().iterator().next() instanceof TypedEntityReference){ |
|
48 |
for(Object key : map.keySet()){ |
|
49 |
json.element(key.toString(), map.get(key), jsonConfig); |
|
50 |
} |
|
51 |
} else { |
|
52 |
for (Object val : map.values()){ |
|
53 |
if(val instanceof LanguageString){ |
|
54 |
json.element(((LanguageString)val).getLanguageLabel(), val, jsonConfig); |
|
55 |
} else { |
|
56 |
return JSONObject.fromObject(value, jsonConfig); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
return json; |
|
61 |
} |
|
62 |
} |
|
63 |
return JSONObject.fromObject(value, jsonConfig); |
|
64 |
} |
|
65 |
|
|
66 |
/* (non-Javadoc) |
|
67 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public Object processObjectValue(String key, Object value, |
|
71 |
JsonConfig jsonConfig) { |
|
72 |
return processArrayValue(value, jsonConfig); |
|
73 |
} |
|
74 |
|
|
75 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2009 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.remote.json.processor.value; |
|
10 |
|
|
11 |
import java.util.Map; |
|
12 |
import java.util.Objects; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n; |
|
15 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet; |
|
16 |
import eu.etaxonomy.cdm.model.common.LanguageString; |
|
17 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
18 |
import eu.etaxonomy.cdm.ref.TypedEntityReference; |
|
19 |
import net.sf.json.JSONObject; |
|
20 |
import net.sf.json.JsonConfig; |
|
21 |
import net.sf.json.processors.JsonValueProcessor; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author a.kohlbecker |
|
25 |
* @since 23.06.2010 |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class MapJSONValueProcessor implements JsonValueProcessor { |
|
29 |
|
|
30 |
|
|
31 |
@Override |
|
32 |
public Object processArrayValue(Object value, JsonConfig jsonConfig) { |
|
33 |
|
|
34 |
if(value instanceof TypeDesignationSet){ |
|
35 |
TypeDesignationSet map = (TypeDesignationSet)value; |
|
36 |
JSONObject json = new JSONObject(); |
|
37 |
for(TypeDesignationStatusBase<?> key : map.keySet()){ |
|
38 |
TermRepresentation_L10n term_L10n = new TermRepresentation_L10n(key, false); |
|
39 |
String label = Objects.toString(term_L10n.getLabel(), "NULL"); |
|
40 |
json.element(label, map.get(key), jsonConfig); |
|
41 |
} |
|
42 |
return json; |
|
43 |
} else if(value instanceof Map){ |
|
44 |
Map<?,?> map= (Map<?,?>)value; |
|
45 |
if( ! map.isEmpty()){ |
|
46 |
JSONObject json = new JSONObject(); |
|
47 |
if(map.keySet().iterator().next() instanceof TypedEntityReference){ |
|
48 |
for(Object key : map.keySet()){ |
|
49 |
json.element(key.toString(), map.get(key), jsonConfig); |
|
50 |
} |
|
51 |
} else { |
|
52 |
for (Object val : map.values()){ |
|
53 |
if(val instanceof LanguageString){ |
|
54 |
json.element(((LanguageString)val).getLanguageLabel(), val, jsonConfig); |
|
55 |
} else { |
|
56 |
return JSONObject.fromObject(value, jsonConfig); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
return json; |
|
61 |
} |
|
62 |
} |
|
63 |
return JSONObject.fromObject(value, jsonConfig); |
|
64 |
} |
|
65 |
|
|
66 |
/* (non-Javadoc) |
|
67 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public Object processObjectValue(String key, Object value, |
|
71 |
JsonConfig jsonConfig) { |
|
72 |
return processArrayValue(value, jsonConfig); |
|
73 |
} |
|
74 |
|
|
75 |
} |
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml | ||
---|---|---|
238 | 238 |
<entry key="java.util.LinkedHashMap"> |
239 | 239 |
<bean class="eu.etaxonomy.cdm.remote.json.processor.value.MapJSONValueProcessor" /> |
240 | 240 |
</entry> |
241 |
<entry key="eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet">
|
|
241 |
<entry key="eu.etaxonomy.cdm.api.service.name.TypeDesignationSet"> |
|
242 | 242 |
<bean class="eu.etaxonomy.cdm.remote.json.processor.value.MapJSONValueProcessor" /> |
243 | 243 |
</entry> |
244 | 244 |
<entry key="eu.etaxonomy.cdm.common.URI"> |
... | ... | |
535 | 535 |
<entry key="java.util.LinkedHashMap"> |
536 | 536 |
<bean class="eu.etaxonomy.cdm.remote.json.processor.value.MapJSONValueProcessor" /> |
537 | 537 |
</entry> |
538 |
<entry key="eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet">
|
|
538 |
<entry key="eu.etaxonomy.cdm.api.service.name.TypeDesignationSet"> |
|
539 | 539 |
<bean class="eu.etaxonomy.cdm.remote.json.processor.value.MapJSONValueProcessor" /> |
540 | 540 |
</entry> |
541 | 541 |
<entry key="eu.etaxonomy.cdm.common.URI"> |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/RegistrationDTO.java | ||
---|---|---|
26 | 26 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationDTO; |
27 | 27 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetFormatter; |
28 | 28 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager; |
29 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet;
|
|
29 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet; |
|
30 | 30 |
import eu.etaxonomy.cdm.format.reference.NomenclaturalSourceFormatter; |
31 | 31 |
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod; |
32 | 32 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
... | ... | |
258 | 258 |
return name; |
259 | 259 |
} |
260 | 260 |
|
261 |
public Map<VersionableEntity,TypeDesignationWorkingSet> getOrderedTypeDesignationWorkingSets() {
|
|
262 |
return typeDesignationManager != null ? typeDesignationManager.getOrderedTypeDesignationWorkingSets() : null;
|
|
261 |
public Map<VersionableEntity,TypeDesignationSet> getOrderedTypeDesignationSets() {
|
|
262 |
return typeDesignationManager != null ? typeDesignationManager.getOrderedTypeDesignationSets() : null; |
|
263 | 263 |
} |
264 | 264 |
|
265 |
public TypeDesignationWorkingSet getTypeDesignationWorkingSet(VersionableEntity baseEntity) {
|
|
266 |
return typeDesignationManager != null ? typeDesignationManager.getOrderedTypeDesignationWorkingSets().get(baseEntity) : null;
|
|
265 |
public TypeDesignationSet getTypeDesignationSet(VersionableEntity baseEntity) {
|
|
266 |
return typeDesignationManager != null ? typeDesignationManager.getOrderedTypeDesignationSets().get(baseEntity) : null; |
|
267 | 267 |
} |
268 | 268 |
|
269 | 269 |
public Set<TypeDesignationBase> getTypeDesignationsInWorkingSet(VersionableEntity baseEntity) { |
270 | 270 |
Set<TypeDesignationBase> typeDesignations = new HashSet<>(); |
271 |
TypeDesignationWorkingSet workingSet = getTypeDesignationWorkingSet(baseEntity);
|
|
271 |
TypeDesignationSet workingSet = getTypeDesignationSet(baseEntity);
|
|
272 | 272 |
for(TypeDesignationDTO<?> ref : workingSet.getTypeDesignations()){ |
273 | 273 |
typeDesignations.add(findTypeDesignation(ref)); |
274 | 274 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSet.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2020 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.api.service.name; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.Comparator; |
|
14 |
import java.util.LinkedHashMap; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Set; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.compare.name.NullTypeDesignationStatus; |
|
19 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|
20 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
21 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
22 |
|
|
23 |
/** |
|
24 |
* TypeDesignations which refer to the same base entity (e.g. FieldUnit for SpecimenTypeDesignations |
|
25 |
* or TaxonName/NameTypeDesignation for NameTypeDesignation form a type designation set. |
|
26 |
* The <code>TypeDesignationSet</code> internally stores the entity base |
|
27 |
* and an ordered map that maps type status (TypeDesignationStatusBase) to the type designations |
|
28 |
* in the <code>TypeDesignationSet</code>. |
|
29 |
* |
|
30 |
* The TypeDesignationStatusBase keys can be ordered by the term order defined in the vocabulary. |
|
31 |
* |
|
32 |
* A typeDesignationSet can be referenced by the <code>baseEntity</code>. |
|
33 |
* |
|
34 |
* @author a.kohlbecker |
|
35 |
* @author a.mueller |
|
36 |
* @since Mar 10, 2017 |
|
37 |
*/ |
|
38 |
public class TypeDesignationSet { |
|
39 |
|
|
40 |
public static final NullTypeDesignationStatus NULL_STATUS = NullTypeDesignationStatus.SINGLETON(); |
|
41 |
|
|
42 |
private String label = null; |
|
43 |
|
|
44 |
private VersionableEntity baseEntity; |
|
45 |
|
|
46 |
private LinkedHashMap<TypeDesignationStatusBase<?>,Collection<TypeDesignationDTO>> designationByStatusMap = new LinkedHashMap<>(); |
|
47 |
|
|
48 |
public enum TypeDesignationSetType { |
|
49 |
SPECIMEN_TYPE_DESIGNATION_SET, |
|
50 |
NAME_TYPE_DESIGNATION_SET; |
|
51 |
boolean isSpecimenType(){return this == SPECIMEN_TYPE_DESIGNATION_SET;} |
|
52 |
boolean isNameType(){return this == NAME_TYPE_DESIGNATION_SET;} |
|
53 |
} |
|
54 |
|
|
55 |
// ********************************* CONSTRUCTOR **************************/ |
|
56 |
|
|
57 |
public TypeDesignationSet(VersionableEntity baseEntity) { |
|
58 |
this.baseEntity = baseEntity; |
|
59 |
} |
|
60 |
|
|
61 |
// ***********************************************************************/ |
|
62 |
|
|
63 |
public VersionableEntity getBaseEntity() { |
|
64 |
return baseEntity; |
|
65 |
} |
|
66 |
|
|
67 |
public List<TypeDesignationDTO> getTypeDesignations() { |
|
68 |
List<TypeDesignationDTO> typeDesignations = new ArrayList<>(); |
|
69 |
designationByStatusMap.values().forEach(typeDesignationDtos -> typeDesignationDtos.forEach(td -> typeDesignations.add(td))); |
|
70 |
return typeDesignations; |
|
71 |
} |
|
72 |
|
|
73 |
public Set<TypeDesignationStatusBase<?>> keySet() { |
|
74 |
return designationByStatusMap.keySet(); |
|
75 |
} |
|
76 |
|
|
77 |
public Collection<TypeDesignationDTO> get(TypeDesignationStatusBase<?> typeStatus) { |
|
78 |
return designationByStatusMap.get(typeStatus); |
|
79 |
} |
|
80 |
|
|
81 |
public void insert(TypeDesignationStatusBase<?> status, |
|
82 |
TypeDesignationDTO<?> typeDesignationDto) { |
|
83 |
|
|
84 |
if(status == null){ |
|
85 |
status = NULL_STATUS; |
|
86 |
} |
|
87 |
if(!designationByStatusMap.containsKey(status)){ |
|
88 |
designationByStatusMap.put(status, new ArrayList<>()); |
|
89 |
} |
|
90 |
designationByStatusMap.get(status).add(typeDesignationDto); |
|
91 |
} |
|
92 |
|
|
93 |
public Collection<TypeDesignationDTO> put(TypeDesignationStatusBase<?> status, |
|
94 |
Collection<TypeDesignationDTO> typeDesignationDtos) { |
|
95 |
if(status == null){ |
|
96 |
status = NULL_STATUS; |
|
97 |
} |
|
98 |
return designationByStatusMap.put(status, typeDesignationDtos); |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
public String getLabel() { |
|
103 |
return label; |
|
104 |
} |
|
105 |
public void setRepresentation(String representation){ |
|
106 |
this.label = representation; |
|
107 |
} |
|
108 |
|
|
109 |
//TODO if not needed anymore |
|
110 |
// /** |
|
111 |
// * A reference to the entity which is the common base entity for all TypeDesignations in this workingset. |
|
112 |
// * For a {@link SpecimenTypeDesignation} this is usually the {@link FieldUnit} if it is present. Otherwise it can also be |
|
113 |
// * a {@link DerivedUnit} or something else depending on the specific use case. |
|
114 |
// * |
|
115 |
// * @return the baseEntityReference |
|
116 |
// */ |
|
117 |
// public TypedEntityReference<? extends VersionableEntity> getBaseEntityReference() { |
|
118 |
// return baseEntityReference; |
|
119 |
// } |
|
120 |
|
|
121 |
public boolean isSpecimenWorkingSet() { |
|
122 |
return getWorkingsetType().isSpecimenType(); |
|
123 |
} |
|
124 |
public boolean isNameWorkingSet() { |
|
125 |
return getWorkingsetType().isNameType(); |
|
126 |
} |
|
127 |
|
|
128 |
private boolean isSpecimenTypeDesigationWorkingSet() { |
|
129 |
return SpecimenOrObservationBase.class.isAssignableFrom(baseEntity.getClass()); |
|
130 |
} |
|
131 |
|
|
132 |
public TypeDesignationSetType getWorkingsetType() { |
|
133 |
return isSpecimenTypeDesigationWorkingSet() ? TypeDesignationSetType.SPECIMEN_TYPE_DESIGNATION_SET : TypeDesignationSetType.NAME_TYPE_DESIGNATION_SET; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Uses the <code>comparator</code> to find the highest {@link TypeDesignationStatusBase} term and returns that. |
|
138 |
*/ |
|
139 |
public TypeDesignationStatusBase<?> highestTypeStatus(Comparator<TypeDesignationStatusBase<?>> comparator) { |
|
140 |
TypeDesignationStatusBase<?> highestTypeStatus = null; |
|
141 |
for(TypeDesignationStatusBase<?> status : designationByStatusMap.keySet()) { |
|
142 |
if(comparator.compare(status, highestTypeStatus) < 0){ |
|
143 |
highestTypeStatus = status; |
|
144 |
} |
|
145 |
} |
|
146 |
return highestTypeStatus; |
|
147 |
} |
|
148 |
|
|
149 |
// **************************** toString() ************************************ |
|
150 |
|
|
151 |
@Override |
|
152 |
public String toString(){ |
|
153 |
if(label != null){ |
|
154 |
return label; |
|
155 |
} else { |
|
156 |
return super.toString(); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetFormatter.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
import org.apache.commons.lang3.StringUtils; |
18 | 18 |
|
19 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType;
|
|
19 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet.TypeDesignationSetType;
|
|
20 | 20 |
import eu.etaxonomy.cdm.common.CdmUtils; |
21 | 21 |
import eu.etaxonomy.cdm.common.UTF8; |
22 | 22 |
import eu.etaxonomy.cdm.format.reference.OriginalSourceFormatter; |
... | ... | |
107 | 107 |
} |
108 | 108 |
|
109 | 109 |
int typeSetCount = 0; |
110 |
Map<VersionableEntity,TypeDesignationWorkingSet> orderedByTypesByBaseEntity
|
|
111 |
= manager.getOrderedTypeDesignationWorkingSets();
|
|
112 |
TypeDesignationWorkingSetType lastWsType = null;
|
|
110 |
Map<VersionableEntity,TypeDesignationSet> orderedByTypesByBaseEntity |
|
111 |
= manager.getOrderedTypeDesignationSets(); |
|
112 |
TypeDesignationSetType lastWsType = null; |
|
113 | 113 |
if (orderedByTypesByBaseEntity != null){ |
114 | 114 |
for(VersionableEntity baseEntity : orderedByTypesByBaseEntity.keySet()) { |
115 | 115 |
buildTaggedTextForSingleTypeSet(manager, withBrackets, finalBuilder, |
... | ... | |
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
private void buildTaggedTextForSingleTypeSet(TypeDesignationSetManager manager, boolean withBrackets, |
125 |
TaggedTextBuilder finalBuilder, int typeSetCount, VersionableEntity baseEntity, TypeDesignationWorkingSetType lastWsType) {
|
|
125 |
TaggedTextBuilder finalBuilder, int typeSetCount, VersionableEntity baseEntity, TypeDesignationSetType lastWsType) { |
|
126 | 126 |
|
127 |
Map<VersionableEntity,TypeDesignationWorkingSet>
|
|
128 |
orderedByTypesByBaseEntity = manager.getOrderedTypeDesignationWorkingSets();
|
|
129 |
TypeDesignationWorkingSet typeDesignationWorkingSet = orderedByTypesByBaseEntity.get(baseEntity);
|
|
127 |
Map<VersionableEntity,TypeDesignationSet> |
|
128 |
orderedByTypesByBaseEntity = manager.getOrderedTypeDesignationSets(); |
|
129 |
TypeDesignationSet typeDesignationSet = orderedByTypesByBaseEntity.get(baseEntity);
|
|
130 | 130 |
|
131 | 131 |
TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder(); |
132 | 132 |
if(typeSetCount > 0){ |
... | ... | |
136 | 136 |
//name types separately, but this is such a rare case (if at all) and |
137 | 137 |
//increases complexity so it is not yet implemented |
138 | 138 |
boolean isPlural = hasMultipleTypes(orderedByTypesByBaseEntity); |
139 |
if(typeDesignationWorkingSet.getWorkingsetType().isSpecimenType()){
|
|
139 |
if(typeDesignationSet.getWorkingsetType().isSpecimenType()){ |
|
140 | 140 |
workingsetBuilder.add(TagEnum.label, (isPlural? "Types:": "Type:")); |
141 |
} else if (typeDesignationWorkingSet.getWorkingsetType().isNameType()){
|
|
141 |
} else if (typeDesignationSet.getWorkingsetType().isNameType()){ |
|
142 | 142 |
workingsetBuilder.add(TagEnum.label, (isPlural? "Nametypes:": "Nametype:")); |
143 | 143 |
} else { |
144 | 144 |
//do nothing for now |
145 | 145 |
} |
146 | 146 |
} |
147 | 147 |
|
148 |
boolean hasExplicitBaseEntity = hasExplicitBaseEntity(baseEntity, typeDesignationWorkingSet);
|
|
148 |
boolean hasExplicitBaseEntity = hasExplicitBaseEntity(baseEntity, typeDesignationSet); |
|
149 | 149 |
if(hasExplicitBaseEntity && !entityLabel(baseEntity).isEmpty()){ |
150 | 150 |
workingsetBuilder.add(TagEnum.specimenOrObservation, entityLabel(baseEntity), baseEntity); |
151 | 151 |
} |
... | ... | |
153 | 153 |
if (withBrackets && hasExplicitBaseEntity){ |
154 | 154 |
workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_LEFT); |
155 | 155 |
} |
156 |
for(TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
|
|
156 |
for(TypeDesignationStatusBase<?> typeStatus : typeDesignationSet.keySet()) { |
|
157 | 157 |
typeStatusCount = buildTaggedTextForSingleTypeStatus(manager, workingsetBuilder, |
158 |
typeDesignationWorkingSet, typeStatusCount, typeStatus,
|
|
158 |
typeDesignationSet, typeStatusCount, typeStatus, |
|
159 | 159 |
lastWsType, typeSetCount); |
160 | 160 |
} |
161 | 161 |
if (withBrackets && hasExplicitBaseEntity){ |
162 | 162 |
workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_RIGHT); |
163 | 163 |
} |
164 |
typeDesignationWorkingSet.setRepresentation(workingsetBuilder.toString());
|
|
164 |
typeDesignationSet.setRepresentation(workingsetBuilder.toString()); |
|
165 | 165 |
finalBuilder.addAll(workingsetBuilder); |
166 | 166 |
return; |
167 | 167 |
} |
... | ... | |
170 | 170 |
* Checks if the baseType is the same as the (only?) type in the type designation workingset. |
171 | 171 |
*/ |
172 | 172 |
private boolean hasExplicitBaseEntity(VersionableEntity baseEntity, |
173 |
TypeDesignationWorkingSet typeDesignationWorkingSet) {
|
|
174 |
if (!typeDesignationWorkingSet.isSpecimenWorkingSet()){
|
|
173 |
TypeDesignationSet typeDesignationSet) {
|
|
174 |
if (!typeDesignationSet.isSpecimenWorkingSet()){ |
|
175 | 175 |
return false; //name type designations are not handled here |
176 | 176 |
}else{ |
177 | 177 |
UUID baseUuid = baseEntity.getUuid(); |
178 |
for (TypeDesignationDTO<?> dto: typeDesignationWorkingSet.getTypeDesignations()){
|
|
178 |
for (TypeDesignationDTO<?> dto: typeDesignationSet.getTypeDesignations()){ |
|
179 | 179 |
if (!baseUuid.equals(dto.getTypeUuid())){ |
180 | 180 |
return true; |
181 | 181 |
} |
... | ... | |
185 | 185 |
} |
186 | 186 |
|
187 | 187 |
private int buildTaggedTextForSingleTypeStatus(TypeDesignationSetManager manager, |
188 |
TaggedTextBuilder workingsetBuilder, TypeDesignationWorkingSet typeDesignationWorkingSet,
|
|
188 |
TaggedTextBuilder workingsetBuilder, TypeDesignationSet typeDesignationSet,
|
|
189 | 189 |
int typeStatusCount, TypeDesignationStatusBase<?> typeStatus, |
190 |
TypeDesignationWorkingSetType lastWsType, int typeSetCount) {
|
|
190 |
TypeDesignationSetType lastWsType, int typeSetCount) { |
|
191 | 191 |
|
192 | 192 |
//starting separator |
193 | 193 |
if(typeStatusCount++ > 0){ |
194 | 194 |
workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_SEPARATOR); |
195 | 195 |
} |
196 | 196 |
|
197 |
boolean isPlural = typeDesignationWorkingSet.get(typeStatus).size() > 1;
|
|
197 |
boolean isPlural = typeDesignationSet.get(typeStatus).size() > 1; |
|
198 | 198 |
String label = null; |
199 |
if(typeStatus != TypeDesignationWorkingSet.NULL_STATUS){
|
|
199 |
if(typeStatus != TypeDesignationSet.NULL_STATUS){ |
|
200 | 200 |
label = typeStatus.getLabel(); |
201 |
}else if (typeDesignationWorkingSet.getWorkingsetType() != lastWsType
|
|
201 |
}else if (typeDesignationSet.getWorkingsetType() != lastWsType |
|
202 | 202 |
&& (workingsetBuilder.size() > 0 && typeSetCount > 0)){ |
203 | 203 |
//only for the first name type (coming after a specimen type add the label (extremely rare case, if at all existing) |
204 |
if (typeDesignationWorkingSet.getWorkingsetType().isNameType()) {
|
|
204 |
if (typeDesignationSet.getWorkingsetType().isNameType()) { |
|
205 | 205 |
label = "nametype"; |
206 |
}else if (typeDesignationWorkingSet.getWorkingsetType().isSpecimenType()) {
|
|
206 |
}else if (typeDesignationSet.getWorkingsetType().isSpecimenType()) { |
|
207 | 207 |
label = "type"; |
208 | 208 |
} |
209 | 209 |
} |
... | ... | |
218 | 218 |
|
219 | 219 |
//designation + sources |
220 | 220 |
int typeDesignationCount = 0; |
221 |
for(TypeDesignationDTO<?> typeDesignationDTO : createSortedList(typeDesignationWorkingSet, typeStatus)) {
|
|
221 |
for(TypeDesignationDTO<?> typeDesignationDTO : createSortedList(typeDesignationSet, typeStatus)) { |
|
222 | 222 |
TypeDesignationBase<?> typeDes = manager.findTypeDesignation(typeDesignationDTO.getUuid()); |
223 | 223 |
|
224 | 224 |
typeDesignationCount = buildTaggedTextForSingleType(typeDes, withCitation, |
... | ... | |
279 | 279 |
} |
280 | 280 |
|
281 | 281 |
private List<TypeDesignationDTO> createSortedList( |
282 |
TypeDesignationWorkingSet typeDesignationWorkingSet, TypeDesignationStatusBase<?> typeStatus) {
|
|
282 |
TypeDesignationSet typeDesignationSet, TypeDesignationStatusBase<?> typeStatus) {
|
|
283 | 283 |
|
284 |
List<TypeDesignationDTO> typeDesignationDTOs = new ArrayList<>(typeDesignationWorkingSet.get(typeStatus));
|
|
284 |
List<TypeDesignationDTO> typeDesignationDTOs = new ArrayList<>(typeDesignationSet.get(typeStatus)); |
|
285 | 285 |
Collections.sort(typeDesignationDTOs); |
286 | 286 |
return typeDesignationDTOs; |
287 | 287 |
} |
... | ... | |
291 | 291 |
* or if it has a single working set but this workingset has multiple type designations. |
292 | 292 |
*/ |
293 | 293 |
private boolean hasMultipleTypes( |
294 |
Map<VersionableEntity,TypeDesignationWorkingSet> typeWorkingSets) {
|
|
294 |
Map<VersionableEntity,TypeDesignationSet> typeWorkingSets) { |
|
295 | 295 |
if (typeWorkingSets == null || typeWorkingSets.isEmpty()){ |
296 | 296 |
return false; |
297 | 297 |
}else if (typeWorkingSets.keySet().size() > 1) { |
298 | 298 |
return true; |
299 | 299 |
} |
300 |
TypeDesignationWorkingSet singleSet = typeWorkingSets.values().iterator().next();
|
|
300 |
TypeDesignationSet singleSet = typeWorkingSets.values().iterator().next(); |
|
301 | 301 |
return singleSet.getTypeDesignations().size() > 1; |
302 | 302 |
} |
303 | 303 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java | ||
---|---|---|
23 | 23 |
import java.util.UUID; |
24 | 24 |
|
25 | 25 |
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException; |
26 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType;
|
|
26 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet.TypeDesignationSetType;
|
|
27 | 27 |
import eu.etaxonomy.cdm.compare.name.NullTypeDesignationStatus; |
28 | 28 |
import eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator; |
29 | 29 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
... | ... | |
52 | 52 |
* if the former is missing. The type designations per base type are furthermore ordered by the {@link TypeDesignationStatusBase}. |
53 | 53 |
* |
54 | 54 |
* The TypeDesignationSetManager also provides string representations of the whole ordered set of all |
55 |
* {@link TypeDesignationBase TypeDesignations} and of the TypeDesignationWorkingSets:
|
|
55 |
* {@link TypeDesignationBase TypeDesignations} and of the TypeDesignationSets: |
|
56 | 56 |
* <ul> |
57 | 57 |
* <li>{@link #print()} |
58 |
* <li>{@link #getOrderedTypeDesignationWorkingSets()} ... {@link TypeDesignationWorkingSet#getLabel()}
|
|
58 |
* <li>{@link #getOrderedTypeDesignationSets()} ... {@link TypeDesignationSet#getLabel()}
|
|
59 | 59 |
* </ul> |
60 | 60 |
* Prior using the representations you need to trigger their generation by calling {@link #buildString()} |
61 | 61 |
* |
... | ... | |
87 | 87 |
* |
88 | 88 |
* {@inheritDoc} |
89 | 89 |
*/ |
90 |
private Comparator<Entry<VersionableEntity,TypeDesignationWorkingSet>> entryComparator = (o1,o2)->{
|
|
90 |
private Comparator<Entry<VersionableEntity,TypeDesignationSet>> entryComparator = (o1,o2)->{ |
|
91 | 91 |
|
92 |
TypeDesignationWorkingSet ws1 = o1.getValue();
|
|
93 |
TypeDesignationWorkingSet ws2 = o2.getValue();
|
|
92 |
TypeDesignationSet ws1 = o1.getValue(); |
|
93 |
TypeDesignationSet ws2 = o2.getValue(); |
|
94 | 94 |
|
95 | 95 |
if (ws1.getWorkingsetType() != ws2.getWorkingsetType()){ |
96 | 96 |
//first specimen types, then name types (very rare case anyway) |
97 |
return ws1.getWorkingsetType() == TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET? 1:-1;
|
|
97 |
return ws1.getWorkingsetType() == TypeDesignationSetType.NAME_TYPE_DESIGNATION_SET? 1:-1;
|
|
98 | 98 |
} |
99 | 99 |
|
100 | 100 |
boolean hasStatus1 = !ws1.keySet().contains(null) && !ws1.keySet().contains(NullTypeDesignationStatus.SINGLETON()); |
... | ... | |
129 | 129 |
* Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus. |
130 | 130 |
* The TypeDesignationStatusBase keys are already ordered by the term order defined in the vocabulary. |
131 | 131 |
*/ |
132 |
private LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> orderedByTypesByBaseEntity;
|
|
132 |
private LinkedHashMap<VersionableEntity,TypeDesignationSet> orderedByTypesByBaseEntity; |
|
133 | 133 |
|
134 | 134 |
private List<String> problems = new ArrayList<>(); |
135 | 135 |
|
... | ... | |
205 | 205 |
*/ |
206 | 206 |
protected void mapAndSort() { |
207 | 207 |
|
208 |
Map<VersionableEntity,TypeDesignationWorkingSet> byBaseEntityByTypeStatus = new HashMap<>();
|
|
208 |
Map<VersionableEntity,TypeDesignationSet> byBaseEntityByTypeStatus = new HashMap<>(); |
|
209 | 209 |
this.typeDesignations.values().forEach(td -> mapTypeDesignation(byBaseEntityByTypeStatus, td)); |
210 | 210 |
orderedByTypesByBaseEntity = orderByTypeByBaseEntity(byBaseEntityByTypeStatus); |
211 | 211 |
} |
212 | 212 |
|
213 |
private void mapTypeDesignation(Map<VersionableEntity,TypeDesignationWorkingSet> byBaseEntityByTypeStatus,
|
|
213 |
private void mapTypeDesignation(Map<VersionableEntity,TypeDesignationSet> byBaseEntityByTypeStatus, |
|
214 | 214 |
TypeDesignationBase<?> td){ |
215 | 215 |
|
216 | 216 |
td = HibernateProxyHelper.deproxy(td); |
... | ... | |
233 | 233 |
getTypeUuid(td)); |
234 | 234 |
|
235 | 235 |
if(!byBaseEntityByTypeStatus.containsKey(baseEntity)){ |
236 |
byBaseEntityByTypeStatus.put(baseEntity, new TypeDesignationWorkingSet(baseEntity));
|
|
236 |
byBaseEntityByTypeStatus.put(baseEntity, new TypeDesignationSet(baseEntity)); |
|
237 | 237 |
} |
238 | 238 |
byBaseEntityByTypeStatus.get(baseEntity).insert(status, typeDesignationDTO); |
239 | 239 |
|
... | ... | |
296 | 296 |
return baseEntityReference; |
297 | 297 |
} |
298 | 298 |
|
299 |
private LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> orderByTypeByBaseEntity(
|
|
300 |
Map<VersionableEntity,TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
|
|
299 |
private LinkedHashMap<VersionableEntity,TypeDesignationSet> orderByTypeByBaseEntity( |
|
300 |
Map<VersionableEntity,TypeDesignationSet> stringsByTypeByBaseEntity){ |
|
301 | 301 |
|
302 | 302 |
// order the FieldUnit TypeName keys |
303 |
Set<Entry<VersionableEntity,TypeDesignationWorkingSet>> entrySet
|
|
303 |
Set<Entry<VersionableEntity,TypeDesignationSet>> entrySet |
|
304 | 304 |
= stringsByTypeByBaseEntity.entrySet(); |
305 |
LinkedList<Entry<VersionableEntity,TypeDesignationWorkingSet>> baseEntityKeyList
|
|
305 |
LinkedList<Entry<VersionableEntity,TypeDesignationSet>> baseEntityKeyList |
|
306 | 306 |
= new LinkedList<>(entrySet); |
307 | 307 |
Collections.sort(baseEntityKeyList, entryComparator); |
308 | 308 |
|
309 | 309 |
// new LinkedHashMap for the ordered FieldUnitOrTypeName keys |
310 |
LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> stringsOrderedbyBaseEntityOrderdByType
|
|
310 |
LinkedHashMap<VersionableEntity,TypeDesignationSet> stringsOrderedbyBaseEntityOrderdByType |
|
311 | 311 |
= new LinkedHashMap<>(stringsByTypeByBaseEntity.size()); |
312 | 312 |
|
313 |
for(Entry<VersionableEntity,TypeDesignationWorkingSet> entry : baseEntityKeyList){
|
|
313 |
for(Entry<VersionableEntity,TypeDesignationSet> entry : baseEntityKeyList){ |
|
314 | 314 |
VersionableEntity baseEntity = entry.getKey(); |
315 |
TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntity);
|
|
315 |
TypeDesignationSet typeDesignationSet = stringsByTypeByBaseEntity.get(baseEntity);
|
|
316 | 316 |
// order the TypeDesignationStatusBase keys |
317 |
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet());
|
|
317 |
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationSet.keySet()); |
|
318 | 318 |
Collections.sort(keyList, new TypeDesignationStatusComparator()); |
319 | 319 |
// new LinkedHashMap for the ordered TypeDesignationStatusBase keys |
320 |
TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet(
|
|
321 |
typeDesignationWorkingSet.getBaseEntity());
|
|
322 |
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationWorkingSet.get(key)));
|
|
320 |
TypeDesignationSet orderedStringsByOrderedTypes = new TypeDesignationSet(
|
|
321 |
typeDesignationSet.getBaseEntity()); |
|
322 |
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationSet.get(key))); |
|
323 | 323 |
stringsOrderedbyBaseEntityOrderdByType.put(baseEntity, orderedStringsByOrderedTypes); |
324 | 324 |
} |
325 | 325 |
|
... | ... | |
399 | 399 |
return this.typeDesignations.get(uuid); |
400 | 400 |
} |
401 | 401 |
|
402 |
public Map<VersionableEntity,TypeDesignationWorkingSet> getOrderedTypeDesignationWorkingSets() {
|
|
402 |
public Map<VersionableEntity,TypeDesignationSet> getOrderedTypeDesignationSets() {
|
|
403 | 403 |
return orderedByTypesByBaseEntity; |
404 | 404 |
} |
405 | 405 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationWorkingSet.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2020 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.api.service.name; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.Comparator; |
|
14 |
import java.util.LinkedHashMap; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Set; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.compare.name.NullTypeDesignationStatus; |
|
19 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|
20 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
21 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
22 |
|
|
23 |
/** |
|
24 |
* TypeDesignations which refer to the same FieldUnit (SpecimenTypeDesignation) or TaxonName |
|
25 |
* (NameTypeDesignation) form a working set. The <code>TypeDesignationWorkingSet</code> internally |
|
26 |
* works with EnityReferences to the actual TypeDesignations. |
|
27 |
* |
|
28 |
* The EntityReferences for TypeDesignations are grouped by the according TypeDesignationStatus. |
|
29 |
* The TypeDesignationStatusBase keys can be ordered by the term order defined in the vocabulary. |
|
30 |
* |
|
31 |
* A workingset can be referenced by the <code>baseEntityReference</code>. |
|
32 |
* |
|
33 |
* @author a.kohlbecker |
|
34 |
* @since Mar 10, 2017 |
|
35 |
*/ |
|
36 |
public class TypeDesignationWorkingSet { |
|
37 |
|
|
38 |
public static final NullTypeDesignationStatus NULL_STATUS = NullTypeDesignationStatus.SINGLETON(); |
|
39 |
|
|
40 |
private String label = null; |
|
41 |
|
|
42 |
private VersionableEntity baseEntity; |
|
43 |
|
|
44 |
private LinkedHashMap<TypeDesignationStatusBase<?>,Collection<TypeDesignationDTO>> designationByStatusMap = new LinkedHashMap<>(); |
|
45 |
|
|
46 |
|
|
47 |
public enum TypeDesignationWorkingSetType { |
|
48 |
SPECIMEN_TYPE_DESIGNATION_WORKINGSET, |
|
49 |
NAME_TYPE_DESIGNATION_WORKINGSET; |
|
50 |
boolean isSpecimenType(){return this == SPECIMEN_TYPE_DESIGNATION_WORKINGSET;} |
|
51 |
boolean isNameType(){return this == NAME_TYPE_DESIGNATION_WORKINGSET;} |
|
52 |
} |
|
53 |
|
|
54 |
// ********************************* CONSTRUCTOR **************************/ |
|
55 |
|
|
56 |
public TypeDesignationWorkingSet(VersionableEntity baseEntity) { |
|
57 |
this.baseEntity = baseEntity; |
|
58 |
} |
|
59 |
|
|
60 |
// ***********************************************************************/ |
|
61 |
|
|
62 |
public VersionableEntity getBaseEntity() { |
|
63 |
return baseEntity; |
|
64 |
} |
|
65 |
|
|
66 |
public List<TypeDesignationDTO> getTypeDesignations() { |
|
67 |
List<TypeDesignationDTO> typeDesignations = new ArrayList<>(); |
|
68 |
designationByStatusMap.values().forEach(typeDesignationDtos -> typeDesignationDtos.forEach(td -> typeDesignations.add(td))); |
|
69 |
return typeDesignations; |
|
70 |
} |
|
71 |
|
|
72 |
public Set<TypeDesignationStatusBase<?>> keySet() { |
|
73 |
return designationByStatusMap.keySet(); |
|
74 |
} |
|
75 |
|
|
76 |
public Collection<TypeDesignationDTO> get(TypeDesignationStatusBase<?> typeStatus) { |
|
77 |
return designationByStatusMap.get(typeStatus); |
|
78 |
} |
|
79 |
|
|
80 |
public void insert(TypeDesignationStatusBase<?> status, |
|
81 |
TypeDesignationDTO<?> typeDesignationDto) { |
|
82 |
|
|
83 |
if(status == null){ |
|
84 |
status = NULL_STATUS; |
|
85 |
} |
|
86 |
if(!designationByStatusMap.containsKey(status)){ |
|
87 |
designationByStatusMap.put(status, new ArrayList<>()); |
|
88 |
} |
|
89 |
designationByStatusMap.get(status).add(typeDesignationDto); |
|
90 |
} |
|
91 |
|
|
92 |
public Collection<TypeDesignationDTO> put(TypeDesignationStatusBase<?> status, |
|
93 |
Collection<TypeDesignationDTO> typeDesignationDtos) { |
|
94 |
if(status == null){ |
|
95 |
status = NULL_STATUS; |
|
96 |
} |
|
97 |
return designationByStatusMap.put(status, typeDesignationDtos); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
public String getLabel() { |
|
102 |
return label; |
|
103 |
} |
|
104 |
public void setRepresentation(String representation){ |
|
105 |
this.label = representation; |
|
106 |
} |
|
107 |
|
|
108 |
//TODO if not needed anymore |
|
109 |
// /** |
|
110 |
// * A reference to the entity which is the common base entity for all TypeDesignations in this workingset. |
|
111 |
// * For a {@link SpecimenTypeDesignation} this is usually the {@link FieldUnit} if it is present. Otherwise it can also be |
|
112 |
// * a {@link DerivedUnit} or something else depending on the specific use case. |
|
113 |
// * |
|
114 |
// * @return the baseEntityReference |
|
115 |
// */ |
|
116 |
// public TypedEntityReference<? extends VersionableEntity> getBaseEntityReference() { |
|
117 |
// return baseEntityReference; |
|
118 |
// } |
|
119 |
|
|
120 |
public boolean isSpecimenWorkingSet() { |
|
121 |
return getWorkingsetType().isSpecimenType(); |
|
122 |
} |
|
123 |
public boolean isNameWorkingSet() { |
|
124 |
return getWorkingsetType().isNameType(); |
|
125 |
} |
|
126 |
|
|
127 |
private boolean isSpecimenTypeDesigationWorkingSet() { |
|
128 |
return SpecimenOrObservationBase.class.isAssignableFrom(baseEntity.getClass()); |
|
129 |
} |
|
130 |
|
|
131 |
public TypeDesignationWorkingSetType getWorkingsetType() { |
|
132 |
return isSpecimenTypeDesigationWorkingSet() ? TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET : TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Uses the <code>comparator</code> to find the highest {@link TypeDesignationStatusBase} term and returns that. |
|
137 |
*/ |
|
138 |
public TypeDesignationStatusBase<?> highestTypeStatus(Comparator<TypeDesignationStatusBase<?>> comparator) { |
|
139 |
TypeDesignationStatusBase<?> highestTypeStatus = null; |
|
140 |
for(TypeDesignationStatusBase<?> status : designationByStatusMap.keySet()) { |
|
141 |
if(comparator.compare(status, highestTypeStatus) < 0){ |
|
142 |
highestTypeStatus = status; |
|
143 |
} |
|
144 |
} |
|
145 |
return highestTypeStatus; |
|
146 |
} |
|
147 |
|
|
148 |
// **************************** toString() ************************************ |
|
149 |
|
|
150 |
@Override |
|
151 |
public String toString(){ |
|
152 |
if(label != null){ |
|
153 |
return label; |
|
154 |
} else { |
|
155 |
return super.toString(); |
|
156 |
} |
|
157 |
} |
|
158 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManagerTest.java | ||
---|---|---|
212 | 212 |
, result |
213 | 213 |
); |
214 | 214 |
|
215 |
Map<VersionableEntity,TypeDesignationWorkingSet> orderedTypeDesignations =
|
|
216 |
typeDesignationManager.getOrderedTypeDesignationWorkingSets();
|
|
217 |
Iterator<TypeDesignationWorkingSet> byStatusMapIterator = orderedTypeDesignations.values().iterator();
|
|
215 |
Map<VersionableEntity,TypeDesignationSet> orderedTypeDesignations = |
|
216 |
typeDesignationManager.getOrderedTypeDesignationSets(); |
|
217 |
Iterator<TypeDesignationSet> byStatusMapIterator = orderedTypeDesignations.values().iterator(); |
|
218 | 218 |
Iterator<TypeDesignationStatusBase<?>> keyIt_1 = byStatusMapIterator.next().keySet().iterator(); |
219 | 219 |
Iterator<TypeDesignationStatusBase<?>> keyIt_2 = byStatusMapIterator.next().keySet().iterator(); |
220 | 220 |
assertEquals("isotype", keyIt_1.next().getLabel()); |
Also available in: Unified diff
ref #10089 rename TypeDesignationWorkingSet to TypeDesignationSet in cdmlib