Commit 54c47e5e authored by Klaus Wölfel's avatar Klaus Wölfel

data analysis creation: automaticall add items such as device configuration and data configuration

parent 41fc9bb3
...@@ -25,7 +25,7 @@ for movement in portal_catalog(query): ...@@ -25,7 +25,7 @@ for movement in portal_catalog(query):
if movement.DataIngestionLine_hasMissingRequiredItem(): if movement.DataIngestionLine_hasMissingRequiredItem():
raise ValueError("Transformation requires movement to have " + raise ValueError("Transformation requires movement to have " +
"aggregated data ingestion batch") "aggregated data ingestion batch")
data_ingestion = movement.getParentValue() delivery = movement.getParentValue()
# Get applicable transformation # Get applicable transformation
for transformation in portal_catalog( for transformation in portal_catalog(
portal_type = "Data Transformation", portal_type = "Data Transformation",
...@@ -35,23 +35,24 @@ for movement in portal_catalog(query): ...@@ -35,23 +35,24 @@ for movement in portal_catalog(query):
data_analysis = portal_catalog.getResultValue( data_analysis = portal_catalog.getResultValue(
portal_type="Data Analysis", portal_type="Data Analysis",
specialise_relative_url = transformation.getRelativeUrl(), specialise_relative_url = transformation.getRelativeUrl(),
causality_relative_url = data_ingestion.getRelativeUrl()) causality_relative_url = delivery.getRelativeUrl())
if data_analysis is not None: if data_analysis is not None:
continue continue
data_supply = delivery.getSpecialiseValueList(portal_type="Data Supply")
# Create Analysis # Create Analysis
data_analysis = portal.data_analysis_module.newContent( data_analysis = portal.data_analysis_module.newContent(
portal_type = "Data Analysis", portal_type = "Data Analysis",
title = transformation.getTitle(), title = transformation.getTitle(),
reference = data_ingestion.getReference(), reference = delivery.getReference(),
start_date = now, start_date = now,
specialise_value = transformation, specialise_value_list = [transformation] + data_supply,
causality_value = data_ingestion, causality_value = delivery,
source = data_ingestion.getSource(), source = delivery.getSource(),
source_section = data_ingestion.getSourceSection(), source_section = delivery.getSourceSection(),
source_project = data_ingestion.getSourceProject(), source_project = delivery.getSourceProject(),
destination = data_ingestion.getDestination(), destination = delivery.getDestination(),
destination_section = data_ingestion.getDestinationSection(), destination_section = delivery.getDestinationSection(),
destination_project = data_ingestion.getDestinationProject()) destination_project = delivery.getDestinationProject())
# create input and output lines # create input and output lines
for transformation_line in transformation.objectValues( for transformation_line in transformation.objectValues(
...@@ -62,14 +63,8 @@ for movement in portal_catalog(query): ...@@ -62,14 +63,8 @@ for movement in portal_catalog(query):
if isinstance(quantity, tuple): if isinstance(quantity, tuple):
quantity = quantity[0] quantity = quantity[0]
aggregate_set = set() aggregate_set = set()
# manually add device and device configuration to every line # manually add device to every line
aggregate_set.add(movement.getAggregateDevice()) aggregate_set.add(movement.getAggregateDevice())
# workaround the case that no device configuration portal type exists
# without this work around aggregate from any portal type
# would be returned, because getAggregateValue(portal_type=[]) does not
# return None as expected. This must be fixed properly in generic erp5
if portal.getPortalDeviceConfigurationTypeList():
aggregate_set.add(movement.getAggregateDeviceConfiguration())
if transformation_line.getPortalType() == \ if transformation_line.getPortalType() == \
"Data Transformation Resource Line": "Data Transformation Resource Line":
# at the moment, we only check for positive or negative quantity # at the moment, we only check for positive or negative quantity
...@@ -107,13 +102,23 @@ for movement in portal_catalog(query): ...@@ -107,13 +102,23 @@ for movement in portal_catalog(query):
item = module.newContent(portal_type = item_type, item = module.newContent(portal_type = item_type,
title = transformation.getTitle(), title = transformation.getTitle(),
reference = "%s-%s" %(transformation.getTitle(), reference = "%s-%s" %(transformation.getTitle(),
data_ingestion.getReference()), delivery.getReference()),
version = '001') version = '001')
try: try:
item.validate() item.validate()
except AttributeError: except AttributeError:
pass pass
aggregate_set.add(item.getRelativeUrl()) aggregate_set.add(item.getRelativeUrl())
elif transformation_line.getPortalType() == \
"Data Transformation Operation Line":
# find other items such as device configuration and data configuration
# from data ingestion and data supply
composed = data_analysis.asComposedDocument()
line_list = [l for l in delivery.objectValues(portal_type="Data Ingestion Line")]
line_list += [l for l in composed.objectValues(portal_type="Data Supply Line")]
for line in line_list:
if line.getResourceValue().getPortalType() == "Data Operation":
aggregate_set.update(line.getAggregateList())
data_analysis.newContent( data_analysis.newContent(
portal_type = "Data Analysis Line", portal_type = "Data Analysis Line",
......
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