Project

General

Profile

« Previous | Next » 

Revision 3fb08830

Added by Andreas Müller almost 2 years ago

ref #10089 remove TypedEntityReference from TypeDesignationWorkingSet

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
87 87
     *
88 88
     * {@inheritDoc}
89 89
     */
90
    private Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entryComparator = (o1,o2)->{
90
    private Comparator<Entry<VersionableEntity,TypeDesignationWorkingSet>> entryComparator = (o1,o2)->{
91 91

  
92 92
         TypeDesignationWorkingSet ws1 = o1.getValue();
93 93
         TypeDesignationWorkingSet ws2 = o2.getValue();
......
106 106

  
107 107
         //boolean hasStatus1 = ws1.getTypeDesignations(); //.stream().filter(td -> td.getSt);
108 108

  
109
         Class<?> type1 = o1.getKey().getType();
110
         Class<?> type2 = o2.getKey().getType();
109
         Class<?> type1 = o1.getKey().getClass();
110
         Class<?> type2 = o2.getKey().getClass();
111 111

  
112 112
         if(!type1.equals(type2)) {
113 113
             if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){
......
118 118
                 return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1;
119 119
             }
120 120
         } else {
121
             return o1.getKey().getLabel().compareTo(o2.getKey().getLabel());
121
//             tdType1 = ws1.getTypeDesignations().stream().map(td->td.get).sorted(null).findFirst().orElseGet(()->{return null;});
122
             String label1 = TypeDesignationSetFormatter.entityLabel(o1.getKey());
123
             String label2 = TypeDesignationSetFormatter.entityLabel(o2.getKey());
124
             return label1.compareTo(label2);
122 125
         }
123 126
     };
124 127

  
......
126 129
     * Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus.
127 130
     * The TypeDesignationStatusBase keys are already ordered by the term order defined in the vocabulary.
128 131
     */
129
    private LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedByTypesByBaseEntity;
132
    private LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> orderedByTypesByBaseEntity;
130 133

  
131 134
    private List<String> problems = new ArrayList<>();
132 135

  
......
202 205
     */
203 206
    protected void mapAndSort() {
204 207

  
205
        Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> byBaseEntityByTypeStatus = new HashMap<>();
208
        Map<VersionableEntity,TypeDesignationWorkingSet> byBaseEntityByTypeStatus = new HashMap<>();
206 209
        this.typeDesignations.values().forEach(td -> mapTypeDesignation(byBaseEntityByTypeStatus, td));
207 210
        orderedByTypesByBaseEntity = orderByTypeByBaseEntity(byBaseEntityByTypeStatus);
208 211
    }
209 212

  
210
    private void mapTypeDesignation(Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> byBaseEntityByTypeStatus,
213
    private void mapTypeDesignation(Map<VersionableEntity,TypeDesignationWorkingSet> byBaseEntityByTypeStatus,
211 214
            TypeDesignationBase<?> td){
212 215

  
213 216
        td = HibernateProxyHelper.deproxy(td);
......
215 218

  
216 219
        try {
217 220
            final VersionableEntity baseEntity = baseEntity(td);
218
            final TypedEntityReference<? extends VersionableEntity> baseEntityReference = makeEntityReference(baseEntity);
221
//            final TypedEntityReference<? extends VersionableEntity> baseEntityReference = makeEntityReference(baseEntity);
219 222

  
220 223
            TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder();
221 224
            boolean withCitation = true;
......
229 232
                    workingsetBuilder.getTaggedText(),
230 233
                    getTypeUuid(td));
231 234

  
232
            if(!byBaseEntityByTypeStatus.containsKey(baseEntityReference)){
233
                byBaseEntityByTypeStatus.put(baseEntityReference, new TypeDesignationWorkingSet(baseEntity, baseEntityReference));
235
            if(!byBaseEntityByTypeStatus.containsKey(baseEntity)){
236
                byBaseEntityByTypeStatus.put(baseEntity, new TypeDesignationWorkingSet(baseEntity));
234 237
            }
235
            byBaseEntityByTypeStatus.get(baseEntityReference).insert(status, typeDesignationDTO);
238
            byBaseEntityByTypeStatus.get(baseEntity).insert(status, typeDesignationDTO);
236 239

  
237 240
        } catch (DataIntegrityException e){
238 241
            problems.add(e.getMessage());
......
281 284
        return baseEntity;
282 285
    }
283 286

  
287
    //TODO maybe not needed anymore
284 288
    protected static TypedEntityReference<? extends VersionableEntity> makeEntityReference(VersionableEntity baseEntity) {
285 289

  
286 290
        baseEntity = CdmBase.deproxy(baseEntity);
287
        String label = entityLabel(baseEntity);
291
        String label = TypeDesignationSetFormatter.entityLabel(baseEntity);
288 292

  
289 293
        TypedEntityReference<? extends VersionableEntity> baseEntityReference =
290 294
                new TypedEntityReference<>(baseEntity.getClass(), baseEntity.getUuid(), label);
......
292 296
        return baseEntityReference;
293 297
    }
294 298

  
295
    //TODO move to formatter?
296
    protected static String entityLabel(VersionableEntity baseEntity) {
297
        String label = "";
298
        if(baseEntity instanceof IdentifiableEntity<?>){
299
                label = ((IdentifiableEntity<?>)baseEntity).getTitleCache();
300
        }
301
        return label;
302
    }
303

  
304
    private LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderByTypeByBaseEntity(
305
            Map<TypedEntityReference<? extends VersionableEntity>,TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
299
    private LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> orderByTypeByBaseEntity(
300
            Map<VersionableEntity,TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
306 301

  
307 302
       // order the FieldUnit TypeName keys
308
       Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet
303
       Set<Entry<VersionableEntity,TypeDesignationWorkingSet>> entrySet
309 304
               = stringsByTypeByBaseEntity.entrySet();
310
       LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList
305
       LinkedList<Entry<VersionableEntity,TypeDesignationWorkingSet>> baseEntityKeyList
311 306
               = new LinkedList<>(entrySet);
312 307
       Collections.sort(baseEntityKeyList, entryComparator);
313 308

  
314 309
       // new LinkedHashMap for the ordered FieldUnitOrTypeName keys
315
       LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> stringsOrderedbyBaseEntityOrderdByType
310
       LinkedHashMap<VersionableEntity,TypeDesignationWorkingSet> stringsOrderedbyBaseEntityOrderdByType
316 311
           = new LinkedHashMap<>(stringsByTypeByBaseEntity.size());
317 312

  
318
       for(Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> entry : baseEntityKeyList){
319
           TypedEntityReference<? extends VersionableEntity> baseEntityRef = entry.getKey();
320
           TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntityRef);
313
       for(Entry<VersionableEntity,TypeDesignationWorkingSet> entry : baseEntityKeyList){
314
           VersionableEntity baseEntity = entry.getKey();
315
           TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntity);
321 316
           // order the TypeDesignationStatusBase keys
322 317
            List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet());
323 318
            Collections.sort(keyList, new TypeDesignationStatusComparator());
......
325 320
            TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet(
326 321
                    typeDesignationWorkingSet.getBaseEntity());
327 322
            keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationWorkingSet.get(key)));
328
            stringsOrderedbyBaseEntityOrderdByType.put(baseEntityRef, orderedStringsByOrderedTypes);
329
       }
323
            stringsOrderedbyBaseEntityOrderdByType.put(baseEntity, orderedStringsByOrderedTypes);
324
        }
330 325

  
331 326
        return stringsOrderedbyBaseEntityOrderdByType;
332 327
    }
333 328

  
334

  
335 329
    /**
336 330
     * FIXME use the validation framework validators to store the validation problems!!!
337 331
     *
......
405 399
        return this.typeDesignations.get(uuid);
406 400
    }
407 401

  
408
    public Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> getOrderedTypeDesignationWorkingSets() {
402
    public Map<VersionableEntity,TypeDesignationWorkingSet> getOrderedTypeDesignationWorkingSets() {
409 403
        return orderedByTypesByBaseEntity;
410 404
    }
411 405

  

Also available in: Unified diff