Commit 00a6dd7c authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: minor fix in create data analysis

parent fc1e8f8a
...@@ -36,67 +36,68 @@ for line_data_ingestion in portal_catalog(**query_dict): ...@@ -36,67 +36,68 @@ for line_data_ingestion in portal_catalog(**query_dict):
destination_section = data_ingestion.getDestinationSection(), destination_section = data_ingestion.getDestinationSection(),
destination_project = data_ingestion.getDestinationProject()) destination_project = data_ingestion.getDestinationProject())
context.logEntry("Data Analyisis created for Data Ingestion %s (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId())) context.logEntry("Data Analyisis created for Data Ingestion %s (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId()))
except: except Exception as e:
context.logEntry("[ERROR] Error creating Data Analysis for Data Ingestion '%s' (ID: %s). Script returned" % (str(data_ingestion.getReference()), data_ingestion.getId())) context.logEntry("[WARNING] Exception creating Data Analysis (already created?): " + str(e))
return # Data Analysis was already created data_analysis = None
# create input and output lines if data_analysis is not None:
context.logEntry("creating input and output lines of data analysis %s (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId())) # create input and output lines
for transformation_line in transformation.objectValues( context.logEntry("creating input and output lines of data analysis %s (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId()))
portal_type=["Data Transformation Resource Line", for transformation_line in transformation.objectValues(
"Data Transformation Operation Line"]): portal_type=["Data Transformation Resource Line",
resource = transformation_line.getResourceValue() "Data Transformation Operation Line"]):
quantity = transformation_line.getQuantity() resource = transformation_line.getResourceValue()
if isinstance(quantity, tuple): quantity = transformation_line.getQuantity()
quantity = quantity[0] if isinstance(quantity, tuple):
aggregate_set = set() quantity = quantity[0]
# manually add device and device configuration to every line aggregate_set = set()
if line_data_ingestion.getAggregateDevice() is not None: # manually add device and device configuration to every line
aggregate_set.add(line_data_ingestion.getAggregateDevice()) if line_data_ingestion.getAggregateDevice() is not None:
if line_data_ingestion.getAggregateDeviceConfiguration() is not None: aggregate_set.add(line_data_ingestion.getAggregateDevice())
aggregate_set.add(line_data_ingestion.getAggregateDeviceConfiguration()) if line_data_ingestion.getAggregateDeviceConfiguration() is not None:
if transformation_line.getPortalType() == "Data Transformation Resource Line": aggregate_set.add(line_data_ingestion.getAggregateDeviceConfiguration())
# at the moment, we only check for positive or negative quantity if transformation_line.getPortalType() == "Data Transformation Resource Line":
if quantity < 0: # at the moment, we only check for positive or negative quantity
# it is an input line. If it is an input resource line, then we search for an if quantity < 0:
# ingestion line with the same resource. If it is an operation line # it is an input line. If it is an input resource line, then we search for an
# then we search for an ingestion line with resource portal type Data Product # ingestion line with the same resource. If it is an operation line
related_lines_list = portal_catalog( # then we search for an ingestion line with resource portal type Data Product
portal_type="Data Ingestion Line", related_lines_list = portal_catalog(
simulation_state="stopped", portal_type="Data Ingestion Line",
resource_relative_url = resource.getRelativeUrl()) simulation_state="stopped",
for related_line in related_lines_list: resource_relative_url = resource.getRelativeUrl())
if(related_line.getParentValue().getReference() == data_ingestion.getReference() and related_line.getParentValue().getSimulationState() == "stopped"): for related_line in related_lines_list:
aggregate_set.update(related_line.getAggregateSet()) if(related_line.getParentValue().getReference() == data_ingestion.getReference() and related_line.getParentValue().getSimulationState() == "stopped"):
related_line.getParentValue().deliver() aggregate_set.update(related_line.getAggregateSet())
context.logEntry("Data Ingestion '%s' delivered. (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId())) related_line.getParentValue().deliver()
else: context.logEntry("Data Ingestion '%s' delivered. (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId()))
# it is an output line else:
# create new item based on item_type: data array, stream, descriptor, etc. # it is an output line
item_type = resource.getAggregatedPortalType() # create new item based on item_type: data array, stream, descriptor, etc.
module = portal.getDefaultModule(item_type) item_type = resource.getAggregatedPortalType()
item = module.newContent(portal_type = item_type, module = portal.getDefaultModule(item_type)
title = data_ingestion.getTitle(), item = module.newContent(portal_type = item_type,
id = data_ingestion.getId(), title = data_ingestion.getTitle(),
reference = data_ingestion.getReference(), id = data_ingestion.getId(),
version = '001') reference = data_ingestion.getReference(),
if "Data Descriptor" not in item_type: version = '001')
item.validate() if "Data Descriptor" not in item_type:
context.logEntry(str(item_type) + " %s created (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId())) item.validate()
aggregate_set = set() context.logEntry(str(item_type) + " %s created (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId()))
aggregate_set.add(item) aggregate_set = set()
aggregate_set.add(item)
data_analysis.newContent( data_analysis.newContent(
portal_type = "Data Analysis Line", portal_type = "Data Analysis Line",
title = transformation_line.getTitle(), title = transformation_line.getTitle(),
reference = transformation_line.getReference(), reference = transformation_line.getReference(),
int_index = transformation_line.getIntIndex(), int_index = transformation_line.getIntIndex(),
resource_value = resource, resource_value = resource,
quantity = quantity, quantity = quantity,
quantity_unit = transformation_line.getQuantityUnit(), quantity_unit = transformation_line.getQuantityUnit(),
aggregate_value_set = aggregate_set) aggregate_value_set = aggregate_set)
data_analysis.plan() data_analysis.plan()
context.logEntry("Data Anaysis '%s' planned. (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId())) context.logEntry("Data Anaysis '%s' planned. (ID: %s)" % (str(data_ingestion.getReference()), data_ingestion.getId()))
except Exception as e: except Exception as e:
context.logEntry("[ERROR] Error creating Data Analysis for Data Ingestion '%s' (ID: %s): %s" % (data_ingestion.getReference(), data_ingestion.getId(), str(e))) context.logEntry("[ERROR] Error creating Data Analysis for Data Ingestion '%s' (ID: %s): %s" % (data_ingestion.getReference(), data_ingestion.getId(), str(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