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
.l10n
.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
>{
33 public static final String USER
= "User";
36 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
39 public User
createEntity(String text
) {
40 return createEntity(null, text
);
44 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
47 public User
createEntity(Object key
, String text
) {
49 User user
= User
.NewInstance(text
, text
);
50 List
<User
> userList
=CdmStore
.getService(IUserService
.class).listByUsername(user
.getUsername(), MatchMode
.EXACT
, null, 100, 0, null, null);
51 if (userList
.isEmpty()){
52 CdmStore
.getService(IUserService
.class).createUser(user
);
53 user
= CdmStore
.getService(IUserService
.class).loadWithUpdate(user
.getUuid());
56 MessagingUtils
.messageDialog(Messages
.USER_CREATOR_user_exists_title
, user
, Messages
.USER_CREATOR_user_exists
);
59 } catch (AccessDeniedException e
){
60 MessagingUtils
.messageDialog("Access denied", getClass(), e
.getMessage(), e
);
66 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
69 public Map
<Object
, String
> getKeyLabelPairs() {
70 Map
<Object
, String
> result
= new HashMap
<Object
, String
>();
71 result
.put(User
.class, USER
);
76 public boolean savesEntity() {
77 // TODO Auto-generated method stub