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.DeleteResult;
|
17
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
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.SpecimenDeleteConfigurator;
|
21
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
24
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
25
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
26
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.OccurrenceCreator;
|
27
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
28
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
|
31
|
/**
|
32
|
* <p>OccurrenceEditorInput class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created Jun 16, 2010
|
36
|
*/
|
37
|
public class OccurrenceEditorInput extends AbstractBulkEditorInput<SpecimenOrObservationBase> {
|
38
|
|
39
|
/**
|
40
|
*
|
41
|
*/
|
42
|
private static final long serialVersionUID = 1014860873939989973L;
|
43
|
|
44
|
/** Constant <code>ID="bulkeditor.input.occurrence"</code> */
|
45
|
public static final String ID = "bulkeditor.input.occurrence"; //$NON-NLS-1$
|
46
|
|
47
|
private static OccurrenceEditorInput instance;
|
48
|
|
49
|
/**
|
50
|
* <p>Getter for the field <code>instance</code>.</p>
|
51
|
*
|
52
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
53
|
*/
|
54
|
public static AbstractBulkEditorInput<SpecimenOrObservationBase> getInstance() {
|
55
|
if (instance == null) {
|
56
|
instance = new OccurrenceEditorInput();
|
57
|
}
|
58
|
return instance;
|
59
|
}
|
60
|
|
61
|
/** {@inheritDoc} */
|
62
|
@Override
|
63
|
protected List<SpecimenOrObservationBase> listEntities(
|
64
|
IIdentifiableEntityServiceConfigurator configurator) {
|
65
|
return CdmStore.getSearchManager().findOccurrences(configurator);
|
66
|
}
|
67
|
|
68
|
/** {@inheritDoc}
|
69
|
@Override
|
70
|
protected SpecimenOrObservationBase loadEntity(UUID entityUuid) {
|
71
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
72
|
return CdmStore.getService(IOccurrenceService.class).load(entityUuid, propertyPaths);
|
73
|
}*/
|
74
|
|
75
|
@Override
|
76
|
public String getName() {
|
77
|
return BulkEditorInputType.OCCURRENCE.label;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public String getEditorName() {
|
82
|
return Messages.OccurrenceEditorInput_EDITOR_NAME;
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public String getTypeText(Object entity) {
|
87
|
if(HibernateProxyHelper.isInstanceOf(entity, SpecimenOrObservationBase.class)){
|
88
|
return ((SpecimenOrObservationBase) entity).getRecordBasis().getMessage();
|
89
|
}
|
90
|
return super.getTypeText(entity);
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* <p>getId</p>
|
95
|
*
|
96
|
* @return a {@link java.lang.Object} object.
|
97
|
*/
|
98
|
public static Object getId(){
|
99
|
return ID;
|
100
|
}
|
101
|
|
102
|
/** {@inheritDoc}
|
103
|
* @throws ReferencedObjectUndeletableException */
|
104
|
@Override
|
105
|
public boolean delete(SpecimenOrObservationBase entity, DeleteConfiguratorBase config ) throws ReferencedObjectUndeletableException {
|
106
|
DeleteResult deleteResult;
|
107
|
SpecimenDeleteConfigurator specimenConfig;
|
108
|
if (config instanceof SpecimenDeleteConfigurator){
|
109
|
specimenConfig = (SpecimenDeleteConfigurator)config;
|
110
|
}else{
|
111
|
specimenConfig = new SpecimenDeleteConfigurator();
|
112
|
}
|
113
|
deleteResult = CdmStore.getService(IOccurrenceService.class).delete(entity.getUuid(), specimenConfig);
|
114
|
|
115
|
return deleteResult.isOk();
|
116
|
}
|
117
|
|
118
|
/** {@inheritDoc} */
|
119
|
@Override
|
120
|
public SpecimenOrObservationBase<?> save(SpecimenOrObservationBase entity) {
|
121
|
return CdmStore.getService(IOccurrenceService.class).merge(entity, true).getMergedEntity();
|
122
|
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
protected IEntityCreator<SpecimenOrObservationBase> createEntityCreator() {
|
127
|
return new OccurrenceCreator();
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public List<IBulkEditorSortProvider<SpecimenOrObservationBase>> getSortProviders() {
|
132
|
List<IBulkEditorSortProvider<SpecimenOrObservationBase>> sortProviders = super.getSortProviders();
|
133
|
|
134
|
sortProviders.add(0, new IdentifiableEntitySortProvider<SpecimenOrObservationBase>());
|
135
|
|
136
|
return sortProviders;
|
137
|
}
|
138
|
|
139
|
@Override
|
140
|
public void merge() {
|
141
|
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
protected SpecimenOrObservationBase loadEntity(UUID entityUuid) {
|
146
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
147
|
return CdmStore.getService(IOccurrenceService.class).load(entityUuid, propertyPaths);
|
148
|
}
|
149
|
}
|