Project

General

Profile

Download (4.06 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.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.common.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
 * @version 1.0
33
 */
34
public class UserEditorInput extends AbstractBulkEditorInput<User> {
35

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

    
38
	private static UserEditorInput instance;
39

    
40
	/**
41
	 * @return the instance
42
	 */
43
	public static UserEditorInput getInstance() {
44
		if(instance == null){
45
			instance = new UserEditorInput();
46
		}
47
		return instance;
48
	}
49

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

    
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#save(java.lang.Object)
57
	 */
58
	@Override
59
	public User save(User entity) {
60
	    return CdmStore.getService(IUserService.class).merge(entity, true).getMergedEntity();
61
	}
62

    
63
	/* (non-Javadoc)
64
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
65
	 */
66
	@Override
67
	public boolean delete(User entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
68
		return CdmStore.getService(IUserService.class).delete(entity) != null;
69
	}
70

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

    
77
	/* (non-Javadoc)
78
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
79
	 */
80
	@Override
81
	protected List<User> listEntities(
82
			IIdentifiableEntityServiceConfigurator configurator) {
83
	    configurator.setOrderHints(new OrderHint("username", SortOrder.ASCENDING).asList());
84
		return CdmStore.getSearchManager().findUsers(configurator);
85
	}
86

    
87

    
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#loadEntity(java.util.UUID)
90

    
91
	@Override
92
	protected User loadEntity(UUID entityUuid) {
93
		List<String> propertyPaths = Arrays.asList(new String[]{});
94
		return CdmStore.getService(IUserService.class).load(entityUuid, propertyPaths);
95
	}
96
 */
97
	/* (non-Javadoc)
98
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
99
	 */
100
	@Override
101
	protected IEntityCreator<User> createEntityCreator() {
102
		return new UserCreator();
103
	}
104

    
105
	/* (non-Javadoc)
106
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getText(eu.etaxonomy.cdm.model.common.ICdmBase)
107
	 */
108
	@Override
109
	public String getText(User entity) {
110
		return String.format("%s, %s", entity.getUsername(), entity.getPerson());
111
	}
112

    
113
    /* (non-Javadoc)
114
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
115
     */
116
    @Override
117
    public void merge() {
118

    
119
    }
120

    
121

    
122
	@Override
123
	protected User loadEntity(UUID entityUuid) {
124
		List<String> propertyPaths = Arrays.asList(new String[]{});
125
		return CdmStore.getService(IUserService.class).load(entityUuid, propertyPaths);
126
	}
127

    
128
	@Override
129
	public Comparator<User> getTitleComparator(){
130
        return new UserNameComparator();
131
    }
132

    
133

    
134

    
135

    
136
}
(11-11/11)