Revision 1ddf0695
Added by Andreas Müller almost 2 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/ref/TypedEntityReference.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
private static final long serialVersionUID = -4619590272174606288L; |
26 | 26 |
|
27 |
public static <T extends CdmBase> TypedEntityReference<T> fromEntity(T entity) { |
|
28 |
return TypedEntityReference.fromEntity(entity, true); |
|
29 |
} |
|
30 |
|
|
27 | 31 |
private Class<T> type; |
28 | 32 |
|
29 | 33 |
/** |
... | ... | |
39 | 43 |
* @deprecated use factory method instead, should only be used by in DTO sub-class constructors (TODO: to be made protected once no longer used publicly) |
40 | 44 |
*/ |
41 | 45 |
@Deprecated |
42 |
public TypedEntityReference(T entity) { |
|
43 |
super(); |
|
46 |
protected TypedEntityReference(T entity) { |
|
44 | 47 |
this.type = (Class<T>) entity.getClass(); |
45 | 48 |
this.uuid = entity.getUuid(); |
46 | 49 |
} |
... | ... | |
79 | 82 |
return new TypedEntityReference<>(subType, getUuid()); |
80 | 83 |
} |
81 | 84 |
|
82 |
public static <T extends CdmBase> TypedEntityReference<T> fromEntity(T entity) { |
|
83 |
return TypedEntityReference.fromEntity(entity, true); |
|
84 |
} |
|
85 |
|
|
86 | 85 |
public Class<T> getType() { |
87 | 86 |
return type; |
88 | 87 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/RegistrationDTO.java | ||
---|---|---|
18 | 18 |
import java.util.UUID; |
19 | 19 |
|
20 | 20 |
import org.apache.commons.lang3.StringUtils; |
21 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
21 |
import org.apache.logging.log4j.LogManager; |
|
22 |
import org.apache.logging.log4j.Logger; |
|
22 | 23 |
import org.joda.time.DateTime; |
23 | 24 |
|
24 | 25 |
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException; |
... | ... | |
268 | 269 |
public Set<TypeDesignationBase> getTypeDesignationsInWorkingSet(TypedEntityReference baseEntityReference) { |
269 | 270 |
Set<TypeDesignationBase> typeDesignations = new HashSet<>(); |
270 | 271 |
TypeDesignationWorkingSet workingSet = getTypeDesignationWorkingSet(baseEntityReference); |
271 |
for(TypeDesignationDTO ref : workingSet.getTypeDesignations()){ |
|
272 |
for(TypeDesignationDTO<?> ref : workingSet.getTypeDesignations()){
|
|
272 | 273 |
typeDesignations.add(findTypeDesignation(ref)); |
273 | 274 |
} |
274 | 275 |
return typeDesignations; |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java | ||
---|---|---|
76 | 76 |
|
77 | 77 |
private TaxonName typifiedName; |
78 | 78 |
|
79 |
private Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entryComparator = new Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>>(){ |
|
80 |
|
|
81 |
/** |
|
82 |
* Sorts the base entities (TypedEntityReference) in the following order: |
|
83 |
* |
|
84 |
* 1. FieldUnits |
|
85 |
* 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit) |
|
86 |
* 3. NameType |
|
87 |
* |
|
88 |
* {@inheritDoc} |
|
89 |
*/ |
|
90 |
@Override |
|
91 |
public int compare(Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> o1, Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> o2) { |
|
92 |
|
|
93 |
TypeDesignationWorkingSet ws1 = o1.getValue(); |
|
94 |
TypeDesignationWorkingSet ws2 = o2.getValue(); |
|
95 |
|
|
96 |
if (ws1.getWorkingsetType() != ws2.getWorkingsetType()){ |
|
97 |
//first specimen types, then name types (very rare case anyway) |
|
98 |
return ws1.getWorkingsetType() == TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET? 1:-1; |
|
99 |
} |
|
79 |
private Class tdType1; |
|
100 | 80 |
|
101 |
boolean hasStatus1 = !ws1.keySet().contains(null) && !ws1.keySet().contains(NullTypeDesignationStatus.SINGLETON()); |
|
102 |
boolean hasStatus2 = !ws2.keySet().contains(null) && !ws2.keySet().contains(NullTypeDesignationStatus.SINGLETON()); |
|
103 |
if (hasStatus1 != hasStatus2){ |
|
104 |
//first without status as it is difficult to distinguish a non status from a "same" status record if the first record has a status and second has no status |
|
105 |
return hasStatus1? 1:-1; |
|
106 |
} |
|
81 |
/** |
|
82 |
* Sorts the base entities (TypedEntityReference) in the following order: |
|
83 |
* |
|
84 |
* 1. FieldUnits |
|
85 |
* 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit) |
|
86 |
* 3. NameType |
|
87 |
* |
|
88 |
* {@inheritDoc} |
|
89 |
*/ |
|
90 |
private Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entryComparator = (o1,o2)->{ |
|
91 |
|
|
92 |
TypeDesignationWorkingSet ws1 = o1.getValue(); |
|
93 |
TypeDesignationWorkingSet ws2 = o2.getValue(); |
|
94 |
|
|
95 |
if (ws1.getWorkingsetType() != ws2.getWorkingsetType()){ |
|
96 |
//first specimen types, then name types (very rare case anyway) |
|
97 |
return ws1.getWorkingsetType() == TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET? 1:-1; |
|
98 |
} |
|
99 |
|
|
100 |
boolean hasStatus1 = !ws1.keySet().contains(null) && !ws1.keySet().contains(NullTypeDesignationStatus.SINGLETON()); |
|
101 |
boolean hasStatus2 = !ws2.keySet().contains(null) && !ws2.keySet().contains(NullTypeDesignationStatus.SINGLETON()); |
|
102 |
if (hasStatus1 != hasStatus2){ |
|
103 |
//first without status as it is difficult to distinguish a non status from a "same" status record if the first record has a status and second has no status |
|
104 |
return hasStatus1? 1:-1; |
|
105 |
} |
|
107 | 106 |
|
108 |
// boolean hasStatus1 = ws1.getTypeDesignations(); //.stream().filter(td -> td.getSt);
|
|
107 |
//boolean hasStatus1 = ws1.getTypeDesignations(); //.stream().filter(td -> td.getSt);
|
|
109 | 108 |
|
110 |
Class<?> type1 = o1.getKey().getType();
|
|
111 |
Class<?> type2 = o2.getKey().getType();
|
|
109 |
Class<?> type1 = o1.getKey().getType(); |
|
110 |
Class<?> type2 = o2.getKey().getType(); |
|
112 | 111 |
|
113 |
if(!type1.equals(type2)) { |
|
114 |
if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){ |
|
115 |
// FieldUnits first |
|
116 |
return type1.equals(FieldUnit.class) ? -1 : 1; |
|
117 |
} else { |
|
118 |
// name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle) |
|
119 |
return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1; |
|
120 |
} |
|
112 |
if(!type1.equals(type2)) { |
|
113 |
if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){ |
|
114 |
// FieldUnits first |
|
115 |
return type1.equals(FieldUnit.class) ? -1 : 1; |
|
121 | 116 |
} else { |
122 |
return o1.getKey().getLabel().compareTo(o2.getKey().getLabel()); |
|
117 |
// name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle) |
|
118 |
return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1; |
|
123 | 119 |
} |
124 |
}}; |
|
120 |
} else { |
|
121 |
return o1.getKey().getLabel().compareTo(o2.getKey().getLabel()); |
|
122 |
} |
|
123 |
}; |
|
125 | 124 |
|
126 | 125 |
/** |
127 | 126 |
* Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus. |
... | ... | |
303 | 302 |
} |
304 | 303 |
|
305 | 304 |
private LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderByTypeByBaseEntity( |
306 |
Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
|
|
305 |
Map<TypedEntityReference<? extends VersionableEntity>,TypeDesignationWorkingSet> stringsByTypeByBaseEntity){ |
|
307 | 306 |
|
308 | 307 |
// order the FieldUnit TypeName keys |
309 |
Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet = stringsByTypeByBaseEntity.entrySet(); |
|
310 |
LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList = new LinkedList<>(entrySet); |
|
308 |
Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet |
|
309 |
= stringsByTypeByBaseEntity.entrySet(); |
|
310 |
LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList |
|
311 |
= new LinkedList<>(entrySet); |
|
311 | 312 |
Collections.sort(baseEntityKeyList, entryComparator); |
312 | 313 |
|
313 | 314 |
// new LinkedHashMap for the ordered FieldUnitOrTypeName keys |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationWorkingSet.java | ||
---|---|---|
51 | 51 |
|
52 | 52 |
private VersionableEntity baseEntity; |
53 | 53 |
|
54 |
public enum TypeDesignationWorkingSetType { |
|
55 |
SPECIMEN_TYPE_DESIGNATION_WORKINGSET, |
|
56 |
NAME_TYPE_DESIGNATION_WORKINGSET; |
|
57 |
boolean isSpecimenType(){return this == SPECIMEN_TYPE_DESIGNATION_WORKINGSET;} |
|
58 |
boolean isNameType(){return this == NAME_TYPE_DESIGNATION_WORKINGSET;} |
|
59 |
} |
|
60 |
|
|
54 | 61 |
// ********************************* CONSTRUCTOR **************************/ |
55 | 62 |
|
56 | 63 |
public TypeDesignationWorkingSet(VersionableEntity baseEntity) { |
... | ... | |
120 | 127 |
return isSpecimenTypeDesigationWorkingSet() ? TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET : TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET; |
121 | 128 |
} |
122 | 129 |
|
123 |
|
|
124 |
public enum TypeDesignationWorkingSetType { |
|
125 |
SPECIMEN_TYPE_DESIGNATION_WORKINGSET, |
|
126 |
NAME_TYPE_DESIGNATION_WORKINGSET; |
|
127 |
boolean isSpecimenType(){return this == SPECIMEN_TYPE_DESIGNATION_WORKINGSET;} |
|
128 |
boolean isNameType(){return this == NAME_TYPE_DESIGNATION_WORKINGSET;} |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public String toString(){ |
|
133 |
if(label != null){ |
|
134 |
return label; |
|
135 |
} else { |
|
136 |
return super.toString(); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 | 130 |
/** |
141 | 131 |
* Uses the <code>comparator</code> to find the highest {@link TypeDesignationStatusBase} term and returns that. |
142 | 132 |
*/ |
... | ... | |
149 | 139 |
} |
150 | 140 |
return highestTypeStatus; |
151 | 141 |
} |
142 |
|
|
143 |
@Override |
|
144 |
public String toString(){ |
|
145 |
if(label != null){ |
|
146 |
return label; |
|
147 |
} else { |
|
148 |
return super.toString(); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 | 152 |
} |
Also available in: Unified diff
cleanup