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 org
.springframework
.security
.access
.AccessDeniedException
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
19 import eu
.etaxonomy
.cdm
.model
.common
.User
;
20 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
21 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
22 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.Messages
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 * @created Mar 9, 2011
31 public class UserCreator
implements IEntityCreator
<User
>{
34 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
37 public User
createEntity(String text
) {
38 return createEntity(null, text
);
42 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
45 public User
createEntity(Object key
, String text
) {
47 User user
= User
.NewInstance(text
, text
);
48 List
<User
> userList
=CdmStore
.getService(IUserService
.class).listByUsername(user
.getUsername(), MatchMode
.EXACT
, null, 100, 0, null, null);
49 if (userList
.isEmpty()){
50 CdmStore
.getService(IUserService
.class).createUser(user
);
51 user
= CdmStore
.getService(IUserService
.class).loadWithUpdate(user
.getUuid());
54 MessagingUtils
.messageDialog(Messages
.USER_CREATOR_user_exists_title
, user
, Messages
.USER_CREATOR_user_exists
);
57 } catch (AccessDeniedException e
){
58 MessagingUtils
.messageDialog("Access denied", getClass(), e
.getMessage(), e
);
64 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
67 public Map
<Object
, String
> getKeyLabelPairs() {
68 Map
<Object
, String
> result
= new HashMap
<Object
, String
>();
69 result
.put(User
.class, "User");
74 public boolean savesEntity() {
75 // TODO Auto-generated method stub