Project

General

Profile

Download (2.73 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
package eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator;
10

    
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14

    
15
import org.eclipse.core.runtime.IStatus;
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
import jakarta.validation.ConstraintViolationException;
27

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

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

    
36
	@Override
37
	public User createEntity(String text) {
38
		return createEntity(null, text);
39
	}
40

    
41
	@Override
42
	public User createEntity(Object key, String text) {
43

    
44
	    try{
45
            User user = User.NewInstance(text, text);
46
            List<User> userList =CdmStore.getService(IUserService.class).listByUsername(user.getUsername(), MatchMode.EXACT, null, 100, 0, null, null);
47
            if (userList.isEmpty()){
48
            	try {
49
                CdmStore.getService(IUserService.class).createUser(user);
50
            	}catch(Exception e) {
51
            		MessagingUtils.messageDialog(Messages.USER_CREATOR_Name_not_accepted, getClass(), Messages.USER_CREATOR_Name_not_accepted_message);
52
            	}
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(Messages.USER_CREATOR_Acces_denied, getClass(), e.getMessage(), e);
61
            return null;
62
        } catch (ConstraintViolationException cve){
63
            MessagingUtils.messageDialog(Messages.USER_CREATOR_Name_not_accepted, getClass(), Messages.USER_CREATOR_Name_not_accepted_message);
64
            return null;
65
        }
66

    
67
	}
68

    
69
	@Override
70
	public Map<Object, String> getKeyLabelPairs() {
71
		Map<Object, String> result = new HashMap<Object, String>();
72
		result.put(User.class, USER);
73
		return result;
74
	}
75

    
76
	@Override
77
	public boolean savesEntity() {
78
		// TODO Auto-generated method stub
79
		return false;
80
	}
81
}
(8-8/8)