Project

General

Profile

« Previous | Next » 

Revision 085f44ab

Added by Andreas Müller over 3 years ago

ref #9262 unify buildString methods in TypeDesignationSetManager and unify some minor formatting issues

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
88 88
    private static final String REFERENCE_DESIGNATED_BY = " designated by ";
89 89
    private static final String REFERENCE_FIDE = "fide ";
90 90
    private static final String SOURCE_SEPARATOR = ", ";
91
    private static final String POST_STATUS_SEPARATOR = ": ";
91 92

  
92 93
    private Map<UUID,TypeDesignationBase<?>> typeDesignations;
93 94

  
......
312 313
    }
313 314
*/
314 315

  
316
    public void buildStringWithCitation(){
317
        buildString(true);
318
    }
315 319
    public void buildString(){
316

  
317
        if(finalString == null){
318

  
319
            TaggedTextBuilder finalBuilder = new TaggedTextBuilder();
320
            finalString = "";
321

  
322
            if(getTypifiedNameCache() != null){
323
                finalString += getTypifiedNameCache() + " ";
324
                finalBuilder.add(TagEnum.name, getTypifiedNameCache(), new TypedEntityReference<>(TaxonName.class, getTypifiedNameRef().getUuid()));
325
            }
326

  
327
            int typeCount = 0;
328
            if(orderedByTypesByBaseEntity != null){
329
                for(TypedEntityReference<?> baseEntityRef : orderedByTypesByBaseEntity.keySet()) {
330

  
331
                    TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder();
332
                    if(typeCount++ > 0){
333
                        workingsetBuilder.add(TagEnum.separator, TYPE_SEPARATOR);
334
                    }
335
                    boolean isNameTypeDesignation = false;
336
                    if(SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ){
337
                        workingsetBuilder.add(TagEnum.label, "Type:");
338
                    } else{
339
                        workingsetBuilder.add(TagEnum.label, "Nametype:");
340
                        isNameTypeDesignation = true;
341
                    }
342
                    if(!baseEntityRef.getLabel().isEmpty()){
343
                        workingsetBuilder.add(TagEnum.specimenOrObservation, baseEntityRef.getLabel(), baseEntityRef);
344
                    }
345
                    TypeDesignationWorkingSet typeDesignationWorkingSet = orderedByTypesByBaseEntity.get(baseEntityRef);
346
                    int typeStatusCount = 0;
347
                    for(TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
348
                        if(typeStatusCount++ > 0){
349
                            workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_SEPARATOR);
350
                        }
351
                        boolean isPlural = typeDesignationWorkingSet.get(typeStatus).size() > 1;
352
                        if(!typeStatus.equals(NULL_STATUS)) {
353
                            workingsetBuilder.add(TagEnum.label, typeStatus.getLabel() + (isPlural ? "s:" : ","));
354
                        }
355

  
356
                        int typeDesignationCount = 0;
357
                        for(TypedEntityReference<?> typeDesignationEntityReference : createSortedList(typeDesignationWorkingSet, typeStatus)) {
358
                            if(typeDesignationCount++  > 0){
359
                               workingsetBuilder.add(TagEnum.separator, TYPE_DESIGNATION_SEPARATOR);
360
                            }
361
                            workingsetBuilder.add(TagEnum.typeDesignation, typeDesignationEntityReference.getLabel(), typeDesignationEntityReference);
362
                        }
363
                    }
364
                    typeDesignationWorkingSet.setRepresentation(workingsetBuilder.toString());
365
                    finalString += typeDesignationWorkingSet.getRepresentation();
366
                    finalBuilder.addAll(workingsetBuilder);
367
                }
368
            }
369
            finalString = finalString.trim();
370
            taggedText = finalBuilder.getTaggedText();
371
        }
320
        buildString(false);
372 321
    }
373 322

  
374
    public void buildStringWithCitation(){
323
    private void buildString(boolean withCitation){
375 324

  
376 325
        if(finalString == null){
377 326

  
......
392 341
                        workingsetBuilder.add(TagEnum.separator, TYPE_SEPARATOR);
393 342
                    }
394 343
                    boolean isNameTypeDesignation = false;
344
                    if (!withCitation){
345
                        //TODO unclear why only without citation, it probably should be another parameter like
346
                        //"with generic type" or so and comes from different requirements in cdmlight an phycobank
347
                        if(SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ){
348
                            workingsetBuilder.add(TagEnum.label, "Type:");
349
                        } else{
350
                            workingsetBuilder.add(TagEnum.label, "Nametype:");
351
                            isNameTypeDesignation = true;
352
                        }
353
                    }
395 354

  
396 355
                    if(!baseEntityRef.getLabel().isEmpty()){
397 356
                        workingsetBuilder.add(TagEnum.specimenOrObservation, baseEntityRef.getLabel(), baseEntityRef);
......
401 360
                    for(TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
402 361
                        if(typeStatusCount++  > 0){
403 362
                            workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_SEPARATOR);
404

  
405 363
                        }
406 364
                        boolean isPlural = typeDesignationWorkingSet.get(typeStatus).size() > 1;
407 365
                        if(!typeStatus.equals(NULL_STATUS)) {
408
                            workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_LEFT);
409
                            workingsetBuilder.add(TagEnum.label, typeStatus.getLabel() + (isPlural ? "s: " : ": "));
410
                         }
366
                            if (withCitation){
367
                                //TODO maybe
368
                                workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_LEFT);
369
                            }
370
                            //END
371
                            workingsetBuilder.add(TagEnum.label, typeStatus.getLabel() + (isPlural ? "s" : ""));
372
                            workingsetBuilder.add(TagEnum.postSeparator, POST_STATUS_SEPARATOR);
373
                        }
411 374
                        int typeDesignationCount = 0;
412 375
                        for(TypedEntityReference<?> typeDesignationEntityReference : createSortedList(typeDesignationWorkingSet, typeStatus)) {
413 376
                            if(typeDesignationCount++  > 0){
......
416 379

  
417 380
                            workingsetBuilder.add(TagEnum.typeDesignation, typeDesignationEntityReference.getLabel(), typeDesignationEntityReference);
418 381

  
419
                            TypeDesignationBase<?> typeDes =  typeDesignations.get(typeDesignationEntityReference.getUuid());
382
                            if (withCitation){
383
                                TypeDesignationBase<?> typeDes = typeDesignations.get(typeDesignationEntityReference.getUuid());
420 384

  
421
                            //lectotype source
422
                            OriginalSourceBase<?> lectoSource = typeDes.getSource();
423
                            if (hasLectoSource(typeDes)){
424
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_DESIGNATED_BY);
425
                                addSource(workingsetBuilder, typeDesignationEntityReference, lectoSource);
426
                            }
427
                            //general sources
428
                            if (!typeDes.getSources().isEmpty()) {
429
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_LEFT + REFERENCE_FIDE);
430
                                int count = 0;
431
                                for (IdentifiableSource source: typeDes.getSources()){
432
                                    if (count++ > 0){
433
                                        workingsetBuilder.add(TagEnum.separator, SOURCE_SEPARATOR);
385
                                //lectotype source
386
                                OriginalSourceBase<?> lectoSource = typeDes.getSource();
387
                                if (hasLectoSource(typeDes)){
388
                                    workingsetBuilder.add(TagEnum.separator, REFERENCE_DESIGNATED_BY);
389
                                    addSource(workingsetBuilder, typeDesignationEntityReference, lectoSource);
390
                                }
391
                                //general sources
392
                                if (!typeDes.getSources().isEmpty()) {
393
                                    workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_LEFT + REFERENCE_FIDE);
394
                                    int count = 0;
395
                                    for (IdentifiableSource source: typeDes.getSources()){
396
                                        if (count++ > 0){
397
                                            workingsetBuilder.add(TagEnum.separator, SOURCE_SEPARATOR);
398
                                        }
399
                                        addSource(workingsetBuilder, typeDesignationEntityReference, source);
434 400
                                    }
435
                                    addSource(workingsetBuilder, typeDesignationEntityReference, source);
401
                                    workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_RIGHT);
402
                                }
403

  
404
                                if ((!typeStatus.equals(NULL_STATUS)) &&(typeDesignationCount ==  typeDesignationWorkingSet.get(typeStatus).size())){
405
                                    workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_RIGHT);
436 406
                                }
437
                                workingsetBuilder.add(TagEnum.separator, REFERENCE_PARENTHESIS_RIGHT);
438
                            }
439 407

  
440
                            if ((!typeStatus.equals(NULL_STATUS)) &&(typeDesignationCount ==  typeDesignationWorkingSet.get(typeStatus).size())){
441
                                workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_RIGHT);
442 408
                            }
443 409
                        }
444 410
                    }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TypeDesignationSetManagerTest.java
200 200
//            Logger.getLogger(this.getClass()).debug(result);
201 201
            assertNotNull(result);
202 202
            assertEquals(
203
                    "Prionus L. Type: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 Isotype, M;"
204
                    + " Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Isotypes: BER, KEW;"
203
                    "Prionus L. Type: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 Isotype: M;"
204
                    + " Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype: OHA; Isotypes: BER, KEW;"
205 205
                    + " Nametype: Prionus coriatius L."
206 206
                    , result
207 207
                    );
......
245 245
            typeDesignationManager.addTypeDesigations(null, std_HT);
246 246

  
247 247
            assertEquals(
248
                    "Prionus L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Nametype: Prionus coriatius L."
248
                    "Prionus L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype: OHA; Nametype: Prionus coriatius L."
249 249
                    , typeDesignationManager.print()
250 250
                    );
251 251
        }
......
262 262
            citation.setAuthorship(Team.NewTitledInstance("Miller", "Mill."));
263 263
            std_LT.addPrimaryTaxonomicSource(citation, "55");
264 264
            typeDesignationManager.buildStringWithCitation();
265
            assertEquals("Prionus coriatius L. Testland, near Bughausen, A.Kohlbecker 81989, 2017 (Lectotype:  LEC designated by Decandolle & al. (1962) [fide Miller (1989)])",
265
            assertEquals("Prionus coriatius L. Testland, near Bughausen, A.Kohlbecker 81989, 2017 (Lectotype: LEC designated by Decandolle & al. (1962) [fide Miller (1989)])",
266 266
                    typeDesignationManager.print());
267 267

  
268 268
            typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
......
272 272
            ntd_LT.addPrimaryTaxonomicSource(citation, "66");
273 273
            typeDesignationManager.buildStringWithCitation();
274 274
            //TODO capital letter or not still needs to be discussed, currently it differs for SpecimenTD and NameTD in original csv data
275
            assertEquals("Prionus L. (lectotype:  Prionus arealus L. designated by Decandolle & al. (1962) [fide Miller (1989)])",
275
            assertEquals("Prionus L. (lectotype: Prionus arealus L. designated by Decandolle & al. (1962) [fide Miller (1989)])",
276 276
                    typeDesignationManager.print());
277 277
        }
278 278

  
......
292 292
                typeDesignationManager.addTypeDesigations(null, mtd_IT_unpublished);
293 293

  
294 294
                assertEquals("failed after repreating " + i + " times",
295
                        "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, [icon] p.33 in A.K. & W.K (2008) Algae of the BGBM; Isotype, [icon] B Slide A565656."
295
                        "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype: [icon] p.33 in A.K. & W.K (2008) Algae of the BGBM; Isotype: [icon] B Slide A565656."
296 296
                        , typeDesignationManager.print()
297 297
                        );
298 298
            }

Also available in: Unified diff