Merge branch 'release/4.2.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / entitycreator / UserCreator.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.springframework.security.access.AccessDeniedException;
17
18 import eu.etaxonomy.cdm.api.service.IUserService;
19 import eu.etaxonomy.cdm.model.common.User;
20 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
21 import eu.etaxonomy.taxeditor.model.MessagingUtils;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author n.hoffmann
26 * @created Mar 9, 2011
27 * @version 1.0
28 */
29 public class UserCreator implements IEntityCreator<User>{
30
31 /* (non-Javadoc)
32 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
33 */
34 @Override
35 public User createEntity(String text) {
36 return createEntity(null, text);
37 }
38
39 /* (non-Javadoc)
40 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
41 */
42 @Override
43 public User createEntity(Object key, String text) {
44 try{
45 User user = User.NewInstance(text, text);
46 if(CdmStore.getCurrentSessionManager().isRemoting()) {
47 CdmStore.getService(IUserService.class).createUser(user);
48 user = CdmStore.getService(IUserService.class).loadWithUpdate(user.getUuid());
49 } else {
50 CdmStore.getService(IUserService.class).createUser(user);
51 }
52 return user;
53 } catch (AccessDeniedException e){
54 MessagingUtils.messageDialog("Access denied", getClass(), e.getMessage(), e);
55 return null;
56 }
57 }
58
59 /* (non-Javadoc)
60 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
61 */
62 @Override
63 public Map<Object, String> getKeyLabelPairs() {
64 Map<Object, String> result = new HashMap<Object, String>();
65 result.put(User.class, "User");
66 return result;
67 }
68
69 @Override
70 public boolean savesEntity() {
71 // TODO Auto-generated method stub
72 return false;
73 }
74
75 }