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.DeleteResult;
|
18
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
19
|
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
|
20
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
21
|
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
|
22
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
23
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
25
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
27
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
28
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
29
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.OccurrenceCreator;
|
32
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
33
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
|
36
|
/**
|
37
|
* @author n.hoffmann
|
38
|
* @created Jun 16, 2010
|
39
|
*/
|
40
|
public class OccurrenceEditorInput extends AbstractBulkEditorInput<SpecimenOrObservationBase> {
|
41
|
|
42
|
private static final long serialVersionUID = 1014860873939989973L;
|
43
|
|
44
|
public static final String ID = "bulkeditor.input.occurrence"; //$NON-NLS-1$
|
45
|
|
46
|
private static final String PROPERTY_PUBLISH = "Publish";
|
47
|
private static final String PROPERTY_COUNTRY = "Country";
|
48
|
private static final String PROPERTY_COLLECTOR = "Collector";
|
49
|
private static final String PROPERTY_FIELD_NUMBER = "Field Number";
|
50
|
private static final String PROPERTY_ACCESSION_NUMBER = "Acc. Number";
|
51
|
private static final String PROPERTY_BARCODE = "Barcode";
|
52
|
private static final String PROPERTY_CATALOG_NUMBER = "Catalog Number";
|
53
|
private static final String PROPERTY_COLLECTION = "Collection";
|
54
|
|
55
|
private static OccurrenceEditorInput instance;
|
56
|
|
57
|
public static AbstractBulkEditorInput<SpecimenOrObservationBase> getInstance() {
|
58
|
if (instance == null) {
|
59
|
instance = new OccurrenceEditorInput();
|
60
|
}
|
61
|
return instance;
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
protected List<String> getPropertyKeys_internal() {
|
66
|
List<String> propertyKeysInternal = new ArrayList<>();
|
67
|
propertyKeysInternal.add(PROPERTY_PUBLISH);
|
68
|
propertyKeysInternal.add(PROPERTY_COUNTRY);
|
69
|
propertyKeysInternal.add(PROPERTY_COLLECTOR);
|
70
|
propertyKeysInternal.add(PROPERTY_FIELD_NUMBER);
|
71
|
propertyKeysInternal.add(PROPERTY_ACCESSION_NUMBER);
|
72
|
propertyKeysInternal.add(PROPERTY_BARCODE);
|
73
|
propertyKeysInternal.add(PROPERTY_CATALOG_NUMBER);
|
74
|
propertyKeysInternal.add(PROPERTY_COLLECTION);
|
75
|
return propertyKeysInternal;
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public Object getPropertyValue(SpecimenOrObservationBase cdmBase, String property) {
|
80
|
if(property.equals(PROPERTY_PUBLISH)){
|
81
|
return cdmBase.isPublish();
|
82
|
}
|
83
|
else if(property.equals(PROPERTY_COUNTRY)){
|
84
|
return getCountry(cdmBase);
|
85
|
}
|
86
|
else if(property.equals(PROPERTY_COLLECTOR)){
|
87
|
return getCollector(cdmBase);
|
88
|
}
|
89
|
else if(property.equals(PROPERTY_FIELD_NUMBER)){
|
90
|
return getFieldNumber(cdmBase);
|
91
|
}
|
92
|
else if(property.equals(PROPERTY_ACCESSION_NUMBER)){
|
93
|
return getAccessionNumber(cdmBase);
|
94
|
}
|
95
|
else if(property.equals(PROPERTY_BARCODE)){
|
96
|
return getBarcode(cdmBase);
|
97
|
}
|
98
|
else if(property.equals(PROPERTY_CATALOG_NUMBER)){
|
99
|
return getCatalogNumber(cdmBase);
|
100
|
}
|
101
|
else if(property.equals(PROPERTY_COLLECTION)){
|
102
|
return getCollection(cdmBase);
|
103
|
}
|
104
|
return super.getPropertyValue(cdmBase, property);
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public boolean isBooleanProperty(String property) {
|
109
|
if(property.equals(PROPERTY_PUBLISH)){
|
110
|
return true;
|
111
|
}
|
112
|
return super.isBooleanProperty(property);
|
113
|
}
|
114
|
|
115
|
private Object getCollector(SpecimenOrObservationBase<?> cdmBase) {
|
116
|
if(cdmBase.isInstanceOf(FieldUnit.class)){
|
117
|
GatheringEvent gatheringEvent = HibernateProxyHelper.deproxy(cdmBase, FieldUnit.class).getGatheringEvent();
|
118
|
if(gatheringEvent!=null){
|
119
|
return gatheringEvent.getCollector();
|
120
|
}
|
121
|
}
|
122
|
return null;
|
123
|
}
|
124
|
|
125
|
private Object getCountry(SpecimenOrObservationBase<?> cdmBase) {
|
126
|
if(cdmBase.isInstanceOf(FieldUnit.class)){
|
127
|
GatheringEvent gatheringEvent = HibernateProxyHelper.deproxy(cdmBase, FieldUnit.class).getGatheringEvent();
|
128
|
if(gatheringEvent!=null && gatheringEvent.getCountry()!=null){
|
129
|
return gatheringEvent.getCountry().getLabel();
|
130
|
}
|
131
|
}
|
132
|
return null;
|
133
|
}
|
134
|
|
135
|
private Object getFieldNumber(SpecimenOrObservationBase<?> cdmBase) {
|
136
|
if(cdmBase.isInstanceOf(FieldUnit.class)){
|
137
|
return HibernateProxyHelper.deproxy(cdmBase, FieldUnit.class).getFieldNumber();
|
138
|
}
|
139
|
return null;
|
140
|
}
|
141
|
|
142
|
private Object getAccessionNumber(SpecimenOrObservationBase<?> cdmBase) {
|
143
|
if(cdmBase.isInstanceOf(DerivedUnit.class)){
|
144
|
return HibernateProxyHelper.deproxy(cdmBase, DerivedUnit.class).getAccessionNumber();
|
145
|
}
|
146
|
return null;
|
147
|
}
|
148
|
|
149
|
private Object getBarcode(SpecimenOrObservationBase<?> cdmBase) {
|
150
|
if(cdmBase.isInstanceOf(DerivedUnit.class)){
|
151
|
return HibernateProxyHelper.deproxy(cdmBase, DerivedUnit.class).getBarcode();
|
152
|
}
|
153
|
return null;
|
154
|
}
|
155
|
|
156
|
private Object getCatalogNumber(SpecimenOrObservationBase<?> cdmBase) {
|
157
|
if(cdmBase.isInstanceOf(DerivedUnit.class)){
|
158
|
return HibernateProxyHelper.deproxy(cdmBase, DerivedUnit.class).getCatalogNumber();
|
159
|
}
|
160
|
return null;
|
161
|
}
|
162
|
|
163
|
private Object getCollection(SpecimenOrObservationBase<?> cdmBase) {
|
164
|
if(cdmBase.isInstanceOf(DerivedUnit.class)){
|
165
|
Collection collection = HibernateProxyHelper.deproxy(cdmBase, DerivedUnit.class).getCollection();
|
166
|
if(collection!=null){
|
167
|
return collection.getTitleCache();
|
168
|
}
|
169
|
}
|
170
|
return null;
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
175
|
return CdmStore.getService(IOccurrenceService.class).countByTitle(configurator);
|
176
|
}
|
177
|
|
178
|
@Override
|
179
|
protected List<SpecimenOrObservationBase> listEntities(
|
180
|
IIdentifiableEntityServiceConfigurator configurator) {
|
181
|
return CdmStore.getSearchManager().findOccurrences(configurator, false);
|
182
|
}
|
183
|
|
184
|
@Override
|
185
|
public String getName() {
|
186
|
return BulkEditorInputType.OCCURRENCE.label;
|
187
|
}
|
188
|
|
189
|
@Override
|
190
|
public String getEditorName() {
|
191
|
return Messages.OccurrenceEditorInput_EDITOR_NAME;
|
192
|
}
|
193
|
|
194
|
@Override
|
195
|
public String getTypeText(Object entity) {
|
196
|
if(HibernateProxyHelper.isInstanceOf(entity, SpecimenOrObservationBase.class)){
|
197
|
return ((SpecimenOrObservationBase) entity).getRecordBasis().getMessage();
|
198
|
}
|
199
|
return super.getTypeText(entity);
|
200
|
}
|
201
|
|
202
|
public static Object getId(){
|
203
|
return ID;
|
204
|
}
|
205
|
|
206
|
@Override
|
207
|
public boolean delete(SpecimenOrObservationBase entity, DeleteConfiguratorBase config ) throws ReferencedObjectUndeletableException {
|
208
|
DeleteResult deleteResult;
|
209
|
SpecimenDeleteConfigurator specimenConfig;
|
210
|
if (config instanceof SpecimenDeleteConfigurator){
|
211
|
specimenConfig = (SpecimenDeleteConfigurator)config;
|
212
|
}else{
|
213
|
specimenConfig = new SpecimenDeleteConfigurator();
|
214
|
}
|
215
|
deleteResult = CdmStore.getService(IOccurrenceService.class).delete(entity.getUuid(), specimenConfig);
|
216
|
|
217
|
return deleteResult.isOk();
|
218
|
}
|
219
|
|
220
|
@Override
|
221
|
public SpecimenOrObservationBase<?> save(SpecimenOrObservationBase entity) {
|
222
|
return CdmStore.getService(IOccurrenceService.class).merge(entity, true).getMergedEntity();
|
223
|
|
224
|
}
|
225
|
|
226
|
@Override
|
227
|
protected IEntityCreator<SpecimenOrObservationBase> createEntityCreator() {
|
228
|
return new OccurrenceCreator();
|
229
|
}
|
230
|
|
231
|
@Override
|
232
|
public List<IBulkEditorSortProvider<SpecimenOrObservationBase>> getSortProviders() {
|
233
|
List<IBulkEditorSortProvider<SpecimenOrObservationBase>> sortProviders = super.getSortProviders();
|
234
|
|
235
|
sortProviders.add(0, new IdentifiableEntitySortProvider<SpecimenOrObservationBase>());
|
236
|
|
237
|
return sortProviders;
|
238
|
}
|
239
|
|
240
|
@Override
|
241
|
public void merge() {
|
242
|
|
243
|
}
|
244
|
|
245
|
@Override
|
246
|
protected SpecimenOrObservationBase loadEntity(UUID entityUuid) {
|
247
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
248
|
return CdmStore.getService(IOccurrenceService.class).load(entityUuid, propertyPaths);
|
249
|
}
|
250
|
}
|