Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / services / CreateUserService.java @ 17:4173ef25ee8d

History | View | Annotate | Download (3.04 KB)

1
/**
2
 * Copyright (c) 2010 Penril Datability (M) Sdn Bhd All rights reserved.
3
 *
4
 * This software is copyrighted. Under the copyright laws, this software
5
 * may not be copied, in whole or in part, without prior written consent
6
 * of Penril Datability (M) Sdn Bhd or its assignees. This software is
7
 * provided under the terms of a license between Penril Datability (M)
8
 * Sdn Bhd and the recipient, and its use is subject to the terms of that
9
 * license.
10
 */
11

    
12
package my.com.upass.services;
13

    
14
import java.util.Date;
15

    
16
import my.com.upass.Constants;
17
import my.com.upass.UPassControllerV2;
18
import my.com.upass.dao.DAOFactoryProvider;
19
import my.com.upass.dao.UserDAO;
20
import my.com.upass.factory.UPassFactory;
21
import my.com.upass.pojo.TacBean;
22
import my.com.upass.pojo.UserBean;
23
import my.com.upass.pojo.UserMasterBean;
24
import my.com.upass.spassword.PasswordController;
25

    
26
/**
27
 * PROGRAMMER: Danniell
28
 * CHANGE-NO:
29
 * TASK-NO:
30
 * DATE CREATED: Dec 28, 2011
31
 * TAG AS:
32
 * REASON(S):
33
 * MODIFICATION:
34
 */
35

    
36
/**
37
 * <Class description>
38
 */
39
public class CreateUserService
40
{
41
        private UPassControllerV2 upc;
42
        
43
        public CreateUserService(UPassControllerV2 upc)
44
        {
45
                this.upc = upc;
46
        }
47
        
48
        public int addUser (String userAlias, int userType, String userDesc,
49
                        String userPassword, int userState, int applicationId)
50
        {
51
                int rc = Constants.ERR_SYSTEM_NOT_READY;
52

    
53
                if (userAlias == null || userPassword == null)
54
                {
55
                        return Constants.ERR_INVALID_INPUT;
56
                }
57

    
58
                UserDAO userDao;
59

    
60
                try
61
                {
62
                        userDao = DAOFactoryProvider.getDAOFactory ().getUserDAO ();
63
                        
64
                        UserBean ub = userDao.getUserFromStore (userAlias);
65
                        
66
                        if(ub == null)
67
                        {
68
                                long nextVal = userDao.getNextSequenceNumber ("SEQ_USER_ID_SEQ_VALUE_SEQ");
69
                                
70
                                ub = new UserBean ();
71
                                ub.setUserID (nextVal);
72
                                ub.setUserAlias (userAlias);
73
                                ub.setDescription (userDesc);
74
                                ub.setUserType (userType);
75
                                ub.setUstate (userState);
76
                                ub.setUdateCreated (new Date());
77
                                ub.setPdateCreated (new Date());
78
                                ub.setApplicationId(applicationId);
79
                                
80
                                PasswordController pc = UPassFactory.getPasswordController (ub,
81
                                                upc.getConfigurationsMap ());
82
                                rc = pc.VerifyUserAlias (userAlias);
83
                                
84
                                if(rc != Constants.ERR_SUCCESS)
85
                                {
86
                                        return rc;
87
                                }
88
                                
89
                                rc = pc.GeneratePassword (userPassword, true);
90
                                
91
                                if(rc != Constants.ERR_SUCCESS)
92
                                {
93
                                        return rc;
94
                                }
95
                                
96
                                ub = (UserBean) pc.getUpdatedObject ();
97

    
98
                                UserMasterBean master = new UserMasterBean ();
99
                                master.setUserAlias (ub.getUserAlias ());
100
                                master.setUserID (ub.getUserID ());
101
                                ub.setUpassUserMaster (master);
102
                                TacBean tac = new TacBean ();
103
                                tac.setUserID (ub.getUserID ());
104
                                tac.setUpassUser (ub);
105
                                ub.setTacbean (tac);
106
                                
107
                                if (userDao.insertUserToStore (ub))
108
                                {
109
                                        rc = Constants.ERR_SUCCESS;
110
                                }
111
                                else
112
                                {
113
                                        rc = Constants.ERR_SYSTEM_NOT_READY;
114
                                }
115
                        }
116
                        else
117
                        {
118
                                rc = Constants.ERR_ALREADY_EXIST;
119
                        }
120
                }
121
                catch (Exception e)
122
                {
123
                        e.printStackTrace ();
124
                }
125
                return rc;
126
        }
127
}