Commit f68899a8 authored by Klaus Wölfel's avatar Klaus Wölfel

allow to get ingestion parameters and operation without creating data ingestion

parent e08b1192
from DateTime import DateTime
if data_ingestion_id is None:
now = DateTime()
today_string = now.strftime('%Y%m%d')
data_ingestion_id = "%s-%s" %(today_string, data_ingestion_reference)
portal = context.getPortalObject()
data_ingestion = portal.data_ingestion_module.newContent(
id = data_ingestion_id,
portal_type = "Data Ingestion",
reference = data_ingestion_reference,
specialise_list = specialise_list)
composed = data_ingestion.asComposedDocument()
property_list = ["title",
"source",
"source_section",
"source_project",
"destination",
"destination_section",
"destination_project",
"specialise"]
property_dict = {p: composed.getProperty(p) for p in property_list}
property_dict["start_date"] = composed.getEffectiveDate()
property_dict["stop_date"] = composed.getExpirationDate()
data_ingestion.edit(**property_dict)
# create ingestion lines from specialise lines
for supply_line in composed.objectValues(
portal_type = 'Data Supply Line'):
current_line = data_ingestion.newContent(
portal_type = "Data Ingestion Line",
title = supply_line.getTitle(),
aggregate = supply_line.getAggregateList(),
int_index = supply_line.getIntIndex(),
quantity = supply_line.getQuantity(),
reference = supply_line.getReference(),
resource = supply_line.getResource(),
use = supply_line.getUse()
)
if current_line.getResourceValue().getPortalType() == "Data Product":
# we set quantity=0 for the data product lines
current_line.setQuantity(0)
data_ingestion.start()
return data_ingestion
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>specialise_list, data_ingestion_reference, data_ingestion_id=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_createDataIngestion</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -14,7 +14,7 @@ specialise_reference = movement_dict.get('specialise_reference', None) ...@@ -14,7 +14,7 @@ specialise_reference = movement_dict.get('specialise_reference', None)
data_ingestion = portal_catalog.getResultValue( data_ingestion = portal_catalog.getResultValue(
portal_type = 'Data Ingestion', portal_type = 'Data Ingestion',
simulation_state = ['started', 'stopped'], simulation_state = ['started', 'stopped'],
reference =data_ingestion_reference) reference = data_ingestion_reference)
def init_input_line(input_line, operation_line): def init_input_line(input_line, operation_line):
# copy device and configuration from operation line to input line # copy device and configuration from operation line to input line
...@@ -95,79 +95,32 @@ if data_ingestion is None: ...@@ -95,79 +95,32 @@ if data_ingestion is None:
if (document is not None) and document.getSimulationState() == 'started': if (document is not None) and document.getSimulationState() == 'started':
data_ingestion = document data_ingestion = document
if data_ingestion is None: if modify and data_ingestion is None:
specialise_value_list = [x.getObject() for x in portal_catalog.searchResults( specialise_list = [x.getRelativeUrl() for x in portal_catalog.searchResults(
portal_type = 'Data Supply', portal_type = 'Data Supply',
reference = specialise_reference, reference = specialise_reference,
validation_state = 'validated')] validation_state = 'validated')]
# if we do not find a validated data supply, we look for a default data supply # if we do not find a validated data supply, we look for a default data supply
if not specialise_value_list: if not specialise_list:
specialise_value_list = [x.getObject() for x in portal_catalog.searchResults( specialise_list = [x.getRelativeUrl() for x in portal_catalog.searchResults(
portal_type = 'Data Supply', portal_type = 'Data Supply',
reference = specialise_reference, reference = specialise_reference,
validation_state = 'default')] validation_state = 'default')]
# create a new data ingestion # create a new data ingestion
data_ingestion = portal.data_ingestion_module.newContent( data_ingestion = portal.ERP5Site_createDataIngestion(specialise_list,
id = data_ingestion_id, data_ingestion_reference,
portal_type = "Data Ingestion", data_ingestion_id)
reference = data_ingestion_reference,
specialise_value_list = specialise_value_list)
composed = data_ingestion.asComposedDocument()
property_list = ["title",
"source",
"source_section",
"source_project",
"destination",
"destination_section",
"destination_project",
"specialise"]
property_dict = {p: composed.getProperty(p) for p in property_list}
property_dict["start_date"] = composed.getEffectiveDate()
property_dict["stop_date"] = composed.getExpirationDate()
data_ingestion.edit(**property_dict)
# create ingestion lines from specialise lines and assign input line
# and operation line
input_line = None
operation_line = None
for supply_line in composed.objectValues(
portal_type = 'Data Supply Line'):
current_line = data_ingestion.newContent(
portal_type = "Data Ingestion Line",
title = supply_line.getTitle(),
aggregate = supply_line.getAggregateList(),
int_index = supply_line.getIntIndex(),
quantity = supply_line.getQuantity(),
reference = supply_line.getReference(),
resource = supply_line.getResource(),
use = supply_line.getUse()
)
if current_line.getResourceReference() == resource_reference:
input_line = current_line
elif current_line.getResourceValue().getPortalType() == "Data Operation":
operation_line = current_line
else:
# we set quantity=0 for the empty line
current_line.setQuantity(0)
init_input_line(input_line, operation_line)
data_ingestion.start()
else: # find ingestion line for current resource
# find ingestion line for current resource for line in data_ingestion.objectValues(portal_type="Data Ingestion Line"):
for line in data_ingestion.objectValues(portal_type="Data Ingestion Line"):
if line.getResourceReference() == resource_reference: if line.getResourceReference() == resource_reference:
input_line = line input_line = line
elif line.getResourceValue().getPortalType() == "Data Operation": elif line.getResourceValue().getPortalType() == "Data Operation":
operation_line = line operation_line = line
if input_line.getQuantity() == 0: if modify and input_line.getQuantity() == 0:
init_input_line(input_line, operation_line) init_input_line(input_line, operation_line)
data_operation = operation_line.getResourceValue() data_operation = operation_line.getResourceValue()
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>movement_dict, reference</string> </value> <value> <string>movement_dict, reference, modify=True</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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