Project

General

Profile

Download (7.29 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.taxeditor.bulkeditor.input;
11

    
12
import java.util.ArrayList;
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.api.service.INameService;
18
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
19
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
20
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
21
import eu.etaxonomy.cdm.model.name.HybridRelationship;
22
import eu.etaxonomy.cdm.model.name.TaxonName;
23
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
24
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
25
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.NameCreator;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 *
31
 * @author p.ciardelli
32
 * @created 20.08.2009
33
 */
34
public class NameEditorInput extends AbstractBulkEditorInput<TaxonName> {
35

    
36
	private static final long serialVersionUID = -3085029575759626823L;
37

    
38
	private static NameEditorInput instance;
39

    
40
	public static final String ID = "bulkeditor.input.name";
41

    
42
	private static final String PROPERTY_NAME_CACHE = "Name Cache";
43
	private static final String PROPERTY_PROTECT_NAME_CACHE = "Protect Name Cache";
44
	private static final String PROPERTY_AUTHORSHIP_CACHE = "Authorship Cache";
45
	private static final String PROPERTY_PROTECT_AUTHORSHIP_CACHE = "Protect Authorship Cache";
46
	private static final String PROPERTY_GENUS = "Genus";
47
	private static final String PROPERTY_INFRA_GENERIC = "Infra Generic";
48
	private static final String PROPERTY_SPECIFIC_EPITHET = "Spec. Epithet";
49
	private static final String PROPERTY_INFRA_SPECIFIC_EPITHET = "Infra Spec. Epithet";
50

    
51
	public static AbstractBulkEditorInput getInstance() {
52
		if (instance == null) {
53
			instance = new NameEditorInput();
54
		}
55
		return instance;
56
	}
57

    
58
	@Override
59
    protected List<String> getPropertyKeys_internal() {
60
        List<String> propertyKeysInternal = new ArrayList<>();
61
        propertyKeysInternal.add(PROPERTY_NAME_CACHE);
62
        propertyKeysInternal.add(PROPERTY_PROTECT_NAME_CACHE);
63
        propertyKeysInternal.add(PROPERTY_AUTHORSHIP_CACHE);
64
        propertyKeysInternal.add(PROPERTY_PROTECT_AUTHORSHIP_CACHE);
65
        propertyKeysInternal.add(PROPERTY_GENUS);
66
        propertyKeysInternal.add(PROPERTY_INFRA_GENERIC);
67
        propertyKeysInternal.add(PROPERTY_SPECIFIC_EPITHET);
68
        propertyKeysInternal.add(PROPERTY_INFRA_SPECIFIC_EPITHET);
69
        return propertyKeysInternal;
70
    }
71

    
72
	@Override
73
	public Object getPropertyValue(TaxonName cdmBase, String property) {
74
	    if(property.equals(PROPERTY_NAME_CACHE)){
75
	        return cdmBase.getNameCache();
76
	    }
77
	    else if(property.equals(PROPERTY_PROTECT_NAME_CACHE)){
78
	        return cdmBase.isProtectedNameCache();
79
	    }
80
	    else if(property.equals(PROPERTY_AUTHORSHIP_CACHE)){
81
	        return cdmBase.getAuthorshipCache();
82
	    }
83
	    else if(property.equals(PROPERTY_PROTECT_AUTHORSHIP_CACHE)){
84
	        return cdmBase.isProtectedAuthorshipCache();
85
	    }
86
	    else if(property.equals(PROPERTY_GENUS)){
87
	        return cdmBase.getGenusOrUninomial();
88
	    }
89
	    else if(property.equals(PROPERTY_INFRA_GENERIC)){
90
	        return cdmBase.getInfraGenericEpithet();
91
	    }
92
	    else if(property.equals(PROPERTY_SPECIFIC_EPITHET)){
93
	        return cdmBase.getSpecificEpithet();
94
	    }
95
	    else if(property.equals(PROPERTY_INFRA_SPECIFIC_EPITHET)){
96
	        return cdmBase.getInfraSpecificEpithet();
97
	    }
98
	    return super.getPropertyValue(cdmBase, property);
99
	}
100

    
101
	@Override
102
	public boolean isBooleanProperty(String property) {
103
	    if(property.equals(PROPERTY_PROTECT_NAME_CACHE)
104
	            || property.equals(PROPERTY_PROTECT_AUTHORSHIP_CACHE)){
105
	        return true;
106
	    }
107
	    return super.isBooleanProperty(property);
108
	}
109

    
110
    @Override
111
    public String getName() {
112
		return BulkEditorInputType.NAME.label;
113
	}
114

    
115
	public static Object getID() {
116
		return ID;
117
	}
118

    
119
	@Override
120
	public boolean isMergingEnabled() {
121
		return false;
122
	}
123

    
124
	@Override
125
	protected int getPageSize() {
126
	    return 50;
127
	}
128

    
129
	@Override
130
	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
131
	    return CdmStore.getService(INameService.class).countByTitle(configurator);
132
	}
133

    
134
	@Override
135
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
136
		configurator.setPropertyPaths(getPropertyPaths());
137
		return CdmStore.getSearchManager().findNames(configurator, this.getConversation());
138
	}
139

    
140
	@Override
141
    public boolean delete(TaxonName entity, DeleteConfiguratorBase config)  {
142
		NameDeletionConfigurator nameConfig = null;
143
		if (config instanceof NameDeletionConfigurator){
144
			nameConfig = (NameDeletionConfigurator) config;
145
		} else{
146

    
147
		}
148
		return CdmStore.getService(INameService.class).delete(entity.getUuid(), nameConfig) != null;
149
	}
150

    
151
	@Override
152
    public TaxonName save(TaxonName entity) {
153
		TaxonName mergedName = null;
154
		mergedName =  CdmStore.getService(INameService.class).merge(entity, true).getMergedEntity();
155
	   	return mergedName;
156

    
157
	}
158

    
159
	@Override
160
	protected IEntityCreator<TaxonName> createEntityCreator() {
161
		return new NameCreator();
162
	}
163

    
164
	@Override
165
	public List<IBulkEditorSortProvider<TaxonName>> getSortProviders() {
166
		List<IBulkEditorSortProvider<TaxonName>> sortProviders = super.getSortProviders();
167

    
168
		sortProviders.add(0, new IdentifiableEntitySortProvider<>());
169

    
170
		return sortProviders;
171
	}
172

    
173
	@Override
174
	public String getTypeText(Object entity) {
175
		if((entity instanceof TaxonName) && (((TaxonName) entity).getNomenclaturalCode() != null)){
176
			return ((TaxonName) entity).getNomenclaturalCode().getTitleCache();
177
		}
178
		return super.getTypeText(entity);
179
	}
180

    
181
	@Override
182
	public String getText(TaxonName entity) {
183
		return (entity).getFullTitleCache();
184
	}
185

    
186
    @Override
187
    public void merge() {
188

    
189
    }
190

    
191
	@Override
192
	protected TaxonName loadEntity(UUID entityUuid) {
193
		List<String> propertyPaths = Arrays.asList(new String[]{});
194
		return CdmStore.getService(INameService.class).load(entityUuid, getPropertyPaths());
195
	}
196
	@Override
197
	 public void addSaveCandidate(TaxonName name){
198
	    if (!name.getHybridChildRelations().isEmpty()){
199
	        for (HybridRelationship rel: name.getHybridChildRelations()){
200
	            if (!rel.getParentName().isPersited()){
201
	                super.addSaveCandidate(rel.getParentName());
202
	            }
203
	            if (!rel.getHybridName().isPersited()){
204
                    super.addSaveCandidate(rel.getHybridName());
205
                }
206
	        }
207
	    }
208

    
209
        super.addSaveCandidate(name);
210
    }
211

    
212

    
213
    private List<String> getPropertyPaths(){
214
    	 List<String> nameBasePropertyPaths = Arrays.asList(new String[] {
215
    	 "name.descriptions",
216
         "name.typeDesignations",
217
         "name.status",
218
         "name.nomenclaturalReference.inReference",
219
         "name.taxonBases.taxonNodes",
220
         "name.relationsFromThisName",
221
         "name.relationsToThisName",
222
         "name.homotypicalGroup.typifiedNames.taxonBases.synonyms.synonym.name.status",
223
         "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName"});
224

    
225
    	 return nameBasePropertyPaths;
226
    }
227

    
228
}
(6-6/11)