Project

General

Profile

Download (4.75 KB) Statistics
| Branch: | Tag: | Revision:
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
	/**
75
	 * <p>getName</p>
76
	 *
77
	 * @return a {@link java.lang.String} object.
78
	 */
79
	@Override
80
    public String getName() {
81
		return BulkEditorInputType.OCCURRENCE.label;
82
	}
83

    
84
	/**
85
	 * <p>getToolTipText</p>
86
	 *
87
	 * @return a {@link java.lang.String} object.
88
	 */
89
	@Override
90
    public String getToolTipText() {
91
		return getName();
92
	}
93

    
94
	@Override
95
	public String getTypeText(Object entity) {
96
        if(HibernateProxyHelper.isInstanceOf(entity, SpecimenOrObservationBase.class)){
97
            return ((SpecimenOrObservationBase) entity).getRecordBasis().getMessage();
98
         }
99
	    return super.getTypeText(entity);
100
	}
101

    
102
	/**
103
	 * <p>getId</p>
104
	 *
105
	 * @return a {@link java.lang.Object} object.
106
	 */
107
	public static Object getId(){
108
		return ID;
109
	}
110

    
111
	/** {@inheritDoc}
112
	 * @throws ReferencedObjectUndeletableException */
113
	@Override
114
    public boolean delete(SpecimenOrObservationBase entity, DeleteConfiguratorBase config ) throws ReferencedObjectUndeletableException {
115
	    DeleteResult deleteResult;
116
	    SpecimenDeleteConfigurator specimenConfig;
117
	    if (config instanceof SpecimenDeleteConfigurator){
118
	        specimenConfig = (SpecimenDeleteConfigurator)config;
119
	    }else{
120
	        specimenConfig = new SpecimenDeleteConfigurator();
121
	    }
122
	    deleteResult = CdmStore.getService(IOccurrenceService.class).delete(entity.getUuid(), specimenConfig);
123

    
124
		return deleteResult.isOk();
125
	}
126

    
127
	/** {@inheritDoc} */
128
	@Override
129
    public SpecimenOrObservationBase<?> save(SpecimenOrObservationBase entity) {
130
	    return CdmStore.getService(IOccurrenceService.class).merge(entity, true).getMergedEntity();
131

    
132
	}
133

    
134
	@Override
135
	protected IEntityCreator<SpecimenOrObservationBase> createEntityCreator() {
136
		return new OccurrenceCreator();
137
	}
138

    
139
	@Override
140
	public List<IBulkEditorSortProvider<SpecimenOrObservationBase>> getSortProviders() {
141
		List<IBulkEditorSortProvider<SpecimenOrObservationBase>> sortProviders = super.getSortProviders();
142

    
143
		sortProviders.add(0, new IdentifiableEntitySortProvider<SpecimenOrObservationBase>());
144

    
145
		return sortProviders;
146
	}
147

    
148
    @Override
149
    public void merge() {
150

    
151
    }
152

    
153
	@Override
154
	protected SpecimenOrObservationBase loadEntity(UUID entityUuid) {
155
		List<String> propertyPaths = Arrays.asList(new String[]{});
156
		return CdmStore.getService(IOccurrenceService.class).load(entityUuid, propertyPaths);
157
	}
158
}
(8-8/11)