Project

General

Profile

Download (3.85 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.List;
14
import java.util.UUID;
15

    
16
import eu.etaxonomy.cdm.api.service.IUserService;
17
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
18
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
19
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
20
import eu.etaxonomy.cdm.model.common.User;
21
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
23
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
24
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

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

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

    
36
	private static UserEditorInput instance;
37

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

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

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

    
61
	/* (non-Javadoc)
62
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
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
	/* (non-Javadoc)
76
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
77
	 */
78
	@Override
79
	protected List<User> listEntities(
80
			IIdentifiableEntityServiceConfigurator configurator) {
81
	    configurator.setOrderHints(new OrderHint("username", SortOrder.ASCENDING).asList());
82
		return CdmStore.getSearchManager().findUsers(configurator);
83
	}
84

    
85

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

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

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

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

    
117
    }
118

    
119

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

    
126

    
127

    
128
}
(11-11/11)