Project

General

Profile

« Previous | Next » 

Revision 45356f85

Added by Andreas Müller almost 2 years ago

ref #10089 implement TypeDesignationSetContainer ordered by status not field unit

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSet.java
139 139
     */
140 140
    public TypeDesignationStatusBase<?> highestTypeStatus(Comparator<TypeDesignationStatusBase<?>> comparator) {
141 141
        TypeDesignationStatusBase<?> highestTypeStatus = null;
142
        boolean isFirst = true;
142 143
        for(TypeDesignationStatusBase<?> status : designationByStatusMap.keySet()) {
143
            if(comparator.compare(status, highestTypeStatus) < 0){
144
            if(isFirst || comparator.compare(status, highestTypeStatus) < 0){
144 145
                highestTypeStatus = status;
146
                isFirst = false;
145 147
            }
146 148
        }
147 149
        return highestTypeStatus;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetContainer.java
66 66
        TYPE_NAME;
67 67
    }
68 68

  
69
    //not yet used
70
    enum ORDER_BY{
71
        TYPE_STATUS,
72
        BASE_ENTITY;
73
    }
74

  
69 75
    private NameTypeBaseEntityType nameTypeBaseEntityType = NameTypeBaseEntityType.NAME_TYPE_DESIGNATION;
70 76

  
71 77
    private Map<UUID,TypeDesignationBase<?>> typeDesignations = new HashMap<>();
72 78

  
73 79
    private TaxonName typifiedName;
74 80

  
81
    private ORDER_BY orderBy = ORDER_BY.TYPE_STATUS;
82

  
75 83
    /**
76 84
     * Sorts the base entities (TypedEntityReference) in the following order:
77 85
     *
......
112 120
                 return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1;
113 121
             }
114 122
         } else {
115
//             tdType1 = ws1.getTypeDesignations().stream().map(td->td.get).sorted(null).findFirst().orElseGet(()->{return null;});
123
             if (orderBy == ORDER_BY.TYPE_STATUS) {
124
                 @SuppressWarnings({ "unchecked", "rawtypes" })
125
                 Comparator<TypeDesignationStatusBase<?>> statusComparator = (Comparator)new TypeDesignationStatusComparator<>();
126
                 TypeDesignationStatusBase<?> status1 = ws1.highestTypeStatus(statusComparator);
127
                 TypeDesignationStatusBase<?> status2 = ws2.highestTypeStatus(statusComparator);
128
                 int comp = statusComparator.compare(status1, status2);
129
                 if (comp != 0) {
130
                     return comp;
131
                 }
132
             }
133

  
116 134
             String label1 = TypeDesignationSetFormatter.entityLabel(o1.getKey());
117 135
             String label2 = TypeDesignationSetFormatter.entityLabel(o2.getKey());
118 136
             return label1.compareTo(label2);
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetFormatterTest.java
246 246
//                new TaggedText(TagEnum.name, "Prionus coriatius L."), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
247 247
//        Assert.assertEquals("there should be 4 tags only", 4, taggedText.size());
248 248
    }
249

  
250
    //#10089
251
    @Test
252
    public void testOrderedByStatusNotBaseEntity() throws TypeDesignationSetException {
253

  
254
        @SuppressWarnings("rawtypes")
255
        List<TypeDesignationBase> tds = new ArrayList<>();
256
        tds.add(std_HT);
257
        tds.add(std_IT_3);
258

  
259
        TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
260
        typifiedName.setTitleCache("Prionus coriatius L.", true);
261

  
262
        typifiedName.addTypeDesignation(std_HT, false);
263
        typifiedName.addTypeDesignation(std_IT_3, false);
264

  
265
        TypeDesignationSetContainer container = new TypeDesignationSetContainer(tds);
266
        TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(false, false, false);
267
        String text = formatter.format(container);
268
        int holotypeIndex = text.indexOf("holotype");
269
        Assert.assertTrue("Holotype must be first, isotype second", holotypeIndex>0 && (holotypeIndex < text.indexOf("isotype")) );
270
    }
249 271
}

Also available in: Unified diff