<?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>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

person = state_change[\'object\']\n
portal = person.getPortalObject()\n
# Get required arguments\n
kwargs = state_change.kwargs\n
software_release_url_string = state_change.kwargs[\'software_release\']\n
software_title = kwargs["software_title"]\n
software_type = kwargs.get("software_type") or "RootSoftwareInstance"\n
instance_xml = kwargs["instance_xml"]\n
sla_xml = kwargs.get("sla_xml") or ""\n
is_slave = kwargs.get("shared", False)\n
state = kwargs.get(\'state\') or \'started\'\n
\n
hosting_subscription_portal_type = "Hosting Subscription"\n
\n
if is_slave == True:\n
  software_instance_portal_type = "Slave Instance"\n
else:\n
  software_instance_portal_type = "Software Instance"\n
\n
tag = "%s_%s_inProgress" % (person.getUid(), \n
                               software_title)\n
\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
  # The software instance is already under creation but can not be fetched from catalog\n
  # As it is not possible to fetch informations, it is better to raise an error\n
  raise NotImplementedError(tag)\n
\n
# Check if it already exists\n
cleanup_resource = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
request_hosting_subscription = None\n
for hs in portal.portal_catalog(\n
  portal_type=hosting_subscription_portal_type,\n
  title=software_title,\n
  ):\n
  si = hs.portal_catalog.getResultValue(title=software_title,\n
                                        root_uid=hs.getUid())\n
  try:\n
    cleanup_delivery_line = si.Item_getInstancePackingListLine(cleanup_resource)\n
  except ValueError:\n
    order_line = si.getAggregateRelatedValue(portal_type=\'Sale Order Line\')\n
    if order_line.getSimulationState() != \'cancelled\':\n
      request_hosting_subscription = hs\n
      break\n
  else:\n
    if cleanup_delivery_line.getSimulationState() != \'delivered\':\n
      request_hosting_subscription = hs\n
      break\n
\n
if (request_hosting_subscription is None):\n
  hosting_subscription_reference = "HOSTSUBS-%s" % context.getPortalObject().portal_ids\\\n
      .generateNewId(id_group=\'slap_hosting_subscription_reference\', id_generator=\'uid\')\n
  request_hosting_subscription = portal.getDefaultModule(portal_type=hosting_subscription_portal_type).newContent(\n
    portal_type=hosting_subscription_portal_type,\n
    reference=hosting_subscription_reference,\n
    title=software_title,\n
    source_reference=software_type,\n
    text_content=instance_xml,\n
    sla_xml=sla_xml,\n
    root_software_release_url=software_release_url_string,\n
    root_slave=is_slave,\n
    root_state=state,\n
    activate_kw={\'tag\': tag},\n
  )\n
  request_hosting_subscription.portal_workflow.doActionFor(request_hosting_subscription,\n
                                           \'validate_action\')\n
else:\n
  request_hosting_subscription.edit(\n
    text_content=instance_xml,\n
    source_reference=software_type,\n
    sla_xml=sla_xml,\n
    root_software_release_url=software_release_url_string,\n
    root_slave=is_slave,\n
    root_state=state,\n
    activate_kw={\'tag\': tag},\n
  )\n
\n
context.REQUEST.set(\'request_hosting_subscription\', request_hosting_subscription)\n
request_hosting_subscription.HostingSubscription_requestRootSoftwareInstance(tag, person=person)\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Person_requestSoftwareInstance</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
