2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
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
;
38 * @created Jun 16, 2010
40 public class OccurrenceEditorInput
extends AbstractBulkEditorInput
<SpecimenOrObservationBase
> {
42 private static final long serialVersionUID
= 1014860873939989973L;
44 public static final String ID
= "bulkeditor.input.occurrence"; //$NON-NLS-1$
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";
55 private static OccurrenceEditorInput instance
;
57 public static AbstractBulkEditorInput
<SpecimenOrObservationBase
> getInstance() {
58 if (instance
== null) {
59 instance
= new OccurrenceEditorInput();
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
;
79 public Object
getPropertyValue(SpecimenOrObservationBase cdmBase
, String property
) {
80 if(property
.equals(PROPERTY_PUBLISH
)){
81 return cdmBase
.isPublish();
83 else if(property
.equals(PROPERTY_COUNTRY
)){
84 return getCountry(cdmBase
);
86 else if(property
.equals(PROPERTY_COLLECTOR
)){
87 return getCollector(cdmBase
);
89 else if(property
.equals(PROPERTY_FIELD_NUMBER
)){
90 return getFieldNumber(cdmBase
);
92 else if(property
.equals(PROPERTY_ACCESSION_NUMBER
)){
93 return getAccessionNumber(cdmBase
);
95 else if(property
.equals(PROPERTY_BARCODE
)){
96 return getBarcode(cdmBase
);
98 else if(property
.equals(PROPERTY_CATALOG_NUMBER
)){
99 return getCatalogNumber(cdmBase
);
101 else if(property
.equals(PROPERTY_COLLECTION
)){
102 return getCollection(cdmBase
);
104 return super.getPropertyValue(cdmBase
, property
);
108 public boolean isBooleanProperty(String property
) {
109 if(property
.equals(PROPERTY_PUBLISH
)){
112 return super.isBooleanProperty(property
);
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();
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();
135 private Object
getFieldNumber(SpecimenOrObservationBase
<?
> cdmBase
) {
136 if(cdmBase
.isInstanceOf(FieldUnit
.class)){
137 return HibernateProxyHelper
.deproxy(cdmBase
, FieldUnit
.class).getFieldNumber();
142 private Object
getAccessionNumber(SpecimenOrObservationBase
<?
> cdmBase
) {
143 if(cdmBase
.isInstanceOf(DerivedUnit
.class)){
144 return HibernateProxyHelper
.deproxy(cdmBase
, DerivedUnit
.class).getAccessionNumber();
149 private Object
getBarcode(SpecimenOrObservationBase
<?
> cdmBase
) {
150 if(cdmBase
.isInstanceOf(DerivedUnit
.class)){
151 return HibernateProxyHelper
.deproxy(cdmBase
, DerivedUnit
.class).getBarcode();
156 private Object
getCatalogNumber(SpecimenOrObservationBase
<?
> cdmBase
) {
157 if(cdmBase
.isInstanceOf(DerivedUnit
.class)){
158 return HibernateProxyHelper
.deproxy(cdmBase
, DerivedUnit
.class).getCatalogNumber();
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();
174 protected long countEntities(IIdentifiableEntityServiceConfigurator configurator
) {
175 return CdmStore
.getService(IOccurrenceService
.class).countByTitle(configurator
);
179 protected List
<SpecimenOrObservationBase
> listEntities(
180 IIdentifiableEntityServiceConfigurator configurator
) {
181 return CdmStore
.getSearchManager().findOccurrences(configurator
, false);
185 public String
getName() {
186 return BulkEditorInputType
.OCCURRENCE
.label
;
190 public String
getEditorName() {
191 return Messages
.OccurrenceEditorInput_EDITOR_NAME
;
195 public String
getTypeText(Object entity
) {
196 if(HibernateProxyHelper
.isInstanceOf(entity
, SpecimenOrObservationBase
.class)){
197 return ((SpecimenOrObservationBase
) entity
).getRecordBasis().getMessage();
199 return super.getTypeText(entity
);
202 public static Object
getId(){
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
;
213 specimenConfig
= new SpecimenDeleteConfigurator();
215 deleteResult
= CdmStore
.getService(IOccurrenceService
.class).delete(entity
.getUuid(), specimenConfig
);
217 return deleteResult
.isOk();
221 public SpecimenOrObservationBase
<?
> save(SpecimenOrObservationBase entity
) {
222 return CdmStore
.getService(IOccurrenceService
.class).merge(entity
, true).getMergedEntity();
227 protected IEntityCreator
<SpecimenOrObservationBase
> createEntityCreator() {
228 return new OccurrenceCreator();
232 public List
<IBulkEditorSortProvider
<SpecimenOrObservationBase
>> getSortProviders() {
233 List
<IBulkEditorSortProvider
<SpecimenOrObservationBase
>> sortProviders
= super.getSortProviders();
235 sortProviders
.add(0, new IdentifiableEntitySortProvider
<SpecimenOrObservationBase
>());
237 return sortProviders
;
241 public void merge() {
246 protected SpecimenOrObservationBase
loadEntity(UUID entityUuid
) {
247 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
248 return CdmStore
.getService(IOccurrenceService
.class).load(entityUuid
, propertyPaths
);