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