Project

General

Profile

Download (3.26 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.ArrayList;
13
import java.util.Arrays;
14
import java.util.Comparator;
15
import java.util.List;
16
import java.util.UUID;
17

    
18
import eu.etaxonomy.cdm.api.service.IAgentService;
19
import eu.etaxonomy.cdm.api.service.IGroupService;
20
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
21
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
22
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
23
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
24
import eu.etaxonomy.cdm.model.common.Group;
25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
26
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
28
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
29
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.GroupNameComparator;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

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

    
39
	public static final String ID = "bulkeditor.input.group";
40

    
41
	private static GroupEditorInput instance;
42

    
43
	public static GroupEditorInput getInstance() {
44
		if(instance == null){
45
			instance = new GroupEditorInput();
46
		}
47
		return instance;
48
	}
49

    
50
    @Override
51
    protected List<String> getPropertyKeys_internal() {
52
        List<String> propertyKeysInternal = new ArrayList<>();
53
        return propertyKeysInternal;
54
    }
55

    
56
    @Override
57
	public String getName() {
58
		return BulkEditorInputType.GROUP.label;
59
	}
60

    
61
	@Override
62
	public Group save(Group entity) {
63
	    return CdmStore.getService(IGroupService.class).merge(entity, true).getMergedEntity();
64

    
65
	}
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
	@Override
79
	protected List<Group> listEntities(
80
			IIdentifiableEntityServiceConfigurator configurator) {
81
	    configurator.setOrderHints(new OrderHint("name", SortOrder.ASCENDING).asList());
82
		return CdmStore.getSearchManager().findGroups(configurator);
83
	}
84

    
85
	@Override
86
	protected IEntityCreator<Group> createEntityCreator() {
87
		return new GroupCreator();
88
	}
89

    
90
	@Override
91
	public String getText(Group entity) {
92
		return entity.getName();
93
	}
94

    
95
    @Override
96
    public void merge() {
97

    
98
    }
99

    
100
	@Override
101
	protected Group loadEntity(UUID entityUuid) {
102
		List<String> propertyPaths = Arrays.asList(new String[]{});
103
		return HibernateProxyHelper.deproxy(CdmStore.getService(IAgentService.class).load(entityUuid, propertyPaths), Group.class);
104
	}
105

    
106
	@Override
107
	public Comparator<Group> getTitleComparator(){
108
        return new GroupNameComparator();
109
    }
110

    
111
}
(4-4/11)