<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed Materials - Property of IBM Corp.
- IBM UrbanCode Release
- (c) Copyright IBM Corporation 2014, 2017. All Rights Reserved.
-
- U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by
- GSA ADP Schedule Contract with IBM Corp.
-->
<plugin xmlns="http://www.urbancode.com/PluginXMLSchema_v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <header>
    <!-- Plugin version has to be incremented if a change has been made to the UI definition-->
    <!-- Plugin version can stay the same if only groovy scripts have changed. If only Groovy scripts have been modified keeping the same plugin version
    and re-uploading the plugin.zip will override the groovy files previously imported-->
    <identifier id="com.urbancode.plugin.jira" name="JIRA Plug-in" version="8"/>
    <plugin-type>Connector</plugin-type>
    <!-- The description will be the name displayed in the Integration Provider types dropdown-->
    <description>JIRA Integration</description>
    <!-- Only change plugin type is available for now-->
    <tag>Change</tag>
  </header>

  <step-type name="Integration" displayed="true">
    <description>Integration</description>
     <properties>

        <!-- PARAGRAPH -->
        <property name="jiraPluginIntro" >
            <property-ui type="paragraph" label="Configuring an integration provider for JIRA"  description="The JIRA plug-in can import various JIRA objects. Select JIRA Application, Release, Type, and Status mappings to define changes in IBM UrbanCode Release. Migration from the built-in plug-in is not supported." />
        </property>

        <!-- TEXTBOX -->
        <property name="jiraUrl" required="true" >
            <property-ui type="textBox" label="JIRA Base URL"  description="The JIRA server URL" />
        </property>

         <!-- TEXTBOX -->
         <property name="jiraUser" required="true" >
             <property-ui type="textBox" label="JIRA Username"  description="The username to use to connect to JIRA" />
         </property>

         <!-- TEXTBOX -->
         <property name="jiraPassword" required="true" >
             <property-ui type="secureBox" label="JIRA Password"  description="The password to use to connect to JIRA" />
         </property>

         <!-- TEXTBOX -->
         <property name="proxyHost">
             <property-ui type="textBox"
                         label="HTTP Proxy Host"
                         description="Provide the hostname of the HTTP proxy to use to connect to JIRA. Eg proxy.domain.com"/>
         </property>

         <!-- TEXTBOX -->
         <property name="proxyPort">
             <property-ui type="textBox"
                         label="HTTP Proxy Port"
                         description="Provide the port number of the HTTP proxy to use to connect to JIRA."/>
         </property>

         <!-- TEXTBOX -->
         <property name="proxyUser">
             <property-ui type="textBox"
                         label="HTTP Proxy Username"
                         description="Provide the username to authenticate with HTTP proxy."/>
         </property>

         <!-- TEXTBOX -->
         <property name="proxyPass">
             <property-ui type="secureBox"
                         label="HTTP Proxy Password"
                         description="Provide the password to authenticate with HTTP proxy."/>
         </property>

        <!-- BUTTON -->
        <property name="pingServerButton">
              <property-ui description="Click to check the connection to the JIRA server."  label="Ping the JIRA Server" type="button"/>
              <scripted-prop-info source="PingServerButton"  dataSourceType="COMMAND" />
         </property>

         <!-- CHECKBOX -->
         <property depends="jiraUrl,jiraUser,jiraPassword" name="fullIntegration">
              <property-ui type="checkBox" label="Full Integration"  description="Select to run the complete integration regardless of the time last run." />
         </property>

        <!-- PARAGRAPH -->
        <property name="customApplicationIntro"  depends="jiraUrl,jiraUser,jiraPassword">
            <property-ui type="paragraph" label="Application Mapping"
                description="Specify any Text or Single Select field to automatically map to an UrbanCode
                    Release application using the custom auto map dropdown.
                    (The `Component/s` field is the only exception to the Text or Single Select field rule.)
                    JIRA custom values must take the form `[ID:]Name`.
                    Use the manual Application Mapping boxes to have maximum control over
                    the desired Application and Project/Component pairs. If an issue has more than one matching component,
                    a change for each component will be created.
                    Most commonly, JIRA plug-in users will utilize the `Project` or `Component/s` field.
                    If an Auto Map field is specified, the manually mapped values will be ignored." />
        </property>

        <!-- scriptedSelectBox -->
        <property depends="jiraUrl,jiraUser,jiraPassword" name="selectedApplication" >
           <property-ui description="Select the standard or custom JIRA field to map to Applications in UrbanCode Release.
               It is suggested that the `Project` or `Component/s` field is specified."
               label="Auto Map Applications" type="scriptedSelectBox"/>
           <scripted-prop-info source="JiraFields" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
        </property>

        <!-- CHECKBOX -->
        <!-- <property depends="jiraUrl,jiraUser,jiraPassword" name="autoMapApplications">
             <property-ui type="checkBox" label="Auto Map Applications"  description="Select to map only Release Applications and JIRA Projects and Components with the same name. The Application mapping fields are ignored." />
        </property> -->

         <!-- MAPPINGBOX => SCRIPTEDCHECKEDMULTISELECTBOX - HTTPCHECKEDMULTISELECTBOX -->
         <property-group depends="jiraUrl,jiraUser,jiraPassword" name="mappingApplications" title="Application Manual Mapping"
             description="Map UrbanCode Release Applications to JIRA Projects and Components.
                Identified JIRA Components will take the form of 'PROJECT: COMPONENT' to distinguish
                from JIRA Projects and Components with the same name. If an issue with multiple components
                is found, a change will be created for each component."
             type="mappingBox" >
             <property parent="mappingApplications" name="jiraProjects">
                 <property-ui description="Projects in JIRA"  label="JIRA Projects and Components" type="scriptedCheckedMultiSelectBox"/>
                 <scripted-prop-info source="JiraProjects" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
             </property>
             <property parent="mappingApplications" name="applications">
                 <property-ui description="UrbanCode Release Applications"  label="Applications" type="httpCheckedMultiSelectBox"/>
                 <http-prop-info username="${releaseUser}" password="${releasePassword}" url="${releaseUrl}/applications?format=list" labelPath="name" valuePath="id" basePath="" dataFormat="JSON" />
             </property>
         </property-group>

         <!-- PARAGRAPH -->
         <property name="customReleaseIntro"  depends="jiraUrl,jiraUser,jiraPassword">
            <property-ui type="paragraph" label="Release Auto Mapping"
                description="Specify any Text or Single Select JIRA field to automatically map to a
                release in UrbanCode Release using the Release Auto Map dropdown.
                (The `Fix Version/s` field is the only exception to the Text or Single Select field rule.)
                JIRA values must be a single string of name and ID separated by an underscore or colon.
                The auto mapping first uses the ID to determine whether a matching Release ID exists,
                and otherwise uses the name. Only JIRA issues with a corresponding release will be imported.
                Most commonly, JIRA plug-in users will utilize the `Fix Version/s` field." />
         </property>

         <!-- scriptedSelectBox -->
         <property depends="jiraUrl,jiraUser,jiraPassword" name="selectedRelease" >
           <property-ui description="Select the JIRA field to map to Releases in UrbanCode Release." label="Auto Map Releases" type="scriptedSelectBox"/>
           <scripted-prop-info source="JiraFields" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
         </property>

          <!-- CHECKBOX -->
          <!-- <property depends="jiraUrl,jiraUser,jiraPassword" name="createReleases">
               <property-ui type="checkBox" label="Create New Releases"  description="Check this box to create Releases in UrbanCode Release if they do not exist." />
          </property> -->

         <!-- MAPPINGBOX => SCRIPTEDCHECKEDMULTISELECTBOX - HTTPCHECKEDMULTISELECTBOX -->
         <property-group depends="jiraUrl,jiraUser,jiraPassword" name="mappingStatuses" title="Status  Manual Mapping" description="Map UrbanCode Release statuses to JIRA statuses." type="mappingBox" >
             <property parent="mappingStatuses" name="jiraStatuses">
                 <property-ui description="Statuses in JIRA"  label="JIRA Statuses" type="scriptedCheckedMultiSelectBox"/>
                 <scripted-prop-info source="JiraStatuses" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
             </property>
             <property parent="mappingStatuses" name="ucrStatuses">
                 <property-ui description="Statuses in UrbanCode Release"  label="Statuses" type="httpCheckedMultiSelectBox"/>
                 <http-prop-info username="${releaseUser}" password="${releasePassword}" url="${releaseUrl}/integrationProvider/ureleaseStatuses" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" />
             </property>
         </property-group>

         <!-- MAPPINGBOX => HTTPCHECKEDMULTISELECTBOX - HTTPCHECKEDMULTISELECTBOX -->
         <property-group depends="jiraUrl,jiraUser,jiraPassword" name="mappingTypes" title="Type Manual Mapping" description="Map JIRA Types to UrbanCode Release Types" type="mappingBox" >
             <property parent="mappingTypes" name="jiraTypes">
                 <property-ui description="Types in JIRA"  label="JIRA Types" type="scriptedCheckedMultiSelectBox"/>
                 <scripted-prop-info source="JiraTypes" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
             </property>
             <property parent="mappingTypes" name="ucrTypes">
                 <property-ui description="Types in UrbanCode Release"  label=" Types" type="httpCheckedMultiSelectBox"/>
                 <http-prop-info username="${releaseUser}" password="${releasePassword}" url="${releaseUrl}/changeTypes" labelPath="name" valuePath="id" basePath="" dataFormat="JSON" />
             </property>
         </property-group>

         <!-- MAPPINGBOX => HTTPCHECKEDMULTISELECTBOX - HTTPCHECKEDMULTISELECTBOX -->
         <property-group depends="jiraUrl,jiraUser,jiraPassword" name="mappingSeverities" title="Severity Manual Mapping" description="Map JIRA Priorities to UrbanCode Release Severities." type="mappingBox" >
             <property parent="mappingSeverities" name="jiraPriorities">
                 <property-ui description="Priorities in JIRA"  label="JIRA Priorities" type="scriptedCheckedMultiSelectBox"/>
                 <scripted-prop-info source="JiraPriorities" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
             </property>
            <property parent="mappingSeverities" name="ucrSeverities">
                <property-ui description="Severities in UrbanCode Release"  label="Severities" type="checkedMultiSelectBox" default-value="None"/>
                    <value label="None">NONE</value>
                    <value label="S1">S1</value>
                    <value label="S2">S2</value>
                    <value label="OTHER">OTHER</value>
            </property>
         </property-group>

        <!-- PARAGRAPH -->
        <property name="customInitiativeIntro"  depends="jiraUrl,jiraUser,jiraPassword">
            <property-ui type="paragraph" label="Initiative Auto Mapping"  description="Specify any Text or Single Select field to automatically map to an initiative in UrbanCode Release using the custom auto map dropdown. JIRA values must be a single string of name and ID separated by an underscore or colon. The custom mapping first uses the ID to determine whether a matching Initiative ID exists, and otherwise uses the name. If the initiative does not exist, the Initiative field for the change in UrbanCode Release is left blank." />
        </property>

        <!-- scriptedSelectBox -->
        <property depends="jiraUrl,jiraUser,jiraPassword" name="selectedInitiative" >
           <property-ui description="Select the JIRA field to map to Initiatives in UrbanCode Release." label="Custom Auto Map Initiatives" type="scriptedSelectBox"/>
           <scripted-prop-info source="JiraFields" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
        </property>

         <!-- CHECKBOX -->
         <property depends="jiraUrl,jiraUser,jiraPassword" name="createInitiatives">
              <property-ui type="checkBox" label="Create New Initiatives"  description="Check this box to create Initiatives in UrbanCode Release if they do not exist." />
         </property>

        <!-- BUTTON -->
        <property name="resetButton" depends="jiraUrl,jiraUser,jiraPassword">
            <property-ui description="Click to delete all items that were retrieved from the integration."  label="Remove all imported issues" type="button"/>
            <scripted-prop-info source="ResetButton"  dataSourceType="COMMAND" />
        </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
     </post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/log4j.jar:lib/securedata.jar"/>
      <arg file="Integration.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>

  <!-- The check connection step will be executed when the user is clicking on the "check connection" button on the Integration Provider page-->
  <step-type name="PingServerButton">
    <description>Ping the JIRA Server</description>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
     </post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/jettison-1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/securedata.jar"/>
      <arg file="PingServerButton.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>

    <!-- This step is using a groovy script to build a drop down list of values for the UI-->
    <step-type name="JiraProjects">
        <description>Project Select</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/httpclient.jar:lib/HttpComponents-Util.jar:lib/httpcore.jar:lib/log4j.jar:lib/securedata.jar"/>
            <arg file="JiraProjects.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

    <!-- This step is using a groovy script to build a drop down list of values for the UI-->
    <!-- Maintained if manual mapping of Planned For and Releases and add back -->
    <!--
    <step-type name="JiraReleases">
        <description>Release Select</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/httpclient.jar:lib/HttpComponents-Util.jar:lib/httpcore.jar:lib/log4j.jar:lib/securedata.jar"/>
            <arg file="JiraReleases.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>
    -->
    <!-- This step is using a groovy script to build a drop down list of statuses values for the UI-->
    <step-type name="JiraStatuses">
        <description>Status Select</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/securedata.jar"/>
            <arg file="JiraStatuses.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

    <!-- This step is using a groovy script to build a drop down list of statuses values for the UI-->
    <step-type name="JiraTypes">
        <description>Type Select</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/securedata.jar"/>
            <arg file="JiraTypes.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

    <!-- This step is using a groovy script to build a drop down list of statuses values for the UI-->
    <step-type name="JiraPriorities">
        <description>Priorities Select</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/securedata.jar"/>
            <arg file="JiraPriorities.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

    <!-- This step is using a groovy script to build a drop down list of JIRA field values for the UI-->
    <step-type name="JiraFields">
        <description>Allowed Custom Fields Select. Default, Textbox, and Single Select.</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/icu4j-53_1.jar:lib/jsr311-api-1.1.1.jar:lib/translate-util.jar:lib/WebExt-Common.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/securedata.jar"/>
            <arg file="JiraFields.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

    <!-- This step is called from a button and will remove all Changes imported for that integration and return the Output to the UI-->
    <step-type name="ResetButton">
        <description>ResetButton</description>
        <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]>
        </post-processing>
        <command program="${GROOVY_HOME}/bin/groovy">
            <arg value="-cp"/>
            <arg path="classes:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/ucr-plugin-util.jar:lib/commons-lang3.jar:lib/commons-lang.jar:lib/jettison-1.1.jar:lib/securedata.jar"/>
            <arg file="ResetButton.groovy"/>
            <arg file="${PLUGIN_INPUT_PROPS}"/>
            <arg file="${PLUGIN_OUTPUT_PROPS}"/>
        </command>
    </step-type>

</plugin>
