Subversion Repositories SmartDukaan

Rev

Rev 2445 | Rev 3187 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
353 ashish 1
'''
2
Created on 14-Jul-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.helpers.impl import DataAccessor
7
from shop2020.helpers.impl.DataAccessor import getSubstitutedMessage, getMessage,\
2445 chandransh 8
    updateMessage, addMessage, add_user, delete_user, update_password,\
1891 ankur.sing 9
    save_user_email_for_sending, get_emails_to_be_sent, mark_email_as_sent , initialize, close_session,\
2445 chandransh 10
    get_reports, authenticate_dashboard_user
1891 ankur.sing 11
from shop2020.helpers.impl.DataService import LogisticsUser, StatisticsUser,\
2025 ankur.sing 12
    ReportUser, CatalogDashboardUser
759 chandransh 13
from shop2020.thriftpy.utils.ttypes import HelperServiceException
1610 ankur.sing 14
from shop2020.helpers.impl.Converters import to_t_luser, to_t_useremail,\
2025 ankur.sing 15
    to_t_suser, to_t_ruser, to_t_report, to_t_catalog_user
900 rajveer 16
from shop2020.config.client.ConfigClient import ConfigClient
353 ashish 17
 
900 rajveer 18
 
353 ashish 19
class HelperServiceHandler():
20
 
21
 
1248 chandransh 22
    def __init__(self, dbname='helper'):
23
        initialize(dbname)
900 rajveer 24
 
25
        '''
26
        try:
27
            config_client = ConfigClient()
28
            self.customer_care_mail = config_client.get_property('saholic_customer_care_mail')
29
        except:    
30
            self.customer_care_mail = "help@saholic.com"
31
        ''' 
353 ashish 32
 
1395 varun.gupt 33
    def saveUserEmailForSending(self, emailTo, emailFrom, subject, body, source, emailType):
34
        try:
35
            save_user_email_for_sending(emailTo, emailFrom, subject, body, source, emailType)
36
        finally:
37
            close_session()
38
 
3086 rajveer 39
    def getEmailsToBeSent(self):
1422 varun.gupt 40
        try:
3086 rajveer 41
            return [to_t_useremail(user_email) for user_email in get_emails_to_be_sent()]
1422 varun.gupt 42
        finally:
43
            close_session()
44
 
45
    def markEmailAsSent(self, emailId):
46
        try:
47
            mark_email_as_sent(emailId)
48
        finally:
49
            close_session()
50
 
353 ashish 51
    def sendMail(self, mail):
766 rajveer 52
        try:
53
            DataAccessor.sendMail(mail)
54
        finally:
55
            close_session()
56
 
353 ashish 57
    def sendText(self, message):
58
        """
59
        Parameters:
60
         - message
61
        """
766 rajveer 62
        try:
63
            DataAccessor.sendText(message)
64
        finally:
65
            close_session()
66
 
353 ashish 67
    def addMessage(self, message):
68
        """
69
        Parameters:
70
         - message
71
        """
766 rajveer 72
        try:
73
            addMessage(message)
74
        finally:
75
            close_session()
76
 
353 ashish 77
    def updateMessage(self, id, message):
78
        """
79
        Parameters:
80
         - id
81
         - message
82
        """
766 rajveer 83
        try:
84
            return updateMessage(id, message)
85
        finally:
86
            close_session()
87
 
353 ashish 88
    def getMessage(self, id):
89
        """
90
        Parameters:
91
         - id
92
        """
766 rajveer 93
        try:
94
            return getMessage(id)
95
        finally:
96
            close_session()
97
 
353 ashish 98
    def getSubstitutedMessage(self, id, params):
99
        """
100
        Parameters:
101
         - id
102
         - params
103
        """
766 rajveer 104
        try:
105
            return getSubstitutedMessage(id, params)
106
        finally:
107
            close_session()
108
 
494 rajveer 109
    def addUser(self, username, password, warehouseId):
110
        """
111
        Parameters:
112
         - username
113
         - password
114
         - warehouseId
115
        """
766 rajveer 116
        try:
117
            return add_user(username, password, warehouseId)
118
        finally:
119
            close_session()
494 rajveer 120
 
121
    def deleteUser(self, username):
122
        """
123
        Parameters:
124
         - username
125
        """
766 rajveer 126
        try:
127
            return delete_user(username)
128
        finally:
129
            close_session()
130
 
2445 chandransh 131
    def authenticateDashboardUser(self, username, password):
494 rajveer 132
        """
2445 chandransh 133
        Returns the dashboard user if the supplied username and password match. Raises an exception otherwise.
134
        The loggedOn timestamp for the dashboard user is updated .
135
 
494 rajveer 136
        Parameters:
137
         - username
138
         - password
139
        """
766 rajveer 140
        try:
2445 chandransh 141
            return authenticate_dashboard_user(username, password)
766 rajveer 142
        finally:
143
            close_session()
144
 
494 rajveer 145
 
146
    def updatePassword(self, username, oldPassword, newPassword):
147
        """
148
        Parameters:
149
         - username
150
         - oldPassword
151
         - newPassword
152
        """
766 rajveer 153
        try:
154
            update_password(username, oldPassword, newPassword)
155
        finally:
156
            close_session()
759 chandransh 157
 
158
    def authenticateLogisticsUser(self, username, password):
159
        """
160
        Returns the LogisticsUser struct associated with the given username and password if they match.
161
        Throws an exception otherwise.
162
 
163
        Parameters:
164
         - username
165
         - password
166
        """
167
        try:
168
            luser = LogisticsUser.get_by(username=username, password=password)
169
            return to_t_luser(luser)
170
        except:
766 rajveer 171
            raise HelperServiceException(101, "No such user")
172
        finally:
173
            close_session()
174
 
1610 ankur.sing 175
    def authenticateStatisticsUser(self, username, password):
176
        """
177
        Returns the StatisticsUser struct associated with the given username and password if they match.
178
        Throws an exception otherwise.
179
 
180
        Parameters:
181
         - username
182
         - password
183
        """
184
        try:
185
            suser = StatisticsUser.get_by(username=username, password=password)
186
            return to_t_suser(suser)
187
        except:
188
            raise HelperServiceException(101, "No such user")
189
        finally:
190
            close_session()
191
 
1891 ankur.sing 192
    def authenticateReportUser(self, username, password):
193
        """
194
        Returns the ReportUser struct associated with the given username and password if they match.
195
        Throws an exception otherwise.
196
 
197
        Parameters:
198
         - username
199
         - password
200
        """
201
        try:
202
            ruser = ReportUser.get_by(username=username, password=password)
203
            return to_t_ruser(ruser)
204
        except:
205
            raise HelperServiceException(101, "No such user")
206
        finally:
207
            close_session()
208
 
209
    def getReports(self, role):
210
        """
211
        Returns list of reports which are configured for the given role.
212
 
213
        Parameters:
214
         - role
215
        """
216
        try:
217
            reports = get_reports(role) 
218
            return [to_t_report(report) for report in reports]
219
        finally:
220
            close_session()
2025 ankur.sing 221
 
2358 ankur.sing 222
    def authenticateCatalogUser(self, username, password, role):
2025 ankur.sing 223
        """
224
        Returns the CatalogDashboardUser struct associated with the given username and password if they match.
225
        Throws an exception otherwise.
226
 
227
        Parameters:
228
         - username
229
         - password
230
        """
231
        try:
2358 ankur.sing 232
            catalog_user = CatalogDashboardUser.get_by(username=username, password=password, role=role)
2025 ankur.sing 233
            return to_t_catalog_user(catalog_user)
234
        except:
235
            raise HelperServiceException(101, "No such catalog user")
236
        finally:
237
            close_session()         
1610 ankur.sing 238
 
766 rajveer 239
    def closeSession(self, ):
240
        close_session()