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