def datalake_purge(ionfile, ids, purge_filter): """ Deletes Data Objects based on the given filter or a list of IDs. You cannot define both arguments: ids and purge_filter. :param ionfile: Infor IONAPI credentials file. :param ids: Object ids. :param purge_filter: The restrictions to be applied to purge the records """ if ids is not None and purge_filter is not None: raise ValueError("You cannot define both arguments: ids and purge_filter.") inforlogin.load_config(ionfile) inforlogin.login() if ids is not None: ids_list = ids.split(",") response = delete_v1_purge_id(ids_list) if response.status_code == 200: click.echo(response.text) else: logger.error(response.content) if purge_filter is not None: response = delete_v1_purge_filter(purge_filter) if response.status_code == 200: click.echo(response.text) else: logger.error(response.content)
def test_post_messaging_v2_multipart_message(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() # create Document Schema object_name = "CSVSchema2" schema = { "$schema": "http://json-schema.org/draft-06/schema#", "$id": "http://schema.infor.com/json-schema/{}.json".format(object_name), "title": object_name, "type": "object", "dialect": { "separator": ",", "skipLines": 1, "headerLine": 1 }, "properties": { "ID": { "type": "integer", "x-position": 1, "maximum": 9 }, "FIRST_NAME": { "type": "string", "x-position": 2, "maxLength": 25 }, "LAST_NAME": { "type": "string", "x-position": 3, "maxLength": 25 }, "COUNTRY": { "type": "string", "x-position": 4, "maxLength": 25 }, }, } properties = {} assert (post_datacatalog_object(object_name, ObjectSchemaType.DSV, schema, properties).status_code == 200) # post Document parameter_request = { "documentName": "{}".format(object_name), "fromLogicalId": "lid://infor.ims.mongooseims", "toLogicalId": "lid://default", "encoding": "NONE", "characterSet": "UTF-8", } with open("data/sample.csv", "rb") as file: message_payload = file.read() assert (post_messaging_v2_multipart_message( parameter_request, message_payload).status_code == 201)
def test_get_v1_payloads_stream_by_id(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() res = get_v1_payloads_list("dl_document_name eq 'CSVSchema2'", ["event_date:desc"]) documents = json.loads(res.text)["fields"] for document in documents: res1 = get_v1_payloads_stream_by_id(document["dl_id"]) assert res1.status_code == 200
def delete(ionfile, name): inforlogin.load_config(ionfile) inforlogin.login() response = delete_datacatalog_object(name) if response.status_code == 200: click.echo("Data catalog schema {} was deleted.".format(name)) else: logger.error(response.content)
def test_delete_v1_purge_id(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() __create_document() res = get_v1_payloads_list("dl_document_name eq 'CSVSchema2'", ["event_date:desc"]) documents = json.loads(res.text)["fields"] dl_id = documents[0]["dl_id"] res = delete_v1_purge_id(dl_id) assert res.status_code == 200
def test_delete_v1_purge_filter(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() __create_document() res = get_v1_payloads_list("dl_document_name eq 'CSVSchema2'", ["event_date:desc"]) dl_id = json.loads(res.text)["fields"][0]["dl_id"] purge_filter = "dl_id eq '{}'".format(dl_id) res = delete_v1_purge_filter(purge_filter) result = json.loads(res.text) assert res.status_code == 200 assert result["purgedNumber"] > 0
def datalake_get(ionfile, stream_id): """ Retrieve payload based on id from datalake. :param ionfile: Infor IONAPI credentials file. :param stream_id: Object ID. """ inforlogin.load_config(ionfile) inforlogin.login() response = get_v1_payloads_stream_by_id(stream_id) if response.status_code == 200: click.echo(response.text) else: logger.error(response.content)
def upload(ionfile, schema, logical_id, file): inforlogin.load_config(ionfile) inforlogin.login() parameter_request = { "documentName": schema, "fromLogicalId": logical_id, "toLogicalId": "lid://default", "encoding": "NONE", "characterSet": "UTF-8", } with open(file, "rb") as file: message_payload = file.read() response = post_messaging_v2_multipart_message(parameter_request, message_payload) if response.status_code == 201: click.echo("Document uploaded successfully.") else: logger.error(response.content)
def datalake_list(ionfile, list_filter=None, sort=None, page=None, records=None): """ List data object properties using a filter. :param ionfile: Infor IONAPI credentials file. :param list_filter: The restrictions to be applied on the returned records. :param sort: Field name followed by colon followed by direction (asc or desc; default asc). Example: 'event_date:desc'. :param page: The page number from which to start returning records. Starts from 1. :param records: The number of records that will be returned. Starts from 0 """ inforlogin.load_config(ionfile) inforlogin.login() response = get_v1_payloads_list(list_filter, sort, page, records) if response.status_code == 200: click.echo(response.text) else: logger.error(response.content)
def test_post_delete_datacatalog_object(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() object_name = "CSVSchema" + str(round(time.time() * 1000)) schema = { "$schema": "http://json-schema.org/draft-06/schema#", "$id": "http://schema.infor.com/json-schema/{}.json".format(object_name), "title": object_name, "type": "object", "dialect": { "separator": ",", "skipLines": 1, "headerLine": 1 }, "properties": { "ID": { "type": "integer", "x-position": 1, "maximum": 9 }, "FIRST_NAME": { "type": "string", "x-position": 2, "maxLength": 25 }, "LAST_NAME": { "type": "string", "x-position": 3, "maxLength": 25 }, "COUNTRY": { "type": "string", "x-position": 4, "maxLength": 25 }, }, } properties = {"VariationPath": "$['ID']"} assert (post_datacatalog_object(object_name, ObjectSchemaType.DSV, schema, properties).status_code == 200) assert delete_datacatalog_object(object_name).status_code == 200
def create(ionfile, name, schema_type, schema, properties): inforlogin.load_config(ionfile) inforlogin.login() if not os.path.isfile(schema): raise FileNotFoundError("Schema file not found.") if not os.path.isfile(properties): raise FileNotFoundError("Properties file not found.") with open(schema, "r") as file: schema_content = json.loads(file.read()) with open(properties, "r") as file: properties_content = json.loads(file.read()) response = post_datacatalog_object(name, ObjectSchemaType(schema_type), schema_content, properties_content) if response.status_code == 200: logger.info("Data catalog schema {} was created.".format(name)) else: logger.error(response.content)
def test_reconnect(): inforlogin.load_config("FellowKey.ionapi") inforlogin.login() headers = inforlogin.header() headers2 = inforlogin.reconnect() assert headers["Authorization"] != headers2["Authorization"]
def export_data(url, ionfile, company, service_name, outputfile): """Exports business partner to an Excel file""" inforlogin.load_config(ionfile) token = inforlogin.login()["access_token"] lni.export_data(url, token, company, service_name, outputfile)
def check_token(url, ionfile): """Check Login and display the token""" inforlogin.load_config(ionfile) inforlogin.login()
def test_get_messaging_ping(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() assert get_messaging_ping().status_code == 200
def main_load( url=None, ionfile=None, program=None, method=None, dataframe=None, outputfile=None, start=None, end=None, on_progress=None, ): if validators.url(url) != True: logging.info("Error: URL is not valid") return "Error: URL is not valid" if os.path.exists(ionfile) == False: logging.info("Error: File does not exist") return "Error: File does not exist" else: inforlogin.load_config(ionfile) result = spliturl(url) if "Call" in result: if len(result["Call"]) > 0: if result["Call"] == "execute": inforlogin.load_config(ionfile) token = inforlogin.login() headers = inforlogin.header() if "Bearer" not in headers["Authorization"]: return "Error: InforION Login is not working" if start is None or end is None: return execute( url, headers, program, method, dataframe, outputfile, on_progress, ) else: return execute( url, headers, program, method, dataframe, outputfile, start, end, on_progress, ) if result["Call"] == "executeSnd": config = inforlogin.load_config(ionfile) token = inforlogin.login() headers = inforlogin.header() if "Bearer" not in headers["Authorization"]: return "InforION Login is not working" return executeSnd( url, headers, program, method, dataframe, outputfile, start, end ) if method == "checklogin": token = inforlogin.login() headers = inforlogin.header() return headers["Authorization"]
def test_get_v1_payloads_list(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() res = get_v1_payloads_list() assert res.status_code == 200 assert json.loads(res.text)["numFound"] > 0
def test_get_v1_payloads_list_with_filter_and_sort(): inforlogin.load_config("credentials/credentials.ionapi") inforlogin.login() res = get_v1_payloads_list("dl_document_name eq 'CSVSchema2'", ["event_date:desc"]) assert res.status_code == 200 assert json.loads(res.text)["numFound"] > 0