Project

General

Profile

Download (3.11 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
package eu.etaxonomy.taxeditor.bulkeditor.input;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.Comparator;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.api.service.IUserService;
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.model.permission.User;
22
import eu.etaxonomy.cdm.persistence.query.OrderHint;
23
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
24
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
25
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.UserNameComparator;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

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

    
35
	public static final String ID = "bulkeditor.input.user";
36

    
37
	private static UserEditorInput instance;
38

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

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

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

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

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

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

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

    
80
	@Override
81
	protected IEntityCreator<User> createEntityCreator() {
82
		return new UserCreator();
83
	}
84

    
85
	@Override
86
	public String getText(User entity) {
87
		return String.format("%s, %s", entity.getUsername(), entity.getPerson());
88
	}
89

    
90
    @Override
91
    public void merge() {
92

    
93
    }
94

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

    
101
	@Override
102
	public Comparator<User> getTitleComparator(){
103
        return new UserNameComparator();
104
    }
105
}
(11-11/11)