Project

General

Profile

Download (2.34 KB) Statistics
| Branch: | Tag: | Revision:
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
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.api.service.IGroupService;
18
import eu.etaxonomy.cdm.model.common.Group;
19
import eu.etaxonomy.cdm.persistence.query.MatchMode;
20
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
21
import eu.etaxonomy.taxeditor.l10n.Messages;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * @author n.hoffmann
27
 * @created Mar 9, 2011
28
 * @version 1.0
29
 */
30
public class GroupCreator implements IEntityCreator<Group> {
31

    
32
    public static final String GROUP = "Group";
33

    
34
    /* (non-Javadoc)
35
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
36
	 */
37
	@Override
38
	public Group createEntity(String text) {
39
		Group group = createEntity(null, text);
40
		return group;
41
	}
42

    
43
	/* (non-Javadoc)
44
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
45
	 */
46
	@Override
47
	public Group createEntity(Object key, String text) {
48
	    List<Group> groupList =CdmStore.getService(IGroupService.class).listByName(text, MatchMode.EXACT, null, 100, 0, null, null);
49

    
50
        if (groupList.isEmpty()){
51
            Group group = Group.NewInstance(text);
52
            UUID groupUuid = CdmStore.getService(IGroupService.class).saveGroup(group);
53
            group = CdmStore.getService(IGroupService.class).loadWithUpdate(groupUuid);
54
            return group;
55
        } else{
56
            MessagingUtils.messageDialog(Messages.GROUP_CREATOR_group_exists_title, text, Messages.GROUP_CREATOR_group_exists);
57
            return null;
58
        }
59

    
60

    
61
	}
62

    
63
	/* (non-Javadoc)
64
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
65
	 */
66
	@Override
67
	public Map<Object, String> getKeyLabelPairs() {
68
		Map<Object, String> result = new HashMap<Object, String>();
69
		result.put(Group.class, GROUP);
70
		return result;
71
	}
72

    
73
	@Override
74
	public boolean savesEntity() {
75
		// TODO Auto-generated method stub
76
		return false;
77
	}
78

    
79
}
(2-2/8)