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
|
/**
|
42
|
* @return the instance
|
43
|
*/
|
44
|
public static UserEditorInput getInstance() {
|
45
|
if(instance == null){
|
46
|
instance = new UserEditorInput();
|
47
|
}
|
48
|
return instance;
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
protected List<String> getPropertyKeys_internal() {
|
53
|
List<String> propertyKeysInternal = new ArrayList<>();
|
54
|
return propertyKeysInternal;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public String getName() {
|
59
|
return BulkEditorInputType.USER.label;
|
60
|
}
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#save(java.lang.Object)
|
64
|
*/
|
65
|
@Override
|
66
|
public User save(User entity) {
|
67
|
return CdmStore.getService(IUserService.class).merge(entity, true).getMergedEntity();
|
68
|
}
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
|
72
|
*/
|
73
|
@Override
|
74
|
public boolean delete(User entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
|
75
|
return CdmStore.getService(IUserService.class).delete(entity) != null;
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
80
|
//TODO there is no count method for users
|
81
|
return CdmStore.getService(IUserService.class).count(User.class);
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
|
86
|
*/
|
87
|
@Override
|
88
|
protected List<User> listEntities(
|
89
|
IIdentifiableEntityServiceConfigurator configurator) {
|
90
|
configurator.setOrderHints(new OrderHint("username", SortOrder.ASCENDING).asList());
|
91
|
return CdmStore.getSearchManager().findUsers(configurator);
|
92
|
}
|
93
|
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#loadEntity(java.util.UUID)
|
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
|
/* (non-Javadoc)
|
105
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
|
106
|
*/
|
107
|
@Override
|
108
|
protected IEntityCreator<User> createEntityCreator() {
|
109
|
return new UserCreator();
|
110
|
}
|
111
|
|
112
|
/* (non-Javadoc)
|
113
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getText(eu.etaxonomy.cdm.model.common.ICdmBase)
|
114
|
*/
|
115
|
@Override
|
116
|
public String getText(User entity) {
|
117
|
return String.format("%s, %s", entity.getUsername(), entity.getPerson());
|
118
|
}
|
119
|
|
120
|
/* (non-Javadoc)
|
121
|
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
|
122
|
*/
|
123
|
@Override
|
124
|
public void merge() {
|
125
|
|
126
|
}
|
127
|
|
128
|
|
129
|
@Override
|
130
|
protected User loadEntity(UUID entityUuid) {
|
131
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
132
|
return CdmStore.getService(IUserService.class).load(entityUuid, propertyPaths);
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public Comparator<User> getTitleComparator(){
|
137
|
return new UserNameComparator();
|
138
|
}
|
139
|
|
140
|
|
141
|
|
142
|
|
143
|
}
|