def createFieldVal(self, mshipId, field_id, field_value):
     restURL = cfg.url + cfg.custFieldValuesApi.format(str(mshipId))
     jData = cfg.fval_json_string.format(field_id, field_value)
     if cfg.DEBUG:
         print(restURL)
     try:
         s = getSession()
         r = s.post(restURL,
                    data=jData,
                    json=None,
                    auth=(cfg.userName, cfg.password),
                    headers=cfg.headers)
         if (r.ok):
             jData = json.loads(r.content)
             if 'id' in jData:
                 if cfg.DEBUG:
                     print('Field value created.')
                 fv_id = jData['id']
                 self.updateFieldValDB(mshipId, field_id, fv_id)
             else:
                 print('Custom field value creation failed.', str(mshipId),
                       str(field_id), str(fv_id))
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         error, = x.args
         print(error)
 def updateFieldVal(self, v_mship_id, v_id, v_value):
     restURL = cfg.url + cfg.updCustFieldValuesApi.format(
         str(v_mship_id), str(v_id))
     jData = cfg.upd_fval_json_string.format(v_value)
     error = ''
     if cfg.DEBUG:
         print('Updating custom field value:', str(v_id), str(v_mship_id),
               v_value)
         print(restURL)
     try:
         s = getSession()
         r = s.put(restURL,
                   data=jData,
                   json=None,
                   auth=(cfg.userName, cfg.password),
                   headers=cfg.headers)
         if r.ok:
             jData = json.loads(r.content)
             if 'id' in jData:
                 if cfg.DEBUG:
                     print('Field value updated.')
                 return v_id, None
             else:
                 print('Field value update failed.', str(v_id),
                       str(v_mship_id), v_value)
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         error, = x.args
         print(error)
     return None, error
示例#3
0
    def findMembership(self, userId):
        restURL = cfg.url + cfg.membershipApi.format(str(userId))
        if cfg.DEBUG:
            print('Searching membership of user', str(userId))
        try:
            s = getSession()
            r = s.get(restURL,
                      auth=(cfg.userName, cfg.password),
                      headers=cfg.headers)
            membershipId = None
            if r.ok:
                jData = json.loads(r.content)
                items = jData['items']
                count = jData['count']

                if count > 0:
                    for x in items:
                        if x['learnCenterId'] == 178410:
                            membershipId = x['id']
                            membershipStatus = x['status']
                            return membershipId, membershipStatus
        except Exception as x:
            print('Exception :(', x.__class__.__name__)
            print(traceback.format_exc())
        return None, None
示例#4
0
 def createMembership(self, userId):
     jData = cfg.mship_json_string.format(178410, userId, 'approved')
     restURL = cfg.url + cfg.createMshipApi
     if cfg.DEBUG:
         print(restURL)
     try:
         s = getSession()
         r = s.post(restURL,
                    data=jData,
                    json=None,
                    auth=(cfg.userName, cfg.password),
                    headers=cfg.headers)
         if (r.ok):
             jData = json.loads(r.content)
             if 'id' in jData:
                 if cfg.DEBUG:
                     print('Membership created.')
                 membershipId = jData['id']
                 return membershipId, self.errorMsg
             else:
                 self.errorMsg = 'Membership creation failed.'
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         error, = x.args
         self.errorMsg = error
     print(self.errorMsg)
     return None, self.errorMsg
示例#5
0
    def updateMembership(self, mshipId, status):
        restURL = cfg.url + cfg.mshipApi.format(str(mshipId))
        jData = self.mship_json_string.format(status)
        if cfg.DEBUG:
            print('Update membership ', str(mshipId))
        try:
            s = getSession()
            r = s.patch(restURL,
                        data=jData,
                        json=None,
                        auth=(cfg.userName, cfg.password),
                        headers=cfg.headers)
            if r.ok:
                if cfg.DEBUG:
                    print('Membership status updated - ', mshipId, 'to',
                          status)
                return cfg.SUCCESS, self.errorMsg
            else:
                errortxt = json.loads(r.content)
                self.errorMsg = 'Membership status update failed ' + str(
                    mshipId) + ' ' + status + ' ' + errortxt['title']

        except Exception as x:
            self.errorMsg = 'Exception :(' + x.__class__.__name__
            print(traceback.format_exc())
        print(self.errorMsg.encode('utf-8'))
        return None, self.errorMsg
示例#6
0
    def updateUser(self, row):
        try:
            s = getSession()
            v_oracle_id = row[0]
            v_email = row[10]
            v_user_id = row[11]
            v_sysdate = row[12]
            if v_email is None or ' ' in v_email or len(
                    v_email) > 50 or not re.match(r"[^@]+@[^@]+\.[^@]+",
                                                  v_email):
                v_email = '*****@*****.**'
            restURL = cfg.url + cfg.usersApi + '/' + str(v_user_id)
            membershipId = -1
            membershipStatus = None
            if v_user_id is not None:
                membershipId, membershipStatus = self.findMembership(v_user_id)
            else:
                print('Missing User Id for oracle Id ', v_oracle_id)

            if row[13] == 'EXPIRED':
                if cfg.DEBUG:
                    print('Terminating Oracle Id ', v_oracle_id, restURL)
                jData = self.term_json_string.format(v_sysdate)
                if membershipId is not None and membershipId > 0:
                    self.updateMembership(membershipId, 'removed')
                else:
                    print('Missing membership Id for oracle Id ', v_oracle_id)
            else:
                if cfg.DEBUG:
                    print('Updating Oracle Id ', v_oracle_id, restURL)
                jData = self.user_json_string.format(v_oracle_id, row[1],
                                                     row[2], row[3], row[4],
                                                     row[5], row[6], row[7],
                                                     row[8], row[9], v_email,
                                                     None)
                if membershipStatus is not None and membershipStatus == 'removed':
                    self.updateMembership(membershipId, 'approved')

            jsjData = json.loads(jData.encode('utf-8'),
                                 object_pairs_hook=dict_clean)
            r = s.patch(restURL,
                        data=None,
                        json=jsjData,
                        auth=(cfg.userName, cfg.password),
                        headers=cfg.headers)
            if r.ok:
                jData = json.loads(r.content, object_pairs_hook=dict_clean)
                if cfg.DEBUG:
                    print('User Updated.')
                return jData, self.errorMsg
            else:
                errortxt = json.loads(r.content)
                self.errorMsg = 'User not Updated. Failed with status code :' + str(
                    r.status_code) + ' ' + errortxt['title'] + ' ' + str(
                        row[0])
        except Exception as x:
            self.errorMsg = 'Exception :(' + x.__class__.__name__
            print(traceback.format_exc())
        print(self.errorMsg.encode('utf-8').decode('utf-8'))
        return None, self.errorMsg
示例#7
0
 def createSupAccount(self, userId):
     s = getSession()
     actId = None
     try:
         restURL = cfg.url + cfg.createSupApi.format(str(178410))
         jData = cfg.sup_json_string.format(userId)
         if cfg.DEBUG:
             print(restURL)
         r2 = s.post(restURL,
                     data=jData,
                     json=None,
                     auth=(cfg.userName, cfg.password),
                     headers=cfg.headers)
         jData = json.loads(r2.content)
         if (r2.ok):
             if 'id' in jData:
                 if cfg.DEBUG:
                     print('Account created.')
                 actId = jData['id']
             else:
                 self.errorMsg = 'Account creation failed.'
         else:
             if 'Title' in jData:
                 self.errorMsg = jData['Title']
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         self.errorMsg = traceback.format_exc()
     if self.errorMsg is not None:
         print(self.errorMsg)
     return actId, self.errorMsg
示例#8
0
 def findSupAccount(self, userId):
     s = getSession()
     actId = None
     restURL = cfg.url + cfg.mshipApi.format(str(userId))
     try:
         r = s.get(restURL,
                   auth=(cfg.userName, cfg.password),
                   headers=cfg.headers)
         if r.ok:
             jData = json.loads(r.content)
             if 'supervisorAccountId' in jData:
                 actId = jData['supervisorAccountId']
                 return actId
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         print(traceback.format_exc())
     return None
示例#9
0
    def createUser(self, row):
        try:
            s = getSession()
            restURL = cfg.url + cfg.usersApi
            if cfg.DEBUG:
                print('Creating User account for Oracle Id ', row[0])
            v_email = row[10]

            if v_email is not None and len(v_email) > 50:
                v_email = v_email[1:37] + '@DONOTUSE.COM'

            if v_email is None or ' ' in v_email or not re.match(
                    r"[^@]+@[^@]+\.[^@]+", v_email):
                v_email = row[1].replace(' ', '') + '.' + row[2].replace(
                    ' ', '') + '@DONOTUSE.COM'
                self.errorMsg = 'Invalid Email.'
            jData = self.user_json_string.format(
                row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7],
                row[8], row[9], v_email,
                datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"))
            if cfg.DEBUG:
                print(restURL)
            jsjData = json.loads(jData.encode('utf-8'),
                                 object_pairs_hook=dict_clean)
            r = s.post(restURL,
                       data=None,
                       json=jsjData,
                       auth=(cfg.userName, cfg.password),
                       headers=cfg.headers)
            if r.ok:
                jData = json.loads(r.content)
                return jData, self.errorMsg
            else:
                errortxt = json.loads(r.content)
                self.errorMsg = 'User creation failed.' + ' ' + str(
                    row[0]) + ' ' + str(
                        r.status_code) + ' ' + errortxt['title']
        except Exception as x:
            self.errorMsg = 'Exception :(' + x.__class__.__name__
            print(traceback.format_exc())
        if self.errorMsg is not None:
            print(self.errorMsg.encode('utf-8').decode('utf-8'))
        return None, self.errorMsg
示例#10
0
 def findUser(self, oracleId):
     s = getSession()
     searchURL = cfg.url + cfg.usersApi + cfg.searchUser % (str(oracleId))
     if cfg.DEBUG:
         print('Searching for Oracle Id ', str(oracleId), searchURL)
     try:
         r = s.get(searchURL,
                   auth=(cfg.userName, cfg.password),
                   headers=cfg.headers)
         if r.ok:
             jData = json.loads(r.content)
             items = jData['items']
             count = jData['count']
             if count == 1:
                 return items[0]
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         print(traceback.format_exc())
     return None
示例#11
0
    def delSupAccount(self, actId):
        s = getSession()
        restURL = cfg.url + cfg.delSupApi.format(str(178410), actId)
        try:
            r = s.delete(restURL, auth=(cfg.userName, cfg.password))
            if r.status_code == 204:
                if cfg.DEBUG:
                    print('Supervisor Account deleted ', actId)
                return cfg.SUCCESS, self.errorMsg
            elif r.status_code == 404:
                print('Supervisor Account not found ', actId)
                return cfg.SUCCESS, self.errorMsg
            else:
                self.errorMsg = 'Error while deleting account:status code:' + ' ' + str(
                    r.status_code)

        except Exception as x:
            print('Exception :(', x.__class__.__name__)
            error, = x.args
            self.errorMsg = error
        if self.errorMsg is not None:
            print(self.errorMsg)
        return cfg.FAILURE, self.errorMsg
 def findFieldVals(self, mshipId):
     restURL = cfg.url + cfg.custFieldValuesApi.format(str(mshipId))
     if cfg.DEBUG:
         print('Searching custom field values of memeberhsip:',
               str(mshipId))
     try:
         s = getSession()
         r = s.get(restURL,
                   auth=(cfg.userName, cfg.password),
                   headers=cfg.headers)
         if r.ok:
             jData = json.loads(r.content)
             items = jData['items']
             count = jData['count']
             if count is None:
                 count = 0
             return count, items
         else:
             print('Search failed.')
             print(r.text)
     except Exception as x:
         print('Exception :(', x.__class__.__name__)
         print(traceback.format_exc())
     return 0, None
示例#13
0
 def updateManagerName(self, user_id, manager_name):
     try:
         s = getSession()
         restURL = cfg.url + cfg.usersApi + '/' + str(user_id)
         jData = self.sup_json_string.format(manager_name).encode('utf-8')
         r = s.patch(restURL,
                     data=jData,
                     json=None,
                     auth=(cfg.userName, cfg.password),
                     headers=cfg.headers)
         if r.ok:
             if cfg.DEBUG:
                 print('Supervisor name updated for user ', user_id,
                       manager_name)
             return cfg.SUCCESS, self.errorMsg
         else:
             errortxt = json.loads(r.content)
             self.errorMsg = 'Supervisor name update failed ' + str(
                 user_id) + ' ' + manager_name + ' ' + errortxt['title']
     except Exception as x:
         self.errorMsg = 'Exception :(' + x.__class__.__name__
         print(traceback.format_exc())
     print(self.errorMsg.encode('utf-8'))
     return None, self.errorMsg