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 boolean isCacheProperty(String property) {
|
112
|
if(property.equals(PROPERTY_PROTECT_NAME_CACHE)
|
113
|
|| property.equals(PROPERTY_PROTECT_AUTHORSHIP_CACHE)){
|
114
|
return true;
|
115
|
}
|
116
|
return super.isCacheProperty(property);
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public String getName() {
|
121
|
return BulkEditorInputType.NAME.label;
|
122
|
}
|
123
|
|
124
|
public static Object getID() {
|
125
|
return ID;
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
public boolean isMergingEnabled() {
|
130
|
return false;
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
protected int getPageSize() {
|
135
|
return 50;
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
140
|
return CdmStore.getService(INameService.class).countByTitle(configurator);
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
145
|
configurator.setPropertyPaths(getPropertyPaths());
|
146
|
return CdmStore.getSearchManager().findNames(configurator, this.getConversation());
|
147
|
}
|
148
|
|
149
|
@Override
|
150
|
public boolean delete(TaxonName entity, DeleteConfiguratorBase config) {
|
151
|
NameDeletionConfigurator nameConfig = null;
|
152
|
if (config instanceof NameDeletionConfigurator){
|
153
|
nameConfig = (NameDeletionConfigurator) config;
|
154
|
} else{
|
155
|
|
156
|
}
|
157
|
return CdmStore.getService(INameService.class).delete(entity.getUuid(), nameConfig) != null;
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public TaxonName save(TaxonName entity) {
|
162
|
TaxonName mergedName = null;
|
163
|
mergedName = CdmStore.getService(INameService.class).merge(entity, true).getMergedEntity();
|
164
|
return mergedName;
|
165
|
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
protected IEntityCreator<TaxonName> createEntityCreator() {
|
170
|
return new NameCreator();
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
public List<IBulkEditorSortProvider<TaxonName>> getSortProviders() {
|
175
|
List<IBulkEditorSortProvider<TaxonName>> sortProviders = super.getSortProviders();
|
176
|
|
177
|
sortProviders.add(0, new IdentifiableEntitySortProvider<>());
|
178
|
|
179
|
return sortProviders;
|
180
|
}
|
181
|
|
182
|
@Override
|
183
|
public String getTypeText(Object entity) {
|
184
|
if((entity instanceof TaxonName) && (((TaxonName) entity).getNameType() != null)){
|
185
|
return ((TaxonName) entity).getNameType().getTitleCache();
|
186
|
}
|
187
|
return super.getTypeText(entity);
|
188
|
}
|
189
|
|
190
|
@Override
|
191
|
public String getText(TaxonName entity) {
|
192
|
return (entity).getFullTitleCache();
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
public void merge() {
|
197
|
|
198
|
}
|
199
|
|
200
|
@Override
|
201
|
protected TaxonName loadEntity(UUID entityUuid) {
|
202
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
203
|
return CdmStore.getService(INameService.class).load(entityUuid, getPropertyPaths());
|
204
|
}
|
205
|
@Override
|
206
|
public void addSaveCandidate(TaxonName name){
|
207
|
if (!name.getHybridChildRelations().isEmpty()){
|
208
|
for (HybridRelationship rel: name.getHybridChildRelations()){
|
209
|
if (!rel.getParentName().isPersited()){
|
210
|
super.addSaveCandidate(rel.getParentName());
|
211
|
}
|
212
|
if (!rel.getHybridName().isPersited()){
|
213
|
super.addSaveCandidate(rel.getHybridName());
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
|
218
|
super.addSaveCandidate(name);
|
219
|
}
|
220
|
|
221
|
|
222
|
private List<String> getPropertyPaths(){
|
223
|
List<String> nameBasePropertyPaths = Arrays.asList(new String[] {
|
224
|
"descriptions.descriptionElements.multilanguageText",
|
225
|
"descriptions.descriptionElements.*",
|
226
|
"typeDesignations",
|
227
|
"status",
|
228
|
"combinationAuthorship",
|
229
|
"exCombinationAuthorship",
|
230
|
"inCombinationAuthorship",
|
231
|
"basionymAuthorship",
|
232
|
"exBasionymAuthorship",
|
233
|
"inBasionymAuthorship",
|
234
|
"nomenclaturalReference.inReference",
|
235
|
"taxonBases.taxonNodes",
|
236
|
"relationsFromThisName",
|
237
|
"relationsToThisName",
|
238
|
"homotypicalGroup.typifiedNames.taxonBases.synonyms.synonym.name.status",
|
239
|
"homotypicalGroup.typifiedNames.relationsToThisName.fromName"});
|
240
|
|
241
|
return nameBasePropertyPaths;
|
242
|
}
|
243
|
|
244
|
}
|