<?xml version="1.0" encoding="utf-8"?><%
configuratorCreatorRepository = 'com.axelor.apps.sale.db.repo.ConfiguratorCreatorRepository'
def cc = { com.axelor.inject.Beans.get(configuratorCreatorRepository as Class).find(it) }

def attributeMethod = {
    attribute = ""
        cc(it).attributes?.each( { att ->
                attribute += """
                <attribute>
                <name>${att.name}</name>
                <title>"""
                if (att.title != null) {
                attribute += "${att.title}"
                }
                attribute += """</title>
                <type>${att.type}</type>
                <defaultValue>"""
                if (att.defaultValue != null) {
                attribute += "${att.defaultValue}"
                }
                attribute += """</defaultValue>
                <model>${att.model}</model>
                <modelField>${att.modelField}</modelField>
                <jsonModelCode>"""
                if (att.jsonModel?.code != null) {
                attribute += "${att.jsonModel?.code}"
                }
                attribute += """</jsonModelCode>
                    <selection>"""
                    if (att.selection != null) {
                        attribute += "${att.selection}"
                    }
                attribute += """</selection>
                    <widget>"""
                    if (att.widget != null) {
                        attribute += "${att.widget}"
                    }
                attribute += """</widget>
                    <help>"""
                    if (att.help != null) {
                        attribute += "${att.help}"
                    }
                attribute += """</help>
                    <showIf>"""
                    if (att.showIf != null) {
                        attribute += "${att.showIf}"
                    }
                attribute += """</showIf>
                    <hideIf>"""
                    if (att.hideIf != null) {
                        attribute += "${att.hideIf}"
                    }
                attribute += """</hideIf>
                    <requiredIf>"""
                    if (att.requiredIf != null) {
                        attribute += "${att.requiredIf}"
                    }
                attribute += """</requiredIf>
                    <hidden>${att.hidden}</hidden>
                    <required>${att.required}</required>
                    <nameField>${att.nameField}</nameField>
                    <minSize>${att.minSize}</minSize>
                    <maxSize>${att.maxSize}</maxSize>
                    <precision>${att.precision}</precision>
                    <scale>${att.scale}</scale>
                    <regex>"""
                    if (att.regex != null) {
                        attribute += "${att.regex}"
                    }
                attribute += """</regex>
                    <targetModel>"""
                    if (att.targetModel != null) {
                        attribute += "${att.targetModel}"
                    }
                attribute += """</targetModel>
                    <enumType>"""
                    if (att.enumType != null) {
                        attribute += "${att.enumType}"
                    }
                attribute += """</enumType>
                    <formView>"""
                    if (att.formView != null) {
                        attribute += "${att.formView}"
                    }
                attribute += """</formView>
                    <gridView>"""
                    if (att.gridView != null) {
                        attribute += "${att.gridView}"
                    }
                attribute += """</gridView>
                    <domain>"""
                    if (att.domain) {
                        attribute += "${att.domain}"
                    }
                attribute += """</domain>
                    <targetJsonModelCode>"""
                    if (att.targetJsonModel?.code != null) {
                        attribute += "${att.targetJsonModel?.code}"
                    }
                attribute += """</targetJsonModelCode>
                    <sequence>${att.sequence}</sequence>
                    <onChange>"""
                    if (att.onChange != null) {
                        attribute += "${att.onChange}"
                    }
                attribute += """</onChange>
                    <onClick>"""
                    if (att.onClick != null) {
                        attribute += "${att.onClick}"
                    }
                attribute += """</onClick>
                    <widgetAttrs>"""
                    if (att.widgetAttrs != null) {
                        attribute += "${att.widgetAttrs}"
                    }
                attribute += """</widgetAttrs>
                    <contextField>"""
                    if (att.contextField != null) {
                        attribute += "${att.contextField}"
                    }
                attribute += """</contextField>
                    <contextFieldTarget>"""
                    if (att.contextFieldTarget != null) {
                        attribute += "${att.contextFieldTarget}"
                    }
                attribute += """</contextFieldTarget>
                    <contextFieldTargetName>"""
                    if (att.contextFieldTargetName != null) {
                        attribute += "${att.contextFieldTargetName}"
                    }
                attribute += """</contextFieldTargetName>
                    <contextFieldValue>"""
                    if (att.contextFieldValue != null) {
                        attribute += "${att.contextFieldValue}"
                    }
                attribute += """</contextFieldValue>
                    </attribute>
                    """
        })
    return attribute
}

def configuratorProductFormulaMethod = {
    configuratorProductFormula = ""
        cc(it).configuratorProductFormulaList?.each( { cf ->
                configuratorProductFormula += """
                <configuratorProductFormula>
                """
                if (cf.metaField?.id != null) {
                configuratorProductFormula += "<metaField>${cf.metaField?.name}</metaField>"
                }
                configuratorProductFormula += 	"""
                <formula>"""
                if (cf.formula != null) {
                configuratorProductFormula += "${cf.formula}"
                }
                configuratorProductFormula += """</formula>
                <showOnConfigurator>${cf.showOnConfigurator}</showOnConfigurator>
                <configuratorCreatorImportId>${cf.productCreator?.id}</configuratorCreatorImportId>
                </configuratorProductFormula>
                """
                })
    return configuratorProductFormula
}

def configuratorSOLineFormulaMethod = {
    configuratorSOLineFormula = ""
        cc(it).configuratorSOLineFormulaList?.each( { cf ->
                configuratorSOLineFormula += """
                <configuratorSOLineFormula>
                """
                if (cf.metaField?.id != null) {
                configuratorSOLineFormula += "<metaField>${ cf.metaField?.name}</metaField>"
                }
                configuratorSOLineFormula += 	"""
                <formula>"""
                if (cf.formula != null) {
                configuratorSOLineFormula += "${cf.formula}"
                }
                configuratorSOLineFormula += """</formula>
                <showOnConfigurator>${cf.showOnConfigurator}</showOnConfigurator>
                <updateFromSelect>${cf.updateFromSelect}</updateFromSelect>
                <configuratorCreatorImportId>${cf.soLineCreator?.id}</configuratorCreatorImportId>
                </configuratorSOLineFormula>
                """
                })
    return configuratorSOLineFormula
}

def authorizedUserMethod = {
    authorizedUser = ""
        cc(it).authorizedUserSet?.each( { au ->
                authorizedUser += """
                <authorizedUser>${au.code}</authorizedUser>"""
                })
    return authorizedUser
}

def authorizedGroupMethod = {
    authorizedGroup = ""
        cc(it).authorizedGroupSet?.each( { ag ->
                authorizedGroup += """
                <authorizedGroup>${ag.code}</authorizedGroup>"""
                })
    return authorizedGroup
}
%>

<configurator-export>

<configurator-creators><% __ids__.each( { it -> %>

        <configurator-creator>
        <importId><% out << cc(it).id %></importId>
        <name><% out << cc(it).name %></name>
        <attributes><% out << attributeMethod(it) %></attributes>

        <configuratorProductFormulaList><% out << configuratorProductFormulaMethod(it) %></configuratorProductFormulaList>

        <configuratorSOLineFormulaList><% out << configuratorSOLineFormulaMethod(it) %></configuratorSOLineFormulaList>

        <authorizedUserSet><% out << authorizedUserMethod(it) %>
        </authorizedUserSet>

        <authorizedGroupSet><% out << authorizedGroupMethod(it) %>
        </authorizedGroupSet>

        <generateProduct><% out << cc(it).generateProduct %></generateProduct>
        <isActive><% out << cc(it).isActive %></isActive>

        </configurator-creator><% })%>

</configurator-creators>

</configurator-export>
