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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
;
12 import java
.util
.HashMap
;
13 import java
.util
.List
;
16 import javax
.validation
.ConstraintViolationException
;
18 import org
.springframework
.security
.access
.AccessDeniedException
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
21 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
22 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
23 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
24 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * @created Mar 9, 2011
33 public class UserCreator
implements IEntityCreator
<User
>{
35 public static final String USER
= "User"; //$NON-NLS-1$
38 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
41 public User
createEntity(String text
) {
42 return createEntity(null, text
);
46 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
49 public User
createEntity(Object key
, String text
) {
52 User user
= User
.NewInstance(text
, text
);
53 List
<User
> userList
=CdmStore
.getService(IUserService
.class).listByUsername(user
.getUsername(), MatchMode
.EXACT
, null, 100, 0, null, null);
54 if (userList
.isEmpty()){
55 CdmStore
.getService(IUserService
.class).createUser(user
);
56 user
= CdmStore
.getService(IUserService
.class).loadWithUpdate(user
.getUuid());
59 MessagingUtils
.messageDialog(Messages
.USER_CREATOR_user_exists_title
, user
, Messages
.USER_CREATOR_user_exists
);
62 } catch (AccessDeniedException e
){
63 MessagingUtils
.messageDialog(Messages
.USER_CREATOR_Acces_denied
, getClass(), e
.getMessage(), e
);
65 } catch (ConstraintViolationException cve
){
66 MessagingUtils
.messageDialog(Messages
.USER_CREATOR_Name_not_accepted
, getClass(), Messages
.USER_CREATOR_Name_not_accepted_message
);
73 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
76 public Map
<Object
, String
> getKeyLabelPairs() {
77 Map
<Object
, String
> result
= new HashMap
<Object
, String
>();
78 result
.put(User
.class, USER
);
83 public boolean savesEntity() {
84 // TODO Auto-generated method stub