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 javax.validation.ConstraintViolationException;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
19
|
import eu.etaxonomy.cdm.model.permission.Group;
|
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
|
*/
|
30
|
public class GroupCreator implements IEntityCreator<Group> {
|
31
|
|
32
|
public static final String GROUP = "Group";
|
33
|
|
34
|
@Override
|
35
|
public Group createEntity(String text) {
|
36
|
Group group = createEntity(null, text);
|
37
|
return group;
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public Group createEntity(Object key, String text) {
|
42
|
try{
|
43
|
Group group = Group.NewInstance(text);
|
44
|
List<Group> groupList =CdmStore.getService(IGroupService.class).listByName(group.getName(), MatchMode.EXACT, null, 100, 0, null, null);
|
45
|
if (groupList.isEmpty()){
|
46
|
group = CdmStore.getService(IGroupService.class).merge(group, true).getMergedEntity();
|
47
|
// group = CdmStore.getService(IGroupService.class).loadWithUpdate(group.getUuid());
|
48
|
return group;
|
49
|
} else{
|
50
|
MessagingUtils.messageDialog(Messages.GROUP_CREATOR_group_exists_title, group, Messages.GROUP_CREATOR_group_exists);
|
51
|
return null;
|
52
|
}
|
53
|
}catch (ConstraintViolationException cve){
|
54
|
MessagingUtils.messageDialog(Messages.GROUP_CREATOR_Name_not_accepted, getClass(), Messages.GROUP_CREATOR_Name_not_accepted_message);
|
55
|
return null;
|
56
|
}
|
57
|
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
public Map<Object, String> getKeyLabelPairs() {
|
62
|
Map<Object, String> result = new HashMap<>();
|
63
|
result.put(Group.class, GROUP);
|
64
|
return result;
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public boolean savesEntity() {
|
69
|
// TODO Auto-generated method stub
|
70
|
return false;
|
71
|
}
|
72
|
|
73
|
}
|