Commit dd6bfa1d authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: refactoring in data ingestion reference

parent 89478a9c
from DateTime import DateTime
from Products.ERP5Type.Log import log
# reference parameter example: telecom.MNE.filename.fif.EOF
# ingestion reference example: telecom_MNE_filename_fif
# ingestion id example: telecom_MNE_filename_fif_20170615
# reference parameter example: supplier.dataset.filename.fif.EOF
# ingestion reference example: dataset_filename_fif
FALSE = "FALSE"
TRUE = "TRUE"
today_string = DateTime().strftime('%Y%m%d')
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
data_ingestion_reference = '_'.join(reference.split('_')[:-1]) #'_'.join(reference.split('.')[:-1])
data_ingestion_id = '%s_%s' %(data_ingestion_reference, today_string)
# first search for applicable data ingestion
data_ingestion = portal_catalog.getResultValue(
portal_type = 'Data Ingestion',
simulation_state = 'planned',
reference = data_ingestion_reference)
if data_ingestion is None:
document = portal.data_ingestion_module.get(data_ingestion_id)
if (document is not None):
if document.getSimulationState() == 'planned':
return FALSE
else:
return TRUE
else:
try:
context.logEntry("Attempt to do a new ingestion with reference: %s" % reference)
# remove supplier and eof from reference
data_ingestion_reference = '_'.join(reference.split('_')[1:-1])
data_ingestion = portal_catalog.getResultValue(
portal_type = 'Data Ingestion',
reference = data_ingestion_reference)
if data_ingestion is None:
return FALSE
else:
if data_ingestion.getSimulationState() == 'planned':
return FALSE
context.logEntry("[ERROR] Data Ingestion reference %s already exists" % data_ingestion_reference)
return TRUE
except Exception as e:
context.logEntry("[ERROR] At script ingestionReferenceExists \n[ERROR] " + str(e))
raise e
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