Пример #1
0
def sp_runtest(rule_id, ruleDetailsId) -> JsonResponse:
    try:
        logger = get_logger()
        connection = db_conn()
        payload = get_sp_payload(ruleDetailsId)
        if not payload:
            logger.error("Error in executing stored procedure ")
            return create_failure(500, 'Error in executing stored procedure',
                                  'Failed')
        sptable = models.Storedproceduretable.objects.filter(
            ruledetailsid=ruleDetailsId).values_list('storedprocname')
        cursor = connection.cursor()
        for sp in sptable:
            try:
                logger.debug("exec digicube_wam.dbo.test_sp" + str(sp[0]))
                # resultset = cursor.execute("exec "+ str(sp[0])).fetchall()
                # if not resultset:
                #     return create_failure(500, 'Error in executing stored procedure', 'Failed')
            except Exception as e:
                logger.error("Error in executing stored procedure: ", str(e))
                return create_failure(500,
                                      'Error in executing stored procedure',
                                      'Failed')
        cursor.close()
        connection.close()
    except Exception as e:
        logger.error("Error in executing stored procedure: ", str(e))
        return create_failure(500, 'Error in executing stored procedure',
                              'Failed')
    return create_success('Success')
Пример #2
0
 def run_test_function(self, payload) -> JsonResponse:
     try:
         rule_id = payload['RuleID']
         session_id = payload['SessionID']
         toDoList_id = payload['ToDoListID']
         user_id = payload['UserID']
     except Exception as e:
         self.logger.error("Error in fetching data from db : "+str(e))
         return JsonResponse(create_failure(500, 'Please provide valid key', 'Fail'))
     try:
         todayDate = datetime.datetime.now()
         testdetails = Ruledetails.objects.filter(ruleid=rule_id).values_list('ruletype','resultquery','ruledetailsid')
         if testdetails.exists():
             for testdetailsitems in testdetails:
                 try:
                     # create mapping table entry
                     sessionTestId = uuid.uuid4()
                     mappingsessiontest = models.Sessiontestmapping(sessiontestid = sessionTestId, userid = user_id, sessionid = session_id,
                             todolistid = toDoList_id, ruleid = rule_id, createddate = todayDate, ruledetailsid = testdetailsitems[2])
                     mappingsessiontest.save()
                     if str(testdetailsitems[0]) == "sp_query":
                         resSP = sp_runtest(rule_id, testdetailsitems[2])
                         if resSP['statusCode'] == 200:
                             return create_success('Success')
                         else:
                             return create_failure(500, 'Failed to execute Stored Procedure', 'Failed')
                     elif str(testdetailsitems[0]) == "api":
                         resapi = api_run_test(rule_id, testdetailsitems[2])
                         if resapi['statusCode'] == 200:
                             return create_success('Success')
                         else:
                             return create_failure(500, 'Failed to execute Stored Procedure', 'Failed')
                 except Exception as e:
                     self.logger.error("Error in parsing ruledetails table: "+str(e))
                     return create_failure(500, 'Error in parsing ruledetails table', 'Failed')
         else:
             return create_failure(500, 'No data for seleted Rule Id', 'Failed')
         self.connection.close()
     except Exception as e:
         self.logger.error("Error in fetching the tests: "+str(e))
         return create_failure(500, 'Error in parsing ruledetails table', 'Failed')
     return create_success('Success')
Пример #3
0
def api_run_test(rule_id, ruleDetailsId) -> JsonResponse:
    try:
        logger = get_logger()
        payload = get_api_parameter(ruleDetailsId)
        if not payload:
            logger.error("Error in run test API")
            return create_failure(500, 'Error in run test API', 'Failed')
        api_endpoint = ''
    except Exception as e:
        logger.error("Error in run test API: ", str(e))
        return create_failure(500, 'Error in run test API', 'Failed')
    return create_success('success')
Пример #4
0
 def powerbi(self, payload) -> JsonResponse:
     try:
         ruleid = payload['ruleid']
         ruleid_url = TestClientTemplateMapping.objects.filter(ruleid=ruleid).values_list('url')
         try:
             url = ruleid_url[0][0]
         except Exception as e:
             self.logger.error("No URL found for selected ruleid: "+str(e))
             return create_failure(500, 'No URL found for selected ruleid', 'Failed')
     except Exception as e:
         self.logger.error("Error in Powerbi url: "+str(e))
         return create_failure(500, 'Error in Powerbi url', 'Failed')
     return create_success('Success')
Пример #5
0
def insert_into_db(request,data):
    try:
        overwriteMerge = request['Overwrite_merge']
        databaseName = request['DatabaseName']
        tableName = request['TableName']
    except Exception as e:
        logger.error("Error While Inserting into Database"+str(e))
        return create_failure(500, 'Error While Inserting into Database', 'Failed')
    try:
        connection = db_conn(databaseName)
    except Exception as e:
        logger.error("Error While Creation of Engine "+str(e))
        return create_failure(500, 'Error While Creation of Engine', 'Failed')
    try:
        try:
            if(overwriteMerge == "O"):
                cursor = connection.cursor()
                cursor.execute('TRUNCATE TABLE {}'.format(tableName))
                connection.commit()
                cursor.close()
            elif(overwriteMerge != "M"):
                return False
        except Exception as e:
            logger.error("Error While Inserting into DB: "+str(e))
            return create_failure(500, 'Error While Inserting into DB ', 'Failed')
        cursor = connection.cursor()
        tuples = [tuple(x) for x in data.to_numpy()]
        cols = "],[".join([str(i) for i in data.columns.tolist()])
        databaseChunk = int(config['ENV_VARIABLE']['database_chunk'])
        chunk = int(len(tuples)/databaseChunk)
        cursor.fast_executemany = True
        for i in range(1,chunk+2):
            try:
                val = tuples[(i-1)*databaseChunk:i*databaseChunk]
                query = upload_file_sql_query(tableName,cols,data.columns)
                cursor.executemany(query,val)
            except Exception as e:
                cursor.close()
                connection.close()
                logger.error("Error While Inserting into DB "+str(e))
                return create_failure(500, 'Error While Inserting into DB', 'Failed')
        connection.commit()
        cursor.close()
        connection.close()
        logger.info("Success")
    except Exception as e:
        logger.error("Error While Inserting into DB "+str(e))
        return create_failure(500, 'Error While Inserting into DB', 'Failed')
    return(create_success('Data Dumped Successfully',''))
Пример #6
0
 def post(self, request: Request) -> JsonResponse:
     """
     :param request: Client request containing request information
     :return:
     """
     try:
         emailid = request.data['email']
         user_password = request.data['password']
     except Exception as e:
         self.logger.error("Error in email address or password." + str(e))
         return JsonResponse(create_failure(500, 'Value Missing', 'Fail'))
     if len(emailid) < 1:
         self.logger.error("Error in email address.")
         return JsonResponse(
             create_failure(401, 'Incorrect Email Address', 'Fail'))
     try:
         userInfo = Userlogindetails.objects.get(emailaddress=emailid)
     except Exception as e:
         self.logger.error("Error in Email Address." + str(e))
         return JsonResponse(create_failure(401, 'Email not found', 'Fail'))
     try:
         if str(userInfo.password) == (user_password):
             try:
                 jwtToken = make_jwt_token(data={'userid': userInfo.id})
                 outputDict = {
                     'Email': userInfo.emailaddress,
                     'Password': userInfo.password,
                     'UserID': userInfo.id,
                     'Token': jwtToken
                 }
                 output = create_success('Authorization Successful!',
                                         outputDict)
             except Exception as e:
                 self.logger.error(
                     "Error while connecting to POST API of Login Module." +
                     str(e))
                 return JsonResponse(
                     create_failure(401, 'Authorization Failed', 'Fail'))
         else:
             return JsonResponse(
                 create_failure(401, 'Incorrect Password', 'Fail'))
     except Exception as e:
         self.logger.error(
             "Error while connecting to POST API of Login Module." + str(e))
         return JsonResponse(
             create_failure(401, 'Authorization Failed', 'Fail'))
     return JsonResponse(output)
Пример #7
0
 def export_class(self,ruleidVar):
     try:
         output = {}
         fileNameList = []
         ruleidValue  = ruleidVar['RuleID']
         self.logger.info(ruleidValue)
         ruleDetailsObject = Ruledetails.objects.filter(ruleid=ruleidValue)
         ruleDetailsData = ruledetailsSerializer(ruleDetailsObject, many=True)  
         if(ruleDetailsObject.exists()):
             try:
                 for ruledetailsRecord in ruleDetailsData.data:
                     try:
                         annexureFileName = ruledetailsRecord['annexurefilename']
                         if(annexureFileName != None):
                             if(ruleidVar['FileType'].lower() == 'excel'):
                                 fileName = annexureFileName + '.xlsx'
                             else:
                                 fileName = annexureFileName + '.csv'
                         else:
                             if(ruleidVar['FileType'].lower() == 'excel'):
                                 fileName = ruledetailsRecord['ruleid'] + '_' + str(ruledetailsRecord['sequenceno']) + '.xlsx'
                             else:
                                 fileName = ruledetailsRecord['ruleid'] + '_' + str(ruledetailsRecord['sequenceno']) + '.csv'
                         self.logger.info(fileName)
                         fileNameList.append(fileName)
                         dbVar = FetchDatabaseName()
                         dbName = dbVar.fetch(ruleidVar['SessionID'])
                         responseCreateFile = self.create_file(ruledetailsRecord,fileName,ruleidVar['FileType'].lower(),ruleidVar['ID'],dbName)
                         if(responseCreateFile != True):
                             return responseCreateFile
                     except Exception as e:
                         self.logger.error("Error in Export Test API during Fetching Ruleid Details from table"+str(e))
                         return create_failure(500, 'Error in Export Test API during Fetching Ruleid Details from table', 'Failed')
             except Exception as e:
                 self.logger.error("Error in Export Test API during Fetching Ruleid Details from table"+str(e))
                 return create_failure(500, 'Error in Export Test API during Fetching Ruleid Details from table', 'Failed')
         try:
             output['fileName'] = ','.join(fileNameList)
             output['appUrl'] = self.appUrl + self.config['ENV_VARIABLE']['download_files'] + ruleidVar['ID']
         except Exception as e:
             self.logger.error("Error in Export Test API during creation of output"+str(e))
             return create_failure(500, 'Error in Export Test API during creation of output', 'Failed')
     except Exception as e:
         self.logger.error("Error in Export Test API "+str(e))
         return create_failure(500, 'API Fail due to Exception', 'Failed')
     return create_success("Export API is Working",output)
Пример #8
0
 def post(self, request:Request) -> JsonResponse:
     try:
         userid = verify_jwt_token(request.META['HTTP_AUTHORIZATION'])
         if userid == 0:
             self.logger.error("Error in View Results API token: ")
             return JsonResponse(create_failure(400, 'Invalid token', 'Fail'))
     except Exception as e:
         self.logger.error("Error in View Results API: "+str(e))
         return JsonResponse(create_failure(400, 'Please provide valid token', 'Fail'))
     try:
         session_id = request.data['SessionID']
     except Exception as e:
         self.logger.error("invalid SessionID"+str(e))
         return JsonResponse(create_failure(400, 'invalid SessionID', 'Fail'))
     try:
         resultset = []
         testdetails = Sessiontestmapping.objects.filter(userid=userid, sessionid=session_id).values_list('ruledetailsid',
                         'todolistid','ruleid','createddate')
         if testdetails.exists():
             for mappingitems in testdetails:
                 resultdict = {}
                 try:
                     ruledetails = dashboardModels.Ruledetails.objects.filter(ruledetailsid=mappingitems[0]).values_list('shortdescription')
                     for ruledetailsitem in ruledetails:
                         resultdict['ShortDescription'] = ruledetailsitem[0]
                     rulemaster = dashboardModels.Rulemaster.objects.filter(rulemasterid=mappingitems[2]).values_list('testno', 'testname')
                     resultdict['TestNo'] = rulemaster[0][0]
                     resultdict['TestName'] = rulemaster[0][1]
                     todoliststatus = Todolist.objects.filter(id=mappingitems[1]).values_list('status')
                     resultdict['Status'] = todoliststatus[0][0]
                     resultdict['CreatedDate'] = mappingitems[3]
                     resultdict['RuleId'] = mappingitems[2]
                     resultset.append(resultdict)
                 except Exception as e:
                     self.logger.error("Occured error while fetching list of Results: "+str(e))
                     return JsonResponse(create_failure(400, 'Invalid SessionID', 'Fail'))
         else:
             return JsonResponse(create_failure(500, 'No Records Found', 'Fail'))
     except Exception as e:
         self.logger.error("Occured error while fetching list of Results: "+str(e))
         return JsonResponse(create_failure(400, 'Bad Request', 'Fail'))
     return JsonResponse(create_success('success', resultset))
Пример #9
0
    def main_function(self, request):
        try:
            ########## Excel File Delete ##########
            try:
                excelFileRoot = self.config['ENV_VARIABLE']['file_path']
                res = self.file_path_creation(request, excelFileRoot)
                if (res == False):
                    create_failure(500, "API Fail due to Exception", "Failed")
            except Exception as e:
                self.logger.error("Error in Delete API " + str(e))
                return JsonResponse(
                    create_failure(500, "API Fail due to Exception", "Failed"))

            ########## Zip File Delete ##########
            try:
                zipFileRoot = self.config['ENV_VARIABLE']['file_path_zip']
                res = self.file_path_creation(request, zipFileRoot)
                if (res == False):
                    create_failure(500, "API Fail due to Exception", "Failed")
            except Exception as e:
                self.logger.error("Error in Delete API " + str(e))
                return JsonResponse(
                    create_failure(500, "API Fail due to Exception", "Failed"))

            ########## Download File Delete ##########
            try:
                downloadFileRoot = self.config['ENV_VARIABLE'][
                    'file_path_download']
                res = self.file_path_creation(request, downloadFileRoot)
                if (res == False):
                    create_failure(500, "API Fail due to Exception", "Failed")
            except Exception as e:
                self.logger.error("Error in Delete API " + str(e))
                return JsonResponse(
                    create_failure(500, "API Fail due to Exception", "Failed"))
            return create_success('File Deleted Successfully', 'Deleted')
        except Exception as e:
            self.logger.error("Error in Delete API " + str(e))
            return JsonResponse(
                create_failure(500, "API Fail due to Exception", "Failed"))
Пример #10
0
    def post(self,request : Request) -> JsonResponse:
        try:
            token = verify_jwt_token(request.META['HTTP_AUTHORIZATION'])
            if token == 0:
                self.logger.error("Error in Download API token: ")
                return JsonResponse(create_failure(400, 'Invalid token', 'Failed'))
        except Exception as e:
            self.logger.error("Error in Download API."+str(e))
            return JsonResponse(create_failure(500, 'Authentication Error', 'Failed'))

        try:
            toDoListID = request.data['toDoListID']
            zipFilePath = self.config['ENV_VARIABLE']['file_path_zip']
            downloadFilePath = self.config['ENV_VARIABLE']['file_path_download']
            if not os.path.exists(zipFilePath):
                os.makedirs(zipFilePath)
            try:
                settingsObject = Settings.objects.all()
                settingsData = settingsSerializer(settingsObject, many=True) 
                if(settingsData.data):
                    try:
                        appUrl = settingsData.data[0]['appurl']
                        self.zipCount = settingsData.data[0]['layercount']
                    except Exception as e:
                        self.logger.error("Failed to convert files into zip "+str(e))
                        return JsonResponse(create_failure(500, 'Failed to convert files into zip - Error in Settings Table', 'Failed'))
                else:
                    self.logger.error("Failed to convert files into zip - Error in Settings Table "+str(e))
                    return JsonResponse(create_failure(500, 'Failed to convert files into zip - Error in Settings Table', 'Failed'))
            except Exception as e:
                self.logger.error("Failed to convert files into zip "+str(e))
                return JsonResponse(create_failure(500, 'Failed to convert files into zip - Error in Settings Table', 'Failed'))
            urlList = []
            filePathList = []
            for toDoID in toDoListID:
                try:
                    toDoListObject = Todolist.objects.filter(id=toDoID)
                    todoListData = todolistSerializer(toDoListObject, many=True) 
                    if(todoListData.data):
                        try:
                            fileName = todoListData.data[0]['outputfilename']
                            fileList = fileName.split(',')
                            for files in fileList:
                                urlJson = dict()
                                url = appUrl + self.config['ENV_VARIABLE']['download_files'] + toDoID + '/' + files
                                urlJson['ID'] = toDoID 
                                urlJson['DownloadUrl'] = url
                                urlJson['Zip'] = False
                                urlList.append(urlJson)
                                filePath = toDoID + '/' + files
                                filePathList.append(filePath)
                        except Exception as e:
                            self.logger.error("Failed to Fetch Output file name - Error in Todolist Table "+str(e))
                            return JsonResponse(create_failure(500, 'Failed to Fetch Output file name - Error in Todolist Table ', 'Failed'))                       
                except Exception as e:
                    self.logger.error("Failed to Fetch Output file name - Error in Todolist Table "+str(e))
                    return JsonResponse(create_failure(500, 'Failed to Fetch Output file name - Error in Todolist Table ', 'Failed'))                         
            if(len(filePathList) >= self.zipCount):
                compression = zipfile.ZIP_DEFLATED
                now = datetime.datetime.now()
                timeStamp = datetime.datetime.timestamp(now)
                zipfileName = zipFilePath + str(timeStamp) + ".zip"
                zipFiles = zipfile.ZipFile(zipfileName, mode="w")
                for files in filePathList:
                    try:
                        fileName = files.split("/")[-1]
                        filesVar = downloadFilePath + files
                        zipFiles.write(filesVar, fileName, compress_type=compression)
                    except Exception as e:
                        self.logger.error("Failed to convert files into zip"+str(e))
                        return JsonResponse(create_failure(500, 'Failed to convert files into zip', 'Failed'))
                zipFiles.close()
                zipUrl = appUrl + self.config['ENV_VARIABLE']['zip_files'] + str(timeStamp) + '.zip'
                for i in range(len(urlList)):
                    urlList[i]['DownloadUrl'] = zipUrl
                    urlList[i]['Zip'] = True
            output = {'DownloadURL' : urlList}
        except Exception as e:
            self.logger.error("Failed to convert files into zip "+str(e))
            return JsonResponse(create_failure(500, 'Failed to convert files into zip', 'Failed'))
        return JsonResponse(create_success('URL Generated Successfully',output ))
Пример #11
0
    def post(self, payload) -> JsonResponse:
        try:
            client_id = payload['ClientID']
        except Exception as e:
            self.logger.error("invalid clientID"+str(e))
            return create_failure(400, 'provide ClientID', 'Fail')
        try:
            session_id = payload['SessionID']
        except Exception as e:
            self.logger.error("invalid SessionID"+str(e))
            return create_failure(400, 'provide SessionID', 'Fail')
        try:
            AuditFrom = payload['AuditFrom']
        except Exception as e:
            self.logger.error("invalid AuditFrom "+str(e))
            return create_failure(400, 'provide AuditFrom', 'Fail')
        try:
            AuditTo = payload['AuditTo']
        except Exception as e:
            self.logger.error("invalid AuditTo "+str(e))
            return create_failure(400, 'provide AuditTo', 'Fail')
        try:
            ProjectName = payload['ProjectName']
        except Exception as e:
            self.logger.error("invalid ProjectName "+str(e))
            return create_failure(400, 'provide ProjectName', 'Fail')
        try:
            serialno = payload['SerialNo']
        except Exception as e:
            self.logger.error("invalid serialno "+str(e))
            return create_failure(400, 'provide serialno', 'Fail')
        try:
            userid = payload['userid']
        except Exception as e:
            self.logger.error("invalid userid "+str(e))
            return create_failure(400, 'provide valid token', 'Fail')
        try:
            # Step- I Create new database)
            try:
                self.databaseName = datetime.datetime.now().strftime("%B%d%Y%H%M%S")
                self.logger.debug("db name :"+ str(self.databaseName))
                self.connection = db_conn()
                self.connection.autocommit = True
                cursor = self.connection.cursor()
                db_create = cursor.execute("create database "+str(self.databaseName))
                cursor.close()
                self.connection.close()
                create_db = self.create_database()
            except Exception as e:
                self.logger.error("error in creating db: "+str(e))
                return create_failure(400, 'Error in creating database', 'Fail')

            #STEP-II: insert record in Tbl_m_databases table
            try:
                self.tbldbSettingsId = str(uuid.uuid4())
                password = self.config['DIGICUBEDB']['password']
                self.logger.debug("tbldbSettingsId: "+ str(self.tbldbSettingsId))
                self.connection = db_conn()
                self.connection.autocommit = True
                cursor = self.connection.cursor()
                insertIntoTable = cursor.execute(insert_record_in_tbl_m_database_table(self.tbldbSettingsId,self.databaseName,'SQL',self.server,self.username,'1',str(self.todaydate),password))
                cursor.close()
                self.connection.close()
            except Exception as e:
                self.logger.error("Error in Tbl_m_databasessettings table: "+str(e))
                self.connection = db_conn()
                self.connection.autocommit = True
                cursor = self.connection.cursor()
                db_drop = cursor.execute("drop database "+str(self.databaseName))
                cursor.close()
                self.connection.close()
                return create_failure(400, 'Error in creating Tbl_m_databasessettings table', 'Fail')
            
            # Step-III: Insert new record in session main table
            try:
                clientCode = ''
                sessionNum = result_str = ''.join(random.choice(string.ascii_letters) for i in range(10))
                sessionMainId = uuid.uuid4()
                self.logger.debug("sessionMainId: "+ str(sessionMainId))
                clientCodelist = dashboardModels.Clientmaster.objects.filter(clientmasterid=client_id).values_list("clientcode")
                for item in clientCodelist:
                    clientCode = item[0]
                self.sessionMainTbl = dashboardModels.Sessionmain(sessionmainid=sessionMainId, clientid=client_id,
                            dbid=self.tbldbSettingsId, sessionstartdate=self.todaydate, createddate=self.todaydate,
                            auditfrom=AuditFrom, auditto=AuditTo, projectname=ProjectName, serialno=serialno, 
                            sessionno=sessionNum, clientcode=clientCode, userid=userid)
                self.sessionMainTbl.save()
            except Exception as e:
                self.logger.error("Error in creating sessionMainTbl: "+str(e))
                self.connection = db_conn()
                self.connection.autocommit = True
                cursor = self.connection.cursor()
                db_drop = cursor.execute("drop database "+str(self.databaseName))
                deleteFromTable = cursor.execute("DELETE FROM tbl_m_DatabaseSettings WHERE ID='"+self.tbldbSettingsId+"' ")
                cursor.close()
                self.connection.close()
                return create_failure(400, 'Error in creating sessionMainTbl', 'Fail')

            #Step - IV : update client master table
            try:
                clientMaster = dashboardModels.Clientmaster.objects.get(clientmasterid=client_id)
                clientMaster.sessionid = self.sessionMainTbl.sessionmainid
                clientMaster.save()
            except Exception as e:
                self.logger.error("Error in creating sessionMainTbl: "+str(e))
                self.connection = db_conn()
                self.connection.autocommit = True
                cursor = self.connection.cursor()
                db_drop = cursor.execute("drop database "+str(self.databaseName))
                deleteFromTable = cursor.execute("DELETE FROM tbl_m_DatabaseSettings WHERE ID='"+self.tbldbSettingsId+"' ")
                cursor.close()
                self.connection.close()
                self.sessionMainTbl.delete()
                return create_failure(400, 'Error in creating sessionMainTbl', 'Fail')
        except Exception as e:
            self.logger.error("Error in new_session API: "+str(e))
            return create_failure(400, 'new_session API Fail', 'Fail')
        return create_success('success')
Пример #12
0
    def post(self, request):
        try:
            token = verify_jwt_token(request.META['HTTP_AUTHORIZATION'])
            if token == 0:
                self.logger.error("Error in Upload File Import API token: ")
                return JsonResponse(
                    create_failure(400, 'Invalid token', 'Fail'))
        except Exception as e:
            self.logger.error("Error in Fetching Data." + str(e))
            return JsonResponse(
                create_failure_modified(500, 'Data Request Error', 'Failed',
                                        '', 'failed'))

        try:
            toDoID = request.data['toDoID']
            try:
                toDoCount = Todolist.objects.filter(id=toDoID).count()
                if (toDoCount == 0):
                    return JsonResponse(
                        create_failure_modified(500, 'No Entry in DB',
                                                'Failed', '', 'failed'))

                else:
                    toDo = Todolist.objects.get(id=toDoID)
                    toDoVal = list(Todolist.objects.filter(id=toDoID).values())
                    if (toDo.status == 'Pending'):
                        trigger_event(toDoID)
                        if (data['status'] == 'success'):
                            res = self.response_filter(data['data'][0])
                            data['data'][0] = res
                            return JsonResponse(
                                create_success(data['message'], data['data']))
                        else:
                            res = self.response_filter(data['data'][0])
                            data['data'][0] = res
                            return JsonResponse(
                                create_failure_modified(
                                    500, data['message'], 'Fail',
                                    data['data']))
                    elif (toDo.status == 'Failed'):
                        toDoVal[0] = self.response_filter(toDoVal[0])
                        return JsonResponse(
                            create_failure_modified(500,
                                                    'fetched failed status',
                                                    'Fail', toDoVal))
                    else:
                        toDoVal[0] = self.response_filter(toDoVal[0])
                        return JsonResponse(
                            create_success('fetched success status', toDoVal))
                if (data['status'] == 'success'):
                    res = self.response_filter(data['data'][0])
                    data['data'][0] = res
                    return JsonResponse(
                        create_success_modified(data['message'], data['data']))
                else:
                    res = self.response_filter(data['data'][0])
                    data['data'][0] = res
                    return JsonResponse(
                        create_failure_modified(500, data['message'], 'Fail',
                                                data['data']))
            except Exception as e:
                self.logger.error("Bad Request." + str(e))
                return JsonResponse(
                    create_failure_modified(500, 'Bad Request', 'Fail'))
        except Exception as e:
            self.logger.error("Value Missing." + str(e))
            return JsonResponse(
                create_failure_modified(500, 'Value Missing', 'Fail'))
Пример #13
0
 def post(self, request: Request) -> JsonResponse:
     try:
         userid = verify_jwt_token(request.META['HTTP_AUTHORIZATION'])
         if userid == 0:
             self.logger.error("Error in changePassword API token: ")
             return JsonResponse(
                 create_failure(400, 'invalid Token', 'Fail'))
     except Exception as e:
         self.logger.error("Error in changePassword API: " + str(e))
         return JsonResponse(
             create_failure(400, 'Please provide valid Token', 'Fail'))
     try:
         email = request.data['email']
         if not email:
             self.logger.error("invalid email")
             return JsonResponse(
                 create_failure(400, 'provide valid email', 'Fail'))
     except Exception as e:
         self.logger.error("invalid email" + str(e))
         return JsonResponse(create_failure(400, 'provide email', 'Fail'))
     try:
         oldPassword = request.data['old_password']
         if not oldPassword:
             self.logger.error("invalid password")
             return JsonResponse(
                 create_failure(400, 'provide valid old password', 'Fail'))
         userInfo = Userlogindetails.objects.get(emailaddress=email)
         self.logger.info(userInfo.password)
         if userInfo.password != (oldPassword):
             self.logger.error("invalid password")
             return JsonResponse(
                 create_failure(400, 'invalid old password', 'Fail'))
     except Exception as e:
         self.logger.error("invalid password." + str(e))
         return JsonResponse(
             create_failure(400, 'provide valid old password', 'Fail'))
     try:
         newPassword = request.data['new_password']
         if not newPassword:
             self.logger.error("invalid new password")
             return JsonResponse(
                 create_failure(400, 'provide valid new password', 'Fail'))
     except Exception as e:
         self.logger.error("invalid new password" + str(e))
         return JsonResponse(
             create_failure(400, 'provide valid new password', 'Fail'))
     try:
         if newPassword == oldPassword:
             self.logger.error(
                 "old password and new password should not be same")
             return JsonResponse(
                 create_failure(
                     400,
                     'old password and new password should not be same',
                     'Fail'))
     except Exception as e:
         self.logger.error(
             "old password and new password should not be same" + str(e))
         return JsonResponse(
             create_failure(
                 400, 'old password and new password should not be same',
                 'Fail'))
     try:
         currentTime = timezone.now()
         UserlogindetailsUpdate = Userlogindetails.objects.filter(
             emailaddress=email).update(password=newPassword,
                                        modifieddate=currentTime)
         if UserlogindetailsUpdate == 0:
             return JsonResponse(
                 create_failure(204, 'Failed to update password', 'Fail'))
     except Exception as e:
         self.logger.error("invalid email" + str(e))
         return JsonResponse(
             create_failure(500, 'Failed to update password', 'Fail'))
     return JsonResponse(
         create_success("Password Updated Successfully!", []))
Пример #14
0
    def post(self, request: Request) -> JsonResponse:
        try:
            userid = verify_jwt_token(request.META['HTTP_AUTHORIZATION'])
            if userid == 0:
                self.logger.error("Error in Publish Message API token: ")
                return JsonResponse(
                    create_failure(400, 'Invalid token', 'Fail'))
        except Exception as e:
            self.logger.error("Error in Publish Message API: " + str(e))
            return JsonResponse(
                create_failure(400, 'Please provide valid token', 'Fail'))
        try:
            #for send email!
            sendMailFlag = False
            attachFilepath = []

            # To insert record into ToDoList table
            for requestDataVar in request.data:
                try:
                    statusInsert = self.insert_todo_list(requestDataVar)
                    # for Run-Test API
                    if (self.eventType == 'TestExec'):
                        try:
                            # TODO: implement messageQueue and scheduler
                            payload = {
                                "RuleID": requestDataVar['RuleID'],
                                "SessionID": requestDataVar['SessionID'],
                                "ToDoListID": requestDataVar['ID'],
                                "UserID": userid
                            }
                            runTest = run_test_api()
                            responseRuntest = runTest.run_test_function(
                                payload)
                            if responseRuntest['statusCode'] == 200:
                                self.update_todo_list(request, "Success")
                            else:
                                self.update_todo_list(
                                    request, responseRuntest['replyCode'],
                                    responseRuntest['message'])
                        except Exception as e:
                            self.logger.error(
                                "Error in run test execution API: " + str(e))
                            self.update_todo_list(request, "Failed", str(e))

                    # For Upload file functionality
                    elif (self.eventType == 'Import'):
                        try:
                            dbVar = FetchDatabaseName()
                            dbName = dbVar.fetch(self.sessionId)
                            if (len(dbName) != 0):
                                try:
                                    if (self.fileType == 'CSV'):
                                        payload = {
                                            "FileType":
                                            self.fileType,
                                            "ClientID":
                                            self.clientId,
                                            "FilePath":
                                            self.filePath,
                                            "SheetName":
                                            self.sheetName,
                                            "Overwrite_merge":
                                            self.overWriteMerge,
                                            "DatabaseName":
                                            dbName,
                                            "TableName":
                                            self.tableName,
                                            "textqualifier":
                                            self.textQualifier,
                                            "rowdelimeter":
                                            self.rowDelimeter,
                                            "columndelimeter":
                                            self.columnDelimeter,
                                            "numberRowToSkip":
                                            self.numberRowToSkip,
                                            "iscolumnnameinfirstrow":
                                            self.isColumnNameInFirstRow
                                        }
                                    else:
                                        payload = {
                                            "FileType": self.fileType,
                                            "ClientID": self.clientId,
                                            "FilePath": self.filePath,
                                            "SheetName": self.sheetName,
                                            "Overwrite_merge":
                                            self.overWriteMerge,
                                            "DatabaseName": dbName,
                                            "TableName": self.tableName
                                        }
                                    resUpload = dump_file(payload)
                                    if (resUpload['statusCode'] == 200):
                                        self.update_todo_list(
                                            request, "Success")
                                    else:
                                        self.logger.info(
                                            "Response DumpFile- {}".format(
                                                resUpload))
                                        self.update_todo_list(
                                            request, "Failed",
                                            resUpload['message'])
                                except Exception as e:
                                    self.logger.error("Error in DumpFile: " +
                                                      str(e))
                                    self.update_todo_list(
                                        request, "Failed", str(e))
                            else:
                                self.logger.info(
                                    "Response FetchDB- {}".format(dbName))
                                self.update_todo_list(request, "Failed",
                                                      dbName['message'])
                        except Exception as e:
                            self.logger.error("Error in FetchDB: " + str(e))
                            self.update_todo_list(request, "Failed", str(e))

                    # For Export test output file
                    elif (self.eventType == 'Output'):
                        try:
                            classVar = export_test()
                            resExport = classVar.export_class(requestDataVar)
                            if (resExport['statusCode'] == 200):
                                self.fileName = resExport['data']['fileName']
                                self.appUrl = resExport['data']['appUrl']
                                self.update_todo_list(request, "Success",
                                                      'Output')
                            else:
                                self.logger.error(
                                    "Response Export- {}".format(resExport))
                                self.update_todo_list(request, "Failed",
                                                      resExport['message'])
                        except Exception as e:
                            self.logger.error("Error in Export Test: " +
                                              str(e))
                            self.update_todo_list(request, "Failed", str(e))

                    # for sending Email
                    elif (self.eventType == 'Email'):
                        try:
                            classVar = export_test(
                            )  #using export function to attaching files in Email
                            resExport = classVar.export_class(requestDataVar)
                            if (resExport['statusCode'] == 200):
                                self.fileName = resExport['data']['fileName']
                                self.outputPublishFolderPath = self.config[
                                    'ENV_VARIABLE'][
                                        'file_path_download'] + requestDataVar[
                                            'ID']
                                self.appUrl = resExport['data']['appUrl']
                                self.update_todo_list(request, "Success",
                                                      'Output')
                                attachFilepath.append(
                                    str(self.outputPublishFolderPath) + "/" +
                                    str(self.fileName))
                                print(attachFilepath)
                                try:
                                    emailIds = requestDataVar[
                                        'To']  # stroing email from request pyaload
                                    emailIds = emailIds.split(
                                        ';'
                                    )  # spliting emails from string to List
                                    emailIds = [
                                        x.strip(' ') for x in emailIds
                                    ]  # storing email ids  without white spaces
                                    sendMailFlag = True  # to confirm for sending email
                                except Exception as e:
                                    self.logger.error(
                                        "Error In Fething Emails", str(e))
                            else:
                                self.logger.error(
                                    "Response Export- {}".format(resExport))
                                self.update_todo_list(request, "Failed",
                                                      resExport['message'])
                        except Exception as e:
                            self.logger.error(
                                "Error in Export Test for sending email: " +
                                str(e))
                            self.update_todo_list(request, "Failed", str(e))

                    # For creating New Session
                    elif (self.eventType == 'NewSession'):
                        try:
                            #TODO: Implement scheduler and messageQueue
                            payload = {
                                "ClientID": requestDataVar['ClientID'],
                                "SessionID": requestDataVar['SessionID'],
                                "AuditFrom": requestDataVar['AuditFrom'],
                                "AuditTo": requestDataVar['AuditTo'],
                                "ProjectName": requestDataVar['ProjectName'],
                                "SerialNo": requestDataVar['SerialNo'],
                                "userid": userid
                            }
                            newSess = new_session()
                            responseNewSess = newSess.post(payload)
                            if responseNewSess['statusCode'] == 200:
                                self.update_todo_list(request, "Success")
                            else:
                                self.update_todo_list(
                                    request, responseNewSess['replyCode'],
                                    responseNewSess['message'])
                        except Exception as e:
                            self.logger.error("Error in new session API: " +
                                              str(e))
                            self.update_todo_list(request, "Failed", str(e))

                    # For Power BI URL Validity
                    elif (self.eventType == 'ViewInPowerBI'):
                        try:
                            payload = {"ruleid": requestDataVar['RuleID']}
                            powerbi_func = powerbi_url()
                            response_powerbi = powerbi_func.powerbi(payload)
                            if response_powerbi['statusCode'] == 200:
                                self.update_todo_list(request, "Success")
                            else:
                                self.update_todo_list(
                                    request, response_powerbi['replyCode'],
                                    response_powerbi['message'])
                        except Exception as e:
                            self.logger.error("Error in powerbi url API: " +
                                              str(e))
                            self.update_todo_list(request, "Failed", str(e))
                except Exception as e:
                    self.logger.error("Error in Publish Message API: " +
                                      str(e))
                    return JsonResponse(
                        create_failure(400, 'Error in Publish Message API',
                                       'Fail'))

            if sendMailFlag:  #if true mail will be send
                self.send_email(attachFilepath,
                                emailIds)  #calling send_email Function
        except Exception as e:
            self.logger.error("Error in publish_message API: " + str(e))
            return JsonResponse(
                create_failure(500, 'Error in publish_message API', 'Fail'))
        return JsonResponse(create_success('Success', ''))