<service-logic
    xmlns='http://www.onap.org/sdnc/svclogic'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='GENERIC-RESOURCE-API' version='${project.version}'>
    <method rpc='network-topology-operation-assign' mode='sync'>
        <block atomic="true">
            <execute plugin='org.onap.ccsdk.sli.plugins.prop.PropertiesNode' method='readProperties' >
                <parameter name='fileName' value='%SDNC_CONFIG_DIR%/generic-resource-api-dg.properties' />
                <parameter name='contextPrefix' value='prop' />
            </execute>
            <get-resource plugin="org.onap.ccsdk.sli.adaptors.aai.AAIService" 
		resource="tenant" 
		key="cloud-region.cloud-owner = $prop.cloud-region.cloud-owner AND 
		     cloud-region.cloud-region-id = $network-topology-operation-input.network-request-input.aic-cloud-region AND
		     tenant.tenant-id = $network-topology-operation-input.network-request-input.tenant"
        pfx='aai.tenant' local-only='false' >
                <outcome value='success'>
                    <block atomic="true"></block>
                </outcome>
                <outcome value='not-found'>
                    <return status='failure'>
                        <parameter name='ack-final' value='Y'/>
                        <parameter name="error-code" value="500" />
                        <parameter name="error-message" value="Tenant not found in AAI" />
                    </return>
                </outcome>
                <outcome value='Other'>
                    <return status='failure'>
                        <parameter name='ack-final' value='Y'/>
                        <parameter name="error-code" value="500" />
                        <parameter name="error-message" value="Tenant not found in AAI" />
                    </return>
                </outcome>
            </get-resource>
            <switch test='`$network-topology-operation-input.network-information.network-id`'>
                <outcome value=''>
                    <call module='GENERIC-RESOURCE-API' rpc='generate-l3network-network-id' mode='sync' ></call>
                </outcome>
                <outcome value='Other'>
                    <set>
                        <parameter name='tmp.return.generate-l3network-network-id.uuid' value='`$network-topology-operation-input.network-information.network-id`' />
                    </set>
                </outcome>
            </switch>
            <set>
                <parameter name='tmp.l3-network.network-id' value='`$tmp.return.generate-l3network-network-id.uuid`' />
                <parameter name='network-topology-operation-input.network-information.network-id' value='`$tmp.return.generate-l3network-network-id.uuid`' />
            </set>
            <switch test='`$network-topology-operation-input.network-information.network-instance-group-id`'>
                <outcome value=''>
                    <switch test='`$network-topology-operation-input.network-request-input.network-name`'>
                        <outcome value=''>
                            <block atomic="true">
                                <switch test='`$network-model.ecomp-generated-naming`'>
                                    <outcome value='Y'>
                                        <block atomic="true">
                                            <set>
                                                <parameter name='naming-policy-generate-name-input.policy-instance-name' value='`$network-model.naming-policy`' />
                                                <parameter name='naming-policy-generate-name-input.context-id' value='`$tmp.l3-network.network-id`' />
                                                <parameter name='naming-policy-generate-name-input.naming-type' value='NETWORK' />
                                                <parameter name='naming-policy-generate-name-input.action' value='ASSIGN' />
                                                <parameter name='naming-policy-generate-name-input.query-parameter' value='`$network-model.customization-uuid`' />
                                            </set>
                                            <call module='GENERIC-RESOURCE-API' rpc='naming-policy-generate-name' mode='sync' ></call>
                                            <set>
                                                <parameter name='tmp.network-instance-name' value='`$naming-policy-generate-name-output.network-name`' />
                                                <parameter name='tmp.l3-network.network-name' value='`$naming-policy-generate-name-output.network-name`' />
                                            </set>
                                            <call module='GENERIC-RESOURCE-API' rpc='network-topology-operation-assign-automated' mode='sync' ></call>
                                        </block>
                                    </outcome>
                                    <outcome value='Other'>
                                        <return status='failure'>
                                            <parameter name='ack-final' value='Y'/>
                                            <parameter name="error-code" value="500" />
                                            <parameter name="error-message" value="Network name is required if onap naming is false" />
                                        </return>
                                    </outcome>
                                </switch>
                            </block>
                        </outcome>
                        <outcome value='Other'>
                            <block atomic="true">
                                <set>
                                    <parameter name='tmp.network-instance-name' value="`$network-topology-operation-input.network-request-input.network-name`" />
                                    <parameter name='tmp.l3-network.network-name' value="`$network-topology-operation-input.network-request-input.network-name`" />
                                </set>
                                <call module='GENERIC-RESOURCE-API' rpc='network-topology-operation-assign-from-preload' mode='sync' ></call>
                            </block>
                        </outcome>
                    </switch>
                </outcome>
                <outcome value='Other'>
                    <call module='GENERIC-RESOURCE-API' rpc='network-topology-operation-assign-vlantagging-instancegroup' mode='sync' ></call>
                </outcome>
            </switch>
            <return status='success'>
                <parameter name="ack-final-indicator" value="Y" />
                <parameter name="error-code" value="200" />
                <parameter name="error-message" value="`$error-message`" />
            </return>
        </block>
    </method>
</service-logic>