def getFile(fileID): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) accessID = getAccessId() mfileID = fileID if isAccessIdAuthentic(accessID): fileName = dc.translateFileidToFilename(mfileID) userFilesDir = dc.getUserFilesDir(accessID) print("INFO: FILEDOWNLOAD: Requested File Name: " + str(fileName)) if fileName != False: try: md5Checksum = generateMD5(os.path.join(userFilesDir, fileName)) print( "INFO: FILEDOWNLOAD: File with the given FileID found on server." ) status = "File with the given FileID found on server." httpCode = 200 res = createRequestDetails(fileName, mfileID, md5Checksum, status, httpCode, REQUEST_ID) return send_from_directory(userFilesDir, filename=fileName, as_attachment=True) except Exception as e: print( "ERROR: FILEDOWNLOAD: Error(s) encountered while transferring file." ) print(str(e)) status = "Error(s) encountered while transferring file." httpCode = 500 res = createRequestDetails("N/A", mfileID, "N/A", status, httpCode, REQUEST_ID) else: print( "ERROR: FILEDOWNLOAD: File with the given FileID parameter not found" ) status = "File with the given FileID parameter not found" httpCode = 404 res = createRequestDetails("N/A", mfileID, "N/A", status, httpCode, REQUEST_ID) else: print("ERROR: FILEDOWNLOAD: Invalid Access-ID, request denied.") status = "[ERR] Invalid Access-ID, request denied." httpCode = 403 res = createRequestDetails("N/A", "N/A", "N/A", status, httpCode, REQUEST_ID) res = make_response(res, httpCode) return res ############################ END OF SCRIPT ###################################
def generateUmlDiagram(): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) accessID = getAccessId() if isAccessIdAuthentic(accessID): #Get the File IDs from the request parameters inputFileID = request.json #This is the folder in workspace where all the files generated by services shoudl be stored. userFilesDir = dc.getUserFilesDir(accessID) sourceFilePath = dc.getTextUploadPath(accessID) try: inputFile_ID = inputFileID["InputFileID"] except Exception as e: print("ERROR: GEN_UML: " + str(e)) inputFile_ID = "x" print("INFO_GEN_UML: " + inputFile_ID) # File IDs to FileName translation sourceFileName = dc.translateFileidToFilename(inputFile_ID) print("INFO_GEN_UML: FileName on Server: " + sourceFileName) if sourceFileName != False: sourcefile = os.path.join(sourceFilePath, sourceFileName) else: print( "ERROR: GEN_UML: Configuration(source code) with the given FileID parameter not found" ) status = "Configuration(source code) with the given FileID parameter not found" httpCode = 404 res = createRequestDetails("N/A", inputFile_ID, "N/A", status, httpCode, REQUEST_ID) return res # Call the service. tool = TOOL_PATH # the cmd script takes in two parameters Input .TXT file and the path to # the output directory which in this case is the "USER FILES DIRECTORY" #PARAMS = sourcefile + " " + OUTPUT_DIR #cmd = tool + " " + PARAMS try: subprocess.call( ['java', '-jar', tool, sourcefile, "-o", OUTPUT_DIR]) except Exception as e: print("ERROR: GEN_UML: " + str(e)) status = "Error(s) encountered in executing the service." httpCode = 500 res = createRequestDetails("N/A", inputFile_ID, "N/A", status, httpCode, REQUEST_ID) return res #processing on generate file #Plant uml names the generated file the same as input source file. fileName, md5chkSum = postProcessing(sourceFileName, userFilesDir) if fileName != False: print("INFO: GEN_UML: Service executed successfully.") status = "UML diagram generated successfully." Generated_fileID = str(fileNameToHash(REQUEST_ID + getTimeStamp())) httpCode = 201 res = createRequestDetails(fileName, Generated_fileID, md5chkSum, status, httpCode, REQUEST_ID) if createFileDetails(Generated_fileID, fileName, accessID): res = make_response(res, httpCode) return res else: print("ERROR: GEN_UML: Error Saving file to server") status = "[ERR] Error saving file to disk." httpCode = 500 res["Status"] = status res["HttpResponse"] = httpCode res = make_response(res, httpCode) #abort(500, "Error saving file to disk") return res else: print( "ERROR: GEN_UML: Error(s) encountered in post processing the results." ) status = "Error(s) encountered in post processing the results." httpCode = 500 res = createRequestDetails(fileName, inputFile_ID, "N/A", status, httpCode, REQUEST_ID) return res else: print("ERROR: GEN_UML: Invalid Access-ID, request denied.") status = "[ERR] Invalid Access-ID, request denied." httpCode = 403 res = createRequestDetails("N/A", "N/A", "N/A", status, httpCode, REQUEST_ID) res = make_response(res, httpCode) return res
def validateCompuMethods(): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) accessID = getAccessId() if isAccessIdAuthentic(accessID): #########Get the File IDs from the request parameters######### inputFileID = request.json userFilesDir = dc.getUserFilesDir(accessID) try: #Get the File IDs from the request parameters xl_FileID = inputFileID["xlFileID"] except Exception as e: print("ERROR: CM_Validation: " + str(e)) xl_FileID = "x" try: a2l_FileID = inputFileID["a2lFileID"] except Exception as e: print("ERROR: CM_Validation: " + str(e)) a2l_FileID = "x" #########File IDs to FileName translation######### fileName = dc.translateFileidToFilename(xl_FileID) if fileName != False: UPLOAD_XSLX_PATH = dc.getExcelUploadPath(accessID) xl_file = os.path.join(UPLOAD_XSLX_PATH, fileName) print(xl_file) else: print( "ERROR: CM_Validation: Excel file with the given FileID parameter not found" ) status = "Excel file with the given FileID parameter not found" httpCode = 404 res = createRequestDetails("404", xl_FileID, "404", status, httpCode, REQUEST_ID) return res fileName = dc.translateFileidToFilename(a2l_FileID) if fileName != False: UPLOAD_A2L_PATH = dc.getA2lUploadPath(accessID) a2l_file = os.path.join(UPLOAD_A2L_PATH, fileName) print(a2l_file) else: print( "ERROR: CM_Validation: a2l file with the given FileID parameter not found" ) status = "a2l file with the given FileID parameter not found" httpCode = 404 res = createRequestDetails("404", a2l_FileID, "404", status, httpCode, REQUEST_ID) return res OUT_DIR = CMConst.OUTPUT_DIR # Call the service. tool = CMConst.CLI_INTERFACE PARAMS = tool + " " + a2l_file + " " + xl_file + " " + OUT_DIR + " " + OUT_DIR #cmd = PYTHON_PATH + " " + tool + " " + PARAMS try: #subprocess.Popen(cmd) subprocess.call([tool, a2l_file, xl_file, OUT_DIR, OUT_DIR]) except Exception as e: print("ERROR: CM_Validation: " + str(e)) status = "Error(s) encountered in executing the service." httpCode = 500 res = createRequestDetails("404", "404", "404", status, httpCode, REQUEST_ID) return res fileName, md5chkSum = postProcessing(userFilesDir) if fileName != False: print("INFO: CM_Validation: Service executed successfully") status = "Service executed successfully." httpCode = 201 Generated_fileID = str(fileNameToHash(REQUEST_ID + getTimeStamp())) res = createRequestDetails(fileName, Generated_fileID, md5chkSum, status, httpCode, REQUEST_ID) if createFileDetails(Generated_fileID, fileName, accessID): res = make_response(res, httpCode) return res else: print("ERROR: CM_Validation: Error Saving results to server") status = "[ERR] Error saving file to disk." httpCode = 500 res["Status"] = status res["HttpResponse"] = httpCode res = make_response(res, httpCode) #abort(500, "Error saving file to disk") return res else: status = "Error(s) encountered in post processing the results." httpCode = 500 res = createRequestDetails("404", "404", "404", status, httpCode, REQUEST_ID) return res else: print("ERROR: CM_Validation: Invalid Access-ID, request denied.") status = "[ERR] Invalid Access-ID, request denied." httpCode = 403 res = createRequestDetails("xxx", "xxx", "xxx", status, httpCode, REQUEST_ID) res = make_response(res, httpCode) return res
def detectStopSign(): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) accessID = getAccessId() if fh.isAccessIdAuthentic(accessID): #Get the File IDs from the request parameters inputFileID = request.json #This is the folder in workspace where all the files generated by services shoudl be stored. userFilesDir = dc.getUserFilesDir(accessID) inputFilePath = dc.getImageUploadPath((accessID)) try: inputFile_ID = inputFileID["InputFileID"] except Exception as e: print("ERROR: HyAPI_ML: " + str(e)) inputFile_ID = "x" print("INFO: HyAPI_ML: " + inputFile_ID) # File IDs to FileName translation inputFileName = dc.translateFileidToFilename(inputFile_ID) if inputFileName != False: print("INFO: HyAPI_ML FileName on Server: " + inputFileName) inputFile = os.path.join(inputFilePath, inputFileName) else: print( "ERROR: HyAPI_ML: Input image with the given FileID parameter not found" ) status = "Input image with the given FileID parameter not found" httpCode = MLC.HTTP_NOT_FOUND res = createRequestDetails(inputFile_ID, "N/A", status, httpCode, REQUEST_ID) return res #procStatus holds the filename procStatus = ml_od.detectStopSign(inputFile, FGB, LMB, userFilesDir) if procStatus != False: outputFileID = str(fh.generateHash(REQUEST_ID + fh.getTimeStamp())) status = "Object detection process successful" httpCode = MLC.HTTP_CREATED res = createRequestDetails(inputFileName, outputFileID, status, httpCode, REQUEST_ID) if dc.createFileDetails(outputFileID, procStatus, accessID): print("INFO: HyAPI_ML: Object detection process successful") res = make_response(res, httpCode) return res else: #Internal server error print("ERROR: HyAPI_ML: Error Saving file to server") status = "[ERR] Error saving file to disk." httpCode = MLC.HTTP_SERVER_ERROR res["Status"] = status res["HttpResponse"] = httpCode res = make_response(res, httpCode) #abort(500, "Error saving file to disk") return res else: print("ERROR: HyAPI_ML: Invalid Access-ID, request denied.") status = "[ERR] Invalid Access-ID, request denied." httpCode = MLC.HTTP_FORBIDDEN res = createRequestDetails("N/A", "N/A", status, httpCode, REQUEST_ID) res = make_response(res, httpCode) return res