diff --git a/modelDB/src/ModelDBClient.py b/modelDB/src/ModelDBClient.py index bc39e157f530c190ee6bd7a5bbd68d9a1e073b5d..da31f833197e784242afa1bf37f63074eefcf7f9 100644 --- a/modelDB/src/ModelDBClient.py +++ b/modelDB/src/ModelDBClient.py @@ -109,59 +109,98 @@ class ModelDBClient: raise KeyError(application_id) return document - def importCPFiles(self, - application_id: str, - CP_file_path: Path, - camel_model_file_path: Path, - node_candidates_file_path: Path) -> None: - """This method is used to import Constraint Problem, Camel Model and Node Candidates - from the file system to the database and save it under the application id key. + def importCP(self, + application_id: str, + CP_file_path: Path) -> None: + """This method is used to import Constraint Problem from the file system to the database and save it under the application id key. Args: application_id: unique id of the application CP_file_path: path to file containing the Constraint Problem - camel_model_file_path: path to file containing the Camel Model - node_candidates_file_path: path to file containing the Node Candidates Raises: FileNotFoundError: when the given Path does not lead to an actual file """ - document = {} - with CP_file_path.open(mode="rb") as cp_file, \ - camel_model_file_path.open(mode="rb") as camel_model_file, \ - node_candidates_file_path.open(mode="rb") as node_candidates_file: - document = { - "application_id": application_id, - "constraint_problem": cp_file.read(), - "camel_model": camel_model_file.read(), - "node_candidates": node_candidates_file.read() - } - self.saveDocumentToModelDB("cp_files", application_id, document) - - def exportCPFiles(self, - application_id: str, - CP_file_path: Path, - camel_model_file_path: Path, - node_candidates_file_path: Path) -> None: - """This method is used to export Constraint Problem, Camel Model and Node Candidates - with the given application id from the database to the file system. + with CP_file_path.open(mode="rb") as cp_file: + self.saveDocumentToModelDB("constraint_problem", application_id, {"constraint_problem": cp_file.read()}) + + def exportCP(self, + application_id: str, + CP_file_path: Path) -> None: + """This method is used to export Constraint Problem with the given application id from the database to the file system. Args: application_id: unique id of the application CP_file_path: file path to which the Constraint Problem will be exported - camel_model_file_path: file path to which the Camel Model will be exported - node_candidates_file_path: file path to which the Node Candidates will be exported - + Raises: KeyError: when it could not find data in the database for the given application id """ - document = self.loadDocumentFromModelDB("cp_files", application_id) - - with CP_file_path.open(mode="wb") as cp_file, \ - camel_model_file_path.open(mode="wb") as camel_model_file, \ - node_candidates_file_path.open(mode="wb") as node_candidates_file: + document = self.loadDocumentFromModelDB("constraint_problem", application_id) + with CP_file_path.open(mode="wb") as cp_file: cp_file.write(document["constraint_problem"]) + + def importCamelModel(self, + application_id: str, + camel_model_file_path: Path) -> None: + """This method is used to import Camel Model from the file system to the database and save it under the application id key. + + Args: + application_id: unique id of the application + camel_model_file_path: path to file containing the Camel Model + + Raises: + FileNotFoundError: when the given Path does not lead to an actual file + """ + with camel_model_file_path.open(mode="rb") as camel_model_file: + self.saveDocumentToModelDB("camel_model", application_id, {"camel_model": camel_model_file.read()}) + + def exportCamelModel(self, + application_id: str, + camel_model_file_path: Path) -> None: + """This method is used to export Camel Model with the given application id from the database to the file system. + + Args: + application_id: unique id of the application + camel_model_file_path: file path to which the Camel Model will be exported + + Raises: + KeyError: when it could not find data in the database for the given application id + """ + document = self.loadDocumentFromModelDB("camel_model", application_id) + with camel_model_file_path.open(mode="wb") as camel_model_file: camel_model_file.write(document["camel_model"]) + + def importNodeCandidates(self, + application_id: str, + node_candidates_file_path: Path) -> None: + """This method is used to import Node Candidates from the file system to the database and save it under the application id key. + + Args: + application_id: unique id of the application + node_candidates_file_path: path to file containing the Node Candidates + + Raises: + FileNotFoundError: when the given Path does not lead to an actual file + """ + with node_candidates_file_path.open(mode="rb") as node_candidates_file: + self.saveDocumentToModelDB("node_candidates", application_id, + {"node_candidates": node_candidates_file.read()}) + + def exportNodeCandidates(self, + application_id: str, + node_candidates_file_path: Path) -> None: + """This method is used to export Node Candidates with the given application id from the database to the file system. + + Args: + application_id: unique id of the application + node_candidates_file_path: file path to which the Node Candidates will be exported + + Raises: + KeyError: when it could not find data in the database for the given application id + """ + document = self.loadDocumentFromModelDB("node_candidates", application_id) + with node_candidates_file_path.open(mode="wb") as node_candidates_file: node_candidates_file.write(document["node_candidates"]) def importTrainingDataFromFile(self,