Subversion Repositories SmartDukaan

Rev

Rev 7221 | Rev 8020 | 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
'''
4691 mandeep.dh 6
from shop2020.config.client.ConfigClient import ConfigClient
353 ashish 7
from shop2020.helpers.impl import DataAccessor
4691 mandeep.dh 8
from shop2020.helpers.impl.Converters import to_t_luser, to_t_useremail, \
4806 varun.gupt 9
    to_t_suser, to_t_ruser, to_t_report, to_t_catalog_user, to_t_quicklink
4691 mandeep.dh 10
from shop2020.helpers.impl.DataAccessor import getSubstitutedMessage, getMessage, \
4806 varun.gupt 11
    updateMessage, addMessage, add_user, delete_user, update_password, share_entities, \
4691 mandeep.dh 12
    save_user_email_for_sending, get_emails_to_be_sent, mark_email_as_sent, \
4806 varun.gupt 13
    initialize, close_session, get_reports, authenticate_dashboard_user, is_alive,\
5110 mandeep.dh 14
    save_quick_link, get_quick_links, update_quicklink, \
6322 amar.kumar 15
    get_emails_for_notifications_sent, update_password_for_agent, \
7410 amar.kumar 16
    get_order_confirmation_mail,get_order_delivery_mail, get_warehouseIds_for_agent
4691 mandeep.dh 17
from shop2020.helpers.impl.DataService import LogisticsUser, StatisticsUser, \
2025 ankur.sing 18
    ReportUser, CatalogDashboardUser
4754 mandeep.dh 19
from shop2020.helpers.impl.model.Agent import Agent, User_Roles, Roles_Permissions
759 chandransh 20
from shop2020.thriftpy.utils.ttypes import HelperServiceException
5055 varun.gupt 21
from shop2020.utils.Utils import to_py_date
353 ashish 22
 
900 rajveer 23
 
353 ashish 24
class HelperServiceHandler():
25
 
26
 
3187 rajveer 27
    def __init__(self, dbname='helper', db_hostname='localhost'):
28
        initialize(dbname, db_hostname)
900 rajveer 29
 
30
        '''
31
        try:
32
            config_client = ConfigClient()
33
            self.customer_care_mail = config_client.get_property('saholic_customer_care_mail')
34
        except:    
35
            self.customer_care_mail = "help@saholic.com"
36
        ''' 
353 ashish 37
 
5864 rajveer 38
    def saveUserEmailForSending(self, emailTo, emailFrom, subject, body, source, emailType, cc, bcc):
1395 varun.gupt 39
        try:
5864 rajveer 40
            return save_user_email_for_sending(emailTo, emailFrom, subject, body, source, emailType, cc, bcc)
1395 varun.gupt 41
        finally:
42
            close_session()
43
 
3086 rajveer 44
    def getEmailsToBeSent(self):
1422 varun.gupt 45
        try:
3086 rajveer 46
            return [to_t_useremail(user_email) for user_email in get_emails_to_be_sent()]
1422 varun.gupt 47
        finally:
48
            close_session()
49
 
50
    def markEmailAsSent(self, emailId):
51
        try:
52
            mark_email_as_sent(emailId)
53
        finally:
54
            close_session()
55
 
353 ashish 56
    def sendMail(self, mail):
766 rajveer 57
        try:
58
            DataAccessor.sendMail(mail)
59
        finally:
60
            close_session()
61
 
353 ashish 62
    def sendText(self, message):
63
        """
64
        Parameters:
65
         - message
66
        """
766 rajveer 67
        try:
68
            DataAccessor.sendText(message)
69
        finally:
70
            close_session()
71
 
353 ashish 72
    def addMessage(self, message):
73
        """
74
        Parameters:
75
         - message
76
        """
766 rajveer 77
        try:
78
            addMessage(message)
79
        finally:
80
            close_session()
81
 
353 ashish 82
    def updateMessage(self, id, message):
83
        """
84
        Parameters:
85
         - id
86
         - message
87
        """
766 rajveer 88
        try:
89
            return updateMessage(id, message)
90
        finally:
91
            close_session()
92
 
353 ashish 93
    def getMessage(self, id):
94
        """
95
        Parameters:
96
         - id
97
        """
766 rajveer 98
        try:
99
            return getMessage(id)
100
        finally:
101
            close_session()
102
 
353 ashish 103
    def getSubstitutedMessage(self, id, params):
104
        """
105
        Parameters:
106
         - id
107
         - params
108
        """
766 rajveer 109
        try:
110
            return getSubstitutedMessage(id, params)
111
        finally:
112
            close_session()
113
 
494 rajveer 114
    def addUser(self, username, password, warehouseId):
115
        """
116
        Parameters:
117
         - username
118
         - password
119
         - warehouseId
120
        """
766 rajveer 121
        try:
122
            return add_user(username, password, warehouseId)
123
        finally:
124
            close_session()
494 rajveer 125
 
126
    def deleteUser(self, username):
127
        """
128
        Parameters:
129
         - username
130
        """
766 rajveer 131
        try:
132
            return delete_user(username)
133
        finally:
134
            close_session()
135
 
2445 chandransh 136
    def authenticateDashboardUser(self, username, password):
494 rajveer 137
        """
2445 chandransh 138
        Returns the dashboard user if the supplied username and password match. Raises an exception otherwise.
139
        The loggedOn timestamp for the dashboard user is updated .
140
 
494 rajveer 141
        Parameters:
142
         - username
143
         - password
144
        """
766 rajveer 145
        try:
2445 chandransh 146
            return authenticate_dashboard_user(username, password)
766 rajveer 147
        finally:
148
            close_session()
149
 
494 rajveer 150
 
151
    def updatePassword(self, username, oldPassword, newPassword):
152
        """
153
        Parameters:
154
         - username
155
         - oldPassword
156
         - newPassword
157
        """
766 rajveer 158
        try:
159
            update_password(username, oldPassword, newPassword)
160
        finally:
161
            close_session()
759 chandransh 162
 
163
    def authenticateLogisticsUser(self, username, password):
164
        """
165
        Returns the LogisticsUser struct associated with the given username and password if they match.
166
        Throws an exception otherwise.
167
 
168
        Parameters:
169
         - username
170
         - password
171
        """
172
        try:
173
            luser = LogisticsUser.get_by(username=username, password=password)
174
            return to_t_luser(luser)
175
        except:
766 rajveer 176
            raise HelperServiceException(101, "No such user")
177
        finally:
178
            close_session()
179
 
1610 ankur.sing 180
    def authenticateStatisticsUser(self, username, password):
181
        """
182
        Returns the StatisticsUser struct associated with the given username and password if they match.
183
        Throws an exception otherwise.
184
 
185
        Parameters:
186
         - username
187
         - password
188
        """
189
        try:
190
            suser = StatisticsUser.get_by(username=username, password=password)
191
            return to_t_suser(suser)
192
        except:
193
            raise HelperServiceException(101, "No such user")
194
        finally:
195
            close_session()
196
 
1891 ankur.sing 197
    def authenticateReportUser(self, username, password):
198
        """
199
        Returns the ReportUser struct associated with the given username and password if they match.
200
        Throws an exception otherwise.
201
 
202
        Parameters:
203
         - username
204
         - password
205
        """
206
        try:
207
            ruser = ReportUser.get_by(username=username, password=password)
208
            return to_t_ruser(ruser)
209
        except:
210
            raise HelperServiceException(101, "No such user")
211
        finally:
212
            close_session()
213
 
214
    def getReports(self, role):
215
        """
216
        Returns list of reports which are configured for the given role.
217
 
218
        Parameters:
219
         - role
220
        """
221
        try:
222
            reports = get_reports(role) 
223
            return [to_t_report(report) for report in reports]
224
        finally:
225
            close_session()
2025 ankur.sing 226
 
6788 rajveer 227
    def authenticateCatalogUser(self, username, password):
2025 ankur.sing 228
        """
229
        Returns the CatalogDashboardUser struct associated with the given username and password if they match.
230
        Throws an exception otherwise.
231
 
232
        Parameters:
233
         - username
234
         - password
235
        """
236
        try:
6788 rajveer 237
            catalog_user = CatalogDashboardUser.get_by(username=username, password=password)
2025 ankur.sing 238
            return to_t_catalog_user(catalog_user)
239
        except:
240
            raise HelperServiceException(101, "No such catalog user")
241
        finally:
4806 varun.gupt 242
            close_session()
243
 
244
    def shareEntities(self, entityIds, email):
245
        '''
246
        Shares the entities with en email
247
 
248
        Parameters:
249
         - entityIds
250
         - email
251
        '''
252
        try:
253
            share_entities(entityIds, email)
254
        finally:
255
            close_session()
4691 mandeep.dh 256
 
257
    def getAgents(self, ):
258
        return [Agent.to_thrift_object(t) for t in Agent.query.all()]
259
 
260
    def validateLogIn(self, emailId, password):
261
        """
262
        Parameters:
263
         - emailId
264
         - password
265
        """
266
        pass
267
 
268
    def updatePasswordForAgent(self, agentEmailId, password):
269
        """
270
        Parameters:
271
         - agentEmailId
272
         - password
273
        """
5110 mandeep.dh 274
        try:
275
            update_password_for_agent(agentEmailId, password)
276
        finally:
277
            close_session()
4691 mandeep.dh 278
 
279
    def getRoleNamesForAgent(self, agentEmailId):
280
        """
281
        Parameters:
282
         - agentEmailId
283
        """
4754 mandeep.dh 284
        try:
285
            agent = Agent.get_by(emailId = agentEmailId)
286
            return [a.role_name for a in User_Roles.query.filter_by(agentId = agent.id).all()]
287
        finally:
288
            close_session()
4691 mandeep.dh 289
 
290
    def getPermissionsForRoleName(self, roleName):
291
        """
292
        Parameters:
293
         - roleName
294
        """
4754 mandeep.dh 295
        try:
296
            return [a.permission for a in Roles_Permissions.query.filter_by(role_name = roleName).all()]
297
        finally:
298
            close_session()
1610 ankur.sing 299
 
4806 varun.gupt 300
    def saveQuickLink(self, url, text):
301
        try:
302
            save_quick_link(url, text)
303
        finally:
304
            close_session()
305
 
306
    def getQuickLinks(self):
307
        try:
308
            return [to_t_quicklink(quicklink) for quicklink in get_quick_links()]
309
        finally:
310
            close_session()
311
 
4996 varun.gupt 312
    def updateQuickLink(self, id, url, text):
313
        try:
314
            update_quicklink(id, url, text)
315
        finally:
316
            close_session()
5055 varun.gupt 317
 
318
    def getEmailsForNotificationsSent(self, startDatetime, endDatetime):
319
        '''
320
        '''
321
        try:
322
            return [notification.emailTo for notification in get_emails_for_notifications_sent(to_py_date(startDatetime), to_py_date(endDatetime))]
323
        finally:
324
            close_session()
325
 
6322 amar.kumar 326
    def getOrderConfirmationMail(self, orderId):
327
        try:
328
            return get_order_confirmation_mail(orderId)
329
        finally:
330
            close_session()
331
 
7221 kshitij.so 332
    def getOrderDeliveryMail(self,order_id):
333
        try:
334
            return get_order_delivery_mail(order_id)
335
        finally:
336
            close_session()
337
 
7410 amar.kumar 338
    def getWarehouseIdsForAgent(self, agentEmailId):
339
        try:
340
            return get_warehouseIds_for_agent(agentEmailId)
341
        finally:
342
            close_session()
343
 
766 rajveer 344
    def closeSession(self, ):
3376 rajveer 345
        close_session()
346
 
347
    def isAlive(self, ):
348
        """
349
        For checking weather service is active alive or not. It also checks connectivity with database
350
        """
351
        try:
352
            return is_alive()
353
        finally:
354
            close_session()