Commit 0c72b893 authored by Paul Graydon's avatar Paul Graydon

wendelin_telecom_base: Make ORS object management scripts more robust

parent 446f7dad
''' '''
Creates a pre-configured Data Supply related to a Data Acquisition Unit representing an ORS. Creates a pre-configured Data Supply related to a Data Acquisition Unit representing an ORS.
The related Data Supply has the same reference as the Data Acquisition Unit. The related Data Supply has the same reference as the Data Acquisition Unit, which is the
ORS's fluentbit tag and is needed for proper ingestion of its logs.
The script first checks if the Data Supply already exists, and will create it if it doesn't. The script first checks if the Data Supply already exists, and will create it if it doesn't.
If batch == 1, the Data Supply object is returned in both cases of the above check. If batch == 1, the Data Supply object is returned in both cases of the above check.
Otherwise, the user is redirected to the Data Supply's view page. Otherwise, the user is redirected to the Data Supply's view page.
''' '''
if not context.getReference(): if not context.getReference():
if batch:
return None
return context.Base_redirect('view', keep_items={ return context.Base_redirect('view', keep_items={
'portal_status_message': 'Reference is not defined.', 'portal_status_message': 'Reference is not defined.',
'portal_status_level': 'error' 'portal_status_level': 'error'
}) })
reference = context.getReference() reference = context.getReference()
data_supply = context.portal_catalog.getResultValue( data_supply = context.DataAcquisitionUnit_getOrsDataSupply()
portal_type='Data Supply',
reference=reference,
validation_state='validated'
)
if data_supply: if data_supply:
if batch: if batch:
return data_supply return data_supply
......
''' '''
Return the pre-configured Data Supply related to a Data Acquisition Unit representing an ORS. Return the pre-configured Data Supply related to a Data Acquisition Unit representing an ORS.
If the Data Acquisition Unit does not have a reference or the Data Supply does not exist, return None.
The related Data Supply must have the same reference as the Data Acquisition Unit. If the Data Acquisition Unit or the Data Supply do not fit the expected ORS format, return None.
In the unexpected event several matching Data Supplies exist, return the oldest one, as it is
most likely to be the one created by the ORS registration process.
''' '''
if not context.getReference(): if context.getReference() is None:
return None return None
reference = context.getReference() ors_tag = context.getReference()
portal = context.getPortalObject()
return context.portal_catalog.getResultValue( data_supply_list = portal.data_supply_module.searchFolder(
portal_type='Data Supply', portal_type='Data Supply',
reference=reference, reference=ors_tag,
validation_state='validated' validation_state='validated'
) )
data_supply_url_list = [
data_supply.getRelativeUrl() for data_supply in data_supply_list
]
related_data_supply_list = []
for data_supply_line in context.Base_getRelatedObjectList(
portal_type='Data Supply Line',
validation_state='validated'
):
# Be sure to only fetch Data Supplies the user has access to
data_supply_url = data_supply_line.getParentRelativeUrl()
if data_supply_url in data_supply_url_list:
related_data_supply_list.append(portal.restrictedTraverse(data_supply_url))
if not related_data_supply_list:
return None
# Several related Data Supplies have the expected reference: unexpected
# Return the one that was created first
related_data_supply_list.sort(key=lambda x: x.getCreationDate())
return related_data_supply_list[0]
...@@ -49,7 +49,8 @@ related_data_acquisition_unit_list = [ ...@@ -49,7 +49,8 @@ related_data_acquisition_unit_list = [
portal_type='Data Acquisition Unit', portal_type='Data Acquisition Unit',
validation_state='validated' validation_state='validated'
) \ ) \
if related_data_acquisition_unit.getReference().startswith(fluentbit_tag_prefix) if related_data_acquisition_unit.getReference() is not None \
and related_data_acquisition_unit.getReference().startswith(fluentbit_tag_prefix)
] ]
destination_project = None destination_project = None
if related_data_acquisition_unit_list: if related_data_acquisition_unit_list:
......
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