def post(self, uuid=None, user_id=None): """Create model. :param uuid: uuid of the model (not used here) :param user_id: user ID who do the request :request body: { "name": "...", "description": "...", "meta_rules": ["meta_rule_id1", ] } :return: { "model_id1": { "name": "...", "description": "...", "meta_rules": ["meta_rule_id1", ] } } :internal_api: add_model """ try: data = ModelManager.add_model(user_id=user_id, model_id=uuid, value=request.json) except Exception as e: logger.error(e, exc_info=True) return {"result": False, "error": str(e)}, 500 return {"models": data}
def add_model(model_id=None, value=None): from python_moondb.core import ModelManager if not value: value = { "name": "MLS", "description": "test", "meta_rules": "meta_rule_mls_1" } return ModelManager.add_model(user_id=None, model_id=model_id, value=value)
def add_model(model_id=None, value=None): from python_moondb.core import ModelManager if not value: subject_category_id, object_category_id, action_category_id, meta_rule_id = mock_data.create_new_meta_rule() name = "MLS" if model_id is None else "MLS " + model_id value = { "name": name, "description": "test", "meta_rules": [meta_rule_id] } return ModelManager.add_model(user_id=None, model_id=model_id, value=value)
def _import_models_without_new_meta_rules(self, json_models): if not isinstance(json_models, list): raise InvalidJson("models shall be a list!") for json_model in json_models: json_without_new_metarules = dict() JsonUtils.copy_field_if_exists(json_model, json_without_new_metarules, "name", str) # TODO put this in moondb # model_in_db = ModelManager.get_models_by_name(json_without_new_metarules["name"]) models = ModelManager.get_models(self._user_id) model_in_db = None for model_key in models: if models[model_key]["name"] == json_without_new_metarules[ "name"]: model_in_db = models[model_key] model_id = model_key # end TODO JsonUtils.copy_field_if_exists(json_model, json_without_new_metarules, "description", str) if model_in_db is None: model_does_exist = False else: json_without_new_metarules["meta_rules"] = model_in_db[ "meta_rules"] model_does_exist = True model_override = JsonUtils.get_override(json_model) if not model_does_exist: logger.debug( "Creating model {} ".format(json_without_new_metarules)) ModelManager.add_model(self._user_id, None, json_without_new_metarules) elif model_override is True: logger.debug("Updating model with id {} : {} ".format( model_id, json_without_new_metarules)) ModelManager.update_model(self._user_id, model_id, json_without_new_metarules)
def post(self, uuid=None, user_id=None): """Create model. :param uuid: uuid of the model (not used here) :param user_id: user ID who do the request :request body: { "name": "name of the model (mandatory)", "description": "description of the model (optional)", "meta_rules": ["meta_rule_id1", ] } :return: { "model_id1": { "name": "name of the model", "description": "description of the model (optional)", "meta_rules": ["meta_rule_id1", ] } } :internal_api: add_model """ data = ModelManager.add_model(user_id=user_id, model_id=uuid, value=request.json) return {"models": data}