Project

General

Profile

Download (3.13 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.IUserService;
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.model.common.User;
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.UserCreator;
27
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.UserNameComparator;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

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

    
37
	public static final String ID = "bulkeditor.input.user";
38

    
39
	private static UserEditorInput instance;
40

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

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

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

    
59
	@Override
60
	public User save(User entity) {
61
	    return CdmStore.getService(IUserService.class).merge(entity, true).getMergedEntity();
62
	}
63

    
64
	@Override
65
	public boolean delete(User entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
66
		return CdmStore.getService(IUserService.class).delete(entity) != null;
67
	}
68

    
69
	@Override
70
	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
71
	    //TODO there is no count method for users
72
	    return CdmStore.getService(IUserService.class).count(User.class);
73
	}
74

    
75
	@Override
76
	protected List<User> listEntities(
77
			IIdentifiableEntityServiceConfigurator configurator) {
78
	    configurator.setOrderHints(new OrderHint("username", SortOrder.ASCENDING).asList());
79
		return CdmStore.getSearchManager().findUsers(configurator);
80
	}
81

    
82

    
83
	@Override
84
	protected IEntityCreator<User> createEntityCreator() {
85
		return new UserCreator();
86
	}
87

    
88
	@Override
89
	public String getText(User entity) {
90
		return String.format("%s, %s", entity.getUsername(), entity.getPerson());
91
	}
92

    
93
    @Override
94
    public void merge() {
95

    
96
    }
97

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

    
104
	@Override
105
	public Comparator<User> getTitleComparator(){
106
        return new UserNameComparator();
107
    }
108

    
109
}
(11-11/11)