Project

General

Profile

Revision 3c0cadbb

ID3c0cadbbcdb4d44a395a6ab3131090ef811eac3f
Parent a077e729
Child d6455c9e

Added by Patrick Plitzner about 3 years ago

fix #7775 Add source information to description titlecache

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/description/DescriptionBaseDefaultCacheStrategy.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.strategy.cache.description;
11

  
12
import java.util.Set;
13
import java.util.stream.Collectors;
14

  
15
import eu.etaxonomy.cdm.common.CdmUtils;
16
import eu.etaxonomy.cdm.model.common.Marker;
17
import eu.etaxonomy.cdm.model.common.MarkerType;
18
import eu.etaxonomy.cdm.model.description.DescriptionBase;
19
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20
import eu.etaxonomy.cdm.strategy.StrategyBase;
21
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
22

  
23
public abstract class DescriptionBaseDefaultCacheStrategy<T extends DescriptionBase<IIdentifiableEntityCacheStrategy<T>>> extends StrategyBase implements
24
		IIdentifiableEntityCacheStrategy<T> {
25

  
26
    private static final long serialVersionUID = 2704481466414887850L;
27

  
28
    private static final String FOR = " for ";
29

  
30
	@Override
31
    public String getTitleCache(T description) {
32
		String title;
33
		SpecimenOrObservationBase specimen = description.getDescribedSpecimenOrObservation();
34
		if (specimen == null){
35
			title = getFirstPart(description);
36
			title = title.replace(FOR, "");
37
		}else{
38
			title = specimen.getTitleCache();
39
			title = getFirstPart(description) + title;
40
		}
41
		return title;
42
	}
43

  
44
	protected String getFirstPart(T description){
45
		Set<Marker> markers = description.getMarkers();
46
		MarkerType markerType = MarkerType.USE();
47
		Boolean isUseDescription = false;
48
		for (Marker marker : markers) {
49
			if(marker.getMarkerType().equals(markerType)) {
50
				isUseDescription = true;
51
			}
52
		}
53
		String firstPart;
54
		if (description.isImageGallery()){
55
			firstPart = "Image gallery "+getSourceString(description)+" for ";
56
		} else if (isUseDescription) {
57
		    firstPart = "Use description "+getSourceString(description)+" for ";
58
		} else {
59
		    firstPart = getDescriptionName()+" "+getSourceString(description)+" for ";
60
		}
61
		return firstPart+FOR;
62
	}
63

  
64
	protected abstract String getDescriptionName();
65

  
66
    private String getSourceString(T description){
67
	    String sourceString = "";
68
	    sourceString = description.getSources().stream()
69
	            .filter(source->source.getCitation()!=null)
70
	            .map(source->source.getCitation().getTitleCache())
71
	            .collect(Collectors.joining(","));
72
	    if(CdmUtils.isNotBlank(sourceString)){
73
	        sourceString = "from "+sourceString+" ";
74
	    }
75
	    return sourceString;
76
	}
77
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/description/SpecimenDescriptionDefaultCacheStrategy.java
9 9

  
10 10
package eu.etaxonomy.cdm.strategy.cache.description;
11 11

  
12
import java.util.Set;
13 12
import java.util.UUID;
14 13

  
15
import eu.etaxonomy.cdm.model.common.Marker;
16
import eu.etaxonomy.cdm.model.common.MarkerType;
17 14
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
18
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
19
import eu.etaxonomy.cdm.strategy.StrategyBase;
20
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
21 15

  
22
public class SpecimenDescriptionDefaultCacheStrategy extends StrategyBase implements
23
		IIdentifiableEntityCacheStrategy<SpecimenDescription> {
16
public class SpecimenDescriptionDefaultCacheStrategy extends DescriptionBaseDefaultCacheStrategy<SpecimenDescription> {
24 17
    private static final long serialVersionUID = 310092633142719872L;
25 18

  
26 19
    final static UUID uuid = UUID.fromString("73c03fc4-0429-4ca1-b2cb-b9a56aad4d22");
......
31 24
	}
32 25

  
33 26
	@Override
34
    public String getTitleCache(SpecimenDescription specimenDescription) {
35
		String title;
36
		SpecimenOrObservationBase specimen = specimenDescription.getDescribedSpecimenOrObservation();
37
		if (specimen == null){
38
			title = getFirstPart(specimenDescription);
39
			title = title.replace(" for ", "");
40
		}else{
41
			title = specimen.getTitleCache();
42
			title = getFirstPart(specimenDescription) + title;
43
		}
44
		return title;
27
	protected String getDescriptionName() {
28
	    return "Specimen description";
45 29
	}
46 30

  
47
	private String getFirstPart(SpecimenDescription specimenDescription){
48
		Set<Marker> markers = specimenDescription.getMarkers();
49
		MarkerType markerType = MarkerType.USE();
50
		Boolean isUseDescription = false;
51
		for (Marker marker : markers) {
52
			if(marker.getMarkerType().equals(markerType)) {
53
				isUseDescription = true;
54
			}
55
		}
56
		if (specimenDescription.isImageGallery()){
57
			return "Image gallery for " ;
58
		} else if (isUseDescription) {
59
			return "Use description for  ";
60
		} else {
61
			return "Specimen description for ";
62
		}
63
	}
64 31
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/description/TaxonDescriptionDefaultCacheStrategy.java
9 9

  
10 10
package eu.etaxonomy.cdm.strategy.cache.description;
11 11

  
12
import java.util.Set;
13 12
import java.util.UUID;
14 13

  
15
import eu.etaxonomy.cdm.model.common.Marker;
16
import eu.etaxonomy.cdm.model.common.MarkerType;
17 14
import eu.etaxonomy.cdm.model.description.TaxonDescription;
18 15
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.strategy.StrategyBase;
20
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
21 16

  
22
public class TaxonDescriptionDefaultCacheStrategy extends StrategyBase implements
23
		IIdentifiableEntityCacheStrategy<TaxonDescription> {
17
public class TaxonDescriptionDefaultCacheStrategy extends DescriptionBaseDefaultCacheStrategy<TaxonDescription>{
24 18

  
25
	final static UUID uuid = UUID.fromString("0517ae48-597d-4d6b-9f18-8752d689720d");
19
    private static final long serialVersionUID = -3631745932476721570L;
20

  
21
    final static UUID uuid = UUID.fromString("0517ae48-597d-4d6b-9f18-8752d689720d");
26 22

  
27 23
	@Override
28 24
	protected UUID getUuid() {
......
47 43
		return title;
48 44
	}
49 45

  
50
	private String getFirstPart(TaxonDescription taxonDescription){
51
		Set<Marker> markers = taxonDescription.getMarkers();
52
		MarkerType markerType = MarkerType.USE();
53
		Boolean isUseDescription = false;
54
		for (Marker marker : markers) {
55
			if(marker.getMarkerType().equals(markerType)) {
56
				isUseDescription = true;
57
			}
58
		}
59
		if (taxonDescription.isImageGallery()){
60
			return "Image gallery for " ;
61
		} else if (isUseDescription) {
62
			return "Use description for  ";
63
		} else {
64
			return "Factual data for ";
65
		}
46
	@Override
47
	protected String getDescriptionName() {
48
	    return "Factual Data Set";
66 49
	}
50

  
67 51
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)