Revision 4e0052e3
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationConverter.java | ||
---|---|---|
44 | 44 |
private final String separator = ", "; |
45 | 45 |
|
46 | 46 |
private Collection<TypeDesignationBase> typeDesignations; |
47 |
private Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedStringsByType; |
|
47 |
|
|
48 |
/** |
|
49 |
* Groups the EntityReferences for each of the TypeDesignatinos by the according TypeDesignationStatus. |
|
50 |
* The TypeDesignationStatusBase keys are already ordered by the term order defined in the vocabulary. |
|
51 |
*/ |
|
52 |
private LinkedHashMap<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedStringsByOrderedTypes = new LinkedHashMap<>(); |
|
53 |
|
|
54 |
/** |
|
55 |
* Groups the EntityReferences for each of the TypeDesignatinos by the label representations of the |
|
56 |
* according TypeDesignationStatus. The labels are ordered by the term order defined in the vocabulary. |
|
57 |
*/ |
|
48 | 58 |
private LinkedHashMap<String, Collection<EntityReference>> orderedRepresentations = new LinkedHashMap<>(); |
59 |
|
|
49 | 60 |
private EntityReference typifiedName; |
50 | 61 |
|
51 | 62 |
private String finalString = null; |
... | ... | |
59 | 70 |
*/ |
60 | 71 |
public TypeDesignationConverter(Collection<TypeDesignationBase> typeDesignations) throws RegistrationValidationException { |
61 | 72 |
this.typeDesignations = typeDesignations; |
62 |
orderedStringsByType = new HashMap<>(); |
|
63 |
typeDesignations.forEach(td -> putString(td.getTypeStatus(), new EntityReference(td.getId(), stringify(td)))); |
|
73 |
Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedStringsByType = new HashMap<>(); |
|
74 |
typeDesignations.forEach(td -> putString(orderedStringsByType, td.getTypeStatus(), new EntityReference(td.getId(), stringify(td)))); |
|
75 |
orderedStringsByOrderedTypes = orderedByType(orderedStringsByType); |
|
64 | 76 |
orderedRepresentations = buildOrderedRepresentations(); |
65 | 77 |
this.typifiedName = findTypifiedName(); |
66 | 78 |
} |
67 | 79 |
|
68 |
private LinkedHashMap buildOrderedRepresentations(){
|
|
80 |
private LinkedHashMap<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedByType(Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedStringsByType){
|
|
69 | 81 |
|
70 | 82 |
// 1. order by SpecimenType, NameType |
71 | 83 |
|
... | ... | |
83 | 95 |
}); |
84 | 96 |
// NameTypes......... |
85 | 97 |
|
86 |
keyList.forEach(key -> orderedRepresentations.put(getTypeDesignationStytusLabel(key), orderedStringsByType.get(key))); |
|
98 |
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, orderedStringsByType.get(key))); |
|
99 |
return orderedStringsByOrderedTypes; |
|
100 |
} |
|
101 |
|
|
102 |
private LinkedHashMap<String, Collection<EntityReference>> buildOrderedRepresentations(){ |
|
103 |
|
|
104 |
orderedStringsByOrderedTypes.keySet().forEach( |
|
105 |
key -> orderedRepresentations.put( |
|
106 |
getTypeDesignationStytusLabel(key), |
|
107 |
orderedStringsByOrderedTypes.get(key)) |
|
108 |
); |
|
87 | 109 |
return orderedRepresentations; |
88 | 110 |
} |
89 | 111 |
|
... | ... | |
270 | 292 |
return sb.toString(); |
271 | 293 |
} |
272 | 294 |
|
273 |
private void putString(TypeDesignationStatusBase<?> status, EntityReference idAndString){ |
|
295 |
private void putString(Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> orderedStringsByType, TypeDesignationStatusBase<?> status, EntityReference idAndString){
|
|
274 | 296 |
// the cdm orderd term bases are ordered invers, fixing this for here |
275 | 297 |
if(status == null){ |
276 | 298 |
status = SpecimenTypeDesignationStatus.TYPE(); |
Also available in: Unified diff
ref #6719 refactoring and better test