Commit 148367e5 authored by Łukasz Nowak's avatar Łukasz Nowak

Avoid External method decoration.

It just does not work [tm].
parent b734cf39
...@@ -91,163 +91,166 @@ def fixSaleOrder(slap_document): ...@@ -91,163 +91,166 @@ def fixSaleOrder(slap_document):
sale_packing_list.getParentValue().deleteContent(sale_packing_list.getId()) sale_packing_list.getParentValue().deleteContent(sale_packing_list.getId())
return new_sale_order.contentValues(portal_type='Sale Order Line')[0] return new_sale_order.contentValues(portal_type='Sale Order Line')[0]
@WorkflowMethod.disable
def SlapDocument_migrateSlapState(self): def SlapDocument_migrateSlapState(self):
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery @WorkflowMethod.disable
def real(self):
def setUpPeriodicity(hosting_subscription): from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from Products.ERP5Type.DateUtils import addToDate, getClosestDate
start_date = hosting_subscription.getCreationDate() def setUpPeriodicity(hosting_subscription):
start_date = getClosestDate(target_date=start_date, precision='day') from Products.ERP5Type.DateUtils import addToDate, getClosestDate
while start_date.day() >= 29: start_date = hosting_subscription.getCreationDate()
start_date = addToDate(start_date, to_add={'day': -1}) start_date = getClosestDate(target_date=start_date, precision='day')
periodicity_month_day_list = [start_date.day()] while start_date.day() >= 29:
periodicity_hour_list=[0] start_date = addToDate(start_date, to_add={'day': -1})
periodicity_minute_list=[0] periodicity_month_day_list = [start_date.day()]
hosting_subscription.edit( periodicity_hour_list=[0]
periodicity_month_day_list=periodicity_month_day_list, periodicity_minute_list=[0]
periodicity_hour_list=periodicity_hour_list, hosting_subscription.edit(
periodicity_minute_list=periodicity_minute_list periodicity_month_day_list=periodicity_month_day_list,
) periodicity_hour_list=periodicity_hour_list,
periodicity_minute_list=periodicity_minute_list
slap_document = self )
portal = self.getPortalObject()
slap_document = self
portal_type_list = ('Hosting Subscription', 'Software Instance', 'Slave Instance') portal = self.getPortalObject()
portal_type = slap_document.getPortalType()
if portal_type not in portal_type_list: portal_type_list = ('Hosting Subscription', 'Software Instance', 'Slave Instance')
raise TypeError('%s is not %s' % (slap_document.getPath(), portal_type_list)) portal_type = slap_document.getPortalType()
if portal_type not in portal_type_list:
explanation_delivery_line = portal.portal_catalog.getResultValue( raise TypeError('%s is not %s' % (slap_document.getPath(), portal_type_list))
portal_type='Sale Packing List Line',
simulation_state=['ready', 'confirmed', 'started', 'stopped', 'delivered'], explanation_delivery_line = portal.portal_catalog.getResultValue(
query=ComplexQuery( portal_type='Sale Packing List Line',
Query(default_aggregate_uid=slap_document.getUid()), simulation_state=['ready', 'confirmed', 'started', 'stopped', 'delivered'],
Query(default_resource_uid=[ query=ComplexQuery(
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource()).getUid(), Query(default_aggregate_uid=slap_document.getUid()),
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceHostingResource()).getUid(), Query(default_resource_uid=[
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceCleanupResource()).getUid(), portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource()).getUid(),
]), portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceHostingResource()).getUid(),
operator='AND', portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceCleanupResource()).getUid(),
), ]),
sort_on=(('movement.start_date', 'DESC'),) operator='AND',
) ),
if explanation_delivery_line is None: sort_on=(('movement.start_date', 'DESC'),)
explanation_delivery_line = slap_document.getAggregateRelatedValue(portal_type='Sale Order Line')
if slap_document.getRelativeUrl() == 'hosting_subscription_module/20120521-C46CA2':
# special case of destroyed data
explanation_delivery_line = fixSaleOrder(slap_document)
if portal_type == 'Hosting Subscription':
current_periodicity = slap_document.getPeriodicityMonthDayList()
if current_periodicity is None or len(current_periodicity) == 0:
setUpPeriodicity(slap_document)
# Person is now directly associated on the HS
slap_document.edit(
destination_section_value=explanation_delivery_line.getDestinationSectionValue(portal_type="Person"),
)
assert(slap_document.getDestinationSection() == explanation_delivery_line.getDestinationSectionValue().getRelativeUrl())
else:
hosting_subscription = explanation_delivery_line.getAggregateValue(portal_type='Hosting Subscription')
slap_document.edit(
specialise_value=hosting_subscription,
root_software_release_url=explanation_delivery_line.getAggregateValue(portal_type='Software Release').getUrlString()
) )
assert(slap_document.getSpecialise() == hosting_subscription.getRelativeUrl()) if explanation_delivery_line is None:
explanation_delivery_line = slap_document.getAggregateRelatedValue(portal_type='Sale Order Line')
# Migrate slap state if slap_document.getRelativeUrl() == 'hosting_subscription_module/20120521-C46CA2':
if portal_type == 'Hosting Subscription': # special case of destroyed data
state = slap_document.getRootState() explanation_delivery_line = fixSaleOrder(slap_document)
promise_kw = {
'instance_xml': slap_document.getTextContent(), if portal_type == 'Hosting Subscription':
'software_type': slap_document.getSourceReference(), current_periodicity = slap_document.getPeriodicityMonthDayList()
'sla_xml': slap_document.getSlaXml(), if current_periodicity is None or len(current_periodicity) == 0:
'software_release': slap_document.getRootSoftwareReleaseUrl(), setUpPeriodicity(slap_document)
'shared': slap_document.isRootSlave() # Person is now directly associated on the HS
} slap_document.edit(
else: destination_section_value=explanation_delivery_line.getDestinationSectionValue(portal_type="Person"),
if explanation_delivery_line.getPortalType() == 'Sale Packing List Line': )
resource = explanation_delivery_line.getResource() assert(slap_document.getDestinationSection() == explanation_delivery_line.getDestinationSectionValue().getRelativeUrl())
if resource == portal.portal_preferences.getPreferredInstanceSetupResource(): else:
state = 'stopped' hosting_subscription = explanation_delivery_line.getAggregateValue(portal_type='Hosting Subscription')
elif resource == portal.portal_preferences.getPreferredInstanceCleanupResource(): slap_document.edit(
state = 'destroyed' specialise_value=hosting_subscription,
elif resource == portal.portal_preferences.getPreferredInstanceHostingResource(): root_software_release_url=explanation_delivery_line.getAggregateValue(portal_type='Software Release').getUrlString()
if explanation_delivery_line.getSimulationState() in ('confirmed', 'started'): )
state = 'started' assert(slap_document.getSpecialise() == hosting_subscription.getRelativeUrl())
else:
# Migrate slap state
if portal_type == 'Hosting Subscription':
state = slap_document.getRootState()
promise_kw = {
'instance_xml': slap_document.getTextContent(),
'software_type': slap_document.getSourceReference(),
'sla_xml': slap_document.getSlaXml(),
'software_release': slap_document.getRootSoftwareReleaseUrl(),
'shared': slap_document.isRootSlave()
}
else:
if explanation_delivery_line.getPortalType() == 'Sale Packing List Line':
resource = explanation_delivery_line.getResource()
if resource == portal.portal_preferences.getPreferredInstanceSetupResource():
state = 'stopped' state = 'stopped'
elif resource == portal.portal_preferences.getPreferredInstanceCleanupResource():
state = 'destroyed'
elif resource == portal.portal_preferences.getPreferredInstanceHostingResource():
if explanation_delivery_line.getSimulationState() in ('confirmed', 'started'):
state = 'started'
else:
state = 'stopped'
pass
else:
raise TypeError('Bad resource %s' % resource)
pass pass
else: else:
raise TypeError('Bad resource %s' % resource) if explanation_delivery_line.getSimulationState() == 'cancelled':
pass state = 'destroyed'
else:
if explanation_delivery_line.getSimulationState() == 'cancelled':
state = 'destroyed'
else:
assert(explanation_delivery_line.getSimulationState() in ['ordered', 'confirmed'])
previous_workflow_state = self.workflow_history[
'software_instance_slap_interface_workflow'][-1]['slap_state']
if previous_workflow_state == 'start_requested':
state = 'started'
elif previous_workflow_state == 'stop_requested':
state = 'stopped'
else: else:
raise NotImplementedError("Previous state %r not supported" % previous_workflow_state) assert(explanation_delivery_line.getSimulationState() in ['ordered', 'confirmed'])
promise_kw = { previous_workflow_state = self.workflow_history[
'instance_xml': slap_document.getTextContent(), 'software_instance_slap_interface_workflow'][-1]['slap_state']
'software_type': slap_document.getSourceReference(), if previous_workflow_state == 'start_requested':
'sla_xml': slap_document.getSlaXml(), state = 'started'
'software_release': slap_document.getRootSoftwareReleaseUrl(), elif previous_workflow_state == 'stop_requested':
'shared': slap_document.getPortalType() == 'Slave Instance' state = 'stopped'
else:
raise NotImplementedError("Previous state %r not supported" % previous_workflow_state)
promise_kw = {
'instance_xml': slap_document.getTextContent(),
'software_type': slap_document.getSourceReference(),
'sla_xml': slap_document.getSlaXml(),
'software_release': slap_document.getRootSoftwareReleaseUrl(),
'shared': slap_document.getPortalType() == 'Slave Instance'
}
slap_document.setCausalityValue(explanation_delivery_line.getParentValue())
if state != 'destroyed' or explanation_delivery_line.getSimulationState() != 'delivered':
slap_document.setAggregateValue(explanation_delivery_line.getAggregateValue(portal_type='Computer Partition'))
assert(slap_document.getAggregate() == explanation_delivery_line.getAggregate(portal_type='Computer Partition'))
state_map = {
'started': 'start_requested',
'stopped': 'stop_requested',
'destroyed': 'destroy_requested'
} }
required_state = state_map[state]
slap_document.setCausalityValue(explanation_delivery_line.getParentValue()) _jumpToStateFor = portal.portal_workflow._jumpToStateFor
if state != 'destroyed' or explanation_delivery_line.getSimulationState() != 'delivered': if slap_document.getSlapState() != required_state:
slap_document.setAggregateValue(explanation_delivery_line.getAggregateValue(portal_type='Computer Partition')) _jumpToStateFor(slap_document, required_state, 'instance_slap_interface_workflow')
assert(slap_document.getAggregate() == explanation_delivery_line.getAggregate(portal_type='Computer Partition')) if not(slap_document.getSlapState() == required_state):
state_map = { raise ValueError('%s: %s != %s' % (state, slap_document.getSlapState(), required_state))
'started': 'start_requested',
'stopped': 'stop_requested', # Migrate validation state
'destroyed': 'destroy_requested' if portal_type == 'Hosting Subscription':
} if state == 'destroyed':
required_state = state_map[state] _jumpToStateFor(slap_document, 'archived', 'hosting_subscription_workflow')
_jumpToStateFor = portal.portal_workflow._jumpToStateFor assert(slap_document.getValidationState() == 'archived')
if slap_document.getSlapState() != required_state: else:
_jumpToStateFor(slap_document, required_state, 'instance_slap_interface_workflow') _jumpToStateFor(slap_document, 'validated', 'hosting_subscription_workflow')
if not(slap_document.getSlapState() == required_state): assert(slap_document.getValidationState() == 'validated')
raise ValueError('%s: %s != %s' % (state, slap_document.getSlapState(), required_state))
# Migrate validation state
if portal_type == 'Hosting Subscription':
if state == 'destroyed':
_jumpToStateFor(slap_document, 'archived', 'hosting_subscription_workflow')
assert(slap_document.getValidationState() == 'archived')
else:
_jumpToStateFor(slap_document, 'validated', 'hosting_subscription_workflow')
assert(slap_document.getValidationState() == 'validated')
else:
if state == 'destroyed' and \
(explanation_delivery_line.getPortalType() == 'Sale Order Line' or \
explanation_delivery_line.getSimulationState() == 'delivered'):
_jumpToStateFor(slap_document, 'invalidated', 'item_workflow')
else: else:
if not(slap_document.getValidationState() == 'validated'): if state == 'destroyed' and \
raise ValueError('%s != %s' % (slap_document.getValidationState(), 'validated')) (explanation_delivery_line.getPortalType() == 'Sale Order Line' or \
explanation_delivery_line.getSimulationState() == 'delivered'):
_jumpToStateFor(slap_document, 'invalidated', 'item_workflow')
else:
if not(slap_document.getValidationState() == 'validated'):
raise ValueError('%s != %s' % (slap_document.getValidationState(), 'validated'))
# Update Local Roles # Update Local Roles
slap_document.updateLocalRolesOnSecurityGroups() slap_document.updateLocalRolesOnSecurityGroups()
@WorkflowMethod.disable
def SalePackingListLine_deliver(self): def SalePackingListLine_deliver(self):
portal = self.getPortalObject() @WorkflowMethod.disable
assert(self.getResource() in [portal.portal_preferences.getPreferredInstanceSetupResource(), def real(self):
portal.portal_preferences.getPreferredInstanceUpdateResource()]) portal = self.getPortalObject()
if self.getSimulationState() != 'delivered': assert(self.getResource() in [portal.portal_preferences.getPreferredInstanceSetupResource(),
portal.portal_workflow._jumpToStateFor(self.getParentValue(), 'delivered') portal.portal_preferences.getPreferredInstanceUpdateResource()])
self.recursiveReindexObject() if self.getSimulationState() != 'delivered':
portal.portal_workflow._jumpToStateFor(self.getParentValue(), 'delivered')
self.recursiveReindexObject()
real(self)
def Computer_updateLocalRoles(self): def Computer_updateLocalRoles(self):
self.updateLocalRolesOnSecurityGroups(reindex=False) self.updateLocalRolesOnSecurityGroups(reindex=False)
......
113 114
\ No newline at end of file \ No newline at end of file
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