Project

General

Profile

Download (3.98 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.IAgentService;
17
import eu.etaxonomy.cdm.api.service.IGroupService;
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.exception.ReferencedObjectUndeletableException;
21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
22
import eu.etaxonomy.cdm.model.common.Group;
23
import eu.etaxonomy.cdm.persistence.query.OrderHint;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
25
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created Mar 9, 2011
32
 * @version 1.0
33
 */
34
public class GroupEditorInput extends AbstractBulkEditorInput<Group> {
35

    
36
	public static final String ID = "bulkeditor.input.group";
37

    
38
	private static GroupEditorInput instance;
39

    
40
	/**
41
	 * @return the instance
42
	 */
43
	public static GroupEditorInput getInstance() {
44
		if(instance == null){
45
			instance = new GroupEditorInput();
46
		}
47
		return instance;
48
	}
49

    
50
    @Override
51
	public String getName() {
52
		return BulkEditorInputType.GROUP.label;
53
	}
54

    
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#save(java.lang.Object)
57
	 */
58
	@Override
59
	public Group save(Group entity) {
60
	    return CdmStore.getService(IGroupService.class).merge(entity, true).getMergedEntity();
61

    
62
	}
63

    
64
	/* (non-Javadoc)
65
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
66
	 */
67
	@Override
68
	public boolean delete(Group entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
69
		return CdmStore.getService(IGroupService.class).delete(entity.getUuid()) != null;
70
	}
71

    
72
	@Override
73
	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
74
	    //TODO there is no count method for groups
75
	    return CdmStore.getService(IGroupService.class).count(Group.class);
76
	}
77

    
78
	/* (non-Javadoc)
79
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
80
	 */
81
	@Override
82
	protected List<Group> listEntities(
83
			IIdentifiableEntityServiceConfigurator configurator) {
84
	    configurator.setOrderHints(new OrderHint("name", SortOrder.ASCENDING).asList());
85
		return CdmStore.getSearchManager().findGroups(configurator);
86
	}
87

    
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#loadEntity(java.util.UUID)
90

    
91
	@Override
92
	protected Group loadEntity(UUID entityUuid) {
93
		List<String> propertyPaths = Arrays.asList(new String[]{});
94
		return CdmStore.getService(IGroupService.class).load(entityUuid, propertyPaths);
95
	}
96
*/
97
	/* (non-Javadoc)
98
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
99
	 */
100
	@Override
101
	protected IEntityCreator<Group> createEntityCreator() {
102
		return new GroupCreator();
103
	}
104

    
105
	/* (non-Javadoc)
106
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getText(eu.etaxonomy.cdm.model.common.ICdmBase)
107
	 */
108
	@Override
109
	public String getText(Group entity) {
110
		return entity.getName();
111
	}
112

    
113
    /* (non-Javadoc)
114
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
115
     */
116
    @Override
117
    public void merge() {
118

    
119
    }
120

    
121
	@Override
122
	protected Group loadEntity(UUID entityUuid) {
123
		List<String> propertyPaths = Arrays.asList(new String[]{});
124
		return HibernateProxyHelper.deproxy(CdmStore.getService(IAgentService.class).load(entityUuid, propertyPaths), Group.class);
125
	}
126

    
127

    
128

    
129
}
(4-4/11)