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