def put(self): deploymentUnitSet = request.get_json() if deploymentUnitSet.get("_id"): if type(deploymentUnitSet.get("_id")) is not dict: raise Exception("The type of _id is invalid") if not deploymentUnitSet.get("_id").get("oid"): raise Exception("oid was not found in _id") else: raise Exception("_id was not found in input request ") DuHelperService.add_update_du_set(deploymentUnitSet, deploymentUnitSet["_id"]["oid"], logo_path, logo_full_path) return { "result": "success", "message": "The DeploymentUnit Set is updated successfully" }, 200
def add_update_du_set(self, du_set, full_sync_flag="false", directory_to_import_from=None): """Start DUSET Update/Add""" try: du_set_data = du_set.get("duset_data") if du_set_data.get("du_set"): du_set_det = [] for record in du_set_data.get("du_set"): du = self.deploymentunitDB.GetDeploymentUnitByName( str(record.get("du_id"))) if du: record["du_id"] = str(du.get("_id")) else: raise Exception("No such DU found with name: " + str(record.get("du_id"))) du_set_det.append(record) local_du_set = self.deploymentunitsetDB.GetDeploymentUnitSetByName( du_set_data.get("name")) if local_du_set: #directory_to_import_from not required as DUSET has default logo only DuHelperService.add_update_du_set(du_set_data, str(local_du_set.get("_id")), self.logo_path, self.full_logo_path, directory_to_import_from) else: #directory_to_import_from not required as DUSET has default logo only DuHelperService.add_update_du_set(du_set_data, None, self.logo_path, self.full_logo_path, directory_to_import_from) return { "result": "success", "message": du_set_data["name"] + " was handled" } except Exception as e_value: # catch *all* exceptions traceback.print_exc() return {"result": "failed", "message": str(e_value)}
def post(self): newDeploymentUnitSet = request.get_json() if deploymentUnitSetDB.GetDeploymentUnitSetByName( newDeploymentUnitSet.get("name"), False) is not None: raise Exception("Deployment Set with name " + newDeploymentUnitSet.get("name") + " already exists") newDeploymentUnitSet["id"] = id_generator() # ADD UNIQUE ID deployment_unit_set_id = DuHelperService.add_update_du_set( newDeploymentUnitSet, None, logo_path, logo_full_path) return { "result": "success", "message": "The DeploymentUnit Set is added successfully", "data": { "_id": deployment_unit_set_id } }, 200
def post(self): """ Creates or updates requested DU set. """ bulk_du_set_response = [] du_set_details = request.get_json() if type(du_set_details.get("data")) is list and len( du_set_details.get("data")) > 0: for set in du_set_details.get("data"): rec = { "_id": "", "name": set.get("name"), "result": "success", "message": "DU set was created" } try: keys_to_validate_in_set = ["name", "du_set"] # keys_to_validate_in_du_details = ["du_id", "dependent", "order"] for key in keys_to_validate_in_set: if not set.get(key): raise Exception("mandatory key: " + key + " is missing in du set details") if set.get("_id"): if type(set.get("_id")) is not dict: raise Exception( "invalid type was found for key: _id") if not set.get("_id").get("oid"): raise Exception("oid was not found in _id") rec["_id"] = set["_id"]["oid"] result = DuHelperService.add_update_du_set( set, str(rec["_id"]), logo_path, None, logo_full_path) if result == "1": rec["message"] = "DU Set was updated" else: rec["message"] = "no changes found" elif deploymentUnitSetDB.GetDeploymentUnitSetByName( set.get("name")): existing_du_set = deploymentUnitSetDB.GetDeploymentUnitSetByName( set.get("name")) rec["_id"] = str(existing_du_set.get("_id")) result = DuHelperService.add_update_du_set( set, str(rec["_id"]), logo_path, None, logo_full_path) if result == "1": rec["message"] = "DU Set was updated" else: rec["message"] = "no changes found" else: rec["_id"] = DuHelperService.add_update_du_set( set, None, logo_path, None, logo_full_path) except Exception as e: # catch *all* exceptions rec["result"] = "failed" rec["message"] = str(e) traceback.print_exc() bulk_du_set_response.append(rec) else: raise Exception( "expected input type is list with atleast one record") return { "result": "success", "message": "DU Set's has been processed for uploading", "data": bulk_du_set_response }, 200