1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
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.permission.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;
|
25
|
|
26
|
/**
|
27
|
* @author n.hoffmann
|
28
|
* @created Mar 9, 2011
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class UserCreator implements IEntityCreator<User>{
|
32
|
|
33
|
public static final String USER = "User";
|
34
|
|
35
|
/* (non-Javadoc)
|
36
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
|
37
|
*/
|
38
|
@Override
|
39
|
public User createEntity(String text) {
|
40
|
return createEntity(null, text);
|
41
|
}
|
42
|
|
43
|
/* (non-Javadoc)
|
44
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
|
45
|
*/
|
46
|
@Override
|
47
|
public User createEntity(Object key, String text) {
|
48
|
try{
|
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());
|
54
|
return user;
|
55
|
} else{
|
56
|
MessagingUtils.messageDialog(Messages.USER_CREATOR_user_exists_title, user, Messages.USER_CREATOR_user_exists);
|
57
|
return null;
|
58
|
}
|
59
|
} catch (AccessDeniedException e){
|
60
|
MessagingUtils.messageDialog("Access denied", getClass(), e.getMessage(), e);
|
61
|
return null;
|
62
|
}
|
63
|
}
|
64
|
|
65
|
/* (non-Javadoc)
|
66
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
|
67
|
*/
|
68
|
@Override
|
69
|
public Map<Object, String> getKeyLabelPairs() {
|
70
|
Map<Object, String> result = new HashMap<Object, String>();
|
71
|
result.put(User.class, USER);
|
72
|
return result;
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public boolean savesEntity() {
|
77
|
// TODO Auto-generated method stub
|
78
|
return false;
|
79
|
}
|
80
|
|
81
|
}
|