Project

General

Profile

Download (2.86 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

    
16
import javax.validation.ConstraintViolationException;
17

    
18
import org.springframework.security.access.AccessDeniedException;
19

    
20
import eu.etaxonomy.cdm.api.service.IUserService;
21
import eu.etaxonomy.cdm.model.permission.User;
22
import eu.etaxonomy.cdm.persistence.query.MatchMode;
23
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

    
28
/**
29
 * @author n.hoffmann
30
 * @created Mar 9, 2011
31
 * @version 1.0
32
 */
33
public class UserCreator  implements IEntityCreator<User>{
34

    
35
    public static final String USER = "User"; //$NON-NLS-1$
36

    
37
    /* (non-Javadoc)
38
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
39
	 */
40
	@Override
41
	public User createEntity(String text) {
42
		return createEntity(null, text);
43
	}
44

    
45
	/* (non-Javadoc)
46
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
47
	 */
48
	@Override
49
	public User createEntity(Object key, String text) {
50

    
51
	    try{
52
            User user = User.NewInstance(text, text);
53
            List<User> userList =CdmStore.getService(IUserService.class).listByUsername(user.getUsername(), MatchMode.EXACT, null, 100, 0, null, null);
54
            if (userList.isEmpty()){
55
                CdmStore.getService(IUserService.class).createUser(user);
56
                user = CdmStore.getService(IUserService.class).loadWithUpdate(user.getUuid());
57
                return user;
58
            } else{
59
                MessagingUtils.messageDialog(Messages.USER_CREATOR_user_exists_title, user, Messages.USER_CREATOR_user_exists);
60
                return null;
61
            }
62
        } catch (AccessDeniedException e){
63
            MessagingUtils.messageDialog(Messages.USER_CREATOR_Acces_denied, getClass(), e.getMessage(), e);
64
            return null;
65
        } catch (ConstraintViolationException cve){
66
            MessagingUtils.messageDialog(Messages.USER_CREATOR_Name_not_accepted, getClass(), Messages.USER_CREATOR_Name_not_accepted_message);
67
            return null;
68
        }
69

    
70
	}
71

    
72
	/* (non-Javadoc)
73
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
74
	 */
75
	@Override
76
	public Map<Object, String> getKeyLabelPairs() {
77
		Map<Object, String> result = new HashMap<Object, String>();
78
		result.put(User.class, USER);
79
		return result;
80
	}
81

    
82
	@Override
83
	public boolean savesEntity() {
84
		// TODO Auto-generated method stub
85
		return false;
86
	}
87

    
88
}
(8-8/8)