Commit ec5d8491 authored by Luciano Cauzzi's avatar Luciano Cauzzi

Added update function

parent 9808adcf
......@@ -45,10 +45,7 @@ class AppPyramidManager:
try:
url = "{}/{}".format(self.__base_url__, self.__res_url__)
headers = {
'AUTHORIZATION': self.__app_token__.token,
'Content-Type': "application/json"
}
headers = self.__get_auth_header__()
s = self.__network_manager__.get_session()
payload = json.dumps(doc.to_dict())
response = s.post(url, data=payload, headers=headers, timeout=AppPyramidManager.TIMEOUT)
......@@ -60,20 +57,16 @@ class AppPyramidManager:
return False
return True
def exists_injunction(self, inj) -> Optional[str]:
def exists(self, doc) -> Optional[str]:
try:
url = "{}/{}/_search".format(self.__base_url__, self.__res_url__)
headers = {
'AUTHORIZATION': self.__app_token__.token,
'Content-Type': "application/json"
}
headers = self.__get_auth_header__()
payload = "{\n\t\"_source\": {\n " \
"\"includes\": \"*\",\n " \
"\"excludes\": \"attachments\"\n " \
"},\n \"query\": {\n \"terms\": {\n \"numero_cronologico\": [ \"" \
+ inj.progressive_number + "\"] \n }\n }\n}"
+ doc.progressive_number + "\"] \n }\n }\n}"
s = self.__network_manager__.get_session()
response = s.get(url, data=payload, headers=headers, timeout=AppPyramidManager.TIMEOUT)
json_obj = json.loads(response.text)
......@@ -88,3 +81,24 @@ class AppPyramidManager:
logger.exception(e)
return None
def update(self, elastic_id: str, doc) -> bool:
try:
url = "{}/{}/{}".format(self.__base_url__, self.__res_url__, elastic_id)
headers = self.__get_auth_header__()
s = self.__network_manager__.get_session()
payload = json.dumps(doc.to_dict())
response = s.put(url, data=payload, headers=headers, timeout=AppPyramidManager.TIMEOUT)
if response.status_code != 200:
return False
except Exception as e:
logger.error("Error while uploading injunctions to server")
logger.exception(e)
return False
return True
def __get_auth_header__(self):
return {
'AUTHORIZATION': self.__app_token__.token,
'Content-Type': "application/json"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment