def post(self):
     # New Record
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('record', type=dict)
         parser.add_argument('conf_identifier', type=str)
         args = parser.parse_args()
         identifier = uuid1().hex
         r = HierarchicalRecord()
         if args['record']:
             r.data = args['record']
         if args['conf_identifier']:
             validator = retrieve_validator(args['conf_identifier'])
             validity = validator.validate(r)
             if not validity[0]:
                 return jsonify(
                     APIResponse("fail", errors=validity[1]).dictify()
                 )
         write_record(r, identifier)
         resp = APIResponse("success",
                            data={"record_identifier": identifier,
                                  "record": r.data})
         return jsonify(resp.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 2
0
 def post(self):
     # New Record
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('record', type=dict)
         parser.add_argument('conf_identifier', type=str)
         args = parser.parse_args()
         identifier = uuid1().hex
         r = HierarchicalRecord()
         if args['record']:
             r.data = args['record']
         if args['conf_identifier']:
             validator = retrieve_validator(args['conf_identifier'])
             validity = validator.validate(r)
             if not validity[0]:
                 return jsonify(
                     APIResponse("fail", errors=validity[1]).dictify())
         write_record(r, identifier)
         resp = APIResponse("success",
                            data={
                                "record_identifier": identifier,
                                "record": r.data
                            })
         return jsonify(resp.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def get(self, identifier):
     # Get the whole record
     try:
         r = retrieve_record(identifier)
         resp = APIResponse("success",
                            data={"record": r.data,
                                  "record_identifier": identifier})
         return jsonify(resp.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def get(self):
     # List all records
     try:
         r = APIResponse(
             "success",
             data={"record_identifiers": [x for x in
                                          get_existing_record_identifiers()]}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 5
0
 def get(self):
     # list all categories
     try:
         r = APIResponse("success",
                         data={
                             "category_identifiers":
                             [x for x in get_existing_categories()]
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 6
0
 def get(self):
     # List all records
     try:
         r = APIResponse("success",
                         data={
                             "record_identifiers":
                             [x for x in get_existing_record_identifiers()]
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def get(self):
     # list all categories
     try:
         r = APIResponse(
             "success",
             data={"category_identifiers": [x for x in
                                            get_existing_categories()]}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def delete(self, identifier):
     # delete a record
     try:
         delete_record(identifier)
         r = APIResponse(
             "success",
             data={"records": [x for x in get_existing_record_identifiers()],
                   "deleted_identifier": identifier}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def get(self, premisid):
     try:
         answer = expand_agents_list(identifier=premisid)
         print(answer)
         tally = 1
         if len(list(answer.keys())) == 1:
             resp = APIResponse("success", data={"agent events": self._populate_output(answer)})
         else:
             resp = APIResponse("fail", data={"agent events": "no results"})
         return jsonify(resp.dictify())
     except Exception as error:
         return jsonify(_EXCEPTION_HANDLER.handle(error).dictify())
Esempio n. 10
0
 def delete(self, cat_identifier):
     # delete this category
     try:
         delete_category(cat_identifier)
         r = APIResponse("success",
                         data={
                             "category_identifiers":
                             [x for x in get_existing_categories()]
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def delete(self, cat_identifier):
     # delete this category
     try:
         delete_category(cat_identifier)
         r = APIResponse(
             "success",
             data={"category_identifiers": [x for x in
                                            get_existing_categories()]}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 12
0
 def get(self, identifier):
     # Get the whole record
     try:
         r = retrieve_record(identifier)
         resp = APIResponse("success",
                            data={
                                "record": r.data,
                                "record_identifier": identifier
                            })
         return jsonify(resp.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def delete(self, identifier):
     # Delete this conf
     try:
         delete_conf(identifier)
         r = APIResponse(
             "success",
             data={"conf_identifiers": [x for x in
                                        get_existing_conf_identifiers()],
                   "deleted_conf_identifier": identifier}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 14
0
 def delete(self, identifier):
     # Delete this conf
     try:
         delete_conf(identifier)
         r = APIResponse("success",
                         data={
                             "conf_identifiers":
                             [x for x in get_existing_conf_identifiers()],
                             "deleted_conf_identifier":
                             identifier
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 15
0
 def post(self):
     # New Conf
     try:
         new_conf_identifier = uuid1().hex
         c = RecordConf()
         write_conf(c, new_conf_identifier)
         r = APIResponse("success",
                         data={
                             "conf_identifier": new_conf_identifier,
                             "conf": c.data
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 16
0
 def delete(self, identifier):
     # delete a record
     try:
         delete_record(identifier)
         r = APIResponse("success",
                         data={
                             "records":
                             [x for x in get_existing_record_identifiers()],
                             "deleted_identifier":
                             identifier
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def post(self):
     # New Conf
     try:
         new_conf_identifier = uuid1().hex
         c = RecordConf()
         write_conf(c, new_conf_identifier)
         r = APIResponse(
             "success",
             data={"conf_identifier": new_conf_identifier,
                   "conf": c.data}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def post(self, premisid):
     from flask import current_app
     try:
         data = request.get_json(force=True)
         dto = namedtuple("adto", "edit_fields identifier root " + \
                          ' '.join(data.get("fields")))(data.get("fields"), premisid,
                          current_app.config["AGENTS_PATH"], *[data.get(x) for x in data.get("fields")])
         was_it_made = create_or_edit_an_agent_record(dto)
         if was_it_made[0]:
             resp = APIResponse("success", data={'agents':{'result':'new', 'identifier': was_it_made[1]}})
         else:
             resp = APIResponse("fail", errors=["could not create a new agent record"])
         return jsonify(resp.dictify())
     except Exception as error:
         return jsonify(_EXCEPTION_HANDLER.handle(error).dictify())
Esempio n. 19
0
 def get(self, arkid, premisid):
     """
     Get the whole record
     """
     from flask import current_app
     try:
         data = get_data_half_of_object(
             arkid, premisid, current_app.config["LIVEPREMIS_PATH"])
         related_objects = data[1].related_objects
         output = {}
         tally = 1
         for n_object in related_objects:
             output[str(tally)] = {"loc": join("/", arkid, n_object)}
         resp = APIResponse("success", data={"presforms": output})
         return jsonify(resp.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def post(self, premisid):
     from flask import current_app
     try:
         data = request.get_json(force=True)
         dto = namedtuple("edto", "identifier root event")\
                         (premisid, current_app.config["AGENTS_PATH"], data.get("event"))
         was_it_added = add_event_to_a_premis_agent(dto)
         if was_it_added:
             resp  = APIResponse("success",
                                 data={"agent event": {"result":"added event",
                                                       "identifier": premisid,
                                                       "new_event":data.get("eventid")}})
         else:
             resp = APIResponse("fail", errors=["could not attach event {} to {}".format(data.get("linkedevent"), premisid)])
         return jsonify(resp.dictify())
     except Exception as error:
         return jsonify(_EXCEPTION_HANDLER.handle(error).dictify())
Esempio n. 21
0
 def get(self, identifier, rule_id):
     # get a rule
     try:
         c = retrieve_conf(identifier)
         found_one = False
         for x in c.data:
             if x['id'] == rule_id:
                 rule = x
                 found_one = True
         if not found_one:
             raise ValueError("No rule with id {} in conf {}".format(
                 rule_id, identifier))
         r = APIResponse("success",
                         data={
                             "conf_identifier": identifier,
                             "rule": rule
                         })
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
 def get(self, identifier, rule_id):
     # get a rule
     try:
         c = retrieve_conf(identifier)
         found_one = False
         for x in c.data:
             if x['id'] == rule_id:
                 rule = x
                 found_one = True
         if not found_one:
             raise ValueError(
                 "No rule with id {} in conf {}".format(rule_id, identifier)
             )
         r = APIResponse(
             "success",
             data={"conf_identifier": identifier,
                   "rule": rule}
         )
         return jsonify(r.dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
Esempio n. 23
0
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('record_identifier', type=str, required=True)
            parser.add_argument('conf_identifier', type=str, required=True)
            args = parser.parse_args(strict=True)

            v = retrieve_validator(args['conf_identifier'])
            r = retrieve_record(args['record_identifier'])
            validity = v.validate(r)
            resp = APIResponse("success",
                               data={
                                   "is_valid": validity[0],
                                   "validation_errors": validity[1],
                                   "record_identifier":
                                   args['record_identifier'],
                                   "conf_identifier": args['conf_identifier'],
                                   "record": r.data
                               })
            return jsonify(resp.dictify())
        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('record_identifier', type=str, required=True)
            parser.add_argument('conf_identifier', type=str, required=True)
            args = parser.parse_args(strict=True)

            v = retrieve_validator(args['conf_identifier'])
            r = retrieve_record(args['record_identifier'])
            validity = v.validate(r)
            resp = APIResponse("success",
                               data={
                                   "is_valid": validity[0],
                                   "validation_errors": validity[1],
                                   "record_identifier": args['record_identifier'],
                                   "conf_identifier": args['conf_identifier'],
                                   "record": r.data
                                   }
                               )
            return jsonify(resp.dictify())
        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())