Skip to content

Commit

Permalink
control values added
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarocosta committed Jun 18, 2020
1 parent b0aef0c commit 7a7ad3e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def get_project_root():
from neomodel import config

from src.Utils.JsonEncoder import search_cidoc, search_specific_cidoc
from src.Utils.Utils import get_node_by_uid, build_next_json, updated_node, make_result, build_information_eva
from src.Utils.Utils import get_node_by_uid, build_next_json, updated_node, make_result, build_information_eva, \
search_type_identifiers, search_type_titles

#import src.Utils.ArgParser as ArgParser

Expand Down Expand Up @@ -258,6 +259,7 @@ def get_templates_from_entity(uid):
return make_response(jsonify(message="Node doesn't exists"), 404)


#verificar se é do tipo E24, E18
@app.route("/eva/<uid>", methods=["GET"])
@cross_origin()
def response_eva_view(uid):
Expand All @@ -272,6 +274,26 @@ def response_eva_view(uid):
return make_response(jsonify(message="Node doesn't exists"), 404)


@app.route("/control_values/type_identifiers", methods=["GET"])
@cross_origin()
def response_type_identifiers():
response = search_type_identifiers()
if response:
return make_response(jsonify(response), 201)
else:
return make_response(jsonify(message="Doesn't have information"), 404)


@app.route("/control_values/type_titles", methods=["GET"])
@cross_origin()
def response_type_titles():
response = search_type_titles()
if response:
return make_response(jsonify(response), 201)
else:
return make_response(jsonify(message="Doesn't have information"), 404)


# update node
@app.route("/<uid>", methods=["POST"])
@cross_origin()
Expand Down Expand Up @@ -332,22 +354,6 @@ def search_specific(class_name, query):
return make_response(jsonify(message="Failed Search"), 404)


#@app.route("/eva/<uid>", methods=["POST"])
#@cross_origin()
#def get_doc(uid):
# #node = get_node_by_uid(uid)
# template = {
# "E22_Human_Made_Object": {
# "P102_has_title": ["ARE2_formal_title", "Registo de Batismo"],
# "P1_is_identified_by": ["Código de Referência", "PT /ADPRT"]
# }
# }

# print(template)
# if template is not None:
# return make_response(jsonify(template), 201)
# else:
# make_response(jsonify(message="Template doesn't exists"), 404)


# delete_collection("defaultTemplate")
Expand Down
45 changes: 45 additions & 0 deletions src/Utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,48 @@ def build_information_eva(node):
}

return result


def search_type_identifiers():
result = []
identifiers = ARE5_Identifier_Type.nodes.all()
for identifier in identifiers:
uid = read_relationships(identifier.__class__.__name__, identifier.uid, "has_value")[0]
string_node = get_node_by_uid(uid)
if string_node is not None:
element = {
"option": string_node.stringValue,
"value": identifier.uid,
}
result.append(element)

return result


def search_type_titles():
result = []
# formals_titles = ARE2_Formal_Title.nodes.all()
# supplied_titles = ARE3_Supplied_Title.nodes.all()
# result = E71_Human_Made_Thing.nodes.has(P102_has_title=True)
# for node in result:
# uid = read_relationships(node.__class__.__name__, node.uid, "P102_has_title")[0]
# title_node = get_node_by_uid(uid)
# if title_node is not None:
# element = {
# "option": title_node.stringValue,
# "value": title_node.uid,
# }
# result.append(element)
element = {
"option": "Formal",
"value": "ARE2_Formal_Title",
}
element1 = {
"option": "Atribuido",
"value": "ARE3_Supplied_Title",
}
result.append(element)
result.append(element1)

return result

10 changes: 10 additions & 0 deletions test/Unit/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ def test_eva(self):
identifier.has_value.connect(identifier_value)
identifier_type.has_value.connect(codigo)

def test_type_identifier(self):
identifier = ARE5_Identifier_Type(name="identifier1").save()
identifier2 = ARE5_Identifier_Type(name="identifier2").save()
string1 = String(name="string1", stringValue="CodigoDeReferencia").save()
string2 = String(name="string2", stringValue="CodigoDeReferencia2").save()

identifier.has_value.connect(string1)
identifier2.has_value.connect(string2)





Expand Down

0 comments on commit 7a7ad3e

Please sign in to comment.