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