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.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.INameService;
|
17
|
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
|
18
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
19
|
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
|
20
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
21
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
22
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
23
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
24
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.NameCreator;
|
25
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* <p>NameEditorInput class.</p>
|
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
|
private static NameEditorInput instance;
|
38
|
|
39
|
/** Constant <code>ID="bulkeditor.input.name"</code> */
|
40
|
public static final String ID = "bulkeditor.input.name";
|
41
|
|
42
|
/**
|
43
|
* <p>Getter for the field <code>instance</code>.</p>
|
44
|
*
|
45
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
46
|
*/
|
47
|
public static AbstractBulkEditorInput getInstance() {
|
48
|
if (instance == null) {
|
49
|
instance = new NameEditorInput();
|
50
|
}
|
51
|
return instance;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public String getName() {
|
56
|
return BulkEditorInputType.NAME.label;
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* <p>getID</p>
|
61
|
*
|
62
|
* @return a {@link java.lang.Object} object.
|
63
|
*/
|
64
|
public static Object getID() {
|
65
|
return ID;
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
|
70
|
*/
|
71
|
/** {@inheritDoc} */
|
72
|
@Override
|
73
|
public boolean isMergingEnabled() {
|
74
|
return false;
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
protected int getPageSize() {
|
79
|
return 50;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
84
|
return CdmStore.getService(INameService.class).countByTitle(configurator);
|
85
|
}
|
86
|
|
87
|
/** {@inheritDoc} */
|
88
|
@Override
|
89
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
90
|
configurator.setPropertyPaths(getPropertyPaths());
|
91
|
return CdmStore.getSearchManager().findNames(configurator, this.getConversation());
|
92
|
}
|
93
|
|
94
|
/** {@inheritDoc}
|
95
|
@Override
|
96
|
public TaxonNameBase loadEntity(UUID uuid) {
|
97
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
98
|
return CdmStore.getService(INameService.class).load(uuid, propertyPaths);
|
99
|
}
|
100
|
*/
|
101
|
@Override
|
102
|
public boolean delete(TaxonName entity, DeleteConfiguratorBase config) {
|
103
|
NameDeletionConfigurator nameConfig = null;
|
104
|
if (config instanceof NameDeletionConfigurator){
|
105
|
nameConfig = (NameDeletionConfigurator) config;
|
106
|
} else{
|
107
|
|
108
|
}
|
109
|
return CdmStore.getService(INameService.class).delete(entity.getUuid(), nameConfig) != null;
|
110
|
}
|
111
|
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
public TaxonName save(TaxonName entity) {
|
115
|
TaxonName mergedName = null;
|
116
|
mergedName = CdmStore.getService(INameService.class).merge(entity, true).getMergedEntity();
|
117
|
return mergedName;
|
118
|
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
protected IEntityCreator<TaxonName> createEntityCreator() {
|
123
|
return new NameCreator();
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
public List<IBulkEditorSortProvider<TaxonName>> getSortProviders() {
|
128
|
List<IBulkEditorSortProvider<TaxonName>> sortProviders = super.getSortProviders();
|
129
|
|
130
|
sortProviders.add(0, new IdentifiableEntitySortProvider<>());
|
131
|
|
132
|
return sortProviders;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public String getTypeText(Object entity) {
|
137
|
if((entity instanceof TaxonName) && (((TaxonName) entity).getNomenclaturalCode() != null)){
|
138
|
return ((TaxonName) entity).getNomenclaturalCode().getTitleCache();
|
139
|
}
|
140
|
return super.getTypeText(entity);
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
public String getText(TaxonName entity) {
|
145
|
return (entity).getFullTitleCache();
|
146
|
}
|
147
|
|
148
|
@Override
|
149
|
public void merge() {
|
150
|
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
protected TaxonName loadEntity(UUID entityUuid) {
|
155
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
156
|
return CdmStore.getService(INameService.class).load(entityUuid, getPropertyPaths());
|
157
|
}
|
158
|
@Override
|
159
|
public void addSaveCandidate(TaxonName name){
|
160
|
if (!name.getHybridChildRelations().isEmpty()){
|
161
|
for (HybridRelationship rel: name.getHybridChildRelations()){
|
162
|
if (!rel.getParentName().isPersited()){
|
163
|
super.addSaveCandidate(rel.getParentName());
|
164
|
}
|
165
|
if (!rel.getHybridName().isPersited()){
|
166
|
super.addSaveCandidate(rel.getHybridName());
|
167
|
}
|
168
|
}
|
169
|
}
|
170
|
|
171
|
super.addSaveCandidate(name);
|
172
|
}
|
173
|
|
174
|
|
175
|
private List<String> getPropertyPaths(){
|
176
|
List<String> nameBasePropertyPaths = Arrays.asList(new String[] {
|
177
|
"name.descriptions",
|
178
|
"name.typeDesignations",
|
179
|
"name.status",
|
180
|
"name.nomenclaturalReference.inReference",
|
181
|
"name.taxonBases.taxonNodes",
|
182
|
"name.relationsFromThisName",
|
183
|
"name.relationsToThisName",
|
184
|
"name.homotypicalGroup.typifiedNames.taxonBases.synonyms.synonym.name.status",
|
185
|
"name.homotypicalGroup.typifiedNames.relationsToThisName.fromName"});
|
186
|
|
187
|
return nameBasePropertyPaths;
|
188
|
}
|
189
|
|
190
|
}
|