Project

General

Profile

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

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

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

    
40
	private static GroupEditorInput instance;
41

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

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

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

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

    
64
	}
65

    
66
	@Override
67
	public boolean delete(Group entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
68
		return CdmStore.getService(IGroupService.class).delete(entity.getUuid()) != null;
69
	}
70

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

    
77
	@Override
78
	protected List<Group> listEntities(
79
			IIdentifiableEntityServiceConfigurator configurator) {
80
	    configurator.setOrderHints(new OrderHint("name", SortOrder.ASCENDING).asList());
81
		return CdmStore.getSearchManager().findGroups(configurator);
82
	}
83

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

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

    
94
    @Override
95
    public void merge() {
96

    
97
    }
98

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

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

    
110
}
(4-4/11)