예제 #1
0
 def post(self, identifier, key):
     # Set a value
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('value', required=True)
         parser.add_argument('conf_identifier', type=str)
         args = parser.parse_args()
         v = parse_value(args['value'])
         r = retrieve_record(identifier)
         r[key] = v
         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)
         return jsonify(
             APIResponse("success",
                         data={
                             'record': r.data,
                             'record_identifier': identifier
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #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 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())
예제 #4
0
def is_there_a_result(api_category, a_dict):
    if a_dict.keys() == 0:
        return APIResponse("fail", data={api_category: "no results"})
    else:
        if api_category == "agent":
            return APIResponse("success", data={api_category: a_dict[list(a_dict.keys())[0]]})
        else:
            return APIResponse("success", data={api_category: a_dict})
 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())
예제 #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())
예제 #7
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())
 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())
예제 #11
0
 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())
예제 #12
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())
예제 #13
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, 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, 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())
예제 #16
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())
 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())
예제 #18
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())
예제 #19
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())
예제 #20
0
 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())
예제 #21
0
    def post(self):
        # Add a category
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('category_identifier', type=str, required=True)
            args = parser.parse_args()

            if not only_alphanumeric(args['category_identifier']):
                raise ValueError(
                    "Category identifiers can only be alphanumeric.")

            # This line shouldn't do anything, but why not be paranoid about it
            args['category_identifier'] = secure_filename(
                args['category_identifier'])

            if args['category_identifier'] in get_existing_categories():
                raise ValueError("That cat id already exists, " +
                                 "please specify a different identifier.")

            c = retrieve_category(args['category_identifier'])
            write_category(c, args['category_identifier'])
            return jsonify(
                APIResponse("success",
                            data={
                                "category_identifier":
                                args['category_identifier'],
                                "record_identifiers": c.records
                            }).dictify())

        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #22
0
 def delete(self, identifier, rule_id, component):
     # remove a rule component
     try:
         c = retrieve_conf(identifier)
         rule = None
         for x in c.data:
             if x['id'] == rule_id:
                 rule = x
         if rule is None:
             raise ValueError("No rule with id {} in conf {}".format(
                 rule_id, identifier))
         try:
             x[component] = ""
             value = x[component]
         except KeyError:
             raise ValueError(
                 "No component named {} in rule {} in conf {}".format(
                     component, rule_id, identifier))
         write_conf(c, identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             "conf_identifier": identifier,
                             "rule_id": rule_id,
                             "component": component,
                             "value": value
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
     pass
예제 #23
0
    def post(self, identifier, rule_id, component):
        # Add a rule component to this rule
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('component_value', type=str, required=True)
            args = parser.parse_args()

            c = retrieve_conf(identifier)
            rule = None
            for x in c.data:
                if x['id'] == rule_id:
                    rule = x
            if rule is None:
                raise ValueError("No rule with id {} in conf {}".format(
                    rule_id, identifier))
            try:
                x[component] = args['component_value']
                value = x[component]
            except KeyError:
                raise ValueError(
                    "No component named {} in rule {} in conf {}".format(
                        component, rule_id, identifier))
            write_conf(c, identifier)
            return jsonify(
                APIResponse("success",
                            data={
                                "conf_identifier": identifier,
                                "rule_id": rule_id,
                                "component": component,
                                "value": value
                            }).dictify())
        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #24
0
 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())
예제 #25
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())
예제 #26
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())
예제 #27
0
 def get(self, cat_identifier):
     # list all records in this category
     try:
         c = retrieve_category(cat_identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             "category_identifier": cat_identifier,
                             "record_identifiers": c.records
                         }).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())
    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())
예제 #30
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())
예제 #31
0
    def get(self, identifier):
        # return a specific conf
        try:
            c = retrieve_conf(identifier)
            return jsonify(
                APIResponse("success",
                            data={
                                "conf_identifier": identifier,
                                "conf": c.data
                            }).dictify())

        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #32
0
 def delete(self, cat_identifier, rec_identifier):
     # remove this member from the category
     try:
         c = retrieve_category(cat_identifier)
         c.records = [x for x in c.records if x != rec_identifier]
         write_category(c, cat_identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             "category_identifier": cat_identifier,
                             "record_identifiers": c.records
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #33
0
 def get(self, identifier, key):
     # get a value
     try:
         r = retrieve_record(identifier)
         v = r[key]
         return jsonify(
             APIResponse("success",
                         data={
                             'record_identifier': identifier,
                             'key': key,
                             'value': v
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #34
0
 def delete(self, identifier, rule_id):
     # delete a rule
     try:
         c = retrieve_conf(identifier)
         c.data = [x for x in c.data if x['id'] != rule_id]
         write_conf(c, identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             "conf_identifier": identifier,
                             "conf": c.data
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #35
0
 def put(self, identifier):
     # overwrite a whole record
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('record', type=dict, required=True)
         parser.add_argument('conf_identifier', type=str)
         args = parser.parse_args()
         record = retrieve_record(identifier)
         record.data = args.record
         if args['conf_identifier']:
             validator = retrieve_validator(args['conf_identifier'])
             validity = validator.validate(record)
             if not validity[0]:
                 return jsonify(
                     APIResponse("fail", errors=validity[1]).dictify())
         write_record(record, identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             'record_identifier': identifier,
                             'record': record.data
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #36
0
 def post(self, identifier):
     # set validation rule
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('rule', type=dict, required=True)
         args = parser.parse_args()
         c = retrieve_conf(identifier)
         c.add_rule(args['rule'])
         write_conf(c, identifier)
         return jsonify(
             APIResponse("success",
                         data={
                             "conf_identifier": identifier,
                             "conf": c.data
                         }).dictify())
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #37
0
 def get(self, cat_identifier, rec_identifier):
     # Query the category to see if an identifier is in it
     try:
         c = retrieve_category(cat_identifier)
         if rec_identifier in c.records:
             return jsonify(
                 APIResponse("success",
                             data={
                                 "category_identifier": cat_identifier,
                                 "record_identifiers": c.records,
                                 "record_present": True
                             }).dictify())
         else:
             raise ValueError(
                 "Record Identifier: {} not present in Category: {}".format(
                     rec_identifier, cat_identifier))
     except Exception as e:
         return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())
예제 #38
0
    def post(self, cat_identifier):
        # Add a record to this category
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('record_identifier', type=str, required=True)
            args = parser.parse_args()

            c = retrieve_category(cat_identifier)
            c.add_record(args['record_identifier'])
            write_category(c, cat_identifier)
            return jsonify(
                APIResponse("success",
                            data={
                                "category_identifier": cat_identifier,
                                "record_identifiers": c.records
                            }).dictify())
        except Exception as e:
            return jsonify(_EXCEPTION_HANDLER.handle(e).dictify())