Ejemplo n.º 1
0
def entity_delete(payload, solution_id, config, validated=False):
    job_id = None
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        if not validated:
            domain_object = payload["entity_name"]
            valid = validate_entity_delete(solution_id, domain_object)
            if not valid:
                return invalid_edit_msg()
            entities_list = [domain_object]
        else:
            entities_list = payload
        for entities in entities_list:
            complete_list = deepcopy(entities_list)
            get_all_sub_entities(entities, solution_id, complete_list)
        data = {
            "solution_id": solution_id,
            "data": {
                "filter_obj": complete_list
            }
        }
        response = post_job(config["DELETE"], data, timeout=100)
        if 'job_id' in response:
            job_id = response['job_id']
        if not is_request_timeout(response):
            status, result = get_response(response)
            if status:
                for ent in complete_list:
                    query = {"entity_name": ent, "solution_id": solution_id}
                    MongoDbConn.remove(ENTITY_COLLECTION, query)
            else:
                return {
                    'status': 'failure',
                    'msg': 'Failed to remove',
                    'error': result,
                    'job_id': job_id
                }
        else:
            return {
                'status': 'failure',
                'msg': 'Request timeout',
                "error": response,
                'job_id': job_id
            }
        return {
            'status': 'success',
            'msg': 'Successfully removed',
            'job_id': job_id
        }
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
        if job_id:
            return {"status": "failure", "msg": str(e), 'job_id': job_id}
        else:
            return {"status": "failure", "msg": str(e)}
    finally:
        context.end_span()
Ejemplo n.º 2
0
def seed_data(file_name, collection_name):
    try:
        MongoDbConn.remove(collection_name, {})
        data = json.loads(open(os.path.join(SCRIPTS_ROOT, file_name)).read())
        for itm in data:
            MongoDbConn.insert(collection_name, itm)
    except Exception as e:
        print(str(e))
Ejemplo n.º 3
0
def delete_training_set_services(rec_id):
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        MongoDbConn.remove(TRAINING_SET_SERVICES_COLLECTION, {"trset_id": rec_id})
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
    finally:
        context.end_span()
Ejemplo n.º 4
0
def delete_rule(solution_id,rule_id):
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        payload = dict(solution_id=solution_id,rule_id=rule_id)
        rules = RuleManager()
        result = rules.process("deleteRule",payload)
        if result["status"]["success"] is True:
            MongoDbConn.remove(RULES_COLLECTION,dict(solution_id=solution_id,rule_id=rule_id))
            response = {"status":"success"}
        else:
            response = {"status":"failure","msg":result["status"]["msg"]}
        return response
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
        return {"status":"failure","msg":str(e)}
    finally:
        context.end_span()
Ejemplo n.º 5
0
def delete_entity_definitions(solution_id, file_path):
    resp = dict()
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        data = get_entity_definitions_from_ontology(str(file_path))
        for itm in data:
            query = {'solution_id': solution_id}
            if "entity_name" in itm.keys():
                query["entity_name"] = itm["entity_name"]
                MongoDbConn.remove(ENTITY_DEFN_COLL, query)
        resp['status'] = 'success'
        resp['msg'] = 'Entity definitions successfully updated/created'
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
        resp['status'] = 'failure'
        resp['msg'] = "Failed to update Entity Definitions " + str(e)
    context.end_span()
    return resp
Ejemplo n.º 6
0
def training_set_delete(solution_id, payload):
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        result = MongoDbConn.find_one(TRAINING_SET_COLLECTION,
                                          {"_id": ObjectId(payload['_id'])})
        if result is not None and "s3_key" in result.keys():
            key = result['s3_key']
            if result["extn"] in ["owl", "rdf"]:
                delete_entity_definitions(solution_id, result["s3_url"])
            resp = s3_delete(AMAZON_AWS_BUCKET, str(key))
            if resp['status'] == 'success':
                MongoDbConn.remove(TRAINING_SET_COLLECTION, {"_id": ObjectId(payload['_id'])})
                delete_training_set_services(payload['_id'])
            return resp
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
        return {"status": "failure", "msg": "failed to delete resource"}
    finally:
        context.end_span()
Ejemplo n.º 7
0
def test_delete_temp_db(solution_id="aranger1_5f2a66b5-382a-4a37-8161-01a7491a06a7"):
    delete_doc_db = MongoDbConn.remove(TEMPLATE_COLLECTION,
                                       {"solution_id":solution_id})
    return True
Ejemplo n.º 8
0
def delete_chart(chart_id=None):
    MongoDbConn.remove(DASHBOARD_CONFIG, {"chart_id": chart_id})
    return chart['chart_id']
def test_delete_mapdb(solution_id="aranger1_5f2a66b5-382a-4a37-8161-01a7491a06a7"):
    delete_map = MongoDbConn.remove(TEMPLATE_TRAIN_SAMPLES_COLLECTION, {"solution_id":solution_id})
    return True
Ejemplo n.º 10
0
def test_delete_rules_data(rule_id="aa0c6bae1-a458-4a3a-ba0e-30f4cd15128a"):
    delete_rules_data = MongoDbConn.remove(RULES_COLLECTION,
                                           {"rule_id": rule_id})
    return True
Ejemplo n.º 11
0
def del_document_var(var=solution_id):
    MongoDbConn.remove(DOCUMENTS_COLLECTION, {"solution_id": var})
    return True
Ejemplo n.º 12
0
def del_false_case_queue(var):
    MongoDbConn.remove(CASE_QUEUE_COLLECTION, var)
    return True
Ejemplo n.º 13
0
def del_case_queue(var=solution_id):
    MongoDbConn.remove(CASE_QUEUE_COLLECTION, {"solution_id": var})
    return True
Ejemplo n.º 14
0
def del_test_entity(solution_id=None):
    query = {"solution_id": solution_id}
    data = MongoDbConn.remove(CASE_QUEUE_COLLECTION, query)
    return data
Ejemplo n.º 15
0
def del_test_doc_temp(temp_solution_id=test_doc_temp_solution_id):
    MongoDbConn.remove(TEMPLATE_COLLECTION, {"solution_id": temp_solution_id})
    return True
Ejemplo n.º 16
0
def test_delete_doc_db(doc_id="afe2d978a-0f6a-4844-b872-812222764908"):
    delete_doc_db = MongoDbConn.remove(DOCUMENTS_COLLECTION,
                                       {"doc_id":doc_id})
    return True
Ejemplo n.º 17
0
def test_resource_data(resource_id="a9d56d363-21ff-48c8-a489-6c274061247e"):
    MongoDbConn.remove(RESOURCES_COLLECTION,
                                    {"resource_id": resource_id})
    return True
Ejemplo n.º 18
0
def del_test_mapping_doc(temp_solution_id=test_doc_temp_solution_id):
    MongoDbConn.remove(MAPPING_COLLECTION, {"solution_id": temp_solution_id})
    return True
Ejemplo n.º 19
0
def del_test_sec_doc(temp_solution_id=test_doc_temp_solution_id):
    MongoDbConn.remove(SECTIONS_COLLECTION, {"solution_id": temp_solution_id})
    return True