def createPermissionForStudy(studyId): validateUser(studyId) permissionData = request.get_json() if not ("userId" in permissionData and type(permissionData["userId"])==str and len(permissionData["userId"])>0): raise errors.BadRequestError("Permission must have attribute 'userId' (type=str and length>0)") userId = permissionData["userId"] userPermission = permission_db_access.createAdminForStudy(userId, studyId) return toJson(userPermission)
def getPermissionsForStudy(studyId): validateUser(studyId) userPermissionList = permission_db_access.getPermissionsForStudy(studyId) return toJson(userPermissionList)
def getFacilitiesForStudy(studyId): validateUser(studyId) facilityList = facility_db_access.getFacilitiesForStudy(studyId) return toJson(facilityList)
def getStudy(studyId): validateUser(studyId) study = study_db_access.getStudy(studyId) return toJson(study)
def updateStudy(studyId): validateUser(studyId) studyData = request.get_json() study = study_db_access.updateStudy(studyId, studyData) return toJson(study)
def createResourceForStudy(studyId): validateUser(studyId) file = request.files['user_file'] fileName = s3_access.uploadFile(studyId, file) return toJson({"message": "file uploaded successfully", "fileName":fileName})
def getStudiesForUser(): validateUser() studyList = permission_db_access.getStudiesForUser(getUserId()) return toJson(studyList)
def getFacility(facilityId): facility = facility_db_access.getFacility(facilityId) return toJson(facility)
def getAllFacilities(): facilityList = facility_db_access.getAllFacilities() return toJson(facilityList)
def getEquipment(equipmentId): equipment = equipment_db_access.getEquipment(equipmentId) return toJson(equipment)
def getAllEquipment(): equipmentList = equipment_db_access.getAllEquipment() return toJson(equipmentList)
def handleAPIError(e): return toJson({"error":type(e).__name__, "status":e.getStatusCode(), "message":str(e)}), e.getStatusCode()
def handleInternalServerError(e): return toJson({"error":type(e).__name__, "status":500, "message":"Internal Server Error"}), 500
def handleNotFoundEror(e): return toJson({"error":type(e).__name__, "status":404, "message":str(e)}), 404
def getAllDeploymentsForStudy(studyId): validateUser(studyId) deploymentList = deployment_db_access.getAllDeployments(studyId) return toJson(deploymentList)
def createStudy(): validateUser() studyData = request.get_json() study = study_db_access.createStudy(studyData) permission_db_access.createOwnerForStudy(getUserId(), study.studyId) return toJson(study)
def createDeploymentForStudy(studyId): validateUser(studyId) deploymentData = request.get_json() deployment = deployment_db_access.createDeployment(studyId, deploymentData) return toJson(deployment)
def getDeploymentForStudy(studyId, deploymentId): validateUser(studyId) deployment = deployment_db_access.getDeployment(studyId, deploymentId) return toJson(deployment)