Project

General

Profile

« Previous | Next » 

Revision 30190957

Added by Andreas Müller over 3 years ago

ref #9262 fix fide and designated by handling for cdmlight export and TypeDesignationSetManager

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
42 42
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
43 43
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
44 44
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
45
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
45 46
import eu.etaxonomy.cdm.model.reference.Reference;
46 47
import eu.etaxonomy.cdm.model.term.TermVocabulary;
47 48
import eu.etaxonomy.cdm.ref.EntityReference;
......
80 81
    private static final String TYPE_SEPARATOR = "; ";
81 82

  
82 83
    private static final String TYPE_DESIGNATION_SEPARATOR = ", ";
83
    private static final String TYPE_STATUS_SEPARATOR_WITHCITATION = ": ";
84
    private static final String TYPE_STATUS_SEPARATOR_WITH_CITATION = ": ";
84 85
    private static final String TYPE_STATUS_PARENTHESIS_LEFT = " (";
85 86
    private static final String TYPE_STATUS_PARENTHESIS_RIGHT = ") ";
86
    private static final String REFERENCE_PARENTHESIS_RIGHT = "] ";
87
    private static final String REFERENCE_PARENTHESIS_RIGHT = "]";
87 88
    private static final String REFERENCE_PARENTHESIS_LEFT = " [";
89
    private static final String REFERENCE_DESIGNATED_BY = "designated by ";
88 90
    private static final String REFERENCE_FIDE = "fide ";
91
    private static final String SOURCE_SEPARATOR = ", ";
92
    private static final String REFERENCE_DESIGNATED_FIDE_SEPERATOR = " ";
89 93

  
90 94
    private Map<UUID,TypeDesignationBase<?>> typeDesignations;
91 95

  
......
116 120
    	this(typeDesignations, null);
117 121
    }
118 122

  
119
    public TypeDesignationSetManager(Collection<TypeDesignationBase> typeDesignations, TaxonName typifiedName) throws RegistrationValidationException {
123
    public TypeDesignationSetManager(Collection<TypeDesignationBase> typeDesignations, TaxonName typifiedName) throws RegistrationValidationException  {
120 124
        if (this.typeDesignations == null){
121 125
            this.typeDesignations = new HashMap<>();
122 126
        }
......
334 338
                    if(SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ){
335 339
                        workingsetBuilder.add(TagEnum.label, "Type:");
336 340
                    } else{
337
                        workingsetBuilder.add(TagEnum.label, "NameType:");
341
                        workingsetBuilder.add(TagEnum.label, "Nametype:");
338 342
                        isNameTypeDesignation = true;
339 343
                    }
340 344
                    if(!baseEntityRef.getLabel().isEmpty()){
......
415 419
                            workingsetBuilder.add(TagEnum.typeDesignation, typeDesignationEntityReference.getLabel(), typeDesignationEntityReference);
416 420

  
417 421
                            TypeDesignationBase<?> typeDes =  typeDesignations.get(typeDesignationEntityReference.getUuid());
418
                            if (typeDes.getCitation() != null){
422
                            if (hasSources(typeDes)){
419 423
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_LEFT);
420
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_FIDE);
421
                                String shortCitation = ((DefaultReferenceCacheStrategy)typeDes.getCitation().getCacheStrategy()).createShortCitation(typeDes.getCitation());
422
                                workingsetBuilder.add(TagEnum.reference, shortCitation, typeDesignationEntityReference);
424
                                OriginalSourceBase<?> lectoSource = typeDes.getSource();
425
                                if (hasLectoSource(typeDes)){
426
                                    workingsetBuilder.add(TagEnum.separator, REFERENCE_DESIGNATED_BY);
427
                                    addSource(workingsetBuilder, typeDesignationEntityReference, lectoSource);
428
                                }
429
                                if (!typeDes.getSources().isEmpty()) {
430
                                    if (hasLectoSource(typeDes)){
431
                                        workingsetBuilder.add(TagEnum.separator, REFERENCE_DESIGNATED_FIDE_SEPERATOR);
432
                                    }
433
                                    workingsetBuilder.add(TagEnum.separator, REFERENCE_FIDE);
434
                                    int count = 0;
435
                                    for (IdentifiableSource source: typeDes.getSources()){
436
                                        if (count++ > 0){
437
                                            workingsetBuilder.add(TagEnum.separator, SOURCE_SEPARATOR);
438
                                        }
439
                                        addSource(workingsetBuilder, typeDesignationEntityReference, source);                                    }
440
                                }
423 441
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_RIGHT);
424 442
                            }
425 443
                            if ((!typeStatus.equals(NULL_STATUS)) &&(typeDesignationCount ==  typeDesignationWorkingSet.get(typeStatus).size())){
426 444
                                workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_RIGHT);
427 445
                            }
428 446
                        }
429

  
430 447
                    }
431 448
                    typeDesignationWorkingSet.setRepresentation(workingsetBuilder.toString());
432 449
                    finalString += typeDesignationWorkingSet.getRepresentation();
......
438 455
        }
439 456
    }
440 457

  
458
    /**
459
     * Adds the taggs for the given source.
460
     */
461
    private void addSource(TaggedTextBuilder workingsetBuilder, TypedEntityReference<?> typeDesignationEntityReference,
462
            OriginalSourceBase<?> source) {
463
        Reference ref = source.getCitation();
464
        String shortCitation = ((DefaultReferenceCacheStrategy)ref.getCacheStrategy()).createShortCitation(ref);
465
        //TODO still need to add detail
466
        workingsetBuilder.add(TagEnum.reference, shortCitation, typeDesignationEntityReference);
467
    }
468

  
469
    private boolean hasSources(TypeDesignationBase<?> typeDes) {
470
        return hasLectoSource(typeDes) || !typeDes.getSources().isEmpty();
471
    }
472

  
473
    private boolean hasLectoSource(TypeDesignationBase<?> typeDes) {
474
        return typeDes.getSource() != null &&
475
                    (typeDes.getSource().getCitation() != null
476
                      || isNotBlank(typeDes.getSource().getCitationMicroReference())
477
                     );
478
    }
479

  
441 480
    private List<TypedEntityReference<TypeDesignationBase<?>>> createSortedList(
442 481
            TypeDesignationWorkingSet typeDesignationWorkingSet, TypeDesignationStatusBase<?> typeStatus) {
443 482
        List<TypedEntityReference<TypeDesignationBase<?>>> typeDesignationEntityReferences = new ArrayList<>(typeDesignationWorkingSet.get(typeStatus));
......
595 634
                        MediaSpecimen msp = (MediaSpecimen)du;
596 635
                        if(msp.getMediaSpecimen() != null){
597 636
                            for(IdentifiableSource source : msp.getMediaSpecimen().getSources()){
598
                                String refDetailStr = source.getCitationMicroReference();
599 637
                                String referenceStr = source.getCitation() == null? "": source.getCitation().getTitleCache();
600
                                if(StringUtils.isNotBlank(source.getCitationMicroReference())){
638
                                String refDetailStr = source.getCitationMicroReference();
639
                                if(isNotBlank(refDetailStr)){
601 640
                                    typeSpecimenTitle += refDetailStr;
602 641
                                }
603 642
                                if(!typeSpecimenTitle.isEmpty() && !referenceStr.isEmpty()){
......
796 835
        public TypeDesignationWorkingSetType getWorkingsetType() {
797 836
            return isSpecimenTypeDesigationWorkingSet() ? TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET : TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET;
798 837
        }
838
    }
799 839

  
840
    private boolean isNotBlank(String str){
841
        return StringUtils.isNotBlank(str);
800 842
    }
801 843

  
802 844
    public enum TypeDesignationWorkingSetType {
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TypeDesignationSetManagerTest.java
8 8
*/
9 9
package eu.etaxonomy.cdm.api.service;
10 10

  
11

  
12 11
import static org.junit.Assert.assertEquals;
13 12
import static org.junit.Assert.assertNotNull;
14 13

  
15
import java.io.FileNotFoundException;
16 14
import java.util.ArrayList;
17 15
import java.util.Collection;
18 16
import java.util.Iterator;
......
20 18
import java.util.List;
21 19
import java.util.Map;
22 20

  
23
import org.apache.log4j.Logger;
24 21
import org.junit.Before;
25 22
import org.junit.Test;
26 23

  
27 24
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
28 25
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager;
29 26
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager.TypeDesignationWorkingSet;
27
import eu.etaxonomy.cdm.model.agent.Person;
28
import eu.etaxonomy.cdm.model.agent.Team;
30 29
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
31 30
import eu.etaxonomy.cdm.model.media.Media;
32 31
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
......
38 37
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
39 38
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
40 39
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
40
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
41 41
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
42 42
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
43 43
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
......
45 45
import eu.etaxonomy.cdm.model.reference.Reference;
46 46
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
47 47
import eu.etaxonomy.cdm.ref.TypedEntityReference;
48
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
48
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
49
import eu.etaxonomy.cdm.test.TermTestBase;
50

  
49 51
/**
50 52
 * @author a.kohlbecker, k.luther
51 53
 * @since 03.09.2018
52
 *
53 54
 */
54
public class TypeDesignationSetManagerTest extends CdmTransactionalIntegrationTest{
55
public class TypeDesignationSetManagerTest extends TermTestBase{
55 56

  
56 57
        private NameTypeDesignation ntd;
57 58
        private SpecimenTypeDesignation std_IT;
58 59
        private SpecimenTypeDesignation std_HT;
60
        private SpecimenTypeDesignation std_LT;
59 61
        private SpecimenTypeDesignation std_IT_2;
60 62
        private SpecimenTypeDesignation std_IT_3;
61 63
        private SpecimenTypeDesignation mtd_HT_published;
62 64
        private SpecimenTypeDesignation mtd_IT_unpublished;
65
        private Team team;
63 66

  
64 67
        @Before
65 68
        public void init(){
66 69

  
70
            Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
71
            Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
72
            Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
73
            team = Team.NewInstance(person1, person2, person3);
74

  
67 75
            ntd = NameTypeDesignation.NewInstance();
68 76
            ntd.setId(1);
69 77
            TaxonName typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
......
72 80
            Reference citation = ReferenceFactory.newGeneric();
73 81
            citation.setTitleCache("Species Plantarum", true);
74 82
            ntd.setCitation(citation);
83
//          ntd.addPrimaryTaxonomicSource(citation, null);
75 84

  
76 85
            FieldUnit fu_1 = FieldUnit.NewInstance();
77 86
            fu_1.setId(1);
......
98 107
            std_IT.setTypeSpecimen(specimen_IT);
99 108
            std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
100 109

  
110
            std_LT = SpecimenTypeDesignation.NewInstance();
111
            DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
112
            specimen_LT.setTitleCache("LEC", true);
113
            createDerivationEvent(fu_1, specimen_LT);
114
            std_LT.setTypeSpecimen(specimen_LT);
115
            std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
116
            Reference lectoCitation = ReferenceFactory.newBook();
117
            lectoCitation.setAuthorship(team);
118
            lectoCitation.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
119
            std_LT.setCitation(lectoCitation);
120

  
101 121
            std_IT_2 = SpecimenTypeDesignation.NewInstance();
102 122
            std_IT_2.setId(3);
103 123
            DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
......
136 156
            createDerivationEvent(fu_1, mediaSpecimen_unpublished);
137 157
            mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
138 158
            mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
139

  
140 159
        }
141 160

  
142 161
        protected void createDerivationEvent(FieldUnit fu_1, DerivedUnit specimen_IT_2) {
143
            DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance();
162
            DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
144 163
            derivationEvent_3.addOriginal(fu_1);
145 164
            derivationEvent_3.addDerivative(specimen_IT_2);
146 165
        }
......
167 186
            TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(tds);
168 187
            String result = typeDesignationManager.print();
169 188

  
170
            Logger.getLogger(this.getClass()).debug(result);
189
//            Logger.getLogger(this.getClass()).debug(result);
171 190
            assertNotNull(result);
172 191
            assertEquals(
173
                    "Prionus coriatius L. Type: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 Isotype, M; Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Isotypes: BER, KEW; NameType: Prionus L. Species Plantarum"
192
                    "Prionus coriatius L. Type: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 Isotype, M; Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Isotypes: BER, KEW; Nametype: Prionus L. Species Plantarum"
174 193
                    , result
175 194
                    );
176 195

  
......
194 213

  
195 214
            TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
196 215
            String result = typeDesignationManager.print();
197
            Logger.getLogger(this.getClass()).debug(result);
216
//            Logger.getLogger(this.getClass()).debug(result);
198 217
            assertNotNull(result);
199 218
            assertEquals(
200 219
                    "Prionus coriatius L."
......
205 224
            typeDesignationManager.addTypeDesigations(null, ntd);
206 225

  
207 226
            assertEquals(
208
                    "Prionus coriatius L. NameType: Prionus L. Species Plantarum"
227
                    "Prionus coriatius L. Nametype: Prionus L. Species Plantarum"
209 228
                    , typeDesignationManager.print()
210 229
                    );
211 230

  
......
213 232
            typeDesignationManager.addTypeDesigations(null, std_HT);
214 233

  
215 234
            assertEquals(
216
                    "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; NameType: Prionus L. Species Plantarum"
235
                    "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Nametype: Prionus L. Species Plantarum"
217 236
                    , typeDesignationManager.print()
218 237
                    );
219 238
        }
220 239

  
240
        @Test
241
        public void test_desigby_fide(){
242
            TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
243
            typifiedName.setTitleCache("Prionus coriatius L.", true);
244
            TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
245
            typeDesignationManager.addTypeDesigations(null, std_LT);
246
            Reference citation = ReferenceFactory.newBook();
247
            citation.setDatePublished(TimePeriodParser.parseStringVerbatim("1989"));
248
            citation.setAuthorship(Team.NewTitledInstance("Miller", "Mill."));
249
            std_LT.addPrimaryTaxonomicSource(citation, "55");
250
            typeDesignationManager.buildStringWithCitation();
251
            assertEquals("Prionus coriatius L. Testland, near Bughausen, A.Kohlbecker 81989, 2017 (Lectotype:  LEC [designated by Decandolle & al. (1962) fide Miller (1989)])",
252
                    typeDesignationManager.print());
253
        }
254

  
221 255
        @Test
222 256
        public void test_mediaType(){
223 257

  
......
238 272
                        , typeDesignationManager.print()
239 273
                        );
240 274
            }
241

  
242 275
        }
243

  
244
        /**
245
         * {@inheritDoc}
246
         */
247
        @Override
248
        public void createTestDataSet() throws FileNotFoundException {
249
            // TODO Auto-generated method stub
250

  
251
        }
252

  
253

  
254

  
255
}
276
}

Also available in: Unified diff