Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / services / GenerateSecurityCodeService.java @ 0:02300db8682b

History | View | Annotate | Download (2.15 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 my.com.upass.Constants;
15
import my.com.upass.UPassControllerV2;
16
import my.com.upass.dao.DAOFactoryProvider;
17
import my.com.upass.dao.UserSecurityCodeDAO;
18
import my.com.upass.factory.UPassFactory;
19
import my.com.upass.pojo.SecurityCodeBean;
20
import my.com.upass.security.code.SecurityCodeController;
21

    
22
/**
23
 * PROGRAMMER: Danniell
24
 * CHANGE-NO:
25
 * TASK-NO:
26
 * DATE CREATED: Dec 28, 2011
27
 * TAG AS:
28
 * REASON(S):
29
 * MODIFICATION:
30
 */
31

    
32
/**
33
 * <Class description>
34
 */
35
public class GenerateSecurityCodeService
36
{
37
        private UPassControllerV2 upc;
38
        
39
        public GenerateSecurityCodeService(UPassControllerV2 upc)
40
        {
41
                this.upc = upc;
42
        }
43
        
44
        public String generateSecurityCode (String identifier)
45
        {
46
                String sc = "***" + Constants.ERR_SYSTEM_NOT_READY;
47

    
48
                try
49
                {
50
                        UserSecurityCodeDAO dao = DAOFactoryProvider.getDAOFactory ()
51
                                        .getUserSecurityCodeDAO ();
52
                        SecurityCodeBean bean = dao.getSecurityCodeFromStore (identifier);
53

    
54
                        if (bean == null)
55
                        {
56
                                bean = new SecurityCodeBean ();
57
                                bean.setScReferenceId (identifier);
58
                                boolean isUpdated = dao.updateSecurityCodeToStore (bean);
59

    
60
                                if (!isUpdated)
61
                                {
62
                                        return sc;
63
                                }
64
                        }
65

    
66
                        SecurityCodeController tc = UPassFactory.getSecurityCodeController (
67
                                        bean, upc.getConfigurationsMap ());
68
                        sc = tc.GenerateSecurityCode ();
69
                        bean = (SecurityCodeBean) tc.getUpdatedObject ();
70

    
71
                        // update database
72
                        boolean lrc = dao.updateSecurityCodeToStore (bean);
73

    
74
                        if (!lrc)
75
                        {
76
                                return "***" + Constants.ERR_SYSTEM_NOT_READY;
77
                        }
78
                }
79
                catch (Exception e)
80
                {
81
                        e.printStackTrace ();
82
                        return "***" + Constants.ERR_SYSTEM_NOT_READY;
83
                }
84

    
85
                return sc;
86
        }
87
}