Project

General

Profile

Download (5.48 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.cdm.api.facade;
10

    
11
import java.util.UUID;
12

    
13
import org.apache.commons.lang.StringUtils;
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.common.CdmUtils;
17
import eu.etaxonomy.cdm.model.agent.Institution;
18
import eu.etaxonomy.cdm.model.occurrence.Collection;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20
import eu.etaxonomy.cdm.strategy.StrategyBase;
21
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
22

    
23
/**
24
 * @author a.mueller
25
 * @since 03.06.2010
26
 *
27
 * @deprecated with #9678 a similar cache strategy (DerivedUnitCacheStrategy)
28
 *      was implemented in cdmlib-model. This class may be removed in future.
29
 */
30
@Deprecated
31
public class DerivedUnitFacadeCacheStrategy
32
        extends StrategyBase
33
        implements IIdentifiableEntityCacheStrategy<DerivedUnit> {
34

    
35
    private static final long serialVersionUID = 1578628591216605619L;
36
	@SuppressWarnings("unused")
37
	private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategy.class);
38

    
39
	private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
40

    
41
	@Override
42
	protected UUID getUuid() {return uuid;}
43

    
44
	private boolean includeEmptySeconds = false;
45
	private boolean includeReferenceSystem = true;
46

    
47
	@Override
48
    public String getTitleCache(DerivedUnit derivedUnit) {
49
	    return getTitleCache(derivedUnit, false, true);
50
	}
51

    
52
	public String getTitleCache(DerivedUnit derivedUnit, boolean skipFieldUnit, boolean addTrailingDot) {
53

    
54
	    String result = "";
55
	    DerivedUnitFacadeFieldUnitCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldUnitCacheStrategy();
56

    
57
		DerivedUnitFacade facade;
58
		// NOTE: regarding the string representations of MediaTypes, see https://dev.e-taxonomy.eu/redmine/issues/7608
59
		try {
60
			DerivedUnitFacadeConfigurator config = DerivedUnitFacadeConfigurator.NewInstance();
61
			config.setFirePropertyChangeEvents(false);
62
			facade = DerivedUnitFacade.NewInstance(derivedUnit, config);
63

    
64
	        if(!skipFieldUnit){
65
	            result += fieldStrategy.getFieldData(facade);
66
	        }
67

    
68
			//exsiccatum
69
			String exsiccatum = null;
70
			try {
71
				exsiccatum = facade.getExsiccatum();
72
			} catch (MethodNotSupportedByDerivedUnitTypeException e) {
73
				//NO exsiccatum if this facade doe not represent a specimen
74
			}
75
			result = CdmUtils.concat("; ", result, exsiccatum);
76

    
77
			//Herbarium & identifier
78
			String barcode = getSpecimenLabel(facade);
79
	        if (StringUtils.isNotBlank(barcode)) {
80
	            result = (result + " (" +  barcode + ")").trim();
81
	        }
82
			//result
83
			result = fieldStrategy.addPlantDescription(result, facade);
84

    
85
			if (addTrailingDot){
86
			    result = CdmUtils.addTrailingDotIfNotExists(result);
87
			}
88

    
89
		} catch (DerivedUnitFacadeNotSupportedException e) {
90
			e.printStackTrace();
91
		}
92

    
93
		return result;
94
	}
95

    
96
    /**
97
     * Produces the collection barcode which is the combination of the collection code and
98
     * accession number.
99
     *
100
     * @param result
101
     * @param facade
102
     * @return
103
     */
104
    public String getSpecimenLabel(DerivedUnitFacade facade) {
105
        String code = getCode(facade);
106
        String identifier = getUnitNumber(facade /*, code*/);
107
        String collectionData = CdmUtils.concat(" ", code, identifier);
108
        return collectionData;
109
    }
110

    
111

    
112
    /**
113
     * Computes the unit number which might be an accession number, barcode, catalogue number, ...
114
     * In future if the unit number starts with the same string as the barcode
115
     * it might be replaced.
116
     * @param facade the derived unit facade
117
     */
118
    private String getUnitNumber(DerivedUnitFacade facade) {
119
        String result;
120
        if (isNotBlank(facade.getAccessionNumber())){
121
            result = facade.getAccessionNumber();
122
        }else if (isNotBlank(facade.getBarcode())){
123
            result = facade.getBarcode();
124
        }else{
125
            result = facade.getCatalogNumber();
126
        }
127
        String code = getCode(facade);
128
        if(result != null){
129
            result = result.trim();
130
            if(isNotBlank(code) && result.startsWith(code + " ")){
131
                result = result.replaceAll("^" + code + "\\s", "");
132
            }
133
        }
134
        return result;
135
    }
136

    
137
	private String getCode(DerivedUnitFacade facade) {
138
		String code = "";
139
		if(facade.getCollection() != null){
140
			code = facade.getCollection().getCode();
141
			if (StringUtils.isBlank(code)){
142
			    code = facade.getCollection().getName();
143
			}
144
			if (StringUtils.isBlank(code)){
145
				Institution institution = facade.getCollection().getInstitute();
146
				if (institution != null){
147
					code = institution.getCode();
148
				}
149
				if (StringUtils.isBlank(code)){
150
					Collection superCollection = facade.getCollection().getSuperCollection();
151
					if (superCollection != null){
152
						code = superCollection.getCode();
153
					}
154
				}
155
			}
156
		}
157
		return code;
158
	}
159

    
160
// ************************** GETTER / SETTER ******************************************************
161

    
162
	public boolean isIncludeSeconds() {
163
		return includeEmptySeconds;
164
	}
165

    
166
	public void setIncludeSeconds(boolean includeSeconds) {
167
		this.includeEmptySeconds = includeSeconds;
168
	}
169

    
170
	public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
171
		this.includeReferenceSystem = includeReferenceSystem;
172
	}
173

    
174
	public boolean isIncludeReferenceSystem() {
175
		return includeReferenceSystem;
176
	}
177

    
178
}
(2-2/6)