2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
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
;
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
;
31 * @created Mar 9, 2011
33 public class UserEditorInput
extends AbstractBulkEditorInput
<User
> {
35 public static final String ID
= "bulkeditor.input.user";
37 private static UserEditorInput instance
;
39 public static UserEditorInput
getInstance() {
41 instance
= new UserEditorInput();
47 protected List
<String
> getPropertyKeys_internal() {
48 List
<String
> propertyKeysInternal
= new ArrayList
<>();
49 return propertyKeysInternal
;
53 public String
getName() {
54 return BulkEditorInputType
.USER
.label
;
58 public User
save(User entity
) {
59 return CdmStore
.getService(IUserService
.class).merge(entity
, true).getMergedEntity();
63 public boolean delete(User entity
, DeleteConfiguratorBase config
) throws ReferencedObjectUndeletableException
{
64 return CdmStore
.getService(IUserService
.class).delete(entity
) != null;
68 protected long countEntities(IIdentifiableEntityServiceConfigurator configurator
) {
69 //TODO there is no count method for users
70 return CdmStore
.getService(IUserService
.class).count(User
.class);
74 protected List
<User
> listEntities(
75 IIdentifiableEntityServiceConfigurator configurator
) {
76 configurator
.setOrderHints(new OrderHint("username", SortOrder
.ASCENDING
).asList());
77 return CdmStore
.getSearchManager().findUsers(configurator
);
81 protected IEntityCreator
<User
> createEntityCreator() {
82 return new UserCreator();
86 public String
getText(User entity
) {
87 return String
.format("%s, %s", entity
.getUsername(), entity
.getPerson());
96 protected User
loadEntity(UUID entityUuid
) {
97 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
98 return CdmStore
.getService(IUserService
.class).load(entityUuid
, propertyPaths
);
102 public Comparator
<User
> getTitleComparator(){
103 return new UserNameComparator();