Project

General

Profile

Download (3.13 KB) Statistics
| Branch: | Tag: | Revision:
1 a60842d7 n.hoffmann
/**
2
* Copyright (C) 2007 EDIT
3 233a8fe2 Cherian Mathew
* European Distributed Institute of Taxonomy
4 a60842d7 n.hoffmann
* http://www.e-taxonomy.eu
5 233a8fe2 Cherian Mathew
*
6 a60842d7 n.hoffmann
* 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 521ddbfc Patrick Plitzner
import java.util.ArrayList;
13 222d6e76 Patrick Plitzner
import java.util.Arrays;
14 2d912c1b Katja Luther
import java.util.Comparator;
15 a60842d7 n.hoffmann
import java.util.List;
16 222d6e76 Patrick Plitzner
import java.util.UUID;
17 a60842d7 n.hoffmann
18
import eu.etaxonomy.cdm.api.service.IUserService;
19 7dce04a4 Katja Luther
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
20 a60842d7 n.hoffmann
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
21 97e10b7c Katja Luther
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
22 a60842d7 n.hoffmann
import eu.etaxonomy.cdm.model.common.User;
23 8da6ef3f Katja Luther
import eu.etaxonomy.cdm.persistence.query.OrderHint;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
25 a60842d7 n.hoffmann
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
27 2d912c1b Katja Luther
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.UserNameComparator;
28 a60842d7 n.hoffmann
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 233a8fe2 Cherian Mathew
39 a60842d7 n.hoffmann
	private static UserEditorInput instance;
40 233a8fe2 Cherian Mathew
41 a60842d7 n.hoffmann
	public static UserEditorInput getInstance() {
42
		if(instance == null){
43
			instance = new UserEditorInput();
44
		}
45
		return instance;
46
	}
47 233a8fe2 Cherian Mathew
48 521ddbfc Patrick Plitzner
    @Override
49
    protected List<String> getPropertyKeys_internal() {
50
        List<String> propertyKeysInternal = new ArrayList<>();
51
        return propertyKeysInternal;
52
    }
53
54 381bdda4 Patrick Plitzner
    @Override
55 a60842d7 n.hoffmann
	public String getName() {
56
		return BulkEditorInputType.USER.label;
57
	}
58
59
	@Override
60 76fe3732 Cherian Mathew
	public User save(User entity) {
61 d85cfdf3 Katja Luther
	    return CdmStore.getService(IUserService.class).merge(entity, true).getMergedEntity();
62 a60842d7 n.hoffmann
	}
63
64
	@Override
65 7dce04a4 Katja Luther
	public boolean delete(User entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
66 a60842d7 n.hoffmann
		return CdmStore.getService(IUserService.class).delete(entity) != null;
67
	}
68
69 fd28a17f Patrick Plitzner
	@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 a60842d7 n.hoffmann
	@Override
76
	protected List<User> listEntities(
77
			IIdentifiableEntityServiceConfigurator configurator) {
78 8da6ef3f Katja Luther
	    configurator.setOrderHints(new OrderHint("username", SortOrder.ASCENDING).asList());
79 a60842d7 n.hoffmann
		return CdmStore.getSearchManager().findUsers(configurator);
80
	}
81
82 233a8fe2 Cherian Mathew
83 a60842d7 n.hoffmann
	@Override
84
	protected IEntityCreator<User> createEntityCreator() {
85
		return new UserCreator();
86
	}
87 233a8fe2 Cherian Mathew
88 a60842d7 n.hoffmann
	@Override
89
	public String getText(User entity) {
90
		return String.format("%s, %s", entity.getUsername(), entity.getPerson());
91
	}
92
93 8c8ead8a Cherian Mathew
    @Override
94
    public void merge() {
95
96
    }
97 381bdda4 Patrick Plitzner
98 222d6e76 Patrick Plitzner
	@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 2d912c1b Katja Luther
	@Override
105
	public Comparator<User> getTitleComparator(){
106
        return new UserNameComparator();
107
    }
108
109 a60842d7 n.hoffmann
}