<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    
    http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
    
    <simple-method method-name="createSprint" short-description="Create Sprint">
        <!-- Permission Check -->
        <call-simple-method method-name="getWebSiteId"/>
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_SPRINT" action="_CREATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <entity-one entity-name="UserLogin" value-field="sysUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <!-- Error Filtering -->
                 <if-compare operator="less-equals" value="0" field="parameters.maxNum">
                    <add-error error-list-name="_error_message_list_">
                         <fail-message message="There is no product backlogs in the system. Please create the product backlogs before perform this action."/>
                     </add-error>
                 </if-compare>
                 <if-compare-field field="parameters.sprintBacklogs" operator="greater" to-field="parameters.maxNum" type="Integer">
                     <add-error error-list-name="_error_message_list_">
                         <fail-message message="Number of sprint backlogs are too much. Please enter the number equal or less than ${parameters.maxNum}."/>
                     </add-error>
                 </if-compare-field>
                 <if-compare operator="less-equals" value="0" field="parameters.sprintBacklogs" type="Integer">
                     <add-error error-list-name="_error_message_list_">
                         <fail-message message="Number of sprint backlogs must greater than 0 (zero)"/>
                     </add-error>
                 </if-compare>
                 <if-empty field="parameters.sprintEstimatedStart">
                    <add-error error-list-name="_error_message_list_">
                         <fail-message message="Start Date is missing"/>
                     </add-error>
                 </if-empty>
                 
                 <if-not-empty field="_error_message_list_">
                     <return response-code="error"/>
                 </if-not-empty>
                 <!-- calculate estimatedMilliSeconds -->
                 <set field="sprintDuration" from-field="parameters.sprintDuration" type="Integer"/>
                 <set field="actualStartDate" from-field="parameters.sprintEstimatedStart" type="Date"/>
                 <set field="actualCompletionDate"/>
                 <set field="groovy"  value="${groovy: import groovy.time.*;
                 context.actualCompletionDate = (context.actualStartDate-1) + (context.sprintDuration*7);
                  }"/>
                 <set field="actualStartDateT" from-field="actualStartDate" type="Timestamp"/>
                 <set field="actualCompletionDateT" from-field="actualCompletionDate" type="Timestamp"/>
                 <set field="input.estimatedMilliSeconds" type="Long" value="${groovy: import groovy.time.*;
                 def estimatedMilliSeconds = context.sprintDuration*5*8*60*60*1000;
                 return (estimatedMilliSeconds);
                 }"/>
                 
                 <set field="input.workEffortName" from-field="parameters.sprintName"/>
                 <set field="input.description" from-field="parameters.sprintDescription"/>
                 <set field="input.actualStartDate" from-field="actualStartDate"/>
                 <set field="input.actualCompletionDate" from-field="actualCompletionDate"/>
                 <set field="input.workEffortTypeId" value="SCRUM_SPRINT"/>
                 <set field="input.currentStatusId" value="SPRINT_ACTIVE"/>
                 <set field="input.workEffortParentId" from-field="parameters.projectId"/>
                 <set field="input.webSiteId" from-field="parameters.webSiteId"/>
                 <set field="input.userLogin" from-field="sysUserLogin"/>
                 <!-- Create Sprint -->
                 <call-service service-name="createWorkEffort" in-map-name="input">
                     <result-to-field result-name="workEffortId" field="parameters.sprintId"/>
                 </call-service>
                 <!-- Add sprint backlog to sprint -->
                 <call-simple-method method-name="createSprintBacklog"></call-simple-method>
                 
                 <!-- Add default backlog and task to sprint -->
                 <call-simple-method method-name="createBacklogMeeting"/>
                 
                 <entity-one entity-name="WorkEffort" value-field="workEffort">
                    <field-map field-name="workEffortId" from-field="parameters.projectId"/>
                 </entity-one>
            </then>
        <else>
         <set field="_error_message_" value="You are has no permission to perform this action."/>
         <return response-code="error"/>
        </else>
        </if>
    </simple-method>
    
    <simple-method method-name="createBacklogMeeting" short-description="Create Backlog for meeting to sprint">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_SPRINT" action="_CREATE"/>
                </or>
            </condition>
            <then>
                <entity-and entity-name="WorkEffortAndProduct" list="workEffortList">
                     <field-map field-name="workEffortId" from-field="parameters.projectId"/>
                </entity-and>
                <first-from-list list="workEffortList" entry="workEffortMap"/>
                <make-value entity-name="CustRequest" value-field="backlogMeeting"/>
                <sequenced-id sequence-name="CustRequest" field="custRequestId"/>
                <set field="backlogMeeting.custRequestId" from-field="custRequestId"/>
                <set field="backlogMeeting.custRequestTypeId" value="RF_SCRUM_MEETINGS"/>
                <set field="backlogMeeting.statusId" value="CRQ_REVIEWED"/>
                <set field="backlogMeeting.custRequestName" value="Scrum Meeting"/>
                <set field="backlogMeeting.description" value="Scrum Meeting"/>
                <set field="backlogMeeting.fromPartyId" from-field="userLogin.partyId"/>
                <create-value value-field="backlogMeeting"/>
                <set-service-fields service-name="createCustRequestItem" map="parameters" to-map="createItem"/>
                <set field="createItem.custRequestId" from-field="custRequestId"/>
                <set field="createItem.productId" from-field="workEffortMap.productId"/>
                <call-service service-name="createCustRequestItem" in-map-name="createItem"/>
                
                <!-- add default backlog to sprint -->
                <set field="createBL.custRequestId" from-field="custRequestId"/>
                <set field="createBL.workEffortId" from-field="parameters.sprintId"/>
                <set field="createBL.userLogin" from-field="userLogin"/>
                <call-service service-name="createWorkEffortRequest" in-map-name="createBL"/>
                
                <!-- add default task to backlog -->
                <set field="newDefaultTask.workEffortName" value="Scrum Planning"/>
                <set field="newDefaultTask.currentStatusId" value="STS_CREATED"/>
                <set field="newDefaultTask.workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                <set field="newDefaultTask.workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                <set field="newDefaultTask.workEffortParentId" from-field="parameters.sprintId"/>
                <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                    <result-to-field result-name="workEffortId"/>
                </call-service>
                <set field="parameters.custRequestId" from-field="custRequestId"/>
                <set field="parameters.workEffortId" from-field="workEffortId"/>
                <set-service-fields service-name="createWorkEffortRequest" map="parameters" to-map="createWorkEffortRequest"/>
                <call-service service-name="createWorkEffortRequest" in-map-name="createWorkEffortRequest">
                    <result-to-field result-name="workEffortId" field="workEffort"/>
                </call-service>
                
                <set field="newDefaultTask.workEffortName" value="Sprint Evaluation and Sprint Retrospective"/>
                <set field="newDefaultTask.currentStatusId" value="STS_CREATED"/>
                <set field="newDefaultTask.workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                <set field="newDefaultTask.workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                <set field="newDefaultTask.workEffortParentId" from-field="parameters.sprintId"/>
                <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                    <result-to-field result-name="workEffortId"/>
                </call-service>
                <set field="parameters.custRequestId" from-field="custRequestId"/>
                <set field="parameters.workEffortId" from-field="workEffortId"/>
                <set-service-fields service-name="createWorkEffortRequest" map="parameters" to-map="createWorkEffortRequest"/>
                <call-service service-name="createWorkEffortRequest" in-map-name="createWorkEffortRequest">
                    <result-to-field result-name="workEffortId" field="workEffortId"/>
                </call-service>
                
                <set field="newDefaultTask.workEffortName" value="Daily Scrum"/>
                <set field="newDefaultTask.currentStatusId" value="STS_CREATED"/>
                <set field="newDefaultTask.workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                <set field="newDefaultTask.workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                <set field="newDefaultTask.workEffortParentId" from-field="parameters.sprintId"/>
                <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                    <result-to-field result-name="workEffortId"/>
                </call-service>
                <set field="parameters.custRequestId" from-field="custRequestId"/>
                <set field="parameters.workEffortId" from-field="workEffortId"/>
                <set-service-fields service-name="createWorkEffortRequest" map="parameters" to-map="createWorkEffortRequest"/>
                <call-service service-name="createWorkEffortRequest" in-map-name="createWorkEffortRequest">
                    <result-to-field result-name="workEffortId" field="workEffortId"/>
                </call-service>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="updateSprintInfo" short-description="Update Sprint Infomation">
    <!-- Permission Check -->
    <call-simple-method method-name="getWebSiteId"/>
    <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_SPRINT" action="_UPDATE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </or>
        </condition>
        <then>
            <if>
                <condition>
                    <if-compare field="parameters.statusId" value="SPRINT_CLOSED" operator="equals"/>
                </condition>
                 <then>
                    <!-- close sprint and take out incomplete backlog(s) -->
                    <call-simple-method method-name="closeSprint"/>
                 </then>
            <else>
               <!-- Error Filltering -->
                <if-empty field="parameters.workEffortName">
                    <add-error error-list-name="_error_message_list_">
                        <fail-message message="Sprint Name is missing."/>
                    </add-error>
                </if-empty>
                <if-empty field="parameters.actualStartDate">
                    <add-error error-list-name="_error_message_list_">
                        <fail-message message="Start Date is missing."/>
                    </add-error>
                </if-empty>
                <if-not-empty field="_error_message_list_">
                    <return response-code="error"/>
                </if-not-empty>
                <!-- calculate estimatedMilliSeconds -->
                <set field="sprintDuration" from-field="parameters.sprintDuration" type="Integer"/>
                <set field="actualStartDate" from-field="parameters.actualStartDate" type="Date"/>
                <set field="actualCompletionDate"/>
                <set field="groovy"  value="${groovy: import groovy.time.*;
                context.actualCompletionDate = (context.actualStartDate-1) +(context.sprintDuration*7);}"/>
                
                <set field="actualStartDateT" from-field="actualStartDate" type="Timestamp"/>
                <set field="actualCompletionDateT" from-field="actualCompletionDate" type="Timestamp"/>
                <set field="parameters.estimatedMilliSeconds" type="Long" value="${groovy: import groovy.time.*;
                def estimatedMilliSeconds = context.sprintDuration*5*8*60*60*1000;
                return (estimatedMilliSeconds);}"/>
                
                <set field="parameters.actualStartDate" from-field="actualStartDateT"/>
                <set field="parameters.actualCompletionDate" from-field="actualCompletionDateT"/>
                <set field="parameters.currentStatusId" from-field="parameters.statusId"/>
                <set field="parameters.webSiteId" from-field="parameters.webSiteId"/>
                
                <call-service service-name="updateWorkEffort" in-map-name="parameters">
                </call-service>
            </else>
            </if>
        </then>
    <else>
        <set field="_error_message_" value="You are has no permission to perform this action."/>
        <return response-code="error"/>
    </else>
    </if>
    </simple-method>
    
    <simple-method method-name="deleteSprintBacklog" short-description="Delete relation of sprint and customer request">
    <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_SPRINT" action="_UPDATE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </or>
        </condition>
        <then>
        <call-simple-method method-name="getWebSiteId"/>
        <entity-condition entity-name="CustRequestAndWorkEffort" list="taskInSprintBacklogs">
            <condition-list combine="and">
                <condition-expr field-name="custRequestId" from-field="parameters.custRequestId"/>
                <condition-expr field-name="workEffortTypeId" value="SCRUM_SPRINT" operator="not-equals"/>
            </condition-list>
        </entity-condition>
        <!--  Grouping Sprint and Customer Request -->
        <set field="input.custRequestId" from-field="parameters.custRequestId"/>
        <set field="input.workEffortId" from-field="parameters.sprintId"/>
        <if-not-empty field="input.workEffortId">
            <call-service service-name="deleteWorkEffortRequest" in-map-name="input"/>
        </if-not-empty>
        <!-- Change CustRequest status back to Accepted an d reorder backlog Item-->
        <entity-one entity-name="WorkEffort" value-field="sprintMap">
            <field-map field-name="workEffortId" from-field="parameters.sprintId"/>
        </entity-one>
        <entity-and entity-name="WorkEffortAndProduct" list="projectList">
             <field-map field-name="workEffortId" from-field="sprintMap.workEffortParentId"/>
        </entity-and>
        <set field="productId" from-field="projectList[0].productId"/>
        <if-empty field="productId">
            <set field="productId" from-field="parameters.productId"/>
        </if-empty>
        <entity-one entity-name="CustRequest" value-field="custRequest"/>
        <if-compare field="custRequest.custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG">
            <entity-count count-field="getNum" entity-name="CustRequestAndCustRequestItem">
                <condition-list combine="and">
                    <condition-expr field-name="productId" from-field="productId"/>
                    <condition-expr field-name="custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG"/>
                    <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                </condition-list>
            </entity-count>
            <else>
                <entity-count count-field="getNum" entity-name="CustRequestAndCustRequestItem">
                    <condition-list combine="and">
                        <condition-expr field-name="productId" from-field="productId"/>
                        <condition-expr field-name="custRequestTypeId" operator="not-equals" value="RF_UNPLAN_BACKLOG"/>
                        <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                    </condition-list>
                </entity-count>
            </else>
        </if-compare>
        <set field="sequenceNumIn" value="1" type="Long"/>
        <set field="custRequestResultMap.custRequestId" from-field="parameters.custRequestId"/>
        <!-- the first sequence number -->
        <if-compare field="getNum" operator="equals" value="0">
            <set field="custRequestResultMap.custSequenceNum" from-field="sequenceNumIn"/>
            <else>
                <if-compare field="custRequest.custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG">
                    <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
                        <condition-list combine="and">
                            <condition-expr field-name="productId" from-field="productId"/>
                            <condition-expr field-name="custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG"/>
                            <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                        </condition-list>
                        <order-by field-name="custSequenceNum"/>
                    </entity-condition>
                    <else>
                        <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
                            <condition-list combine="and">
                                <condition-expr field-name="productId" from-field="productId"/>
                                <condition-expr field-name="custRequestTypeId" operator="not-equals" value="RF_UNPLAN_BACKLOG"/>
                                <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                            </condition-list>
                            <order-by field-name="custSequenceNum"/>
                        </entity-condition>
                    </else>
                </if-compare>
                <set field="sequenceNumkey" from-field="sequenceNumIn" type="Integer"/>
                <set field="productMap" from-field="custRequestList[sequenceNumkey-1]"/>
                <set field="externalSeq" from-field="productMap.custSequenceNum" type="Long"/>
                <!-- Insert new transaction to CustRequest -->
                <loop count="${getNum}" field="i">
                      <set field="internalSeq" from-field="custRequestList[i].custSequenceNum" type="Long" />
                     <set field="ready" value="${groovy:internalSeq&gt;=externalSeq}" type="Boolean"/>
                    <if-compare field="ready" operator="equals" value="true"  type="Boolean">
                        <set field="custRequestIdIn" from-field="custRequestList[i].custRequestId"/>
                        <entity-one entity-name="CustRequest" value-field="custRequestMap">
                            <field-map field-name="custRequestId" from-field="custRequestIdIn"/>
                        </entity-one>
                        <set field="custSequenceNum" from-field="custRequestMap.custSequenceNum"/>
                        <set field="nextSeqNum" value="${custSequenceNum+1}" type="Long"/>
                        <set field="custRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                        <store-value value-field="custRequestMap"/>
                    </if-compare>
                </loop>
                <set field="custRequestResultMap.custSequenceNum" from-field="externalSeq"/>
            </else>
        </if-compare>
        <!-- update Cust Request -->
        <set field="oldStatusId" from-field="custRequest.statusId"/><!-- use in confirmation email (current status is CRQ_REVIEWED) -->
        <set field="custRequestResultMap.webSiteId" from-field="parameters.webSiteId"/>
        <call-service service-name="updateCustRequest" in-map-name="custRequestResultMap"/>
        
        <set field="setCustRequestStatusCtx.custRequestId" from-field="parameters.custRequestId"/>
        <set field="setCustRequestStatusCtx.statusId" value="CRQ_ACCEPTED"/>
        <set field="setCustRequestStatusCtx.webSiteId" from-field="parameters.webSiteId"/>
        <call-service service-name="setCustRequestStatus" in-map-name="setCustRequestStatusCtx"/>
        
        <entity-condition entity-name="ProductBacklog" list="listTaskInBacklog">
            <condition-list combine="and">
                <condition-expr field-name="custRequestId" from-field="parameters.custRequestId"/>
                <condition-list combine="or">
                    <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                    <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_ERROR"/>
                    <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_INST"/>
                    <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_TEST"/>
                </condition-list>
            </condition-list>
        </entity-condition>
        <if-not-empty field="listTaskInBacklog">
            <loop count="${groovy: listTaskInBacklog.size()}" field="i">
                <set field="updateProject.workEffortId" from-field="listTaskInBacklog[i].workEffortId"/>
                <clear-field field="updateProject.workEffortParentId"/>
                <call-service service-name="updateWorkEffort" in-map-name="updateProject"/>
            </loop>
        </if-not-empty>
        <set field="_event_message_" value="The Sprint backlog has been deleted."/>
        </then>
    <else>
        <set field="_error_message_" value="You are has no permission to perform this action."/>
        <return response-code="error"/>
    </else>
    </if>
    </simple-method>
    
    <simple-method method-name="DeleteSprint" short-description="Delete Sprint">
    <!-- Permission Check -->
    <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_SPRINT" action="_DELETE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </or>
        </condition>
        <then>
            <set field="parameters.sprintId" from-field="parameters.workEffortId"/>
            <entity-and entity-name="CustRequestWorkEffort" list="custRequestWorkEfforts">
                <field-map field-name="workEffortId" from-field="parameters.sprintId"/>
            </entity-and>
             
             <if-not-empty field="custRequestWorkEfforts">
                <!-- Delete Bound Sprint and Customer Request -->
                <remove-list list="custRequestWorkEfforts"/>
             </if-not-empty>
             
            <!-- Delete Sprint -->
            <set field="delSprintInput.workEffortId" from-field="parameters.sprintId"/>
            <call-service service-name="deleteWorkEffort" in-map-name="delSprintInput">
            </call-service>
            
            <!-- Delete Sprint Member -->
            <entity-and entity-name="WorkEffortPartyAssignView" list="membersPartyId">
                <field-map field-name="workEffortId" from-field="parameters.sprintId"/>
            </entity-and>
            
            <if-not-empty field="membersPartyId">
                <iterate list="membersPartyId" entry="memberPartyId">
                    <call-service service-name="unassignPartyFromWorkEffort" in-map-name="memberPartyId"></call-service>
                </iterate>
            </if-not-empty>
        </then>
    <else>
        <set field="_error_message_" value="You are has no permission to perform this action."/>
        <return response-code="error"/>
    </else>
    </if>
    </simple-method>
    
    <simple-method method-name="createScrumProject" short-description="Create Scrum Project and Product Owner">
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PROJECT" action="_CREATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PROJECT_ROLE" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PROJECT" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PROJECT" action="_UPDATE"/>
                </or>
            </condition>
            <then>
                <now-timestamp field="now"/>
                <entity-one entity-name="UserLogin" value-field="sysUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <set-service-fields service-name="createWorkEffort" map="parameters" to-map="createProject"/>
                <set field="createProject.workEffortTypeId" value="SCRUM_PROJECT"/>
                <set field="createProject.currentStatusId" value="SPJ_ACTIVE"/>
                <set field="createProject.userLogin" from-field="sysUserLogin"/>
                <call-service service-name="createWorkEffort" in-map-name="createProject" >
                    <result-to-field result-name="workEffortId" field="workEffortId"/>
                </call-service>
                <field-to-request field="workEffortId" request-name="projectId"/>
                <log level="info" message="Creating new project, projectId=${workEffortId}"/>
                <!-- Create workeffort associate with product -->
                <make-value entity-name="WorkEffortGoodStandard" value-field="goodStandardMap"/>
                <set field="goodStandardMap.workEffortId" from-field="workEffortId"/>
                <set field="goodStandardMap.productId" from-field="parameters.productId"/>
                <set field="goodStandardMap.workEffortGoodStdTypeId" value="SCRUM_PRO_WORKEFF"/>
                <set field="goodStandardMap.fromDate" from-field="now"/>
                <set field="goodStandardMap.statusId" value="WEGS_CREATED"/>
                <create-value value-field="goodStandardMap"/>
                <!-- Create project billed options -->
                <if-not-empty field="parameters.billed">
                    <make-value entity-name="WorkEffortAttribute" value-field="workEffortAttMap"/>
                    <set field="workEffortAttMap.workEffortId" from-field="workEffortId"/>
                    <set field="workEffortAttMap.attrName" value="PROJECT_BILLED"/>
                    <set field="workEffortAttMap.attrValue" from-field="parameters.billed"/>
                    <create-value value-field="workEffortAttMap"/>
                </if-not-empty>
                
                <set-service-fields service-name="assignPartyToWorkEffort" map="parameters" to-map="assign"/>
                <set field="assign.workEffortId" from-field="workEffortId"/>
                <set field="assign.partyId" from-field="productRole[0].partyId"/>
                <set field="assign.roleTypeId" value="PRODUCT_OWNER"/>
                <set field="assign.statusId" value="PRTYASGN_ASSIGNED"/>
                <set field="assign.userLogin" from-field="sysUserLogin"/>
                <log level="info" message="Assign partyId ${assign.partyId} to projectId=${workEffortId}"/>
                <call-service service-name="assignPartyToWorkEffort" in-map-name="assign"/>
                
                <entity-and  entity-name="PartyRole" list="listPartyRoleScrumMaster">
                    <field-map field-name="partyId" from-field="userLogin.partyId"/>
                    <field-map field-name="roleTypeId" value="SCRUM_MASTER"/>
                </entity-and>
                <if-not-empty field="listPartyRoleScrumMaster">
                    <set-service-fields service-name="assignPartyToWorkEffort" map="parameters" to-map="assignScrumMaster"/>
                    <set field="assignScrumMaster.workEffortId" from-field="workEffortId"/>
                    <set field="assignScrumMaster.partyId" from-field="userLogin.partyId"/>
                    <set field="assignScrumMaster.roleTypeId" value="SCRUM_MASTER"/>
                    <set field="assignScrumMaster.statusId" value="PRTYASGN_ASSIGNED"/>
                    <set field="assignScrumMaster.userLogin" from-field="sysUserLogin"/>
                    <log level="info" message="Assign partyId ${assignScrumMaster.partyId} to projectId=${workEffortId}"/>
                    <call-service service-name="assignPartyToWorkEffort" in-map-name="assignScrumMaster"/>
                </if-not-empty>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <log level="error" message="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="updateScrumProject" short-description="Update Scrum Project and Product Owner">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PROJECT" action="_UPDATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PROJECT_ROLE" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <now-timestamp field="now"/>
                <set-service-fields service-name="updateWorkEffort" map="parameters" to-map="updateProject"/>
                <call-service service-name="updateWorkEffort" in-map-name="updateProject"/>
                <!-- remove old workeffort associate with product -->
                <entity-and entity-name="WorkEffortGoodStandard" list="workEffGSDList">
                    <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                    <field-map field-name="workEffortGoodStdTypeId" value="SCRUM_PRO_WORKEFF"/>
                </entity-and>
                <if-not-empty field="workEffGSDList">
                    <remove-list list="workEffGSDList"/>
                </if-not-empty>
                <!-- create old workeffort associate with product -->
                <make-value entity-name="WorkEffortGoodStandard" value-field="goodStandardMap"/>
                <set field="goodStandardMap.workEffortId" from-field="parameters.workEffortId"/>
                <set field="goodStandardMap.productId" from-field="parameters.productId"/>
                <set field="goodStandardMap.workEffortGoodStdTypeId" value="SCRUM_PRO_WORKEFF"/>
                <set field="goodStandardMap.fromDate" from-field="now"/>
                <set field="goodStandardMap.statusId" value="WEGS_CREATED"/>
                <create-value value-field="goodStandardMap"/>
                <!-- update project billed options -->
                <entity-one entity-name="WorkEffortAttribute" value-field="workEffortAttMap">
                    <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                    <field-map field-name="attrName" value="PROJECT_BILLED"/>
                </entity-one>
                <if-not-empty field="workEffortAttMap">
                    <set field="workEffortAttMap.attrValue" from-field="parameters.billed"/>
                    <store-value value-field="workEffortAttMap"/>
                    <else>
                        <make-value entity-name="WorkEffortAttribute" value-field="workEffortAttMap"/>
                        <set field="workEffortAttMap.workEffortId" from-field="parameters.workEffortId"/>
                        <set field="workEffortAttMap.attrName" value="PROJECT_BILLED"/>
                        <set field="workEffortAttMap.attrValue" from-field="parameters.billed"/>
                        <create-value value-field="workEffortAttMap"/>
                    </else>
                </if-not-empty>
                <!-- update project current status to closed -->
                <if-compare field="parameters.currentStatusId" operator="equals" value="SPJ_CLOSED">
<!--                    <entity-and entity-name="ProjectSprintBacklogAndTask" list="sprintList">-->
<!--                        <field-map field-name="projectId" from-field="parameters.projectId"/>-->
<!--                        <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>-->
<!--                    </entity-and>-->
                    <entity-and entity-name="ProjectSprint" list="sprintList">
                        <field-map field-name="projectId" from-field="parameters.projectId"/>
                        <field-map field-name="projectTypeId" value="SCRUM_PROJECT"/>
                    </entity-and>
                    <if-not-empty field="sprintList"></if-not-empty>
                    <iterate list="sprintList" entry="sprint">
                        <!-- Check current status -->
                        <entity-one entity-name="WorkEffort" value-field="sprintEntry">
                            <field-map field-name="workEffortId" from-field="sprint.sprintId"/>
                        </entity-one>
                        <if-not-empty field="sprintEntry">
                            <if-compare operator="not-equals" value="SPRINT_CLOSED" field="sprintEntry.currentStatusId">
                                <set field="updateStatus.currentStatusId" value="SPRINT_CLOSED"/>
                                <set field="updateStatus.workEffortId" from-field="sprint.sprintId"/>
                                <call-service service-name="updateWorkEffort" in-map-name="updateStatus"/>
                                <!-- clear unneccessay parameters -->
                                <clear-field field="parameters.currentStatusId"/>
                                <set field="parameters.projectId" from-field="parameters.projectId"/>
                                <set field="parameters.sprintId" from-field="sprint.sprintId"/>
                                <call-simple-method method-name="closeSprint"/>
                            </if-compare>
                        </if-not-empty>
                    </iterate>
                </if-compare>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="deleteCustRequestItem" short-description="Delete Cust Request Item" login-required="false">
        <set field="custRequestItemCtx.custRequestItemSeqId" from-field="parameters.custRequestItemSeqId"/>
        <remove-by-and entity-name="CustRequestItemNote" map="custRequestItemCtx"/>
        <remove-by-and entity-name="CustRequestItemWorkEffort" map="custRequestItemCtx"/>
        
        <make-value entity-name="CustRequestItem" value-field="deleteCustRequestItem"/>
        <set-pk-fields value-field="deleteCustRequestItem" map="parameters"/>
        <set-nonpk-fields map="parameters" value-field="deleteCustRequestItem"/>
        <remove-value value-field="deleteCustRequestItem"/>
    </simple-method>
    
    <simple-method method-name="deleteCustRequest" short-description="Delete a draft Customer Request with no relations yet">
        <call-simple-method method-name="getWebSiteId"/>
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_DELETE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <entity-one entity-name="CustRequest" value-field="custRequest"/>
                <!-- set default custRequestName -->
                <if-empty field="custRequest.custRequestName">
                    <set field="custRequest.custRequestName" value="product backlog[${custRequest.custRequestId}]"/>
                    <store-value value-field="custRequest"/>
                </if-empty>
                <set field="custRequest.reason" from-field="parameters.reason"/>
                <if-not-empty field="custRequest">
                    <set field="input.custRequestId" from-field="custRequest.custRequestId"/>
                    <set field="input.reason" from-field="custRequest.reason"/>
                    <set field="input.statusId" value="CRQ_CANCELLED"/>
                    <set field="input.webSiteId" from-field="parameters.webSiteId"/>
                    <call-service service-name="setCustRequestStatus" in-map-name="input"/>
                </if-not-empty>
            </then>
        <else>
            <set field="_error_message_" value="You are has no permission to perform this action."/>
            <return response-code="error"/>
        </else>
        </if>
    </simple-method>
    <simple-method method-name="updateProductBacklogItemRows" short-description="Update product backlog item rows in multi form">
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_DELETE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <call-class-method method-name="getParameterMap" class-name="org.apache.ofbiz.base.util.UtilHttp" ret-field="paramMap">
                    <field field="request" type="javax.servlet.http.HttpServletRequest"/>
                </call-class-method>
                <call-class-method method-name="getMultiFormRowCount" class-name="org.apache.ofbiz.base.util.UtilHttp" ret-field="rowCount">
                    <field field="paramMap" type="java.util.Map"/>
                </call-class-method>
                
                <!-- get all data to list -->
                <set field="custRequestIndexList" type="List"/>
                <set field="custRequestList" type="List"/>
                <loop count="${rowCount}" field="j">
                    <set field="custRequestMap" type="NewMap"/>
                    <set field="custRequestMap.custRequestId" from-field="paramMap[&quot;custRequestId_o_${j}&quot;]"/>
                    <set field="custRequestMap.custSequenceNum" from-field="paramMap[&quot;realSequenceNum_o_${j}&quot;]"/>
                    <field-to-list list="custRequestList" field="custRequestMap"/>
                    <field-to-list list="custRequestIndexList" field="paramMap[&quot;realSequenceNum_o_${j}&quot;]"/>
                </loop>
                <set field="newCustRequestList" type="List"/>
                <set field="custRequestListWithNewSeq" type="List"/>
                <loop count="${rowCount}" field="k">
                    <set field="custRequestMap" type="NewMap"/>
                    <set field="custRequestMap.custRequestId" from-field="paramMap[&quot;custRequestId_o_${k}&quot;]"/>
                    <set field="oldSequenceNum" from-field="paramMap[&quot;realSequenceNum_o_${k}&quot;]"/>
                    <set field="newSequenceNum" from-field="paramMap[&quot;newSequenceNum_o_${k}&quot;]"/>
                    <if-not-empty field="newSequenceNum">
                        <set field="custRequestMap.custSequenceNum" from-field="newSequenceNum"/>
                        <field-to-list list="custRequestListWithNewSeq" field="custRequestMap"/>
                        <else>
                            <set field="custRequestMap.custSequenceNum" from-field="oldSequenceNum"/>
                            <field-to-list list="newCustRequestList" field="custRequestMap"/>
                        </else>
                    </if-not-empty>
                </loop>
                
                <!-- get size -->
                <set field="custRequestListSize" value="${groovy: custRequestList.size();}" type="Double"/>
                
                <!-- Check if there are duplicate value will reorder and change it -->
                <set field="custRequestIndex" type="List"/>
                <set field="custRequestIndexToSet" value="${groovy: import java.util.Set; new HashSet(custRequestIndexList);}"/>
                <iterate list="custRequestIndexToSet" entry="custRequestIndexMap">
                    <set field="count" value="0" type="Integer"/>
                    <loop count="${custRequestListSize}" field="l">
                        <if-compare-field field="custRequestList[l].custSequenceNum" operator="equals" to-field="custRequestIndexMap" type="Integer">
                            <set field="count" value="${count + 1}"/>
                        </if-compare-field>
                    </loop>
                    <if-compare field="count" operator="greater" value="1" type="Integer">
                        <set field="custRequestIndexMap" from-field="custRequestIndexMap" type="Integer"/>
                        <field-to-list list="custRequestIndex" field="custRequestIndexMap"/>
                    </if-compare>
                </iterate>
                <if-not-empty field="custRequestIndex">
                    <script>groovy:
                         List indexList = custRequestIndex
                         Collections.sort(indexList)
                         Collections.reverse(indexList)
                         List uniqueCustRequestIndexList = indexList
                         return org.apache.ofbiz.base.util.UtilMisc.toMap("uniqueCustRequestIndexList", uniqueCustRequestIndexList)
                     </script>
                </if-not-empty>
                <if-not-empty field="uniqueCustRequestIndexList">
                    <iterate list="uniqueCustRequestIndexList" entry="custRequestIndexMap">
                        <set field="count" value="0" type="Integer"/>
                        <loop count="${custRequestListSize}" field="m">
                            <if>
                                <condition>
                                        <if-compare-field field="custRequestList[m].custSequenceNum" operator="equals" to-field="custRequestIndexMap" type="Integer"/>
                                </condition>
                                <then>  
                                        <set field="sequenceNumIndex" value="${custRequestList[m].custSequenceNum + count}" type="Integer"/>
                                        <set field="custRequestList[m].custSequenceNum" from-field="sequenceNumIndex" type="String"/>
                                        <entity-one entity-name="CustRequest" value-field="newCustRequestMap">
                                            <field-map field-name="custRequestId" from-field="custRequestList[m].custRequestId"/>
                                        </entity-one>
                                        <set field="nextSeqNum" value="${custRequestList[m].custSequenceNum}" type="Long"/>
                                        <set field="newCustRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                                        <store-value value-field="newCustRequestMap"/>
                                        <set field="count" value="${count + 1}"/>
                                </then>
                                <else>
                                    <if-compare-field field="custRequestList[m].custSequenceNum" operator="greater" to-field="custRequestIndexMap" type="Integer">
                                        <set field="sequenceNumIndex" value="${custRequestIndexMap + count}" type="Integer"/>
                                        <set field="custRequestList[m].custSequenceNum" from-field="sequenceNumIndex" type="String"/>
                                        <entity-one entity-name="CustRequest" value-field="newCustRequestMaps">
                                            <field-map field-name="custRequestId" from-field="custRequestList[m].custRequestId"/>
                                        </entity-one>
                                        <set field="nextSeqNum" value="${custRequestList[m].custSequenceNum}" type="Long"/>
                                        <set field="newCustRequestMaps.custSequenceNum" from-field="nextSeqNum"/>
                                        <store-value value-field="newCustRequestMaps"/>
                                        <set field="count" value="${count + 1}"/>
                                    </if-compare-field>
                                </else>
                            </if>
                        </loop>
                    </iterate>
                </if-not-empty>
                
                <!-- if new sequence not empty -->
                <if-not-empty field="custRequestListWithNewSeq">
                    <if-empty field="newCustRequestList">
                        <!-- use when all field in new sequence not empty -->
                        <loop count="${rowCount}" field="l">
                            <set field="newSeq" from-field="custRequestListWithNewSeq[l].custSequenceNum" type="Integer"/>
                            <set field="oldSeq" from-field="custRequestList[newSeq-1].custSequenceNum" type="Long"/>
                            <set field="custRequestId" from-field="custRequestListWithNewSeq[l].custRequestId"/>
                            <entity-one entity-name="CustRequest" value-field="newCustRequestMap">
                                <field-map field-name="custRequestId" from-field="custRequestId"/>
                            </entity-one>
                            <set field="newCustRequestMap.custSequenceNum" from-field="oldSeq"/>
                            <store-value value-field="newCustRequestMap"/>
                        </loop>
                        <else>
                             <!-- get size -->
                            <script>groovy:
                                 List custRequestSeq = custRequestListWithNewSeq
                                 List custRequestSeqList = org.apache.ofbiz.base.util.UtilMisc.sortMaps(custRequestSeq, org.apache.ofbiz.base.util.UtilMisc.toList("custSequenceNum"))
                                 return org.apache.ofbiz.base.util.UtilMisc.toMap("custRequestSeqList", custRequestSeqList)
                            </script>
                            <set field="custRequestListWithNewSeq" from-field="custRequestSeqList"/>
                            <call-object-method method-name="size" obj-field="custRequestListWithNewSeq" ret-field="newCustCount"/>
                            
                            <!-- start sort transaction -->
                            <loop count="${newCustCount}" field="l">
                                <set field="custRequestId" from-field="custRequestListWithNewSeq[l].custRequestId"/>
                                <entity-one entity-name="CustRequest" value-field="newCustRequestMap">
                                    <field-map field-name="custRequestId" from-field="custRequestId"/>
                                </entity-one>
                                <if-compare field="newCustRequestMap.custRequestTypeId" operator="equals" value="RF_PROD_BACKLOG" >
                                    <entity-and entity-name="CustRequestAndCustRequestItem" list="custRequestItemList">
                                        <field-map field-name="productId" from-field="parameters.productId"/>
                                        <field-map field-name="custRequestTypeId" value="RF_PROD_BACKLOG"/>
                                        <field-map field-name="statusId" value="CRQ_ACCEPTED"/>
                                        <select-field field-name="custRequestId"/>
                                        <select-field field-name="custSequenceNum"/>
                                        <order-by field-name="custSequenceNum"/>
                                    </entity-and>
                                    <set field="custRequestList" from-field="custRequestItemList"/>
                                    <call-object-method method-name="size" obj-field="custRequestList" ret-field="custCount"/>
                                    <else>
                                        <entity-and entity-name="CustRequestAndCustRequestItem" list="custRequestItemList">
                                        <field-map field-name="productId" from-field="parameters.productId"/>
                                        <field-map field-name="custRequestTypeId" value="RF_UNPLAN_BACKLOG"/>
                                        <field-map field-name="statusId" value="CRQ_ACCEPTED"/>
                                        <select-field field-name="custRequestId"/>
                                        <select-field field-name="custSequenceNum"/>
                                        <order-by field-name="custSequenceNum"/>
                                    </entity-and>
                                    <set field="custRequestList" from-field="custRequestItemList"/>
                                    <call-object-method method-name="size" obj-field="custRequestList" ret-field="custCount"/>
                                    </else>
                                </if-compare>
                                <set field="newOfOldSeq" from-field="newCustRequestMap.custSequenceNum" type="Long"/>
                                <set field="newSeq" from-field="custRequestListWithNewSeq[l].custSequenceNum" type="Long"/>
                                <set field="oldSeq" from-field="custRequestList[newSeq-1].custSequenceNum" type="Long" />
                                <loop count="${custCount}" field="m">
                                    <set field="newcustRequestId" from-field="custRequestList[m].custRequestId"/>
                                    <entity-one entity-name="CustRequest" value-field="custRequestMap">
                                        <field-map field-name="custRequestId" from-field="newcustRequestId"/>
                                    </entity-one>
                                    <set field="custSequenceNum" from-field="custRequestMap.custSequenceNum" type="Long"/>
                                    <if-compare-field field="custRequestId" operator="not-equals" to-field="newcustRequestId">
                                         <if-compare-field  field="newOfOldSeq" operator="not-equals" to-field="oldSeq" type="Long">
                                             <set field="readyDown" value="${groovy:(newOfOldSeq&lt;oldSeq)&amp;&amp;(custSequenceNum&lt;=oldSeq)&amp;&amp;(custSequenceNum&gt;newOfOldSeq)}" type="Boolean"/>
                                             <set field="readyUp" value="${groovy:(newOfOldSeq&gt;oldSeq)&amp;&amp;(custSequenceNum&gt;=oldSeq)&amp;&amp;(custSequenceNum&lt;newOfOldSeq)}" type="Boolean"/>
                                             <!-- use when number move down -->
                                             <if>
                                                <condition>
                                                    <if-compare field="readyDown" operator="equals" value="true" type="Boolean"/>
                                                </condition>
                                                <then>
                                                     <set field="nextSeqNum" value="${custSequenceNum-1}" type="Long"/>
                                                     <set field="custRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                                                     <store-value value-field="custRequestMap"/>
                                                </then>
                                             </if>
                                             <!-- use when number move up -->
                                             <if>
                                                <condition>
                                                    <and>
                                                        <if-compare field="readyUp" operator="equals" value="true" type="Boolean"/>
                                                    </and>
                                                </condition>
                                                <then>
                                                    <set field="nextSeqNum" value="${custSequenceNum+1}" type="Long"/>
                                                    <set field="custRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                                                    <store-value value-field="custRequestMap"/>
                                                </then>
                                            </if>
                                         </if-compare-field>
                                    </if-compare-field>
                                </loop>
                                <set field="newCustRequestMap.custSequenceNum" from-field="oldSeq" type="Long"/>
                                <store-value value-field="newCustRequestMap"/>
                            </loop>
                        </else>
                    </if-empty>
                </if-not-empty>
                
                <set field="beDeleted" value="false" type="Boolean"/>
                <loop count="${rowCount}" field="i">
                    <set field="deleteFlag" from-field="paramMap[&quot;deleteFlag_o_${i}&quot;]" default-value="N"/>
                    <set field="custRequestId" from-field="paramMap[&quot;custRequestId_o_${i}&quot;]"/>
                    <set field="statusId" from-field="paramMap[&quot;statusId_o_${i}&quot;]"/>
                    <!-- check CRQ_COMPLETED status -->
                    <if-compare field="statusId" operator="not-equals" value="CRQ_COMPLETED">
                        <if-compare field="deleteFlag" operator="equals" value="Y">
                            <!-- delete product backlog -->
                            <call-simple-method method-name="deleteCustRequest"/>
                            <set field="beDeleted" value="true" type="Boolean"/>
                            <else>
                                <!-- update category and plan hour -->
                                <entity-condition entity-name="CustRequestAndWorkEffort" list="existTasks">
                                    <condition-list combine="and">
                                        <condition-expr field-name="custRequestId" from-field="custRequestId"/>
                                        <condition-expr field-name="workEffortTypeId" operator="not-equals" value="SCRUM_SPRINT"/>
                                    </condition-list>
                                </entity-condition>
                                <set field="parentCustRequestId" from-field="paramMap[&quot;parentCustRequestId_o_${i}&quot;]"/>
                                <set field="estimatedHours" from-field="paramMap[&quot;estimatedHours_o_${i}&quot;]" type="Double"/>
                                <set field="updateCustRequestInMap.custRequestId" from-field="custRequestId"/>
                                <set field="updateCustRequestInMap.parentCustRequestId" from-field="parentCustRequestId"/>
                                <set field="custEstimatedMilliSeconds" value="${estimatedHours*1000*60*60}" default-value="0" type="Double"/>
                                <set field="updateCustRequestInMap.custEstimatedMilliSeconds" from-field="custEstimatedMilliSeconds" type="Double"/>
                                <if-not-empty field="existTasks">
                                    <log level="info" message="warningMessage====================Cannot update plan hour of backlog item[${custRequestId}] because there is existing task for that already."></log>
                                </if-not-empty>
                                <call-service service-name="updateCustRequest" in-map-name="updateCustRequestInMap"/>
                            </else>
                        </if-compare>
                    </if-compare>
                </loop>
                <!-- if some backlog item be deleted then re arrange custSequenceNum field -->
                <if-compare field="beDeleted" operator="equals" value="true" type="Boolean">
                    <set field="reOrderProductBacklogItemSequenceNumberInMap.productId" from-field="parameters.productId"/>
                    <call-service service-name="reOrderProductBacklogItemSequenceNumber" in-map-name="reOrderProductBacklogItemSequenceNumberInMap"/>
                </if-compare>
                <!-- check warning message list -->
                <if-not-empty field="warningMessageList">
                    <set field="_event_message_" value="Warning ${warningMessageList}"/>
                </if-not-empty>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
        <field-to-request field="parameters.sequence" request-name="sequence"/>
        <field-to-request field="parameters.UnplannedSequence" request-name="UnplannedSequence"/>
        <field-to-request field="parameters.VIEW_SIZE_1" request-name="VIEW_SIZE_1"/>
        <field-to-request field="parameters.VIEW_INDEX_1" request-name="VIEW_INDEX_1"/>
    </simple-method>
    
    <simple-method method-name="createProductBacklog" short-description="">
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_CREATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <call-simple-method method-name="getWebSiteId"/>
                <if-compare operator="equals" value="Y" field="parameters.unplannedFlag">
                    <set field="custRequestTypeId" value="RF_UNPLAN_BACKLOG"/>
                    <else>
                        <set field="custRequestTypeId" value="RF_PROD_BACKLOG"/>
                    </else>
                </if-compare>
                <if-empty field="parameters.description">
                    <add-error >
                        <fail-message message="There Product Backlog Item is missing, Please add."/>
                    </add-error>
                    <check-errors/>
                </if-empty>
                <if-empty field="parameters.custSequenceNum">
                        <set field="sequenceNumIn" value="1" type="Long"/>
                       <entity-count count-field="getNum" entity-name="CustRequestAndCustRequestItem">
                           <condition-list combine="and">
                               <condition-expr field-name="productId" from-field="parameters.productId"/>
                               <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                           </condition-list>
                       </entity-count>
                    <if-compare operator="equals" value="0" field="getNum">
                        <set field="createCustRequestInMap.custSequenceNum" from-field="sequenceNumIn"/>
                        <else>
                            <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
                                   <condition-list combine="and">
                                       <condition-expr field-name="productId" from-field="parameters.productId"/>
                                       <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                                   </condition-list>
                                   <order-by field-name="custSequenceNum"/>
                             </entity-condition>
                             <set field="productMap" from-field="custRequestList[getNum-1]"/>
                             <set field="nextSeq" from-field="productMap.custSequenceNum" type="Integer"/>
                            <set field="newSequenceNum" value="${nextSeq+1}" type="Long"/>
                            <set field="createCustRequestInMap.custSequenceNum" from-field="newSequenceNum" />
                        </else>
                    </if-compare>
                    <else>
                       <!-- check duplicate data  -->
                       <entity-count count-field="getNum" entity-name="CustRequestAndCustRequestItem">
                           <condition-list combine="and">
                               <condition-expr field-name="productId" from-field="parameters.productId"/>
                               <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                           </condition-list>
                       </entity-count>
                       <!-- the first sequence number -->
                       <if-compare field="getNum" operator="equals" value="0">
                           <set field="createCustRequestInMap.custSequenceNum" from-field="parameters.custSequenceNum"/>
                        <else>
                               <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
                                   <condition-list combine="and">
                                       <condition-expr field-name="productId" from-field="parameters.productId"/>
                                       <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                                   </condition-list>
                                   <order-by field-name="custSequenceNum"/>
                               </entity-condition>
                               <set field="sequenceNumkey" from-field="parameters.custSequenceNum" type="Integer"/>
                               <set field="productMap" from-field="custRequestList[sequenceNumkey-1]"/>
                               <set field="externalSeq" from-field="productMap.custSequenceNum" type="Long"/>
                               <!-- Insert new transaction to CustRequest -->
                               <loop count="${getNum}" field="j">
                                     <set field="internalSeq" from-field="custRequestList[j].custSequenceNum" type="Long" />
                                    <set field="ready" value="${groovy:internalSeq&gt;=externalSeq}" type="Boolean"/>
                                   <if-compare field="ready" operator="equals" value="true"  type="Boolean">
                                       <set field="custRequestId" from-field="custRequestList[j].custRequestId"/>
                                       <entity-one entity-name="CustRequest" value-field="custRequestMap">
                                           <field-map field-name="custRequestId" from-field="custRequestId"/>
                                       </entity-one>
                                       <set field="custSequenceNum" from-field="custRequestMap.custSequenceNum"/>
                                       <set field="nextSeqNum" value="${custSequenceNum+1}" type="Long"/>
                                       <set field="custRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                                       <store-value value-field="custRequestMap"/>
                                   </if-compare>
                               </loop>
                               <set field="createCustRequestInMap.custSequenceNum" from-field="externalSeq"/>
                        </else>
                       </if-compare>
                    </else>
                </if-empty>
                <if-empty field="parameters.fromPartyId">
                    <set field="createCustRequestInMap.fromPartyId" from-field="userLogin.partyId"/>
                </if-empty>
                <set field="changeToMilliSec" value="${parameters.custEstimatedMilliSeconds*1000*60*60}"/>
                <set field="createCustRequestInMap.custEstimatedMilliSeconds" from-field="changeToMilliSec" type="Double"/>
                <set field="createCustRequestInMap.billed" from-field="parameters.billed"/>
                <set field="createCustRequestInMap.custRequestTypeId" from-field="custRequestTypeId"/>
                <set field="createCustRequestInMap.statusId" value="CRQ_ACCEPTED"/>
                <set field="createCustRequestInMap.custRequestName" value="Product Backlog"/>
                <set field="createCustRequestInMap.description" from-field="parameters.description"/>
                <set field="createCustRequestInMap.openDateTime" from-field="parameters.openDateTime"/>
                <set field="createCustRequestInMap.closedDateTime" from-field="parameters.closedDateTime"/>
                <set field="createCustRequestInMap.parentCustRequestId" from-field="parameters.parentCustRequestId"/>
                <set field="createCustRequestInMap.webSiteId" from-field="parameters.webSiteId"/>
                
                <sequenced-id sequence-name="CustRequestItem" field="custRequestItemSeqId"/>
                <set field="createCustRequestInMap.custRequestItemSeqId" from-field="custRequestItemSeqId"/>
                <set field="createCustRequestInMap.story" from-field="parameters.story"/>
                <set field="createCustRequestInMap.productId" from-field="parameters.productId"/>
                <call-service service-name="createCustRequest" in-map-name="createCustRequestInMap">
                    <result-to-field result-name="custRequestId"/>
                </call-service>
                <!-- create CustRequestNote -->
                <if-not-empty field="parameters.noteInfo">
                    <set field="newNoteMap.note" from-field="parameters.noteInfo"/>
                    <set field="newNoteMap.noteName" value="How to test"/>
                    <call-service service-name="createNote" in-map-name="newNoteMap">
                        <result-to-field result-name="noteId" field="noteId"/>
                    </call-service>
                    <make-value entity-name="CustRequestNote" value-field="newEntity"/>
                    <set from-field="custRequestId" field="newEntity.custRequestId"/>
                    <set from-field="noteId" field="newEntity.noteId"/>
                    <create-value value-field="newEntity"/>
                </if-not-empty>
                <request-to-field field="parameters.productId" request-name="productId"/>
                <request-to-field field="parameters.sequence" request-name="sequence"/>
                <request-to-field field="parameters.UnplannedSequence" request-name="UnplannedSequence"/>
            </then>
        <else>
            <set field="_error_message_" value="You are has no permission to perform this action."/>
            <return response-code="error"/>
        </else>
            
        </if>
        
    </simple-method>

    <simple-method method-name="updateSprintBacklog" short-description="Update Sprint Backlog">
        <call-simple-method method-name="getWebSiteId"/>
        <set field="parameters.custEstimatedMilliSeconds" from-field="parameters.estimatedHours" type="Float"/>
        <calculate field="parameters.custEstimatedMilliSeconds" type="Float">
            <calcop operator="multiply" field="parameters.custEstimatedMilliSeconds">
                <number value="3600000"/>
            </calcop>
        </calculate>
        <set-service-fields service-name="updateCustRequest" map="parameters" to-map="inMap"/>
        <call-service service-name="updateCustRequest" in-map-name="inMap"/>
    </simple-method>
    
    <simple-method method-name="createSprintBacklog" short-description="Create Sprint Backlog">
    <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_SPRINT" action="_UPDATE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </or>
            </condition>
    <then>
        <call-simple-method method-name="getWebSiteId"/>
        <set field="parameters.sprintBacklogs" value="${parameters.sprintBacklogs}-1" type="Integer"/>
         <entity-and entity-name="WorkEffortAndProduct" list="projectList">
             <field-map field-name="workEffortId" from-field="parameters.projectId"/>
        </entity-and>
        <first-from-list entry="project" list="projectList"/>
        <entity-one entity-name="WorkEffortAttribute" value-field="workEffortAttMap">
            <field-map field-name="workEffortId" from-field="parameters.projectId"/>
            <field-map field-name="attrName" value="PROJECT_BILLED"/>
        </entity-one>
        <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
            <condition-list combine="and">
                <condition-expr field-name="custRequestTypeId" value="RF_PROD_BACKLOG" />
                <condition-expr field-name="statusId" value="CRQ_ACCEPTED" />
                <condition-expr field-name="productId" from-field="project.productId"/>
           </condition-list>
           <order-by field-name="custSequenceNum"/>
        </entity-condition>

        <loop count="${parameters.sprintBacklogs}" field="i">
            <set field="sequenceNumx" value="${i+1}"/>
            <set field="sprintBL.custRequestId" from-field="custRequestList[i].custRequestId"/>
            <set field="sprintBL.workEffortId" from-field="parameters.sprintId"/>
            <set field="sprintBL.userLogin" from-field="userLogin"/>
            <call-service service-name="createWorkEffortRequest" in-map-name="sprintBL"/>
            <set field="inMap.custRequestId" from-field="custRequestList[i].custRequestId"/>
            <set field="inMap.statusId" value="CRQ_REVIEWED"/>
            <set field="inMap.custRequestName" value=" "/>
            <set field="inMap.webSiteId" from-field="parameters.webSiteId"/>
            <!-- if the Billed field of the project was set. -->
            <if-not-empty field="workEffortAttMap">
                <set field="inMap.billed" from-field="workEffortAttMap.attrValue"/>
            </if-not-empty>
            <set field="inMap.webSiteId" from-field="parameters.webSiteId"/>
            <call-service service-name="updateCustRequest" in-map-name="inMap"/>
            <!-- Check If there are tasks already in a backlog -->
            <entity-condition entity-name="WorkEffortCustRequestView" list="backlogItemTaskList">
                <condition-list combine="and">
                    <condition-expr field-name="custRequestId" from-field="custRequestList[i].custRequestId"/>
                    <condition-list combine="or">
                        <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_ERROR"/>
                        <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                        <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_INST"/>
                        <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_TEST"/>
                    </condition-list>
                </condition-list>
            </entity-condition>
            <if-empty field="backlogItemTaskList">
                <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                    <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                    <field-map field-name="productId" from-field="project.productId"/>
                </entity-and>
                <if-not-empty field="defaultTaskList">
                <iterate list="defaultTaskList" entry="defaultTask">
                    <set field="newDefaultTask.workEffortName" from-field="defaultTask.workEffortName"/>
                    <set field="newDefaultTask.estimatedMilliSeconds" from-field="defaultTask.estimatedMilliSeconds"/>
                    <set field="newDefaultTask.currentStatusId" from-field="defaultTask.currentStatusId"/>
                    <set field="newDefaultTask.workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                    <set field="newDefaultTask.workEffortParentId" from-field="parameters.sprintId"/>
                    <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                        <result-to-field result-name="workEffortId"/>
                    </call-service>
                    <set field="newBacklogItemTask.custRequestId" from-field="custRequestList[i].custRequestId"/>
                    <set field="newBacklogItemTask.workEffortId" from-field="workEffortId"/>
                    <set field="newBacklogItemTask.userLogin" from-field="userLogin"/>
                    <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTask"/>
                    <!-- Assigned party for default task-->
                    <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                        <condition-list combine="and">
                            <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                            <condition-expr field-name="workEffortId" from-field="defaultTask.workEffortId"/>
                        </condition-list>
                    </entity-condition>
                    <if-not-empty field="assigneds">
                        <first-from-list list="assigneds" entry="assignedMap"/>
                        <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                        <set field="newInput.workEffortId" from-field="workEffortId"></set>
                        <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                        <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                        <set field="newInput.userLogin" from-field="userLogin"/>
                        <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                        <!-- Assigned party for sprint -->
                        <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintAssigneds">
                            <condition-list combine="and">
                                <condition-expr field-name="partyId" from-field="assignedMap.partyId"/>
                                <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                <condition-expr field-name="workEffortId" from-field="parameters.sprintId"/>
                            </condition-list>
                        </entity-condition>
                        <if-empty field="sprintAssigneds">
                            <set field="sprintInput.partyId" from-field="assignedMap.partyId"></set>
                            <set field="sprintInput.workEffortId" from-field="parameters.sprintId"></set>
                            <set field="sprintInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                            <set field="sprintInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                            <set field="sprintInput.userLogin" from-field="userLogin"/>
                            <call-service service-name="assignPartyToWorkEffort" in-map-name="sprintInput"/>
                        </if-empty>
                    </if-not-empty>
                </iterate>
                <else>
                    <!-- If not have default task in product level -->
                    <entity-and entity-name="WorkEffort" list="defaultTaskScrum">
                        <field-map field-name="workEffortPurposeTypeId" value="SYSTEM_DEFAULT_TASK"/>
                    </entity-and>
                    <if-not-empty field="defaultTaskScrum">
                        <iterate list="defaultTaskScrum" entry="defaultScrum">
                            <set field="newDefaultTaskScrum.workEffortName" from-field="defaultScrum.workEffortName"/>
                            <set field="newDefaultTaskScrum.estimatedMilliSeconds" from-field="defaultScrum.estimatedMilliSeconds"/>
                            <set field="newDefaultTaskScrum.currentStatusId" from-field="defaultScrum.currentStatusId"/>
                            <set field="newDefaultTaskScrum.workEffortTypeId" from-field="defaultScrum.workEffortTypeId"/>
                            <set field="newDefaultTaskScrum.workEffortParentId" from-field="parameters.sprintId"/>
                            <call-service service-name="createWorkEffort" in-map-name="newDefaultTaskScrum">
                                <result-to-field result-name="workEffortId"/>
                            </call-service>
                            <set field="newBacklogItemTaskScrum.custRequestId" from-field="custRequestList[i].custRequestId"/>
                            <set field="newBacklogItemTaskScrum.workEffortId" from-field="workEffortId"/>
                            <set field="newBacklogItemTaskScrum.userLogin" from-field="userLogin"/>
                            <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTaskScrum"/>
                            <!-- Assigned party for default task-->
                            <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                                <condition-list combine="and">
                                    <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                    <condition-expr field-name="workEffortId" from-field="defaultScrum.workEffortId"/>
                                </condition-list>
                            </entity-condition>
                            <if-not-empty field="assigneds">
                                <first-from-list list="assigneds" entry="assignedMap"/>
                                <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                                <set field="newInput.workEffortId" from-field="workEffortId"></set>
                                <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                                <set field="newInput.userLogin" from-field="userLogin"/>
                                <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                                <!-- Assigned party for sprint -->
                               <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintAssigneds">
                                   <condition-list combine="and">
                                       <condition-expr field-name="partyId" from-field="assignedMap.partyId"/>
                                       <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                       <condition-expr field-name="workEffortId" from-field="parameters.sprintId"/>
                                   </condition-list>
                               </entity-condition>
                               <if-empty field="sprintAssigneds">
                                   <set field="sprintInput.partyId" from-field="assignedMap.partyId"></set>
                                   <set field="sprintInput.workEffortId" from-field="parameters.sprintId"></set>
                                   <set field="sprintInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                   <set field="sprintInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                                   <set field="sprintInput.userLogin" from-field="userLogin"/>
                                   <call-service service-name="assignPartyToWorkEffort" in-map-name="sprintInput"/>
                               </if-empty>
                            </if-not-empty>
                        </iterate>
                    </if-not-empty>
                </else>
                </if-not-empty>
                <else>
                    <loop count="${groovy: backlogItemTaskList.size()}" field="j">
                        <set field="updateWorkEffort.workEffortId" from-field="backlogItemTaskList[j].workEffortId"/>
                        <set field="updateWorkEffort.workEffortParentId" from-field="parameters.sprintId"/>
                        <call-service service-name="updateWorkEffort" in-map-name="updateWorkEffort"/>
                    </loop>
                </else>
            </if-empty>
        </loop>
        <if-not-empty field="parameters.sprintId">
            <field-to-request field="parameters.sprintId" request-name="sprintId"/>
        </if-not-empty>
    </then>
    <else>
        <set field="_error_message_" value="You are has no permission to perform this action."/>
        <return response-code="error"/>
    </else>
    </if>
    </simple-method>
    <simple-method method-name="addScrumResource" short-description="make parties available in the Scrum.">
        <set field="userLoginIdDesc" from-field="parameters.userLoginIdDesc"/>
        <set field="userLoginId" value="${groovy:userLoginIdDesc.substring(userLoginIdDesc.indexOf(&quot;|&quot;)+1)}"/>
        <entity-and entity-name="UserLogin" list="userLogins">
            <field-map field-name="partyId" from-field="parameters.partyId"/>
        </entity-and>
        <entity-one entity-name="PartyNameView" value-field="partyNameView"/>
        <if-empty field="userLogins">
            <set field="_error_message_" value="${partyNameView.lastName}, ${partyNameView.firstName} [${parameters.partyId}] does not have UserLogin."/>
            <return response-code="error"/>
        </if-empty>
        <if-compare operator="equals" value="SCRUM_PRODUCT_OWNER" field="parameters.groupId">
            <set field="parameters.roleTypeId" value="PRODUCT_OWNER"/>
        </if-compare>
        <if-compare operator="equals" value="SCRUM_MASTER" field="parameters.groupId">
            <set field="parameters.roleTypeId" value="SCRUM_MASTER"/>
        </if-compare>
        <if-compare operator="equals" value="SCRUM_TEAM" field="parameters.groupId">
            <set field="parameters.roleTypeId" value="SCRUM_TEAM"/>
        </if-compare>
        <!-- For special role -->
        <if-compare operator="equals" value="SCRUM_STAKEHOLDER" field="parameters.groupId">
            <set field="parameters.roleTypeId" value="STAKEHOLDER"/>
        </if-compare>

        <set-service-fields service-name="ensurePartyRole" map="parameters" to-map="ensurePartyRole"/>
        <set field="ensurePartyRole.userLogin" from-field="sysUserLogin"/>
        <call-service service-name="ensurePartyRole" in-map-name="ensurePartyRole"/>
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        
        <entity-and entity-name="UserLoginSecurityGroup" list="listGroupId">
            <field-map field-name="userLoginId" from-field="userLoginId"/>
            <field-map field-name="groupId" from-field="parameters.groupId"/>
        </entity-and>
        <if-empty field="listGroupId">
            <set field="parameters.userLoginId" from-field="userLoginId"/>
            <set-service-fields service-name="addUserLoginToSecurityGroup" map="parameters" to-map="inMap"/>
            <set field="inMap.userLogin" from-field="sysUserLogin"/>
            <call-service service-name="addUserLoginToSecurityGroup" in-map-name="inMap"/>
            <else>
                <entity-one entity-name="RoleType" value-field="roleTypeMap">
                    <field-map field-name="roleTypeId" from-field="parameters.roleTypeId"/>
                </entity-one>
                <add-error>
                    <fail-message message="There are partyId : ${parameters.partyId} , userLoginId : ${userLoginId} and roleTypeId : ${roleTypeMap.description} already exist."/>
                </add-error>
                <check-errors/>
            </else>
        </if-empty>
        <set field="roleData.partyId" from-field="parameters.partyId"/>
        <set field="roleData.roleTypeId" value="SCRUM_MEMBER"/>
        <set field="roleData.userLogin" from-field="sysUserLogin"/>
        <call-service service-name="ensurePartyRole" in-map-name="roleData">
            <default-message resource="CommonUiLabels" property="CommonSuccessfullyCreated"/>
        </call-service>
    </simple-method>
    
    <simple-method method-name="createSprintBacklogTask" short-description="Create Sprint Backlog Task">
        <call-class-method class-name="org.apache.ofbiz.content.layout.LayoutWorker" method-name="uploadImageAndParameters" ret-field="formInput">
            <field field="request" type="javax.servlet.http.HttpServletRequest"/>
            <string value="uploadedFile"/>
        </call-class-method>
        <entity-one entity-name="UserLogin" value-field="systemUser">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <entity-one entity-name="CustRequest" value-field="custRequestMap">
            <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
        </entity-one>
        <if-empty field="formInput.formInput.sprintId">
            <entity-and entity-name="CustRequestAndWorkEffort" list="custRequestWorkEfforts">
                <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
                <field-map field-name="currentStatusId" value="SPRINT_ACTIVE"/>
            </entity-and>
            <if-not-empty field="custRequestWorkEfforts">
                <first-from-list list="custRequestWorkEfforts" entry="custRequestWorkEffort"/>
                <set field="formInput.formInput.sprintId" from-field="custRequestWorkEffort.workEffortId"/>
            </if-not-empty>
        </if-empty>
        <if>
            <condition>
                <not><if-empty field="formInput.formInput.actualStartDate"/></not>
            </condition>
            <then>
                <entity-one entity-name="WorkEffort" value-field="sprint">
                    <field-map field-name="workEffortId" from-field="formInput.formInput.sprintId"/>
                </entity-one>
                <set field="formInput.formInput.actualStartDate" from-field="sprint.actualStartDate"/>
                <if>
                    <condition>
                        <or>
                           <if-compare-field operator="less" field="formInput.formInput.actualStartDate" to-field="sprint.actualStartDate" type="Timestamp"/>
                           <if-compare-field operator="greater" field="formInput.formInput.actualStartDate" to-field="sprint.actualCompletionDate" type="Timestamp"/>
                        </or>
                    </condition>
                    <then>
                        <add-error>
                            <fail-message message="Start Date isn't in Sprint Duration."/>
                        </add-error>
                    </then>
               </if>
            </then>
        </if>
        <check-errors/>
        <if-empty field="formInput.formInput.workEffortName">
            <add-error >
                <fail-message message="Task name is empty, please enter task name."/>
            </add-error>
        </if-empty>
        <check-errors/>
        <if-not-empty field="formInput.formInput.planHours">
            <set field="formInput.formInput.estimatedMilliSeconds" from-field="formInput.formInput.planHours" type="Float"/>
            <calculate field="formInput.formInput.estimatedMilliSeconds" type="Float">
             <calcop operator="multiply" field="formInput.formInput.estimatedMilliSeconds">
                 <number value="3600000"/>
             </calcop>
            </calculate>
        </if-not-empty>
        <if-compare field="custRequestMap.custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG">
            <if-empty field="formInput.formInput.actualStartDate">
                <now-timestamp field="nowTimesamp"/>
                <set field="formInput.formInput.actualStartDate" from-field="nowTimesamp"/>
            </if-empty>
        </if-compare>
        <set field="custRequestId" from-field="formInput.formInput.custRequestId"/>
        <clear-field field="formInput.formInput.custRequestId"/>
        <if-compare field="custRequestMap.custRequestTypeId" operator="not-equals" value="RF_UNPLAN_BACKLOG">
            <set field="formInput.formInput.workEffortParentId" from-field="formInput.formInput.sprintId"/>
        </if-compare>
        <set field="formInput.formInput.currentStatusId" value="STS_CREATED"/>
        <if-compare field="formInput.formInput.workEffortTypeId" operator="equals" value="SCRUM_TASK_ERROR">
            <set field="formInput.formInput.priority" value="1"/>
        </if-compare>
        <if-compare field="formInput.formInput.workEffortTypeId" operator="equals" value="SCRUM_TASK_TEST">
            <set field="formInput.formInput.priority" value="2"/>
        </if-compare>
        <if-compare field="formInput.formInput.workEffortTypeId" operator="equals" value="SCRUM_TASK_IMPL">
            <set field="formInput.formInput.priority" value="3"/>
        </if-compare>
        <if-compare field="formInput.formInput.workEffortTypeId" operator="equals" value="SCRUM_TASK_INST">
            <set field="formInput.formInput.priority" value="4"/>
        </if-compare>
        <set-service-fields service-name="createWorkEffort" map="formInput.formInput" to-map="createWorkEffort"/>
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <if-has-permission permission="SCRUM" action="_ADMIN">
            <set field="createWorkEffort.userLogin" from-field="sysUserLogin"/>
        </if-has-permission>
        <call-service service-name="createWorkEffort" in-map-name="createWorkEffort">
            <result-to-field result-name="workEffortId" field="formInput.formInput.workEffortId"/>
        </call-service>
        <set field="formInput.formInput.custRequestId" from-field="custRequestId"/>
        <set-service-fields service-name="createWorkEffortRequest" map="formInput.formInput" to-map="createWorkEffortRequest"/>
        <call-service service-name="createWorkEffortRequest" in-map-name="createWorkEffortRequest"/>
        
        <!--if plan hours(from task) more than first plan hours -->
        <set field="backlogPlanMap.custRequestId" from-field="formInput.formInput.custRequestId" />
        <set field="taskPlanMap.custRequestId" from-field="formInput.formInput.custRequestId" />
        <call-service service-name="getScrumPlanHour" in-map-name="backlogPlanMap">
            <result-to-field result-name="planHours" />
        </call-service>
        <call-service service-name="getScrumPlanHour" in-map-name="taskPlanMap">
            <result-to-field result-name="initPlanHours"/>
        </call-service>
        <if-compare-field field="planHours"  operator="greater" to-field="initPlanHours"  type="Double">
            <entity-one entity-name="CustRequest" value-field="custRequestMap">
                <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
            </entity-one>
            <set field="planHoursIn" from-field="planHours" type="Double"/>
            <set field="custRequestMap.custEstimatedMilliSeconds" value="${groovy:planHoursIn*1000*60*60}" type="Double"/>
            <store-value value-field="custRequestMap"/>
            <else>
                <if-compare-field field="initPlanHours"  operator="greater" to-field="planHours"  type="Double">
                    <entity-one entity-name="CustRequest" value-field="custRequestMap">
                        <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
                    </entity-one>
                    <set field="planHoursIn" from-field="planHours" type="Double"/>
                    <set field="custRequestMap.custEstimatedMilliSeconds" value="${groovy:planHoursIn*1000*60*60}" type="Double"/>
                    <store-value value-field="custRequestMap"/>
                </if-compare-field>
            </else>
        </if-compare-field>
        <if-not-empty field="formInput.formInput.partyId">
        <!-- Assigned -->
            <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                <condition-list combine="and">
                    <condition-expr field-name="partyId" from-field="formInput.formInput.partyId"/>
                    <condition-expr field-name="statusId" value="SCAS_ASSIGNED"/>
                    <condition-expr field-name="workEffortId" from-field="formInput.formInput.workEffortId"/>
                </condition-list>
            </entity-condition>
            <if-empty field="assigneds">
                <entity-and entity-name="WorkEffortPartyAssignment" list="assigneds">
                    <field-map field-name="workEffortId" from-field="formInput.formInput.workEffortId"/>
                </entity-and>
                <entity-and entity-name="PartyRole" list="taskOwnerRoles">
                    <field-map field-name="partyId" from-field="formInput.formInput.partyId"/>
                    <field-map field-name="roleTypeId" value="SCRUM_TEAM"/>
                </entity-and>
                <entity-one entity-name="UserLogin" value-field="systemUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <iterate list="assigneds" entry="assigned">
                    <remove-value value-field="assigned"/>
                </iterate>
                <set field="newInput.partyId" from-field="formInput.formInput.partyId"></set>
                <set field="newInput.workEffortId" from-field="formInput.formInput.workEffortId"></set>
                <set field="newInput.roleTypeId" from-field="taskOwnerRoles[0].roleTypeId"></set>
                <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
            </if-empty>
        </if-not-empty>
        <!-- for contents -->
        <if-not-empty field="formInput.imageFileName">
            <add-error><fail-message message="Upload file is missing..."/></add-error> 
            <set field="parameters.imageFileName" from-field="formInput.imageFileName"/>
            
            <!-- Create Data Resource -->
            <set-service-fields service-name="createContentFromUploadedFile"
                map="formInput.formInput" to-map="data"/>
            <set field="data.dataResourceTypeId" value="LOCAL_FILE"/>
            <set field="data.dataTemplateTypeId" value="NONE"/>
            <set field="data.dataCategoryId" from-field="formInput.formInput.dataCategoryId"/>
            <set field="data.userLogin" from-field="systemUser"/>
            <set field="data.statusId" from-field="formInput.formInput.resourceStatusId"/>
            <set field="data.dataResourceName" from-field="formInput.imageFileName"/>
            <set field="data.mimeTypeId" from-field="mimeType.mimeTypeId"/>
            <set field="data.uploadedFile" from-field="formInput.imageData"/>
            <set field="data._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="data._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <call-service service-name="createDataResource" in-map-name="data">
                <result-to-field result-name="dataResourceId" field="parameters.dataResourceId"/>
            </call-service>
            <!-- Create attach upload to data resource -->
            <set-service-fields service-name="attachUploadToDataResource" map="formInput.formInput"
                to-map="attachMap"/>
            <set field="attachMap.uploadedFile" from-field="formInput.imageData"/>
            <set field="attachMap._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="attachMap._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <set field="attachMap.dataResourceId" from-field="parameters.dataResourceId"/>
            <set field="attachMap.mimeTypeId" from-field="mimeType.mimeTypeId"/>
            <call-service service-name="attachUploadToDataResource" in-map-name="attachMap"/>
            <!-- Create content from dataResource -->
            <set-service-fields service-name="createContentFromDataResource"
                map="formInput.formInput" to-map="contentMap"/>
            <set field="contentMap.roleTypeId" from-field="formInput.formInput.roleTypeId"/>
            <set field="contentMap.partyId" from-field="formInput.formInput.partyId"/>
            <set field="contentMap.contentTypeId" from-field="formInput.formInput.contentTypeId"/>
            <set field="contentMap.dataResourceId" from-field="parameters.dataResourceId"/>
            <set field="contentMap.userLogin" from-field="systemUser"/>
            <call-service service-name="createContentFromDataResource" in-map-name="contentMap">
                <result-to-field result-name="contentId" field="formInput.formInput.contentId"/>
            </call-service>
            <!-- Create WorkEffort Content -->
            <set-service-fields service-name="createWorkEffortContent" map="formInput.formInput" to-map="workEffortContent"/>
            <set field="workEffortContent.userLogin" from-field="systemUser"/>
            <set field="workEffortContent.workEffortContentTypeId" from-field="formInput.formInput.workEffortContentTypeId"/>
            <call-service service-name="createWorkEffortContent" in-map-name="workEffortContent"/>
        </if-not-empty>
        <field-to-request field="formInput.formInput.workEffortId" request-name="taskId"/>
    </simple-method>
    <simple-method method-name="addProjectMember" short-description="Add Project Member">
        <set field="groupIdDesc" from-field="parameters.groupIdDesc"/>
        <set field="groupName" value="${groovy:groupIdDesc.substring(0, groupIdDesc.indexOf(&quot;--&quot;))}"/>
        <set field="fullName" value="${groovy:groupIdDesc.substring(groupIdDesc.indexOf(&quot;--&quot;)+2, groupIdDesc.indexOf(&quot;|&quot;))}"/>
        <set field="groupId" value="${groovy:groupIdDesc.substring(groupIdDesc.indexOf(&quot;|&quot;)+1)}"/>
        <entity-condition entity-name="WorkEffortPartyAssignment" list="project">
            <condition-list>
                <condition-expr field-name="workEffortId" from-field="parameters.projectId"/>
                <condition-expr field-name="roleTypeId" value="PRODUCT_OWNER"/>
            </condition-list>
        </entity-condition>
        <entity-and entity-name="UserLogin" list="userLogins">
            <field-map field-name="partyId" from-field="parameters.partyId"/>
        </entity-and>
        <entity-one entity-name="PartyNameView" value-field="partyNameView"/>
        <if-not-empty field="project">
            <if-compare operator="equals" value="PRODUCT_OWNER" field="roleTypeId">
                <set field="_error_message_" value="The system can add only one product owner!"/>
                <return response-code="error"/>
            </if-compare>
        </if-not-empty>
        <if-compare operator="equals" value="SCRUM_PRODUCT_OWNER" field="groupId">
            <set field="parameters.roleTypeId" value="PRODUCT_OWNER"/>
        </if-compare>
        <if-compare operator="equals" value="SCRUM_MASTER" field="groupId">
            <set field="parameters.roleTypeId" value="SCRUM_MASTER"/>
        </if-compare>
        <if-compare operator="equals" value="SCRUM_TEAM" field="groupId">
            <set field="parameters.roleTypeId" value="SCRUM_TEAM"/>
        </if-compare>
        <if-compare operator="equals" value="SCRUM_STAKEHOLDER" field="groupId">
            <set field="parameters.roleTypeId" value="STAKEHOLDER"/>
        </if-compare>
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>

        <set-service-fields service-name="ensurePartyRole" map="parameters" to-map="ensurePartyRole"/>
        <set field="ensurePartyRole.userLogin" from-field="sysUserLogin"/>
        <set field="ensurePartyRole.roleTypeId" from-field="parameters.roleTypeId"/>
        <call-service service-name="ensurePartyRole" in-map-name="ensurePartyRole"/>
        <set-service-fields service-name="assignPartyToWorkEffort" map="parameters" to-map="assignPartyToWorkEffort"/>
        <set field="assignPartyToWorkEffort.userLogin" from-field="sysUserLogin"/>
        <call-service service-name="assignPartyToWorkEffort" in-map-name="assignPartyToWorkEffort"/>
    </simple-method>
    
    <simple-method method-name="addMemberTask" short-description="Assign member to Tasks">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_TASK" action="_CREATE"/>
                </or>
            </condition>
            <then>
                <set field="taskId" from-field="parameters.taskId" default-value="${parameters.workEffortId}"/>
                <!-- get backlog from task -->
                <entity-and entity-name="ProductBacklog" list="scrumMeetingBacklogs">
                    <field-map field-name="workEffortId" from-field="taskId"/>
                    <field-map field-name="custRequestTypeId" value="RF_SCRUM_MEETINGS"/>
                </entity-and>
                <if-not-empty field="scrumMeetingBacklogs">
                <!-- be able to assign more than one person in this task -->
                    <set field="member.partyId" from-field="parameters.partyId"/>
                    <set field="member.roleTypeId" from-field="parameters.roleTypeId"/>
                    <set field="member.statusId" value="SCAS_ASSIGNED"/>
                    <set field="member.workEffortId" from-field="taskId"/>
                    <call-service service-name="assignPartyToWorkEffort" in-map-name="member"/>
                <else>
                    <!-- check if this task assign to member, and they also enter actual hour. return error -->
                    <entity-and entity-name="WorkEffortPartyAssignment" list="workEffortPartyAssignments">
                        <field-map field-name="workEffortId" from-field="taskId"/>
                    </entity-and>
                    <if-not-empty field="workEffortPartyAssignments">
                        <!-- remove existing party and add new party -->
                        <iterate list="workEffortPartyAssignments" entry="workEffortPartyAssignment">
                            <remove-value value-field="workEffortPartyAssignment"/>
                        </iterate>
                    </if-not-empty>
                    <!-- assign new party to task -->
                    <set field="newInput.partyId" from-field="parameters.partyId"/>
                    <set field="newInput.workEffortId" from-field="taskId"/>
                    <set field="newInput.fromDate" from-field="parameters.fromDate"/>
                    <set field="newInput.thruDate" from-field="parameters.thruDate"/>
                    <if-empty field="taskOwnerRoles">
                        <set field="newInput.roleTypeId" from-field="parameters.roleTypeId"/>
                    </if-empty>
                    <set field="newInput.roleTypeId" from-field="taskOwnerRoles[0].roleTypeId"/>
                    <set field="newInput.statusId" value="SCAS_ASSIGNED"/>
                    <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                </else>
                </if-not-empty>
                <field-to-request field="taskId" request-name="workEffortId"/>
                <field-to-request field="taskId" request-name="taskId"/>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>

    <simple-method method-name="deleteProduct" short-description="">
        <if>
            <condition>
                <or>
                    <!-- Permission Check -->
                    <if-has-permission permission="SCRUM_PRODUCT" action="_DELETE"/>
                    <if-has-permission permission="SCRUM_PRODUCT" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM" action="_DELETE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <entity-one entity-name="Product" value-field="product"/>
                <make-value entity-name="Product" value-field="product"/>
                <set field="product.productId" from-field="parameters.productId"/>
                <set field="product.productTypeId" value="SCRUM_ITEM"/>
                <!--<remove-related relation-name="CustRequestItem" value-field="product"/>-->
                <remove-related relation-name="ProductRole" value-field="product"/>
                <remove-related relation-name="ProductKeyword" value-field="product"/>
                <remove-related relation-name="CustRequestItem" value-field="product"/>
                <remove-value value-field="product"/>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    <simple-method method-name="updateProductBacklog" short-description="">
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_UPDATE"/>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
               </or>
            </condition>
            <then>
                <call-simple-method method-name="getWebSiteId"/>
                <entity-one entity-name="CustRequest" value-field="custRequest">
                    <field-map field-name="custRequestId" from-field="parameters.custRequestId"/>
                </entity-one>
                <set field="update.custRequestId" from-field="parameters.custRequestId"/>
                <if-empty field="parameters.description">
                    <add-error >
                        <fail-message message="There Product Backlog Item is missing, Please add."/>
                    </add-error>
                    <check-errors/>
                </if-empty>
                <set field="update.description" from-field="parameters.description"/>
                <set field="update.parentCustRequestId" from-field="parameters.parentCustRequestId"/>
                <set-service-fields service-name="updateCustRequest" map="parameters" to-map="update"/>
                <set field="changeToMilliSec" value="${parameters.custEstimatedMilliSeconds *1000*60*60}"></set>
                <set field="update.custEstimatedMilliSeconds" from-field="changeToMilliSec" type="Double"/>
                <set field="update.fromPartyId" from-field="parameters.partyIdTo" default-value="${custRequest.fromPartyId}"/>
                <set field="update.custRequestTypeId" from-field="parameters.custRequestTypeId"/>
                <call-service service-name="updateCustRequest" in-map-name="update"/>
                <!-- Update CustRequestItem -->
                <entity-and entity-name="CustRequestItem" list="custRequestItemList">
                    <field-map field-name="custRequestId" from-field="parameters.custRequestId"/>
                </entity-and>
                <first-from-list list="custRequestItemList" entry="custRequestItemMap"/>
                <if-compare-field field="custRequestItemMap.productId" operator="not-equals" to-field="parameters.productId" type="String">
                    <set field="nullField" type="String"/>
                    <set field="custRequest.parentCustRequestId" from-field="nullField"/>
                    <store-value value-field="custRequest"/>
                    <set field="custRequestItemMap.productId" from-field="parameters.productId"/>
                    <store-value value-field="custRequestItemMap"/>
                </if-compare-field>
                
                <entity-and entity-name="CustRequestNoteView" list="custRequestNoteViews">
                    <field-map field-name="custRequestId" from-field="parameters.custRequestId"/>
                    <field-map field-name="noteName" value="How to test"/>
                </entity-and>
                
                <if-empty field="custRequestNoteViews">
                    <!-- create CustRequestNote -->
                    <if-not-empty field="parameters.noteInfo">
                        <make-value entity-name="CustRequestNote" value-field="newEntity"/>
                        <set from-field="parameters.custRequestId" field="newEntity.custRequestId"/>
                        <set field="newNoteMap.note" from-field="parameters.noteInfo"/>
                        <set field="newNoteMap.noteName" value="How to test"/>
                        <call-service service-name="createNote" in-map-name="newNoteMap" >
                            <result-to-field result-name="noteId" field="newEntity.noteId" />
                        </call-service>
                        <create-value value-field="newEntity"/>
                    </if-not-empty>
                    <else>
                        <!-- update noteData -->
                        <set-service-fields service-name="updateNote" map="parameters" to-map="updateNoteCtx"/>
                        <call-service service-name="updateNote" in-map-name="updateNoteCtx"/>
                    </else>
                </if-empty>
                <set field="productId" from-field="custRequestItem[0].productId"/>
                <field-to-request field="custRequestItem[0].productId" request-name="productId"/>
                <field-to-request field="parameters.sequence" request-name="sequence"/>
                <field-to-request field="parameters.UnplannedSequence" request-name="UnplannedSequence"/>
            </then>
        <else>
            <set field="_error_message_" value="You has no permission to perform this action."/>
            <return response-code="error"/>
        </else>
        </if>
    </simple-method>
    <simple-method method-name="createProductAndRole" short-description="">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PRODUCT" action="_CREATE"/>
                </or>
            </condition>
            <then>
                <now-timestamp field="nowTimestamp"/>
                <entity-one entity-name="UserLogin" value-field="sysUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <if-not-empty field="parameters.internalName">
                    <set field="product.internalName" from-field="parameters.internalName"/>
                    <set field="product.longDescription" from-field="parameters.longDescription"/>
                    <set field="product.productTypeId" value="SCRUM_ITEM"/>
                    <set field="product.introductionDate" from-field="nowTimestamp"/>
                    <set field="product.userLogin" from-field="sysUserLogin"/>
                    <call-service service-name="createProduct" in-map-name="product">
                        <result-to-field result-name="productId"/>
                    </call-service>
                    <!-- create ProductRole -->
                    <set field="partyId" from-field="parameters.partyId"/>
                    <set field="parameters.partyIdTo" from-field="partyId"/>
                    <set field="parameters.productId" from-field="productId"/>
                    <call-simple-method method-name="createProductRole"/>
                <else>
                    <set field="_error_message_" value="There is no product name."/>
                    <return response-code="error"/>
                </else>
                </if-not-empty>
                <field-to-request field="productId"/>
            </then>
        <else>
            <set field="_error_message_" value="You are has no permission to perform this action."/>
            <return response-code="error"/>
        </else>
        </if>
    </simple-method>
    
    <simple-method method-name="createProductRole"
        short-description="Create Product Role" login-required="true">
        <now-timestamp field="nowTimestamp" />
            <set field="partyCompany" from-field="parameters.partyCompany"/>
            <set field="companyId" value="${groovy:partyCompany.substring(partyCompany.indexOf('[')+1,partyCompany.indexOf(']'))}"/>
            <!-- Create partyPreson -->
            <entity-one entity-name="PartyRole" value-field="partyRoles">
                <field-map field-name="partyId" value="${parameters.partyId}"/>
                <field-map field-name="roleTypeId" value="PRODUCT_OWNER"/>
            </entity-one>
            <if-empty field="partyRoles">
                <make-value entity-name="PartyRole" value-field="partyRole"/>
                <set field="partyRole.partyId" value="${parameters.partyId}"/>
                <set field="partyRole.roleTypeId" value="PRODUCT_OWNER"/>
                <create-value value-field="partyRole"/>
            </if-empty>
            <make-value entity-name="ProductRole" value-field="productRole"/>
            <set field="productRole.productId" from-field="parameters.productId" />
                <set field="productRole.partyId" value="${parameters.partyId}"/>
            <set field="productRole.roleTypeId" value="PRODUCT_OWNER"/>
            <set field="productRole.fromDate" from-field="nowTimestamp" />
            <create-value value-field="productRole"/>
            <!-- Create partyCompany -->
            <entity-one entity-name="PartyRole" value-field="partyRoles">
                <field-map field-name="partyId" value="${companyId}"/>
                <field-map field-name="roleTypeId" value="PRODUCT_OWNER_COMP"/>
            </entity-one>
            <if-empty field="partyRoles">
                <make-value entity-name="PartyRole" value-field="partyRole"/>
                <set field="partyRole.partyId" value="${companyId}"/>
                <set field="partyRole.roleTypeId" value="PRODUCT_OWNER_COMP"/>
                <create-value value-field="partyRole"/>
            </if-empty>
            <make-value entity-name="ProductRole" value-field="productRole"/>
            <set field="productRole.productId" from-field="parameters.productId" />
            <set field="productRole.partyId" value="${companyId}"/>
            <set field="productRole.roleTypeId" value="PRODUCT_OWNER_COMP"/>
            <set field="productRole.fromDate" from-field="nowTimestamp" />
            <create-value value-field="productRole"/>
    </simple-method>
    
    <simple-method method-name="updateProduct" short-description="">
        <!-- CHECK PERMISSION -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM" action="_UPDATE"/>
                    <if-has-permission permission="SCRUM_PRODUCT" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PRODUCT" action="_UPDATE"/>
                </or>
            </condition>
            <then>
                <entity-one entity-name="UserLogin" value-field="systemUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <if-empty field="parameters.partyCompany">
                    <if-not-empty field="parameters.partyId">
                        <set field="partyCompany" value="${parameters.partyId}"/>
                        <if-compare operator="equals" value="Y" field="parameters.isCloseBtn">
                           <set field="companyId" from-field="parameters.companyId"/>
                           <entity-and entity-name="PartyRelationship" list="owner">
                               <field-map field-name="partyIdFrom" from-field="companyId"/>
                           </entity-and>
                           <!--<set field="partyOwnerId" from-field="userLogin.partyId"/>-->
                           <set field="partyOwnerId" from-field="owner[0].partyIdTo"/>
                        <else>
                           <set field="companyId" value="${groovy:partyCompany.substring(partyCompany.indexOf('[')+1,partyCompany.indexOf(']'))}"/>
                           <set field="partyOwnerId" value="${groovy:partyCompany.substring(partyCompany.indexOf('(')+1,partyCompany.indexOf(')'))}"/>
                        </else>
                        </if-compare>
                    </if-not-empty>
                    <else>
                        <set field="partyCompany" from-field="parameters.partyCompany"/>
                        <set field="companyId" value="${groovy:partyCompany.substring(partyCompany.indexOf('[')+1,partyCompany.indexOf(']'))}"/>
                        <set field="partyOwnerId" from-field="parameters.partyId"/>
                    </else>
                </if-empty>
                <if-not-empty field="companyId" >
                    <now-timestamp field="nowTimestamp"/>
                    <entity-and entity-name="ProductRole" list="productRoleList">
                        <field-map field-name="productId" from-field="parameters.productId"/>
                        <field-map field-name="roleTypeId" value="PRODUCT_OWNER_COMP"/>
                    </entity-and>
                    <if-empty field="productRoleList">
                        <entity-and entity-name="PartyRole" list="partyRoleList">
                            <field-map field-name="partyId" value="${companyId}"/>
                            <field-map field-name="roleTypeId" value="PRODUCT_OWNER_COMP"/>
                        </entity-and>  
                        <if-empty field="partyRoleList">
                            <make-value entity-name="PartyRole" value-field="partyRole"/>
                            <set field="partyRole.partyId" value="${companyId}"/>
                            <set field="partyRole.roleTypeId" value="PRODUCT_OWNER_COMP"/>
                            <create-value value-field="partyRole"/>
                        </if-empty>
                        <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayStart" ret-field="formDate">
                            <field field="nowTimestamp" type="java.sql.Timestamp"/>
                        </call-class-method>
                        <make-value entity-name="ProductRole" value-field="productRole"/>
                        <set field="productRole.productId" from-field="parameters.productId" />
                        <set field="productRole.partyId" value="${companyId}"/>
                        <set field="productRole.roleTypeId" value="PRODUCT_OWNER_COMP"/>
                        <set field="productRole.fromDate" from-field="nowTimestamp" type="Timestamp"/>
                        <create-value value-field="productRole"/>
                    </if-empty>
                    <log level="info" message="${productRoleList[0].partyId}"/>
                    <if-compare operator="not-equals" value="${companyId}" field="productRoleList[0].partyId">
                        <entity-and entity-name="ProductRole" list="ownerProductRoles" filter-by-date="true">
                            <field-map field-name="productId" from-field="parameters.productId"/>
                            <field-map field-name="roleTypeId" value="PRODUCT_OWNER"/>
                        </entity-and>
                        <if-not-empty field="ownerProductRoles">
                           <first-from-list list="ownerProductRoles" entry="ownerProductRole"/>
                           <set-service-fields service-name="removePartyFromProduct" to-map="removeProductOwnerRole" map="ownerProductRole"/>
                           <set field="removeProductOwnerRole.userLogin" from-field="systemUserLogin"/>
                           <call-service service-name="removePartyFromProduct" in-map-name="removeProductOwnerRole"/>
                        </if-not-empty>
                        <entity-and entity-name="ProductRole" list="companyRoles" filter-by-date="true">
                            <field-map field-name="productId" from-field="parameters.productId"/>
                            <field-map field-name="roleTypeId" value="PRODUCT_OWNER_COMP"/>
                            <field-map field-name="partyId" from-field="productRoleList[0].partyId"/>
                        </entity-and>
                        <if-not-empty field="companyRoles">
                            <first-from-list list="companyRoles" entry="companyRole"/>
                            <set-service-fields service-name="removePartyFromProduct" to-map="removeCompanyRole" map="companyRole"/>
                            <set field="removeCompanyRole.userLogin" from-field="systemUserLogin"/>
                            <call-service service-name="removePartyFromProduct" in-map-name="removeCompanyRole"/>
                        </if-not-empty>
                        
                        <set field="updateProdOwner.partyId" from-field="partyOwnerId"/>
                        <set field="updateProdOwner.roleTypeId" value="PRODUCT_OWNER"/>
                        <set field="updateProdOwner.productId" from-field="parameters.productId"/>
                        <set field="updateProdOwner.fromDate" from-field="productRole.fromDate"/>
                        <set field="updateProdOwner.userLogin" from-field="systemUserLogin"/>
                        <call-service service-name="addPartyToProduct" in-map-name="updateProdOwner"/>
                        <entity-and entity-name="ProductRole" list="productCompList">
                            <field-map field-name="productId" from-field="parameters.productId"/>
                            <field-map field-name="partyId" from-field="companyId"/>
                            <field-map field-name="roleTypeId" value="PRODUCT_OWNER_COMP"/>
                        </entity-and>
                        <if-empty field="productCompList">
                            <make-value entity-name="ProductRole" value-field="productComp"/>
                            <set field="productComp.productId" from-field="parameters.productId" />
                            <set field="productComp.partyId" value="${companyId}"/>
                            <set field="productComp.roleTypeId" value="PRODUCT_OWNER_COMP"/>
                            <set field="productComp.fromDate" from-field="nowTimestamp"/>
                            <create-value value-field="productComp"/>
                        </if-empty>
                    </if-compare>
                    <entity-one entity-name="UserLogin" value-field="sysUserLogin">
                        <field-map field-name="userLoginId" value="system"/>
                    </entity-one>
                    <set field="update.productId" from-field="parameters.productId"/>
                    <set field="update.internalName" from-field="parameters.internalName"/>
                    <if-compare field="parameters.statusId" operator="equals" value="PRODUCT_CLOSED">
                        <set field="update.supportDiscontinuationDate" from-field="nowTimestamp"/>
                    </if-compare>
                    <set field="update.longDescription" from-field="parameters.longDescription"/>
                    <set field="update.userLogin" from-field="sysUserLogin"/>
                    <call-service service-name="updateProduct" in-map-name="update"/>
                    <if-compare operator="equals" value="PRODUCT_CLOSED" field="parameters.statusId">
                        <!-- Commplete Default Tasks -->
                        <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                            <field-map field-name="productId" from-field="parameters.productId"/>
                            <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                        </entity-and>
                        <if-not-empty field="defaultTaskList">
                            <iterate list="defaultTaskList" entry="defaultTaskMap">
                                <set field="defaultTaskMap.currentStatusId" value="STS_COMPLETED"/>
                                <store-value value-field="defaultTaskMap"/>
                            </iterate>
                        </if-not-empty>
                        <!-- Close The Project -->
                        <entity-and entity-name="WorkEffortAndProduct" list="projects">
                            <field-map field-name="productId" from-field="parameters.productId"/>
                            <field-map field-name="workEffortTypeId" value="SCRUM_PROJECT"/>
                        </entity-and>
                        <if-not-empty field="projects">
                           <iterate list="projects" entry="project">
                               <set field="workEffortId" from-field="project.workEffortId"/>
                               <set field="projectId" from-field="project.workEffortId"/>
                               <set field="parameters.workEffortId" from-field="workEffortId"/>
                               <set field="parameters.projectId" from-field="projectId"/>
                               <set field="parameters.currentStatusId" value="SPJ_CLOSED"/>
                               <call-simple-method method-name="updateScrumProject"/>
                           </iterate>
                        </if-not-empty>
                    </if-compare>
                <else>
                    <set field="_error_message_" value="Please Select the Product Owner and Company"/>
                    <return response-code="error"/>
                </else>
                </if-not-empty>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if> 
    </simple-method>
    
    <simple-method method-name="createDailyNote" short-description="Create Daily Meeting Minute Note">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_DAILY" action="_CREATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <now-timestamp field="nowTimestamp"/>
                <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayStart" ret-field="noteDateTime">
                    <field field="nowTimestamp" type="java.sql.Timestamp"/>
                </call-class-method>
    
                <if-not-empty field="parameters.noteInfo1">
                    <make-value entity-name="NoteData" value-field="noteData"/>
                    <sequenced-id sequence-name="NoteData" field="noteId"/>
                    <set field="noteData.noteId" from-field="noteId"/>
                    <set field="noteData.noteName" from-field="parameters.noteName1"/>
                    <set field="noteData.noteInfo" from-field="parameters.noteInfo1"/>
                    <set field="noteData.noteParty" from-field="userLogin.partyId"/>
                    <set field="noteData.noteDateTime" from-field="noteDateTime" type="Timestamp"/>
                    <create-value value-field="noteData"/>
                    
                    <make-value entity-name="WorkEffortNote" value-field="newWorkEffortNote"/>
                    <set from-field="noteId" field="newWorkEffortNote.noteId"/>
                    <set from-field="parameters.workEffortId" field="newWorkEffortNote.workEffortId"/>
                    <create-value value-field="newWorkEffortNote"/>
                    
                    <make-value entity-name="NoteData" value-field="noteData"/>
                </if-not-empty>
                
                <if-not-empty field="parameters.noteInfo2">
                    <make-value entity-name="NoteData" value-field="noteData"/>
                    <sequenced-id sequence-name="NoteData" field="noteId"/>
                    <set field="noteData.noteId" from-field="noteId"/>
                    <set field="noteData.noteName" from-field="parameters.noteName2"/>
                    <set field="noteData.noteInfo" from-field="parameters.noteInfo2"/>
                    <set field="noteData.noteParty" from-field="userLogin.partyId"/>
                    <set field="noteData.noteDateTime" from-field="noteDateTime" type="Timestamp"/>
                    <create-value value-field="noteData"/>
                    
                    <make-value entity-name="WorkEffortNote" value-field="newWorkEffortNote"/>
                    <set from-field="noteId" field="newWorkEffortNote.noteId"/>
                    <set from-field="parameters.workEffortId" field="newWorkEffortNote.workEffortId"/>
                    <create-value value-field="newWorkEffortNote"/>
                    
                    <make-value entity-name="NoteData" value-field="noteData"/>
                </if-not-empty>
                
                <if-not-empty field="parameters.noteInfo3">
                    <make-value entity-name="NoteData" value-field="noteData"/>
                    <sequenced-id sequence-name="NoteData" field="noteId"/>
                    <set field="noteData.noteId" from-field="noteId"/>
                    <set field="noteData.noteName" from-field="parameters.noteName3"/>
                    <set field="noteData.noteInfo" from-field="parameters.noteInfo3"/>
                    <set field="noteData.noteParty" from-field="userLogin.partyId"/>
                    <set field="noteData.noteDateTime" from-field="noteDateTime" type="Timestamp"/>
                    <create-value value-field="noteData"/>
                    
                    <make-value entity-name="WorkEffortNote" value-field="newWorkEffortNote"/>
                    <set from-field="noteId" field="newWorkEffortNote.noteId"/>
                    <set from-field="parameters.workEffortId" field="newWorkEffortNote.workEffortId"/>
                    <create-value value-field="newWorkEffortNote"/>
                    
                    <make-value entity-name="NoteData" value-field="noteData"/>
                </if-not-empty>
                <field-to-request field="parameters.workEffortId" request-name="projectId"/>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="updateDailyNote" short-description="Update Daily Meeting Minute Note">
    <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_DAILY" action="_UPDATE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </or>
        </condition>
        <then>
            <set field="update.workEffortId" from-field="parameters.workEffortId"/>
            <set field="update.noteId" from-field="parameters.noteId"/>
            <set field="update.internalNote" value="N"/>
            <call-service service-name="updateWorkEffortNote" in-map-name="update"/>
            <set field="_event_message_" value="Daily Meeting Minutes has been updated."/>
        </then>
        <else>
            <set field="_error_message_" value="You are has no permission to perform this action."/>
            <return response-code="error"/>
        </else>
    </if>
    </simple-method>
    
    <simple-method method-name="updateTask" short-description="Update Task">
        <!-- Update planned hours -->
        <!-- If a task have time entry, planned hours will update last time entry of task and always update in estimatedMilliSeconds field of task  -->
        <calculate field="parameters.estimatedMilliSeconds" type="Float">
            <calcop operator="multiply" field="parameters.planHours">
                <number value="3600000"/>
            </calcop>
        </calculate>
        <!-- update if task has TimeEntry -->
        <entity-condition entity-name="TimeEntry" list="lastTimeEntrys">
            <condition-list combine="and">
                <condition-expr field-name="workEffortId" from-field="parameters.workEffortId"/>
            </condition-list>
            <order-by field-name="-fromDate"/>
        </entity-condition>
        <entity-and entity-name="ProjectSprintBacklogAndTask" list="meetingTasks">
            <field-map field-name="taskId" from-field="parameters.taskId"/>
            <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>
            <field-map field-name="custRequestTypeId" value="RF_SCRUM_MEETINGS"/>
        </entity-and>
        <if-empty field="meetingTasks">
            <first-from-list list="lastTimeEntrys" entry="lastTimeEntry"/>
            <if-not-empty field="lastTimeEntry">
                <set field="lastTimeEntry.planHours" from-field="parameters.planHours" type="Double"/>
                <set field="parameters.timeEntryId" from-field="lastTimeEntry.timeEntryId"/>
                <set field="parameters.timesheetId" from-field="lastTimeEntry.timesheetId"/>
                <set field="parameters.planHours" from-field="lastTimeEntry.planHours"/>
                <call-simple-method method-name="updateScrumTimeEntry"/>
            </if-not-empty>
        </if-empty>
        
        <set-service-fields service-name="updateWorkEffort" map="parameters" to-map="inMap"/>
        <call-service service-name="updateWorkEffort" in-map-name="inMap"/>
        <if-not-empty field="parameters.partyId">
        <!-- Assigned -->
            <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                <condition-list combine="and">
                    <condition-expr field-name="partyId" from-field="parameters.partyId"/>
                    <condition-expr field-name="statusId" value="SCAS_ASSIGNED"/>
                    <condition-expr field-name="workEffortId" from-field="parameters.workEffortId"/>
                </condition-list>
            </entity-condition>
            
            <if-empty field="assigneds">
                <!-- get roletype from sprint member -->
                <entity-condition entity-name="ProjectSprintBacklogAndTask" list="sprintList">
                    <condition-list combine="and">
                        <condition-expr field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                        <condition-expr field-name="taskId" from-field="parameters.workEffortId"/>
                    </condition-list>
                </entity-condition>
                <first-from-list list="sprintList" entry="sprint"/>
                <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintRoles">
                    <condition-list combine="and">
                        <condition-expr field-name="partyId" from-field="parameters.partyId"/>
                        <condition-expr field-name="workEffortId" from-field="sprint.sprintId"/>
                        <condition-expr field-name="roleTypeId" value="SCRUM_TEAM"/>
                    </condition-list>
                </entity-condition>
                <!-- Use when role type id still empty -->
                <entity-and entity-name="ScrumPersonAndCompanyAndSecurityGroup" list="roleList">
                    <field-map field-name="partyId" from-field="parameters.partyId"/>
                    <field-map field-name="groupId" value="SCRUM_TEAM"/>
                </entity-and>
                <entity-and entity-name="WorkEffortPartyAssignment" list="assigneds">
                    <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                </entity-and>
                <entity-one entity-name="UserLogin" value-field="systemUserLogin">
                    <field-map field-name="userLoginId" value="system"/>
                </entity-one>
                <iterate list="assigneds" entry="assigned">
                    <remove-value value-field="assigned"/>
                </iterate>
                <set field="newInput.partyId" from-field="parameters.partyId"/>
                <set field="newInput.workEffortId" from-field="parameters.workEffortId"/>
                <if-not-empty field="sprintRoles[0].roleTypeId">
                    <set field="newInput.roleTypeId" from-field="sprintRoles[0].roleTypeId"/>
                    <else>
                        <set field="newInput.roleTypeId" from-field="roleList[0].groupId"/>
                    </else>
                </if-not-empty>
                <set field="newInput.statusId" value="SCAS_ASSIGNED"/>
                <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
            </if-empty>
        </if-not-empty>
        
        <!--if plan hours(from task) more than first plan hours -->
        <entity-and entity-name="CustRequestWorkEffort" list="custRequestWorkEffortList">
            <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
        </entity-and>
        <first-from-list list="custRequestWorkEffortList" entry="custRequestWorkEffortMap"/>
        <set field="backlogPlanMap.custRequestId" from-field="custRequestWorkEffortMap.custRequestId" />
        <set field="taskPlanMap.custRequestId" from-field="custRequestWorkEffortMap.custRequestId" />
        <call-service service-name="getScrumPlanHour" in-map-name="backlogPlanMap">
            <result-to-field result-name="planHours" />
        </call-service>
        <call-service service-name="getScrumPlanHour" in-map-name="taskPlanMap">
            <result-to-field result-name="initPlanHours"/>
        </call-service>
        <if-compare-field field="planHours"  operator="greater" to-field="initPlanHours"  type="Double">
            <entity-one entity-name="CustRequest" value-field="custRequestMap">
                <field-map field-name="custRequestId" from-field="custRequestWorkEffortMap.custRequestId"/>
            </entity-one>
            <set field="planHoursIn" from-field="planHours" type="Double"/>
            <set field="custRequestMap.custEstimatedMilliSeconds" value="${groovy:planHoursIn*1000*60*60}" type="Double"/>
            <store-value value-field="custRequestMap"/>
            <else>
                <if-compare-field field="initPlanHours"  operator="greater" to-field="planHours"  type="Double">
                    <entity-one entity-name="CustRequest" value-field="custRequestMap">
                        <field-map field-name="custRequestId" from-field="custRequestWorkEffortMap.custRequestId"/>
                    </entity-one>
                    <set field="planHoursIn" from-field="planHours" type="Double"/>
                    <set field="custRequestMap.custEstimatedMilliSeconds" value="${groovy:planHoursIn*1000*60*60}" type="Double"/>
                    <store-value value-field="custRequestMap"/>
                </if-compare-field>
            </else>
        </if-compare-field>
    </simple-method>
    <!-- Task Note -->
    <simple-method method-name="createTaskNote" short-description="Create Task Note">
        <if-empty field="parameters.noteName">
            <set field="newNoteMap.noteName" value="Task Note"/>
            <else>
                <set field="newNoteMap.noteName" from-field="parameters.noteName"/>
            </else>
        </if-empty>
        <if-empty field="parameters.noteInfo">
            <add-error>
                <fail-message message="Can not empty noteInfo"/>
            </add-error>
            <check-errors/>
            <else>
                <set field="newNoteMap.note" from-field="parameters.noteInfo"/>
            </else>
        </if-empty>
        <if-not-empty field="parameters.workEffortId">
            <call-service service-name="createNote" in-map-name="newNoteMap">
                <result-to-field result-name="noteId" field="noteId"/>
            </call-service>
            <make-value entity-name="WorkEffortNote" value-field="newEntity"/>
            <set field="newEntity.workEffortId" from-field="parameters.workEffortId" />
            <set field="newEntity.noteId" from-field="noteId" />
            <set field="newEntity.internalNote" value="Y"/>
            <create-value value-field="newEntity"/>
        </if-not-empty>
    </simple-method>
    <simple-method method-name="deleteTaskNote" short-description="Delete Task Note">
        <entity-one entity-name="WorkEffortNote" value-field="workNoteMap" auto-field-map="true"/>
        <remove-value value-field="workNoteMap"/>
        <remove-related relation-name="NoteData" value-field="workNoteMap"/>
    </simple-method>
    <simple-method method-name="DeleteTaskFromSprintOverview" short-description="Delete Task From Sprint Overview Screen">
        <entity-one entity-name="CustRequestWorkEffort" value-field="taskWorkEffort">
            <field-map field-name="workEffortId" from-field="parameters.workEffort"/>
            <field-map field-name="custRequestId" from-field="parameters.custRequestId"/>
        </entity-one>
        <remove-value value-field="taskWorkEffort"/>
    </simple-method>
    
    <simple-method method-name="deleteScrumResource" short-description="remove scrum resource">
        <now-timestamp field="nowTimestamp" />
        <entity-and entity-name="UserLoginSecurityGroup" list="userLoginSecurityGroups">
            <field-map field-name="userLoginId" from-field="parameters.userLoginId"/>
            <field-map field-name="groupId" from-field="parameters.groupId"/>
        </entity-and>
        <if-not-empty field="userLoginSecurityGroups">
            <iterate list="userLoginSecurityGroups" entry="userLoginSecurityGroup">
                <set field="userLoginSecurityGroup.thruDate" from-field="nowTimestamp"/>
                <store-value value-field="userLoginSecurityGroup"/>
            </iterate>
        </if-not-empty>
    </simple-method>
    
    <simple-method method-name="assignPartyToWorkEffort" short-description="Assign Party To WorkEffort">
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set-service-fields service-name="assignPartyToWorkEffort" map="parameters" to-map="assignPartyToWorkEffortCtx"/>
        <set field="assignPartyToWorkEffortCtx.userLogin" from-field="sysUserLogin"/>
        <entity-condition entity-name="PartyRole" list="partyRoleList">
            <condition-expr field-name="partyId" from-field="assignPartyToWorkEffortCtx.partyId"/>
            <select-field field-name="roleTypeId"/>
        </entity-condition>
        <if-not-empty field="partyRoleList">
            <iterate list="partyRoleList" entry="partyRoleMap">
                <if>
                <condition>
                    <and>
                        <or>
                            <if-compare field="partyRoleMap.roleTypeId" operator="equals" value="SCRUM_MASTER"/>
                            <if-compare field="partyRoleMap.roleTypeId" operator="equals" value="SCRUM_TEAM"/>
                        </or>
                        <if-compare field="assignPartyToWorkEffortCtx.roleTypeId" operator="equals" value="PRODUCT_OWNER" ></if-compare>
                    </and>
                </condition>
                <then>
                    <add-error>
                        <fail-property resource="scrumUiLabels" property="ScrumPartyAssignmentError"/>
                    </add-error>
                    <check-errors/>
                </then>
                </if>
            </iterate>
        </if-not-empty>
        <call-service service-name="assignPartyToWorkEffort" in-map-name="assignPartyToWorkEffortCtx"/>
    </simple-method>
    
    <simple-method method-name="createTestTask" short-description="Create A test task">
        <call-class-method class-name="org.apache.ofbiz.content.layout.LayoutWorker" method-name="uploadImageAndParameters" ret-field="formInput">
            <field field="request" type="javax.servlet.http.HttpServletRequest"/>
            <string value="uploadedFile"/>
        </call-class-method>
        <entity-one entity-name="UserLogin" value-field="systemUser">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <!--<log level="info" message="=========================parameters:${formInput.formInput}"></log>-->
        <if-not-empty field="formInput.formInput.workEffortName">
            <set-service-fields service-name="createWorkEffortAndPartyAssign" map="formInput.formInput" to-map="assignPartyToWorkEffortCtx"/>
            <set field="assignPartyToWorkEffortCtx.userLogin" from-field="systemUser"/>
            <call-service service-name="createWorkEffortAndPartyAssign" in-map-name="assignPartyToWorkEffortCtx" include-user-login="false" >
                <result-to-field result-name="workEffortId" field="workEffortId"/>
            </call-service>
            <field-to-request field="workEffortId"/>
            <set field="formInput.formInput.workEffortId" from-field="workEffortId"/>
            <set-service-fields service-name="createWorkEffortRequest" map="formInput.formInput" to-map="workEffortRequestCtx"/>
            <call-service service-name="createWorkEffortRequest" in-map-name="workEffortRequestCtx"/>
            
            <!-- createWorkEffortRequest not provide to add the workEffortParentId into WorkEffort entity. -->
            <!-- So, we have to add to the entity manualy -->
            <entity-one entity-name="WorkEffort" value-field="taskInfo">
                <field-map field-name="workEffortId"/>
            </entity-one>
            <if-not-empty field="formInput.formInput.sprintId">
                <set field="taskInfo.workEffortParentId" from-field="formInput.formInput.sprintId"/>
                <store-value value-field="taskInfo"/>
            </if-not-empty>
            <set field="workEffortParentId" from-field="formInput.formInput.sprintId"/>
            <set field="custRequestId" from-field="formInput.formInput.custRequestId"/>
            <field-to-request field="workEffortParentId"/>
            <field-to-request field="custRequestId"/>
            <else>
                <set field="projectId" from-field="formInput.formInput.projectId"/>
                <set field="custRequestId" from-field="formInput.formInput.custRequestId"/>
                <set field="sprintId" from-field="formInput.formInput.sprintId"/>
                <field-to-request field="projectId"/>
                <field-to-request field="sprintId"/>
                <field-to-request field="custRequestId"/>
                <add-error>
                    <fail-message message="Please insert the Task Name"/>
                    </add-error>
                <check-errors/>
            </else>
        </if-not-empty>
        <if-not-empty field="formInput.imageFileName">
            <add-error><fail-message message="Upload file is missing..."/></add-error> 
            <set field="parameters.imageFileName" from-field="formInput.imageFileName"/>
            
            <!-- Create Data Resource -->
            <set-service-fields service-name="createContentFromUploadedFile"
                map="formInput.formInput" to-map="data"/>
            <set field="data.dataResourceTypeId" value="LOCAL_FILE"/>
            <set field="data.dataTemplateTypeId" value="NONE"/>
            <set field="data.dataCategoryId" from-field="formInput.formInput.dataCategoryId"/>
            <set field="data.userLogin" from-field="systemUser"/>
            <set field="data.statusId" from-field="formInput.formInput.resourceStatusId"/>
            <set field="data.dataResourceName" from-field="formInput.imageFileName"/>
            <set field="data.mimeTypeId" from-field="mimeType.mimeTypeId"/>
            <set field="data.uploadedFile" from-field="formInput.imageData"/>
            <set field="data._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="data._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <call-service service-name="createDataResource" in-map-name="data">
                <result-to-field result-name="dataResourceId" field="parameters.dataResourceId"/>
            </call-service>
            <!-- Create attach upload to data resource -->
            <set-service-fields service-name="attachUploadToDataResource" map="formInput.formInput"
                to-map="attachMap"/>
            <set field="attachMap.uploadedFile" from-field="formInput.imageData"/>
            <set field="attachMap._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="attachMap._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <set field="attachMap.dataResourceId" from-field="parameters.dataResourceId"/>
            <set field="attachMap.mimeTypeId" from-field="mimeType.mimeTypeId"/>
            <call-service service-name="attachUploadToDataResource" in-map-name="attachMap"/>
            <!-- Create content from dataResource -->
            <set-service-fields service-name="createContentFromDataResource"
                map="formInput.formInput" to-map="contentMap"/>
            <set field="contentMap.roleTypeId" from-field="formInput.formInput.roleTypeId"/>
            <set field="contentMap.partyId" from-field="formInput.formInput.partyId"/>
            <set field="contentMap.contentTypeId" from-field="formInput.formInput.contentTypeId"/>
            <set field="contentMap.dataResourceId" from-field="parameters.dataResourceId"/>
            <set field="contentMap.userLogin" from-field="systemUser"/>
            <call-service service-name="createContentFromDataResource" in-map-name="contentMap">
                <result-to-field result-name="contentId" field="formInput.formInput.contentId"/>
            </call-service>
            <!-- Create WorkEffort Content -->
            <set-service-fields service-name="createWorkEffortContent" map="formInput.formInput" to-map="workEffortContent"/>
            <set field="workEffortContent.userLogin" from-field="systemUser"/>
            <set field="workEffortContent.workEffortContentTypeId" from-field="formInput.formInput.workEffortContentTypeId"/>
            <call-service service-name="createWorkEffortContent" in-map-name="workEffortContent"/>
            
            <set field="workEffortParentId" from-field="formInput.formInput.workEffortParentId"/>
            <set field="custRequestId" from-field="formInput.formInput.custRequestId"/>
            <field-to-request field="workEffortParentId"/>
            <field-to-request field="custRequestId"/>
        </if-not-empty>
        <!-- Re-opened the backlog for status CRQ_COMPLETED -->
        <entity-condition entity-name="CustRequest" list="custCompletedList">
            <condition-list combine="and">
                <condition-expr field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
                <condition-expr field-name="statusId" operator="equals" value="CRQ_COMPLETED"/>
            </condition-list>
        </entity-condition>
        <if-not-empty field="custCompletedList">
            <first-from-list list="custCompletedList" entry="custRequestMap"/>
            <if>
                <condition>
                    <and>
                        <if-compare field="formInput.formInput.sprintStatusId" operator="equals" value="SPRINT_CLOSED"/>
                        <if-compare field="custRequestMap.custRequestTypeId" operator="not-equals" value="RF_UNPLAN_BACKLOG"/>
                    </and>
                </condition>
                <then>
                    <get-related relation-name="CustRequestWorkEffort" list="custRequestWorkEffortList" value-field="custRequestMap"/>
                    <!-- Remove the backlog from sprint -->
                    <if-not-empty field="custRequestWorkEffortList">
                        <iterate list="custRequestWorkEffortList" entry="custRequestWorkEffortMap">
                            <get-related-one relation-name="WorkEffort" value-field="custRequestWorkEffortMap" to-value-field="workEffortMap" />
                            <if-compare field="workEffortMap.workEffortTypeId" operator="equals" value="SCRUM_SPRINT" >
                                <remove-value value-field="custRequestWorkEffortMap"/>
                            </if-compare>
                        </iterate>
                    </if-not-empty>
                    <make-value entity-name="CustRequest" value-field="custRequestMap"/>
                    <set field="custRequestMap.custRequestId" from-field="formInput.formInput.custRequestId"/>
                    <set field="custRequestMap.custRequestTypeId" value="RF_UNPLAN_BACKLOG"/>
                    <store-value value-field="custRequestMap"/>
                </then>
            </if>
            <!-- set custRequest status -->
            <set field="setCustStatus.custRequestId" from-field="formInput.formInput.custRequestId"/>
            <set field="setCustStatus.statusId" value="CRQ_REOPENED"/>
            <call-service service-name="setCustRequestStatus" in-map-name="setCustStatus"/>
            <!-- Create default task (task installation and task test) -->
            <entity-and entity-name="CustRequest" list="backlog">
                <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
            </entity-and>
            <entity-and entity-name="ProjectSprintBacklogAndTask" list="projectAndTaskList">
                <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
                <select-field field-name="projectId"/>
                <select-field field-name="sprintId"/>
            </entity-and>
            <entity-and entity-name="UnPlannedBacklogsAndTasks" list="unPlannedTasks">
                <field-map field-name="custRequestId" from-field="formInput.formInput.custRequestId"/>
                <field-map field-name="workEffortId" from-field="formInput.formInput.workEffortId"/>
                <select-field field-name="productId"/>
            </entity-and>
            <if-not-empty field="projectAndTaskList">
                <first-from-list list="projectAndTaskList" entry="projectAndTaskMap"/>
                <entity-and entity-name="WorkEffortAndProduct" list="productList">
                    <field-map field-name="workEffortId" from-field="projectAndTaskMap.projectId"/>
                    <select-field field-name="productId"/>
                </entity-and>
                <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                    <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                    <field-map field-name="productId" from-field="productList[0].productId"/>
                </entity-and>
                <else>
                    <first-from-list list="unPlannedTasks" entry="unPlannedTaskMap"/>
                    <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                        <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                        <field-map field-name="productId" from-field="unPlannedTaskMap.productId"/>
                    </entity-and>
                </else>
            </if-not-empty>
            <if-not-empty field="defaultTaskList">
                <iterate list="defaultTaskList" entry="defaultTask">
                    <set field="workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                    <if>
                        <condition>
                            <and>
                                <or>
                                    <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortTypeId"/>
                                    <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                </or>
                            </and>
                        </condition>
                        <then>
                            <call-simple-method method-name="callCreateDefaultTasks"/>
                        </then>
                    </if>
                </iterate>
                <else>
                    <!-- If not have default task in product level -->
                    <entity-and entity-name="WorkEffort" list="defaultTaskList">
                        <field-map field-name="workEffortPurposeTypeId" value="SYSTEM_DEFAULT_TASK"/>
                    </entity-and>
                    <if-not-empty field="defaultTaskList">
                        <iterate list="defaultTaskList" entry="defaultTask">
                            <set field="workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                            <if>
                                <condition>
                                    <and>
                                        <or>
                                            <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortTypeId"/>
                                            <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                        </or>
                                    </and>
                                </condition>
                                <then>
                                    <call-simple-method method-name="callCreateDefaultTasks"/>
                                </then>
                            </if>
                        </iterate>
                    </if-not-empty>
                </else>
            </if-not-empty>
        </if-not-empty>
    </simple-method>

    <simple-method method-name="closeSprint" short-description="">
        <if>
        <condition>
            <or>
                <if-has-permission permission="SCRUM_SPRINT" action="_UPDATE"/>
                <if-has-permission permission="SCRUM_DAILY" action="_CREATE"/>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
                <if-has-permission permission="SCRUM_ROLE" action="_ADMIN"/>
            </or>
        </condition> 
        <then>
        <call-simple-method method-name="getWebSiteId"/>
        <set field="SprintId" from-field="parameters.sprintId"/>
        <set field="ProjectId" from-field="parameters.projectId"/>
            <entity-one entity-name="WorkEffort" value-field="sprint">
                <field-map field-name="workEffortId" from-field="SprintId"/>
            </entity-one>
            <now-timestamp field="curDate"/>
            <set field="curDate" type="Timestamp"/>
            <set field="status" value="SPRINT_CLOSED"/>
            <if-not-empty  field="sprint.actualCompletionDate">
                <entity-condition entity-name="ProjectSprintBacklogAndTask" list="listBackNotComplete" distinct="true">
                    <condition-list combine="and">
                        <condition-expr field-name="sprintId" operator="equals" from-field="sprint.workEffortId"/>
                        <condition-expr field-name="taskCurrentStatusId" operator="not-equals" value="STS_COMPLETED"/>
                        <condition-expr field-name="custRequestTypeId" operator="equals" value="RF_PROD_BACKLOG"/>
                        <condition-expr field-name="backlogStatusId" operator="equals" value="CRQ_REVIEWED"/>
                    </condition-list>
                    <select-field field-name="custRequestId"/>
                    <select-field field-name="description"/>
                </entity-condition> 
                <loop count="${groovy: listBackNotComplete.size()}" field="i">
                    <if-compare operator="equals" value="0" field="i" type="Integer">
                        <set field="tempBacklog" value="${listBackNotComplete[i].description}[${listBackNotComplete[i].custRequestId}]"/>
                    <else>
                        <set field="tempBacklog" value=", ${listBackNotComplete[i].description}[${listBackNotComplete[i].custRequestId}]"/>
                    </else>
                    </if-compare>
                    <set field="backlog" value="${backlog} ${tempBacklog}"/>
                    <entity-condition entity-name="CustRequestAndWorkEffort" list="taskInSprintBacklogs">
                        <condition-list combine="and">
                            <condition-expr field-name="custRequestId" from-field="listBackNotComplete[i].custRequestId"/>
                            <condition-expr field-name="workEffortTypeId" value="SCRUM_SPRINT" operator="not-equals"/>
                        </condition-list>
                    </entity-condition>
                    <!--  Grouping Sprint and Customer Request -->
                    <set field="input.custRequestId" from-field="listBackNotComplete[i].custRequestId"/>
                    <set field="input.workEffortId" from-field="sprint.workEffortId"/>
                    <call-service service-name="deleteWorkEffortRequest" in-map-name="input"/>
 
                    <!-- Change CustRequest status back to Accepted-->
                    <set field="setCustRequestStatusCtx.custRequestId" from-field="listBackNotComplete[i].custRequestId"/>
                    <set field="setCustRequestStatusCtx.statusId" value="CRQ_ACCEPTED"/>
                    <set field="setCustRequestStatusCtx.webSiteId" from-field="parameters.webSiteId"/>
                    <call-service service-name="setCustRequestStatus" in-map-name="setCustRequestStatusCtx"/>
                </loop>
                
                <!--<entity-condition entity-name="ProjectSprintBacklogAndTask" list="sprintTaskList">
                    <condition-list combine="and">
                        <condition-expr field-name="sprintId" operator="equals" from-field="sprint.workEffortId"/>
                        <condition-expr field-name="taskCurrentStatusId" operator="not-equals" value="STS_COMPLETED"/>
                        <condition-list combine="or">
                            <condition-expr field-name="taskTypeId" operator="equals" value="SCRUM_TASK_IMPL"/>
                            <condition-expr field-name="taskTypeId" operator="equals" value="SCRUM_TASK_ERROR"/>
                            <condition-expr field-name="taskTypeId" operator="equals" value="SCRUM_TASK_INST"/>
                            <condition-expr field-name="taskTypeId" operator="equals" value="SCRUM_TASK_TEST"/>
                        </condition-list>
                    </condition-list>
                </entity-condition>
                <loop count="${groovy: sprintTaskList.size()}" field="j">
                    <set field="parameters.workEffortId" from-field="sprintTaskList[j].taskId"/>
                    <call-simple-method method-name="setTaskStatusToComplete"/>
                </loop>-->
                
                <!-- Change Sprint status to close -->
                <set field="updateSprint.workEffortId" from-field="sprint.workEffortId"/>
                <set field="updateSprint.currentStatusId" value="SPRINT_CLOSED"/>
                <set field="updateSprint.webSiteId" from-field="parameters.webSiteId"/>
                <call-service service-name="updateWorkEffort" in-map-name="updateSprint"/>
                <if-empty field="parameters.isCloseBtn">
                    <if-not-empty field="listBackNotComplete">
                        <set field="_event_message_" value="Moved out the following Product Backlogs : ${backlog}"/>
                    </if-not-empty>
                </if-empty>
                    
            </if-not-empty>
        </then>
            <else>
                <set field="_error_message_" value="You has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="createProductBacklogCategory" short-description="Create a product backlog's category">
             <if-empty field="parameters.productId">
                <add-error><fail-message message="You have to specify product's ID"/></add-error>
            </if-empty>
            <if-empty field="parameters.custRequestName">
                <add-error><fail-message message="You have to specify category's name"/></add-error>
            </if-empty>
            <check-errors/>
            <if>
                <condition>
                    <or>
                        <if-has-permission permission="SCRUM" action="_ADMIN"/>
                        <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_ADMIN"/>
                        <if-has-permission permission="SCRUM_PRODUCT" action="_ADMIN"/>
                        <if-has-permission permission="SCRUM_PRODUCT" action="_VIEW"/>
                    </or>
                </condition>
                <then>
                    <entity-one entity-name="UserLogin" value-field="sysUserLogin">
                        <field-map field-name="userLoginId" value="system"/>
                    </entity-one>
                    <set field="userlogin" from-field="sysUserLogin"/>
                    <!-- create cust request -->
                    <set field="createCustRequestInMap.custRequestName" from-field="parameters.custRequestName"/>
                    <set field="createCustRequestInMap.productId" from-field="parameters.productId"/>
                    <set field="createCustRequestInMap.custRequestTypeId" value="RF_PARENT_BACKLOG"/>
                    <set field="createCustRequestInMap.statusId" value="CRQ_DRAFT"/>
                    <set field="createCustRequestInMap.fromPartyId" value="_NA_"/>
                    <set field="createCustRequestInMap.userLogin" from-field="userlogin"/>
                    <call-service service-name="createCustRequest" in-map-name="createCustRequestInMap">
                        <result-to-field result-name="custRequestId"/>
                    </call-service>
                </then>
            <else>
                <add-error><fail-message message="You don't have permission to create category"/></add-error>
                <check-errors/>
            </else>
            </if>
        <add-error>
            <fail-message message="Permission Error"/>
        </add-error>
    </simple-method>
    
    <simple-method method-name="updateProductBacklogCategory" short-description="Update a product backlog's category">
        <if-empty field="parameters.productId">
            <add-error><fail-message message="You have to specify product's ID"/></add-error>
        </if-empty>
        <if-empty field="parameters.custRequestName">
            <add-error><fail-message message="You have to specify category's name"/></add-error>
        </if-empty>
        <if-empty field="parameters.custRequestId">
            <add-error><fail-message message="You have to specify category's ID"/></add-error>
        </if-empty>
        <check-errors/>
        <!-- update cust request -->
        <set field="updateCustRequestInMap.custRequestId" from-field="parameters.custRequestId"/>
        <set field="updateCustRequestInMap.custRequestName" from-field="parameters.custRequestName"/>
        <call-service service-name="updateCustRequest" in-map-name="updateCustRequestInMap"/>
    </simple-method>
    <simple-method method-name="createDefaultTask" short-description="Create A default Task">
        <if>
            <condition>
                  <or>
                      <if-has-permission permission="SCRUM" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT_ROLE" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT" action="_ADMIN"/>
                  </or>
            </condition>
            <then>
            <if-not-empty field="parameters.workEffortName">
                <now-timestamp field="now"/>
                <!-- calculate estimatedMilliSeconds from initail planned hours -->
                <set field="plannedHours" from-field="parameters.plannedHours" default-value="0" type="Integer"/>
                <set-service-fields service-name="createWorkEffort" map="parameters" to-map="workEffortMap"/>
                <set field="parameters.estimatedMilliSeconds" value="${groovy:plannedHours*60*60*1000}"/>
                <call-service service-name="createWorkEffort" in-map-name="workEffortMap">
                   <result-to-field result-name="workEffortId"/>
                </call-service>
                <if-compare field="parameters.workEffortPurposeTypeId" operator="not-equals" value="SYSTEM_DEFAULT_TASK" >
                    <make-value entity-name="WorkEffortGoodStandard" value-field="goodStandardMap"/>
                    <set field="goodStandardMap.workEffortId" from-field="workEffortId"/>
                    <set field="goodStandardMap.productId" from-field="parameters.productId"/>
                    <set field="goodStandardMap.workEffortGoodStdTypeId" value="SCRUM_PRO_WORKEFF"/>
                    <set field="goodStandardMap.fromDate" from-field="now"/>
                    <set field="goodStandardMap.statusId" value="WEGS_CREATED"/>
                    <create-value value-field="goodStandardMap"/>
                </if-compare>
                 <!-- Assigned party for default task -->
                 <if>
                    <condition>
                        <and>
                            <not> <if-empty field="workEffortId"/></not>
                            <not> <if-empty field="parameters.partyId"/></not>
                        </and>
                    </condition>
                    <then>
                        <set field="assign.workEffortId" from-field="workEffortId"/>
                        <set field="assign.partyId" from-field="parameters.partyId"/>
                        <set field="assign.roleTypeId" value="SCRUM_TEAM"/>
                        <set field="assign.statusId" value="PRTYASGN_ASSIGNED"/>
                        <set field="assign.userLogin" from-field="sysUserLogin"/>
                        <call-service service-name="assignPartyToWorkEffort" in-map-name="assign"/>
                    </then>
                 </if>
                <else>
                    <add-error>
                        <fail-message message="Task name is missing,Please add."/>
                    </add-error>
                    <check-errors/>
                </else>
            </if-not-empty>
            </then>
            <else>
                <add-error>
                    <fail-message message="Permission Error"/>
                </add-error>
                <check-errors/>
            </else>
        </if>
    </simple-method>
    <simple-method method-name="updateDefaultTask" short-description="Update A default Task">
        <if>
            <condition>
                  <or>
                      <if-has-permission permission="SCRUM" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT_ROLE" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT" action="_ADMIN"/>
                  </or>
            </condition>
            <then>
            <if-not-empty field="parameters.workEffortId">
                <!-- calculate estimatedMilliSeconds from initail planned hours -->
                <set field="plannedHours" from-field="parameters.plannedHours" default-value="0" type="Integer"/>
                <set field="parameters.estimatedMilliSeconds" value="${groovy:plannedHours*60*60*1000}"/>
                <call-service service-name="updateWorkEffort" in-map-name="parameters">
                    <default-message>The Default Task record successfully updated.</default-message>
                </call-service>
                <!-- Assigned party for default task -->
                <if-not-empty field="parameters.partyId">
                    <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                        <condition-list combine="and">
                            <condition-expr field-name="partyId" from-field="parameters.partyId"/>
                            <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                            <condition-expr field-name="workEffortId" from-field="parameters.workEffortId"/>
                        </condition-list>
                    </entity-condition>
                    <if-empty field="assigneds">
                        <entity-and entity-name="WorkEffortPartyAssignment" list="assigneds">
                            <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                        </entity-and>
                        <entity-and entity-name="PartyRole" list="taskOwnerRoles">
                            <field-map field-name="partyId" from-field="parameters.partyId"/>
                            <field-map field-name="roleTypeId" value="SCRUM_TEAM"/>
                        </entity-and>
                        <iterate list="assigneds" entry="assigned">
                            <remove-value value-field="assigned"/>
                        </iterate>
                        <set field="newInput.partyId" from-field="parameters.partyId"></set>
                        <set field="newInput.workEffortId" from-field="parameters.workEffortId"></set>
                        <set field="newInput.roleTypeId" from-field="taskOwnerRoles[0].roleTypeId"></set>
                        <set field="newInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                        <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                    </if-empty>
                </if-not-empty>
                <else>
                    <add-error>
                        <fail-message message="Task name is missing,Please add."/>
                    </add-error>
                    <check-errors/>
                </else>
            </if-not-empty>
            </then>
            <else>
                <add-error>
                    <fail-message message="Permission Error"/>
                </add-error>
                <check-errors/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="testTaskBacklog" short-description="To Create actual Hour">
        <call-simple-method method-name="getWebSiteId"/>
        <now-timestamp field="fromdate"/>
        <set field="fDate" from-field="fromdate"/>
        <set field="hours" from-field="parameters.actaulHour" type="Double"/>
        <set field="planHour" from-field="parameters.planHour" type="Double"/>
        <if-not-empty field="parameters.actaulHour">
            <if-not-empty field="parameters.checkComplete">
                <set field="create.workEffortId" from-field="parameters.workEffortId"/>
                <set field="create.planHours" from-field="planHour"/>
                <set field="create.hours" from-field="hours"/>
                <set field="create.partyId" from-field="parameters.partyId"/>
                <set field="create.fromDate" from-field="parameters.fDate"/>
                <set field="create.timesheetId" from-field="parameters.timesheetId"/>
                <call-service service-name="createTimeEntry" in-map-name="create"></call-service>
                <set field="update.workEffortId" from-field="parameters.workEffortId"/>
                <set field="update.currentStatusId" value="STS_COMPLETED"/>
                <set field="update.webSiteId" from-field="parameters.webSiteId"/>
                <call-service service-name="updateWorkEffort" in-map-name="update">
                    <default-message resource="CommonUiLabels" property="CommonSuccessfullyCreated"/>
                </call-service>
            <else>
                <set field="create.workEffortId" from-field="parameters.workEffortId"/>
                <set field="create.planHours" from-field="planHour"/>
                <set field="create.hours" from-field="hours"/>
                <set field="create.partyId" from-field="parameters.partyId"/>
                <set field="create.fromDate" from-field="parameters.fDate"/>
                <set field="create.timesheetId" from-field="parameters.timesheetId"/>
                <call-service service-name="createTimeEntry" in-map-name="create">
                    <default-message>Insert the How To Test Task message successfully.</default-message>
                </call-service>
            </else>
            </if-not-empty>
            <else>
                <add-error>
                    <fail-message message="Cannot insert the data."/>
                </add-error>
                <check-errors/>
            </else>  
        </if-not-empty>
    </simple-method>
    <!-- create Scrum Project content -->
    <simple-method method-name="createScrumProjectContent" short-description="Creates Party Associated Content" login-required="false">
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <call-class-method class-name="org.apache.ofbiz.content.layout.LayoutWorker"
            method-name="uploadImageAndParameters"
            ret-field="formInput">
            <field field="request" type="javax.servlet.http.HttpServletRequest"/>
            <string value="dataResourceName"/>
        </call-class-method>
        <if-empty field="formInput.formInput.contentIdTo">
            <set-service-fields service-name="createContentFromUploadedFile" map="formInput.formInput" to-map="inMap"/>
            <set field="inMap._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="inMap.uploadedFile" from-field="formInput.imageData"/>
            <set field="inMap._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <set field="inMap.userLogin" from-field="sysUserLogin"/>
            <call-service service-name="createContentFromUploadedFile" in-map-name="inMap">
                <result-to-field result-name="contentId" field="context.contentId"/>
            </call-service>
            <else>
                <set field="context.contentId" from-field="formInput.formInput.contentIdTo"/>
            </else>
        </if-empty>
        <if-empty field="formInput.formInput.workEffortId">
            <if-not-empty field="formInput.formInput.projectId">
                <set field="context.workEffortId" from-field="formInput.formInput.projectId"/>
            </if-not-empty>
            <else>
                <set field="context.workEffortId" from-field="formInput.formInput.workEffortId"/>
            </else>
        </if-empty>
        <set field="context.workEffortContentTypeId" from-field="formInput.formInput.workEffortContentTypeId"/>
        <now-timestamp field="context.fromDate"/>
        <set field="context.userLogin" from-field="sysUserLogin"/>
        <call-map-processor in-map-name="context" out-map-name="workEffortContext">
            <simple-map-processor name="newWorkEffortContent">
                <process field="workEffortContentTypeId"><copy to-field="workEffortContentTypeId"/></process>
                <process field="contentId"><copy to-field="contentId"/></process>
                <process field="workEffortId"><copy to-field="workEffortId"/></process>
                <process field="fromDate"><copy to-field="fromDate"/></process>
                <process field="userLogin"><copy to-field="userLogin"/></process>
            </simple-map-processor>
        </call-map-processor>
        <!-- create Scrum Project Content-->
        <call-service service-name="createWorkEffortContent" in-map-name="workEffortContext">
            <result-to-field result-name="contentId" field="contentId"/>
        </call-service>
        
        <!-- create ContentAssoc-->
        <set field="context.contentAssocTypeId" value="SUB_CONTENT"/>
        <if-not-empty field="formInput.formInput.contentIdFrom">
            <set field="context.contentIdFrom" from-field="formInput.formInput.contentIdFrom"/>
            <call-map-processor in-map-name="context" out-map-name="contentAssocContext">
                <simple-map-processor name="newContentAssoc">
                    <process field="contentIdFrom"><copy to-field="contentId"/></process>
                    <process field="contentIdFrom"><copy to-field="contentIdFrom"/></process>
                    <process field="contentId"><copy to-field="contentIdTo"/></process>
                    <process field="contentAssocTypeId"><copy to-field="contentAssocTypeId"/></process>
                    <process field="fromDate"><copy to-field="fromDate"/></process>
                    <process field="userLogin"><copy to-field="userLogin"/></process>
                </simple-map-processor>
            </call-map-processor>
            <entity-and entity-name="ContentAssoc" list="contentAssoList">
                <field-map field-name="contentId" from-field="contentAssocContext.contentId"/>
                <field-map field-name="contentIdTo" from-field="contentAssocContext.contentIdTo"/>
            </entity-and>
            <if-empty field="contentAssonList">
                <call-service service-name="createContentAssoc" in-map-name="contentAssocContext"/>           
            </if-empty>
        </if-not-empty>
        
        <!-- set the partyId in the request -->
        <field-to-request field="context.workEffortId" request-name="workEffortId"/>
        <field-to-request field="context.projectId" request-name="projectId"/>
        <field-to-request field="contentId" request-name="contentId"/>
    </simple-method>
    
    <!-- create Scrum Product content -->
    <simple-method method-name="createScrumProductContent" short-description="Creates Party Associated Content" login-required="false">
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <call-class-method class-name="org.apache.ofbiz.content.layout.LayoutWorker"
            method-name="uploadImageAndParameters"
            ret-field="formInput">
            <field field="request" type="javax.servlet.http.HttpServletRequest"/>
            <string value="dataResourceName"/>
        </call-class-method>
        <if-empty field="formInput.formInput.contentIdTo">
            <set-service-fields service-name="createContentFromUploadedFile" map="formInput.formInput" to-map="inMap"/>
            <set field="inMap._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="inMap.uploadedFile" from-field="formInput.imageData"/>
            <set field="inMap._uploadedFile_contentType" from-field="formInput.formInput.mimeTypeId"/>
            <set field="inMap.userLogin" from-field="sysUserLogin"/>
            <call-service service-name="createContentFromUploadedFile" in-map-name="inMap">
                <result-to-field result-name="contentId" field="context.contentId"/>
            </call-service>
            <else>
                <set field="context.contentId" from-field="formInput.formInput.contentIdTo"/>
            </else>
        </if-empty>
        <if-empty field="formInput.formInput.productId">
            <add-error>
                <fail-message message="Can not empty productId"/>
            </add-error>
            <check-errors/>
            <else>
                <set field="context.productId" from-field="formInput.formInput.productId"/>
            </else>
        </if-empty>
        <set field="context.productContentTypeId" from-field="formInput.formInput.productContentTypeId"/>
        <now-timestamp field="context.fromDate"/>
        <set field="context.userLogin" from-field="sysUserLogin"/>
        <call-map-processor in-map-name="context" out-map-name="productContext">
            <simple-map-processor name="newProductContent">
                <process field="productId"><copy to-field="productId"/></process>
                <process field="contentId"><copy to-field="contentId"/></process>
                <process field="productContentTypeId"><copy to-field="productContentTypeId"/></process>
                <process field="fromDate"><copy to-field="fromDate"/></process>
                <process field="userLogin"><copy to-field="userLogin"/></process>
            </simple-map-processor>
        </call-map-processor>
        <!-- create ProductContent-->
        <call-service service-name="createProductContent" in-map-name="productContext">
            <result-to-field result-name="contentId" field="contentId"/>
        </call-service>
        
        <!-- create Scrum ContentAssoc-->
        <set field="context.contentAssocTypeId" value="SUB_CONTENT"/>
        <if-not-empty field="formInput.formInput.contentIdFrom">
            <set field="context.contentIdFrom" from-field="formInput.formInput.contentIdFrom"/>
            <call-map-processor in-map-name="context" out-map-name="contentAssocContext">
                <simple-map-processor name="newContentAssoc">
                    <process field="contentIdFrom"><copy to-field="contentId"/></process>
                    <process field="contentIdFrom"><copy to-field="contentIdFrom"/></process>
                    <process field="contentId"><copy to-field="contentIdTo"/></process>
                    <process field="contentAssocTypeId"><copy to-field="contentAssocTypeId"/></process>
                    <process field="fromDate"><copy to-field="fromDate"/></process>
                    <process field="userLogin"><copy to-field="userLogin"/></process>
                </simple-map-processor>
            </call-map-processor>
            <entity-and entity-name="ContentAssoc" list="contentAssoList">
                <field-map field-name="contentId" from-field="contentAssocContext.contentId"/>
                <field-map field-name="contentIdTo" from-field="contentAssocContext.contentIdTo"/>
            </entity-and>
            <if-empty field="contentAssonList">
                <call-service service-name="createContentAssoc" in-map-name="contentAssocContext"/>
            </if-empty>
        </if-not-empty>
        
        <!-- set the partyId in the request -->
        <field-to-request field="context.productId" request-name="productId"/>
    </simple-method>
    <simple-method method-name="createProdBacklogNote" short-description="Create Product Backlog Item Note">
        <if-empty field="parameters.noteName">
            <set field="newNoteMap.noteName" value="Backlog Item Note"/>
            <else>
                <set field="newNoteMap.noteName" from-field="parameters.noteName"/>
            </else>
        </if-empty>
        <if-empty field="parameters.noteInfo">
            <add-error>
                <fail-message message="Can not empty noteInfo"/>
            </add-error>
            <check-errors/>
            <else>
                <set field="newNoteMap.note" from-field="parameters.noteInfo"/>
            </else>
        </if-empty>
        <!-- create CustRequestNote -->
        <if-not-empty field="parameters.custRequestId">
            <call-service service-name="createNote" in-map-name="newNoteMap">
                <result-to-field result-name="noteId" field="noteId"/>
            </call-service>
            <make-value entity-name="CustRequestNote" value-field="newEntity"/>
            <set field="newEntity.custRequestId" from-field="parameters.custRequestId" />
            <set field="newEntity.noteId" from-field="noteId" />
            <create-value value-field="newEntity"/>
        </if-not-empty>
    </simple-method>
    <simple-method method-name="deleteProdBacklogNote" short-description="Delete Product Backlog Item Note">
        <entity-one entity-name="CustRequestNote" value-field="custNoteMap" auto-field-map="true"/>
        <remove-value value-field="custNoteMap"/>
        <remove-related relation-name="NoteData" value-field="custNoteMap"/>
    </simple-method>
    <simple-method method-name="createBacklogItemContent"
        short-description="Create Customer Request Content" login-required="false">
        <entity-one entity-name="UserLogin" value-field="sysUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <call-class-method class-name="org.apache.ofbiz.content.layout.LayoutWorker"
            method-name="uploadImageAndParameters" ret-field="formInput">
            <field field="request" type="javax.servlet.http.HttpServletRequest"/>
            <string value="dataResourceName"/>
        </call-class-method>

        <!-- Check input parameters -->
        <if>
            <condition>
                <and>
                    <if-empty field="formInput.formInput.contentId"/>
                    <if-empty field="formInput.imageFileName"/>
                </and>
            </condition>
            <then>
                <add-error>
                    <fail-message message="Content Id or Upload file is missing."/>
                </add-error>
            </then>
        </if>
        <check-errors/>
        <!-- Create new content form upload file / set content from Existing content -->
        <if-empty field="formInput.formInput.contentId">
            <!-- Create new content from upload file -->
            <set-service-fields service-name="createContentFromUploadedFile"
                map="formInput.formInput" to-map="inMap"/>
            <set field="inMap._uploadedFile_fileName" from-field="formInput.imageFileName"/>
            <set field="inMap.uploadedFile" from-field="formInput.imageData"/>
            <set field="inMap._uploadedFile_contentType" from-field="formInput.uploadMimeType"/>
            <set field="inMap.userLogin" from-field="sysUserLogin"/>
            <call-service service-name="createContentFromUploadedFile" in-map-name="inMap">
                <result-to-field result-name="contentId" field="context.contentId"/>
            </call-service>
            <else>
                <!--set content from Existing content-->
                <set field="context.contentId" from-field="formInput.formInput.contentId"/>
            </else>
        </if-empty>
        
        <!-- create ContentAssoc-->
        <set-service-fields service-name="createContentAssoc" map="formInput.formInput" to-map="contentMap"/>
        <if-not-empty field="formInput.formInput.contentIdFrom">
            <set field="contentMap.contentAssocTypeId" value="SUB_CONTENT"/>
            <set field="contentMap.contentIdFrom" from-field="formInput.formInput.contentIdFrom"/>
            <set field="contentMap.contentId" from-field="formInput.formInput.contentIdFrom"/>
            <set field="contentMap.contentIdTo" from-field="context.contentId"/>
            <now-timestamp field="contentMap.fromDate"/>
            <set field="contentMap.userLogin" from-field="sysUserLogin"/>
            <entity-and entity-name="ContentAssoc" list="contentAssoList">
                <field-map field-name="contentId" from-field="contentMap.contentId"/>
                <field-map field-name="contentIdTo" from-field="contentMap.contentIdTo"/>
            </entity-and>
            <if-empty field="contentAssonList">
                <call-service service-name="createContentAssoc" in-map-name="contentMap"/>           
            </if-empty>
        </if-not-empty>
        
        <set field="context.custRequestId" from-field="formInput.formInput.custRequestId"/>
        <set field="context.userLogin" from-field="sysUserLogin"/>
        <call-map-processor in-map-name="context" out-map-name="custRequestContext">
            <simple-map-processor name="newCustRequestContent">
                <process field="contentId">
                    <copy to-field="contentId"/>
                </process>
                <process field="custRequestId">
                    <copy to-field="custRequestId"/>
                </process>
                <process field="fromDate">
                    <copy to-field="fromDate"/>
                </process>
                <process field="userLogin">
                    <copy to-field="userLogin"/>
                </process>
            </simple-map-processor>
        </call-map-processor>

        <!-- Create Backlog Item Content -->
        <call-service service-name="createCustRequestContent" in-map-name="custRequestContext">
            <result-to-field result-name="contentId" field="contentId"/>
        </call-service>
    </simple-method>
    
    <simple-method method-name="removeProjectMember" short-description="Update Project When remove Product Owner">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set field="unassign.roleTypeId" from-field="parameters.roleTypeId"/>
        <set field="unassign.partyId" from-field="parameters.partyId"/>
        <set field="unassign.fromDate" from-field="parameters.fromDate"/>
        <set field="unassign.workEffortId" from-field="parameters.projectId"/>
        <set field="unassign.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="unassignPartyFromWorkEffort" in-map-name="unassign"/>
    </simple-method>
    
    <simple-method method-name="setTaskStatusToComplete" short-description="Set the task status to complete, if resources assigned that status will also be set to complete">
        <call-simple-method method-name="getWebSiteId"/>
        <entity-one entity-name="WorkEffort" value-field="workEffort">
            <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
        </entity-one>
        <if-empty field="workEffort">
            <add-error><fail-property resource="scrumUiLabels" property="ScrumErrorTaskNotFound"/></add-error>
        </if-empty>
        <if-compare field="workEffort.currentStatusId" value="STS_CREATED" operator="not-equals">
            <add-error><fail-property resource="scrumUiLabels" property="ScrumErrorTaskStatusWrong"/></add-error>
        </if-compare>
        <check-errors/>
        <entity-and entity-name="WorkEffortPartyAssignment" list="assigns" filter-by-date="true">
            <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
        </entity-and>
        <loop count="${groovy: assigns.size()}" field="i">
            <set field="actualMap.taskId" from-field="parameters.workEffortId" />
            <set field="actualMap.partyId" from-field="assigns[i].partyId" />
            <set field="planMap.taskId" from-field="parameters.workEffortId" />
            <set field="planMap.partyId" from-field="assigns[i].partyId" />
            <call-service service-name="getScrumActualHour" in-map-name="actualMap">
                <result-to-field result-name="actualHours" />
            </call-service>
            <call-service service-name="getScrumPlanHour" in-map-name="planMap">
                <result-to-field result-name="planHours"/>
            </call-service>
            <if-compare-field field="planHours" operator="not-equals" to-field="actualHours" type="Double">
                <set field="planHours" from-field="actualHours" />
                <entity-condition entity-name="TimeEntry" list="lastTimeEntrys">
                    <condition-list combine="and">
                        <condition-expr field-name="workEffortId" from-field="parameters.workEffortId" />
                        <condition-expr field-name="partyId" from-field="assigns[i].partyId" />
                    </condition-list>
                    <order-by field-name="-fromDate" />
                </entity-condition>
                <first-from-list list="lastTimeEntrys" entry="lastTimeEntry" />
                <if-not-empty field="lastTimeEntry">
                    <set field="lastTimeEntry.planHours" from-field="planHours" />
                    <store-value value-field="lastTimeEntry" />
                <else>
                    <entity-and entity-name="ProjectSprintBacklogAndTask" list="meetingTasks">
                        <field-map field-name="taskId" from-field="parameters.workEffortId"/>
                        <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                        <field-map field-name="custRequestTypeId" value="RF_SCRUM_MEETINGS"/>
                    </entity-and>
                    <if-not-empty field="meetingTasks">
                        <set field="parameters.estimatedMilliSeconds" value="0.0" type="Double"/>
                        <else>
                            <field-to-request field="parameters.workEffortId" request-name="taskId"/>
                            <add-error><fail-property resource="scrumUiLabels" property="ScrumErrorTaskNotFoundInTimeEntry"/></add-error>
                            <check-errors/>
                       </else>
                    </if-not-empty>
                </else>
                </if-not-empty>
            </if-compare-field>
        </loop>
        <!-- if all assigns are complete the task will be set to complete -->
        <if-not-empty field="assigns">
            <iterate list="assigns" entry="assign">
                <set field="assign.statusId" value="SCAS_COMPLETED"/>
                <store-value value-field="assign" />
            </iterate>
            <else>
                <set field="parameters.estimatedMilliSeconds" value="0.0" type="Double"/>
            </else>
        </if-not-empty>
        <if-compare operator="not-equals" value="STS_COMPLETED" field="workEffort.currentStatusId">
            <set field="upd.workEffortId" from-field="parameters.workEffortId"/>
            <set field="upd.currentStatusId" value="STS_COMPLETED"/>
            <set field="upd.webSiteId" from-field="parameters.webSiteId"/>
            <call-service service-name="updateWorkEffort" in-map-name="upd"/>
        </if-compare>
        <field-to-request field="parameters.workEffortId" request-name="taskId"/>
    </simple-method>
    
    <simple-method method-name="setAccept" short-description="Set backlog statusId from CRQ_CANCELLED to CRQ_ACCEPTED">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_UPDATE"/>
                </or>
            </condition>
            <then>
                <call-simple-method method-name="getWebSiteId"/>
                <!-- Re-opened the backlog for status CRQ_CANCELLED -->
                <entity-condition entity-name="CustRequest" list="custCancelledList">
                    <condition-list combine="and">
                        <condition-expr field-name="custRequestId" from-field="parameters.custRequestId"/>
                        <condition-expr field-name="statusId" operator="equals" value="CRQ_CANCELLED"/>
                    </condition-list>
                </entity-condition>
                <if-not-empty field="custCancelledList">
                    <first-from-list list="custCancelledList" entry="custRequest"/>
                    <get-related relation-name="CustRequestWorkEffort" list="custRequestWorkEffortList" value-field="custRequest"/>
                    <!-- Remove the backlog from sprint -->
                    <if-not-empty field="custRequestWorkEffortList">
                        <iterate list="custRequestWorkEffortList" entry="custRequestWorkEffortMap">
                            <get-related-one relation-name="WorkEffort" value-field="custRequestWorkEffortMap" to-value-field="workEffortMap" />
                            <if-compare field="workEffortMap.workEffortTypeId" operator="equals" value="SCRUM_SPRINT" >
                                <remove-value value-field="custRequestWorkEffortMap"/>
                            </if-compare>
                        </iterate>
                    </if-not-empty>
                    <!-- set custRequest status -->
                    <set field="setCustStatus.custRequestId" from-field="parameters.custRequestId"/>
                    <set field="setCustStatus.statusId" value="CRQ_ACCEPTED"/>
                    <set field="setCustStatus.webSiteId" from-field="parameters.webSiteId"/>
                    <call-service service-name="setCustRequestStatus" in-map-name="setCustStatus"/>
                </if-not-empty>
            </then>
            <else>
                <add-error><fail-message message="You are has no permission to perform this action."/></add-error>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="addTaskAssignment" short-description="Update Task">
        <!-- Assigned -->
         <entity-condition entity-name="WorkEffortPartyAssignment" list="assignedList">
             <condition-list combine="and">
                 <condition-expr field-name="workEffortId" from-field="parameters.workEffortId"/>
                 <condition-expr field-name="statusId" value="SCAS_ASSIGNED"/>
             </condition-list>
         </entity-condition>
        <!-- for Scrum Meeting task -->        
        <if-not-empty field="assignedList">
            <entity-condition entity-name="WorkEffortPartyAssignment" list="partyAssignedList">
                <condition-list combine="and">
                    <condition-expr field-name="workEffortId" from-field="parameters.workEffortId"/>
                    <condition-expr field-name="partyId" from-field="userLogin.partyId"/>
                    <condition-expr field-name="statusId" value="SCAS_ASSIGNED"/>
                </condition-list>
            </entity-condition>
            <if-empty field="partyAssignedList">
                 <!-- get roletype from sprint member -->
                <entity-condition entity-name="ProjectSprintBacklogAndTask" list="sprintList">
                    <condition-list combine="and">
                        <condition-expr field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                        <condition-expr field-name="taskId" from-field="parameters.workEffortId"/>
                    </condition-list>
                </entity-condition>
                <first-from-list list="sprintList" entry="sprint"/>
                <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintRoles">
                    <condition-list combine="and">
                        <condition-expr field-name="partyId" from-field="parameters.partyId"/>
                        <condition-expr field-name="workEffortId" from-field="sprint.sprintId"/>
                        <condition-expr field-name="roleTypeId" value="SCRUM_TEAM"/>
                    </condition-list>
                </entity-condition>
                <if-empty field="sprintRoles">
                    <add-error>
                       <fail-message message="Can not assign task to partyId : ${parameters.partyId} because this partyId dose not have the SCRUM_TEAM roleTypeId"/>
                    </add-error>
                    <check-errors/>
                </if-empty>
                <entity-one entity-name="UserLogin" value-field="userLogin">
                    <field-map field-name="userLoginId" from-field="parameters.partyId"/>
                </entity-one>
                <set field="newAssign.partyId" from-field="parameters.partyId"/>
                <set field="newAssign.workEffortId" from-field="parameters.workEffortId"/>
                <set field="newAssign.roleTypeId" from-field="sprintRoles[0].roleTypeId"/>
                <set field="newAssign.statusId" value="SCAS_ASSIGNED"/>
                <set field="newAssign.assignedByUserLoginId" from-field="userLogin"/>
                <now-timestamp field="newAssign.fromDate"/>
                <call-service service-name="assignPartyToWorkEffort" in-map-name="newAssign"/>
                <else>
                    <add-error>
                       <fail-message message="Party : ${parameters.partyId} is already assigned to work effort Id : ${parameters.workEffortId} , not adding again"/>
                    </add-error>
                    <check-errors/>
                </else>
            </if-empty>
        </if-not-empty>

        <if-empty field="assignedList">
            <!-- for other task  -->
            <entity-and entity-name="CustRequestWorkEffort" list="custRequestList">
                <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
            </entity-and>
            <entity-one entity-name="CustRequest" value-field="custRequest">
                <field-map field-name="custRequestId" from-field="custRequestList[0].custRequestId"/>
            </entity-one>
            <set field="custRequestTypeId" from-field="custRequest.custRequestTypeId"/>
            <if-compare field="custRequestTypeId" operator="equals" value="RF_UNPLAN_BACKLOG">
                <entity-one entity-name="PartyRole" value-field="party">
                    <field-map field-name="partyId" from-field="userLogin.partyId"/>
                    <field-map field-name="roleTypeId" value="SCRUM_TEAM"/>
                </entity-one>
                <if-not-empty field="party">
                    <set field="roleTypeId" from-field="party.roleTypeId"/>
                    <set field="partyId" from-field="userLogin.partyId"/>
                    <set field="workEffortId" from-field="parameters.workEffortId"/>
                    <else>
                        <add-error>
                            <fail-message message="Can not assign task to partyId : ${userLogin.partyId} because this partyId dose not have the SCRUM_TEAM roleTypeId"/>
                        </add-error>
                        <check-errors/>
                    </else>
                </if-not-empty>
                <else>
                    <!-- get roletype from sprint member -->
                    <entity-condition entity-name="ProjectSprintBacklogAndTask" list="sprintList">
                        <condition-list combine="and">
                            <condition-expr field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                            <condition-expr field-name="taskId" from-field="parameters.workEffortId"/>
                        </condition-list>
                    </entity-condition>
                    <first-from-list list="sprintList" entry="sprint"/>
                    <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintRoles">
                        <condition-list combine="and">
                            <condition-expr field-name="partyId" from-field="parameters.partyId"/>
                            <condition-expr field-name="workEffortId" from-field="sprint.sprintId"/>
                            <condition-expr field-name="roleTypeId" value="SCRUM_TEAM"/>
                        </condition-list>
                    </entity-condition>
                    <if-empty field="sprintRoles">
                        <add-error>
                            <fail-message message="Can not assign task to partyId : ${parameters.partyId} because this partyId dose not have the SCRUM_TEAM roleTypeId"/>
                        </add-error>
                        <check-errors/>
                    </if-empty>
                    <entity-and entity-name="WorkEffortPartyAssignment" list="assigneds">
                        <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                    </entity-and>
                    <iterate list="assigneds" entry="assigned">
                        <remove-value value-field="assigned"/>
                    </iterate>
                    <set field="partyId" from-field="parameters.partyId"/>
                    <set field="workEffortId" from-field="parameters.workEffortId"/>
                    <set field="roleTypeId" from-field="sprintRoles[0].roleTypeId"/>
                </else>
            </if-compare>
            <entity-one entity-name="UserLogin" value-field="systemUserLogin">
                <field-map field-name="userLoginId" value="system"/>
            </entity-one>
            <set field="newInput.partyId" from-field="partyId"/>
            <set field="newInput.workEffortId" from-field="workEffortId"/>
            <set field="newInput.roleTypeId" from-field="roleTypeId"/>
            <set field="newInput.statusId" value="SCAS_ASSIGNED"/>
            <set field="newInput.userLogin" from-field="systemUserLogin"/>
            <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
        </if-empty>
    </simple-method>
    
    <simple-method method-name="CopyMemberLastSprint" short-description="">
        <entity-and entity-name="WorkEffort" list="sprintList">
            <field-map field-name="workEffortParentId" from-field="parameters.projectId"/>
            <field-map field-name="workEffortTypeId" value="SCRUM_SPRINT"/>
            <order-by field-name="createdDate DESC"/>
        </entity-and>
        <set field="projectId" from-field="parameters.projectId"/>
        <set field="sprintId" from-field="parameters.sprintId"/>
        <set field="lastestSprintId" from-field="sprintList[0].workEffortId"/>
        <set field="size" value="${groovy:sprintList.size();}"/>
        <loop count="${size}" field="i">
            <if-compare operator="equals" value="${sprintId}" field="sprintList[i].workEffortId" >
                <set field="previousSprintId" from-field="sprintList[i+1].workEffortId"/>
                <entity-condition entity-name="WorkEffortPartyAssignment" list="memberPrevSprint">
                    <condition-list combine="and">
                        <condition-expr field-name="workEffortId" from-field="previousSprintId"/>
                        <condition-list combine="or">
                            <condition-expr field-name="roleTypeId" value="SCRUM_MASTER"/>
                            <condition-expr field-name="roleTypeId" value="SCRUM_TEAM"/>
                        </condition-list>
                    </condition-list>
                </entity-condition>
                <if-not-empty field="memberPrevSprint">
                    <iterate list="memberPrevSprint" entry="member">
                        <entity-and list="sprintmember" entity-name="WorkEffortPartyAssignment">
                            <field-map field-name="partyId" from-field="member.partyId"/>
                            <field-map field-name="roleTypeId" from-field="member.roleTypeId"/>
                            <field-map field-name="statusId" from-field="member.statusId"/>
                            <field-map field-name="workEffortId" from-field="sprintId"/>
                        </entity-and>
                        <if-empty field="sprintmember[0]">
                            <set field="assign.partyId" from-field="member.partyId"/>
                            <set field="assign.roleTypeId" from-field="member.roleTypeId"/>
                            <set field="assign.statusId" from-field="member.statusId"/>
                            <set field="assign.workEffortId" from-field="sprintId"/>
                            <call-service service-name="assignPartyToWorkEffort" in-map-name="assign"/>
                        </if-empty>
                    </iterate>
                <else>
                    <field-to-request field="projectId"/>
                    <field-to-request field="sprintId"/>
                    <add-error>
                        <fail-message message="Cannot assign member to this sprint because there is no member from last sprint"/>
                    </add-error>
                    <check-errors/>
                    
                </else>
                </if-not-empty>
            </if-compare>
        </loop>
        <field-to-request field="projectId"/>
        <field-to-request field="sprintId"/>
    </simple-method>
    <simple-method method-name="createScrumCommunicationEvent" short-description="Create Scrum Communication Event">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <map-to-map map="parameters" to-map="communicationMap"/>
        <set field="communicationMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="createCommunicationEvent" in-map-name="communicationMap" >
            <result-to-request result-name="communicationEventId"/>
        </call-service>
        <field-to-request field="parameters.productIdIn" request-name="productId"/>
        <field-to-request field="parameters.custRequestId" request-name="custRequestId"/>
    </simple-method>
    
    <simple-method method-name="updateScrumCommunicationEvent" short-description="Update Scrum Communication Event">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <map-to-map map="parameters" to-map="communicationMap"/>
        <set field="communicationMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="updateCommunicationEvent" in-map-name="communicationMap" >
            <result-to-request result-name="communicationEventId"/>
        </call-service>
        <field-to-request field="parameters.productIdIn" request-name="productId"/>
        <field-to-request field="parameters.custRequestId" request-name="custRequestId"/>
    </simple-method>
    
    <simple-method method-name="createScrumCommunicationEventContent" short-description="Create Scrum Communication Event Content">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set field="updateMap.userLogin" from-field="systemUserLogin"/>
        <set field="data.userLogin" from-field="systemUserLogin"/>
        <set field="attachMap.userLogin" from-field="systemUserLogin"/>
        <set field="contentMap.userLogin" from-field="systemUserLogin"/>
        <set field="partycontent.userLogin" from-field="systemUserLogin"/>
        <set field="contentAssoc.userLogin" from-field="systemUserLogin"/>
        <call-simple-method method-name="createCommunicationEventContent" xml-resource="component://party/minilang/communication/CommunicationEventEvents.xml"/>
    </simple-method>
    
    <simple-method method-name="updateScrumTimeEntry" short-description="Update TimeEntry in the Scrum component">
        <entity-one entity-name="TimeEntry" value-field="lookedUpValue">
            <field-map field-name="timeEntryId" from-field="parameters.timeEntryId"/>
        </entity-one>
        
        <!-- update all fields except invoiceId,invoiceItemSeqId and only those if they are not yet set -->
        <map-to-map map="parameters" to-map="fieldsToCopy"/>
        <clear-field field="fieldsToCopy.invoiceId"/>
        <clear-field field="fieldsToCopy.invoiceItemSeqId"/>
        
        <!-- if dates are updated and no hours value is specified, calc it here -->
        <if>
            <condition>
                <and>
                    <if-empty field="fieldsToCopy.hours"/>
                    <or>
                        <not><if-empty field="fieldsToCopy.fromDate"/></not>
                        <not><if-empty field="fieldsToCopy.thruDate"/></not>
                    </or>
                    <or>
                        <if-compare-field field="fieldsToCopy.fromDate" operator="not-equals" to-field="lookedUpValue.fromDate"/>
                        <if-compare-field field="fieldsToCopy.thruDate" operator="not-equals" to-field="lookedUpValue.thruDate"/>
                    </or>
                </and>
            </condition>
            <then>
                <set field="fieldsToCopy.hours" value="${groovy:org.apache.ofbiz.base.util.UtilDateTime.getInterval((fieldsToCopy.fromDate ? fieldsToCopy.fromDate : lookedUpValue.fromDate), (fieldsToCopy.thruDate ? fieldsToCopy.thruDate : lookedUpValue.thruDate))/3600000}" type="Double"/>
            </then>
        </if>
        <set field="fieldsToCopy.partyId" from-field="lookedUpValue.partyId"/>
        <set-nonpk-fields map="fieldsToCopy" value-field="lookedUpValue"/>
        
        <if-not-empty field="parameters.invoiceId">
            <if-empty field="lookedUpValue.invoiceId">
                <set field="lookedUpValue.invoiceId" from-field="parameters.invoiceId"/>
                <set field="lookedUpValue.invoiceItemSeqId" from-field="parameters.invoiceItemSeqId"/>
            </if-empty>
        </if-not-empty>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    
    <simple-method method-name="deleteDefaultTaskScrum" short-description="Delete default Task for Scrum">
        <if>
            <condition>
                  <or>
                      <if-has-permission permission="SCRUM" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT_ROLE" action="_ADMIN"/>
                      <if-has-permission permission="SCRUM_PROJECT" action="_ADMIN"/>
                  </or>
            </condition>
            <then>
            <if-not-empty field="parameters.workEffortId">
                <entity-one entity-name="WorkEffort" value-field="workEffortMap"/>
                <get-related relation-name="CustRequestWorkEffort" list="custWorkEffortList" value-field="workEffortMap"/>
                <if-not-empty field="custWorkEffortList">
                    <remove-related value-field="workEffortMap" relation-name="CustRequestWorkEffort"/>
                </if-not-empty>
                <entity-and entity-name="WorkEffortGoodStandard" list="workEffGSDList">
                    <field-map field-name="workEffortId" from-field="parameters.workEffortId"/>
                </entity-and>
                <if-not-empty field="workEffGSDList">
                    <remove-list list="workEffGSDList"/>
                </if-not-empty>
                <set-service-fields service-name="deleteWorkEffort" map="workEffortMap" to-map="serviceMap"/>
                <call-service service-name="deleteWorkEffort" in-map-name="serviceMap">
                    <default-message>The Default Task record successfully deleted.</default-message>
                </call-service>
            </if-not-empty>
            </then>
            <else>
                <add-error>
                    <fail-message message="You are has no permission to perform this action."/>
                </add-error>
                <check-errors/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="createQuickAddBacklog" short-description="Create Quick Add Backlog">
        <call-simple-method method-name="getWebSiteId"/>
        <if-empty field="parameters.description">
            <add-error>
                <fail-message message="There is no Product Backlog Item."/>
            </add-error>
            <check-errors/>
        </if-empty>
        <if-empty field="parameters.unplanned">
            <add-error>
                <fail-message message="Please select backlog type."/>
            </add-error>
            <check-errors/>
        </if-empty>
        <if-compare field="parameters.unplanned" operator="equals" value="N" >
            <set field="inputValue" from-field="parameters.keyId"/>
            <set field="parameters.productId" value="${groovy: inputValue.substring(0,inputValue.indexOf(','))}"/>
            <set field="parameters.projectId" value="${groovy: inputValue.substring(inputValue.indexOf(',')+1,inputValue.lastIndexOf(','))}"/>
            <set field="parameters.sprintId" value="${groovy: inputValue.substring(inputValue.lastIndexOf(',')+1,inputValue.length())}"/>
        </if-compare>
        <!-- Permission Check -->
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_CREATE"/>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <!-- We should create baklog in first-->
                <if-not-empty field="parameters.custSequenceNum">
                    <!-- check duplicate data  -->
                    <entity-count count-field="getNum" entity-name="CustRequestAndCustRequestItem">
                        <condition-list combine="and">
                            <condition-expr field-name="productId" from-field="parameters.productId"/>
                            <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                        </condition-list>
                    </entity-count>
                    <!-- the first sequence number -->
                    <if-compare field="getNum" operator="equals" value="0">
                        <set field="createCustRequestInMap.custSequenceNum" from-field="parameters.custSequenceNum"/>
                        <else>
                            <entity-condition entity-name="CustRequestAndCustRequestItem" list="custRequestList">
                                <condition-list combine="and">
                                    <condition-expr field-name="productId" from-field="parameters.productId"/>
                                    <condition-expr field-name="statusId" operator="equals" value="CRQ_ACCEPTED"/>
                                </condition-list>
                                <order-by field-name="custSequenceNum"/>
                            </entity-condition>
                            <set field="sequenceNumkey" from-field="parameters.custSequenceNum" type="Integer"/>
                            <set field="productMap" from-field="custRequestList[sequenceNumkey-1]"/>
                            <set field="externalSeq" from-field="productMap.custSequenceNum" type="Long"/>
                            <!-- Insert new transaction to CustRequest -->
                            <loop count="${getNum}" field="j">
                                 <set field="internalSeq" from-field="custRequestList[j].custSequenceNum" type="Long" />
                                 <set field="ready" value="${groovy:internalSeq&gt;=externalSeq}" type="Boolean"/>
                                <if-compare field="ready" operator="equals" value="true"  type="Boolean">
                                    <set field="custRequestIdIn" from-field="custRequestList[j].custRequestId"/>
                                    <entity-one entity-name="CustRequest" value-field="custRequestMap">
                                        <field-map field-name="custRequestId" from-field="custRequestIdIn"/>
                                    </entity-one>
                                    <set field="custSequenceNum" from-field="custRequestMap.custSequenceNum"/>
                                    <set field="nextSeqNum" value="${custSequenceNum+1}" type="Long"/>
                                    <set field="custRequestMap.custSequenceNum" from-field="nextSeqNum"/>
                                    <store-value value-field="custRequestMap"/>
                                </if-compare>
                            </loop>
                            <set field="createCustRequestInMap.custSequenceNum" from-field="externalSeq"/>
                        </else>
                    </if-compare>
                </if-not-empty>
                <if-empty field="parameters.fromPartyId">
                    <set field="createCustRequestInMap.fromPartyId" from-field="userLogin.partyId"/>
                </if-empty>
                <set field="changeToMilliSec" value="${parameters.custEstimatedMilliSeconds*1000*60*60}"/>
                <set field="createCustRequestInMap.custEstimatedMilliSeconds" from-field="changeToMilliSec" type="Double"/>
                <if-compare field="parameters.unplanned" operator="equals" value="Y" >
                    <set field="createCustRequestInMap.custRequestTypeId" value="RF_UNPLAN_BACKLOG"/>
                    <else>
                        <set field="createCustRequestInMap.custRequestTypeId" value="RF_PROD_BACKLOG"/>
                    </else>
                </if-compare>
                <set field="createCustRequestInMap.billed" from-field="parameters.billed"/>
                <set field="createCustRequestInMap.statusId" value="CRQ_ACCEPTED"/>
                <set field="createCustRequestInMap.custRequestName" value="Product Backlog"/>
                <set field="createCustRequestInMap.description" from-field="parameters.description"/>
                <set field="createCustRequestInMap.openDateTime" from-field="parameters.openDateTime"/>
                <set field="createCustRequestInMap.closedDateTime" from-field="parameters.closedDateTime"/>
                <set field="createCustRequestInMap.parentCustRequestId" from-field="parameters.parentCustRequestId"/>
                <set field="createCustRequestInMap.webSiteId" from-field="parameters.webSiteId"/>
                
                <sequenced-id sequence-name="CustRequestItem" field="custRequestItemSeqId"/>
                <set field="createCustRequestInMap.custRequestItemSeqId" from-field="custRequestItemSeqId"/>
                <set field="createCustRequestInMap.story" from-field="parameters.story"/>
                <set field="createCustRequestInMap.productId" from-field="parameters.productId"/>
                <call-service service-name="createCustRequest" in-map-name="createCustRequestInMap">
                    <result-to-field result-name="custRequestId"/>
                </call-service>
                <!-- create CustRequestNote -->
                <if-not-empty field="parameters.noteInfo">
                    <set field="newNoteMap.note" from-field="parameters.noteInfo"/>
                    <set field="newNoteMap.noteName" value="How to test"/>
                    <call-service service-name="createNote" in-map-name="newNoteMap">
                        <result-to-field result-name="noteId" field="noteId"/>
                    </call-service>
                    <make-value entity-name="CustRequestNote" value-field="newEntity"/>
                    <set from-field="custRequestId" field="newEntity.custRequestId"/>
                    <set from-field="noteId" field="newEntity.noteId"/>
                    <log level="always" message=">>>>>>>>>>>>>>>>>> newEntity : ${newEntity}"></log>
                    <create-value value-field="newEntity"/>
                </if-not-empty>
                <!-- add new backlog to sprint -->
                <if-not-empty field="custRequestId">
                    <if-compare field="parameters.unplanned" operator="equals" value="N" >
                       <set field="sprintBL.custRequestId" from-field="custRequestId"/>
                       <set field="sprintBL.workEffortId" from-field="parameters.sprintId"/>
                       <set field="sprintBL.userLogin" from-field="userLogin"/>
                       <call-service service-name="createWorkEffortRequest" in-map-name="sprintBL"/>
                       <set field="inMap.custRequestId" from-field="custRequestId"/>
                       <set field="inMap.statusId" value="CRQ_REVIEWED"/>
                       <else>
                            <set field="inMap.custRequestId" from-field="custRequestId"/>
                            <set field="inMap.statusId" value="CRQ_REVIEWED"/>
                            <set field="inMap.custRequestName" value="Unplanned Backlog"/>
                       </else>
                    </if-compare>
                    <set field="inMap.webSiteId" from-field="parameters.webSiteId"/>
                    <call-service service-name="updateCustRequest" in-map-name="inMap"/>
                    
                    <!-- Check If there are tasks already in a backlog -->
                    <entity-condition entity-name="WorkEffortCustRequestView" list="backlogItemTaskList">
                        <condition-list combine="and">
                            <condition-expr field-name="custRequestId" from-field="custRequestId"/>
                            <condition-list combine="or">
                                <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_ERROR"/>
                                <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                                <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_INST"/>
                                <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_TEST"/>
                            </condition-list>
                        </condition-list>
                    </entity-condition>
                    <if-empty field="backlogItemTaskList">
                        <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                            <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                            <field-map field-name="productId" from-field="parameters.productId"/>
                        </entity-and>
                        <if-not-empty field="defaultTaskList">
                            <iterate list="defaultTaskList" entry="defaultTask">
                                <set field="newDefaultTask.workEffortName" from-field="defaultTask.workEffortName"/>
                                <set field="newDefaultTask.estimatedMilliSeconds" from-field="defaultTask.estimatedMilliSeconds"/>
                                <set field="newDefaultTask.currentStatusId" from-field="defaultTask.currentStatusId"/>
                                <set field="newDefaultTask.workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                                <if-compare field="parameters.unplanned" operator="equals" value="N" >
                                    <set field="newDefaultTask.workEffortParentId" from-field="parameters.sprintId"/>
                                </if-compare>
                                <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                                    <result-to-field result-name="workEffortId"/>
                                </call-service>
                                <set field="newBacklogItemTask.custRequestId" from-field="custRequestId"/>
                                <set field="newBacklogItemTask.workEffortId" from-field="workEffortId"/>
                                <set field="newBacklogItemTask.userLogin" from-field="userLogin"/>
                                <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTask"/>
                                <!-- Assigned party for default task-->
                                <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                                    <condition-list combine="and">
                                        <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                        <condition-expr field-name="workEffortId" from-field="defaultTask.workEffortId"/>
                                    </condition-list>
                                </entity-condition>
                                <if-not-empty field="assigneds">
                                    <first-from-list list="assigneds" entry="assignedMap"/>
                                    <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                                    <set field="newInput.workEffortId" from-field="workEffortId"></set>
                                    <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                    <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                                    <set field="newInput.userLogin" from-field="userLogin"/>
                                    <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                                    <!-- Assigned party for sprint -->
                                    <if-compare field="parameters.unplanned" operator="equals" value="N" >
                                        <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintAssigneds">
                                            <condition-list combine="and">
                                                <condition-expr field-name="partyId" from-field="assignedMap.partyId"/>
                                                <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                                <condition-expr field-name="workEffortId" from-field="parameters.sprintId"/>
                                            </condition-list>
                                        </entity-condition>
                                        <if-empty field="sprintAssigneds">
                                            <set field="sprintInput.partyId" from-field="assignedMap.partyId"></set>
                                            <set field="sprintInput.workEffortId" from-field="parameters.sprintId"></set>
                                            <set field="sprintInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                            <set field="sprintInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                                            <set field="sprintInput.userLogin" from-field="userLogin"/>
                                            <call-service service-name="assignPartyToWorkEffort" in-map-name="sprintInput"/>
                                        </if-empty>
                                    </if-compare>
                                </if-not-empty>
                            </iterate>
                            <else>
                                <!-- If not have default task in product level -->
                                <entity-and entity-name="WorkEffort" list="defaultTaskScrum">
                                    <field-map field-name="workEffortPurposeTypeId" value="SYSTEM_DEFAULT_TASK"/>
                                </entity-and>
                                <if-not-empty field="defaultTaskScrum">
                                    <iterate list="defaultTaskScrum" entry="defaultScrum">
                                        <set field="newDefaultTaskScrum.workEffortName" from-field="defaultScrum.workEffortName"/>
                                        <set field="newDefaultTaskScrum.estimatedMilliSeconds" from-field="defaultScrum.estimatedMilliSeconds"/>
                                        <set field="newDefaultTaskScrum.currentStatusId" from-field="defaultScrum.currentStatusId"/>
                                        <set field="newDefaultTaskScrum.workEffortTypeId" from-field="defaultScrum.workEffortTypeId"/>
                                        <if-compare field="parameters.unplanned" operator="equals" value="N" >
                                            <set field="newDefaultTaskScrum.workEffortParentId" from-field="parameters.sprintId"/>
                                        </if-compare>
                                        <call-service service-name="createWorkEffort" in-map-name="newDefaultTaskScrum">
                                            <result-to-field result-name="workEffortId"/>
                                        </call-service>
                                        <set field="newBacklogItemTaskScrum.custRequestId" from-field="custRequestId"/>
                                        <set field="newBacklogItemTaskScrum.workEffortId" from-field="workEffortId"/>
                                        <set field="newBacklogItemTaskScrum.userLogin" from-field="userLogin"/>
                                        <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTaskScrum"/>
                                        <!-- Assigned party for default task-->
                                        <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                                            <condition-list combine="and">
                                                <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                                <condition-expr field-name="workEffortId" from-field="defaultScrum.workEffortId"/>
                                            </condition-list>
                                        </entity-condition>
                                        <if-not-empty field="assigneds">
                                            <first-from-list list="assigneds" entry="assignedMap"/>
                                            <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                                            <set field="newInput.workEffortId" from-field="workEffortId"></set>
                                            <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                            <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                                            <set field="newInput.userLogin" from-field="userLogin"/>
                                            <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                                            <!-- Assigned party for sprint -->
                                            <if-compare field="parameters.unplanned" operator="equals" value="N" >
                                                <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintAssigneds">
                                                    <condition-list combine="and">
                                                        <condition-expr field-name="partyId" from-field="assignedMap.partyId"/>
                                                        <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                                        <condition-expr field-name="workEffortId" from-field="parameters.sprintId"/>
                                                    </condition-list>
                                                </entity-condition>
                                                <if-empty field="sprintAssigneds">
                                                    <set field="sprintInput.partyId" from-field="assignedMap.partyId"></set>
                                                    <set field="sprintInput.workEffortId" from-field="parameters.sprintId"></set>
                                                    <set field="sprintInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                                    <set field="sprintInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                                                    <set field="sprintInput.userLogin" from-field="userLogin"/>
                                                    <call-service service-name="assignPartyToWorkEffort" in-map-name="sprintInput"/>
                                                </if-empty>
                                            </if-compare>
                                         </if-not-empty>
                                    </iterate>
                                </if-not-empty>
                            </else>
                        </if-not-empty>
                        <else>
                            <loop count="${groovy: backlogItemTaskList.size()}" field="j">
                                <set field="updateWorkEffort.workEffortId" from-field="backlogItemTaskList[j].workEffortId"/>
                                <set field="updateWorkEffort.workEffortParentId" from-field="parameters.sprintId"/>
                                <call-service service-name="updateWorkEffort" in-map-name="updateWorkEffort"/>
                            </loop>
                        </else>
                    </if-empty>
                </if-not-empty>
                <field-to-request field="parameters.sprintId" request-name="sprintId"/>
                <field-to-request field="parameters.productId" request-name="productId"/>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="setUnplannedSprint" short-description="Change status unplanned backlog to CRQ_REVIEW">
        <if>
            <condition>
                <or>
                    <if-has-permission permission="SCRUM" action="_ADMIN"/>
                    <if-has-permission permission="SCRUM_PRODUCT_BACKLOG" action="_ADMIN"/>
                </or>
            </condition>
            <then>
                <call-simple-method method-name="getWebSiteId"/>
                <set field="update.custRequestId" from-field="parameters.custRequestId"/>
                <set field="update.statusId" value="CRQ_REVIEWED"/>
                <set field="update.custRequestName" value="Unplanned Backlog"/>
                <set field="update.webSiteId" from-field="parameters.webSiteId"/>
                <call-service service-name="updateCustRequest" in-map-name="update"/>
                <!-- Check If there are tasks already in a backlog -->
                <entity-condition entity-name="WorkEffortCustRequestView" list="backlogItemTaskList">
                    <condition-list combine="and">
                        <condition-expr field-name="custRequestId" from-field="parameters.custRequestId"/>
                        <condition-list combine="or">
                            <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_ERROR"/>
                            <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_IMPL"/>
                            <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_INST"/>
                            <condition-expr field-name="workEffortTypeId" value="SCRUM_TASK_TEST"/>
                        </condition-list>
                    </condition-list>
                </entity-condition>
                <if-empty field="backlogItemTaskList">
                    <!-- add default task in product level -->
                    <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                        <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                        <field-map field-name="productId" from-field="parameters.productId"/>
                    </entity-and>
                    <if-not-empty field="defaultTaskList">
                    <iterate list="defaultTaskList" entry="defaultTask">
                        <set field="newDefaultTask.workEffortName" from-field="defaultTask.workEffortName"/>
                        <set field="newDefaultTask.estimatedMilliSeconds" from-field="defaultTask.estimatedMilliSeconds"/>
                        <set field="newDefaultTask.currentStatusId" from-field="defaultTask.currentStatusId"/>
                        <set field="newDefaultTask.workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                        <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
                            <result-to-field result-name="workEffortId"/>
                        </call-service>
                        <set field="newBacklogItemTask.custRequestId" from-field="parameters.custRequestId"/>
                        <set field="newBacklogItemTask.workEffortId" from-field="workEffortId"/>
                        <set field="newBacklogItemTask.userLogin" from-field="userLogin"/>
                        <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTask"/>
                        <!-- Assigned party for default task-->
                        <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                            <condition-list combine="and">
                                <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                <condition-expr field-name="workEffortId" from-field="defaultTask.workEffortId"/>
                            </condition-list>
                        </entity-condition>
                        <if-not-empty field="assigneds">
                            <first-from-list list="assigneds" entry="assignedMap"/>
                            <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                            <set field="newInput.workEffortId" from-field="workEffortId"></set>
                            <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                            <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                            <set field="newInput.userLogin" from-field="userLogin"/>
                            <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                        </if-not-empty>
                    </iterate>
                    <else>
                        <!-- If not have default task in product level -->
                        <entity-and entity-name="WorkEffort" list="defaultTaskScrum">
                            <field-map field-name="workEffortPurposeTypeId" value="SYSTEM_DEFAULT_TASK"/>
                        </entity-and>
                        <if-not-empty field="defaultTaskScrum">
                        <iterate list="defaultTaskScrum" entry="defaultScrum">
                            <set field="newDefaultTaskScrum.workEffortName" from-field="defaultScrum.workEffortName"/>
                            <set field="newDefaultTaskScrum.estimatedMilliSeconds" from-field="defaultScrum.estimatedMilliSeconds"/>
                            <set field="newDefaultTaskScrum.currentStatusId" from-field="defaultScrum.currentStatusId"/>
                            <set field="newDefaultTaskScrum.workEffortTypeId" from-field="defaultScrum.workEffortTypeId"/>
                            <call-service service-name="createWorkEffort" in-map-name="newDefaultTaskScrum">
                                <result-to-field result-name="workEffortId"/>
                            </call-service>
                            <set field="newBacklogItemTaskScrum.custRequestId" from-field="parameters.custRequestId"/>
                            <set field="newBacklogItemTaskScrum.workEffortId" from-field="workEffortId"/>
                            <set field="newBacklogItemTaskScrum.userLogin" from-field="userLogin"/>
                            <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTaskScrum"/>
                            <!-- Assigned party for default task-->
                            <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
                                <condition-list combine="and">
                                    <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                                    <condition-expr field-name="workEffortId" from-field="defaultScrum.workEffortId"/>
                                </condition-list>
                            </entity-condition>
                            <if-not-empty field="assigneds">
                                <first-from-list list="assigneds" entry="assignedMap"/>
                                <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
                                <set field="newInput.workEffortId" from-field="workEffortId"></set>
                                <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                                <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
                                <set field="newInput.userLogin" from-field="userLogin"/>
                                <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
                            </if-not-empty>
                        </iterate>
                        </if-not-empty>
                    </else>
                    </if-not-empty>
                </if-empty>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    
    <simple-method method-name="setTaskStatusReOpen" short-description="Re-Open Task from STS_COMPLETE to STS_CREATED">
        <call-simple-method method-name="getWebSiteId"/>
        <if>
            <condition>
                <if-has-permission permission="SCRUM" action="_ADMIN"/>
            </condition>
            <then>
                <!-- update status task -->
                <entity-one entity-name="WorkEffort" value-field="workEffortMap">
                    <field-map field-name="workEffortId" from-field="parameters.taskId"/>
                </entity-one>
                <set field="update.workEffortId" from-field="parameters.taskId"/>
                <set field="update.currentStatusId" value="STS_CREATED"/>
                <call-service service-name="updateWorkEffort" in-map-name="update"/>
                <!-- if task assign member and input timesheet -->
                <entity-and entity-name="WorkEffortPartyAssignment" list="assign">
                    <field-map field-name="workEffortId" from-field="parameters.taskId"/>
                </entity-and>
                <if-not-empty field="assign">
                    <set field="updatePartyAssign.workEffortId" from-field="parameters.taskId"/>
                    <set field="updatePartyAssign.fromDate" from-field="assign[0].fromDate"/>
                    <set field="updatePartyAssign.partyId" from-field="assign[0].partyId"/>
                    <set field="updatePartyAssign.roleTypeId" from-field="assign[0].roleTypeId"/>
                    <set field="updatePartyAssign.statusId" value="STS_CREATED"/>
                    <call-service service-name="updatePartyToWorkEffortAssignment" in-map-name="updatePartyAssign">
                        <result-to-field result-name="workEffortId"/>
                    </call-service>
                </if-not-empty>
                <!-- if re-open task in complete backlog -->
                <entity-and entity-name="ProjectSprintBacklogAndTask" list="backlogTask">
                    <field-map field-name="taskId" from-field="parameters.taskId"/>
                    <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                </entity-and>
                <if-empty field="backlogTask">
                    <entity-and entity-name="UnPlannedBacklogsAndTasks" list="backlogTask">
                    <field-map field-name="workEffortId" from-field="parameters.taskId"/>
                    <field-map field-name="custRequestTypeId" value="RF_UNPLAN_BACKLOG"/>
                </entity-and>
                </if-empty>
                <entity-and entity-name="CustRequest" list="backlog">
                    <field-map field-name="custRequestId" from-field="backlogTask[0].custRequestId"/>
                </entity-and>
                <!-- re-open completed backlog -->
                <if-compare operator="equals" value="CRQ_COMPLETED" field="backlog[0].statusId">
                    <set field="updateBacklog.custRequestId" from-field="backlog[0].custRequestId"/>
                    <set field="updateBacklog.statusId" value="CRQ_REVIEWED"/>
                    <set field="updateBacklog.webSiteId" from-field="parameters.webSiteId"/>
                    <call-service service-name="setCustRequestStatus" in-map-name="updateBacklog"/>
                    
                    <!-- also add a new task (the installation task and the test task) -->
                    <if-compare field="workEffortMap.workEffortTypeId" operator="not-equals" value="SCRUM_TASK_TEST">
                        <entity-and entity-name="ProjectSprintBacklogAndTask" list="projectAndTaskList">
                            <field-map field-name="sprintTypeId" value="SCRUM_SPRINT"/>
                            <field-map field-name="taskId" from-field="parameters.taskId"/>
                            <select-field field-name="projectId"/>
                            <select-field field-name="sprintId"/>
                        </entity-and>
                        <entity-and entity-name="UnPlannedBacklogsAndTasks" list="unPlannedTasks">
                            <field-map field-name="custRequestId" from-field="backlog[0].custRequestId"/>
                            <field-map field-name="workEffortId" from-field="parameters.taskId"/>
                            <select-field field-name="productId"/>
                        </entity-and>
                        <if-not-empty field="projectAndTaskList">
                            <first-from-list list="projectAndTaskList" entry="projectAndTaskMap"/>
                            <entity-and entity-name="WorkEffortAndProduct" list="productList">
                                <field-map field-name="workEffortId" from-field="projectAndTaskMap.projectId"/>
                                <select-field field-name="productId"/>
                            </entity-and>
                            <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                                <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                                <field-map field-name="productId" from-field="productList[0].productId"/>
                            </entity-and>
                            <else>
                                <first-from-list list="unPlannedTasks" entry="unPlannedTaskMap"/>
                                <entity-and entity-name="WorkEffortAndProduct" list="defaultTaskList">
                                    <field-map field-name="workEffortPurposeTypeId" value="SCRUM_DEFAULT_TASK"/>
                                    <field-map field-name="productId" from-field="unPlannedTaskMap.productId"/>
                                </entity-and>
                            </else>
                        </if-not-empty>
                        <if-not-empty field="defaultTaskList">
                            <iterate list="defaultTaskList" entry="defaultTask">
                                <set field="workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                                <if>
                                    <condition>
                                        <and>
                                            <or>
                                                <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortTypeId"/>
                                                <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                            </or>
                                            <or>
                                                <if-compare operator="equals" value="SCRUM_TASK_ERROR" field="workEffortMap.workEffortTypeId"/>
                                                <if-compare operator="equals" value="SCRUM_TASK_IMPL" field="workEffortMap.workEffortTypeId"/>
                                            </or>
                                        </and>
                                    </condition>
                                    <then>
                                        <call-simple-method method-name="callCreateDefaultTasks"/>
                                    </then>
                                    <else>
                                        <if>
                                            <condition>
                                                <and>
                                                    <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                                    <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortMap.workEffortTypeId"/>
                                                </and>
                                            </condition>
                                            <then>
                                                <call-simple-method method-name="callCreateDefaultTasks"/>
                                            </then>
                                        </if>
                                    </else>
                                </if>
                            </iterate>
                        <else>
                            <!-- If not have default task in product level -->
                            <entity-and entity-name="WorkEffort" list="defaultTaskList">
                                <field-map field-name="workEffortPurposeTypeId" value="SYSTEM_DEFAULT_TASK"/>
                            </entity-and>
                            <if-not-empty field="defaultTaskList">
                                <iterate list="defaultTaskList" entry="defaultTask">
                                    <set field="workEffortTypeId" from-field="defaultTask.workEffortTypeId"/>
                                    <if>
                                        <condition>
                                            <and>
                                                <or>
                                                    <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortTypeId"/>
                                                    <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                                </or>
                                                <or>
                                                    <if-compare operator="equals" value="SCRUM_TASK_ERROR" field="workEffortMap.workEffortTypeId"/>
                                                    <if-compare operator="equals" value="SCRUM_TASK_IMPL" field="workEffortMap.workEffortTypeId"/>
                                                </or>
                                            </and>
                                        </condition>
                                        <then>
                                            <call-simple-method method-name="callCreateDefaultTasks"/>
                                        </then>
                                        <else>
                                            <if>
                                                <condition>
                                                    <and>
                                                        <if-compare operator="equals" value="SCRUM_TASK_TEST" field="workEffortTypeId"/>
                                                        <if-compare operator="equals" value="SCRUM_TASK_INST" field="workEffortMap.workEffortTypeId"/>
                                                    </and>
                                                </condition>
                                                <then>
                                                    <call-simple-method method-name="callCreateDefaultTasks"/>
                                                </then>
                                            </if>
                                        </else>
                                    </if>
                                </iterate>
                            </if-not-empty>
                        </else>
                    </if-not-empty>
                 </if-compare>
                </if-compare>
                <!-- re-open completed sprint -->
                <if-not-empty field="backlogTask[0].sprintId">
                    <entity-one entity-name="WorkEffort" value-field="sprintMap">
                        <field-map field-name="workEffortId" from-field="backlogTask[0].sprintId"/>
                    </entity-one>
                    <if-compare operator="equals" value="SPRINT_CLOSED" field="sprintMap.currentStatusId">
                        <set field="sprintMap.currentStatusId" value="SPRINT_ACTIVE"/>
                        <store-value value-field="sprintMap"/>
                    </if-compare>
                </if-not-empty>
            </then>
            <else>
                <set field="_error_message_" value="You are has no permission to perform this action."/>
                <return response-code="error"/>
            </else>
        </if>
    </simple-method>
    <simple-method method-name="callCreateDefaultTasks" short-description="Call Create Default Tasks">
        <set field="newDefaultTask.workEffortName" from-field="defaultTask.workEffortName"/>
        <set field="newDefaultTask.estimatedMilliSeconds" from-field="defaultTask.estimatedMilliSeconds"/>
        <set field="newDefaultTask.currentStatusId" from-field="defaultTask.currentStatusId"/>
        <set field="newDefaultTask.workEffortTypeId" from-field="workEffortTypeId"/>
        <if-not-empty field="projectAndTaskList">
            <set field="newDefaultTask.workEffortParentId" from-field="projectAndTaskList[0].sprintId"/>
        </if-not-empty>
        <call-service service-name="createWorkEffort" in-map-name="newDefaultTask">
            <result-to-field result-name="workEffortId"/>
        </call-service>
        <set field="newBacklogItemTask.custRequestId" from-field="backlog[0].custRequestId"/>
        <set field="newBacklogItemTask.workEffortId" from-field="workEffortId"/>
        <set field="newBacklogItemTask.userLogin" from-field="userLogin"/>
        <call-service service-name="createWorkEffortRequest" in-map-name="newBacklogItemTask"/>
        <!--  Assigned party for default task -->
        <entity-condition entity-name="WorkEffortPartyAssignment" list="assigneds">
            <condition-list combine="and">
                <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                <condition-expr field-name="workEffortId" from-field="defaultTask.workEffortId"/>
            </condition-list>
        </entity-condition>
        <if-not-empty field="assigneds">
            <first-from-list list="assigneds" entry="assignedMap"/>
            <set field="newInput.partyId" from-field="assignedMap.partyId"></set>
            <set field="newInput.workEffortId" from-field="workEffortId"></set>
            <set field="newInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
            <set field="newInput.statusId" value="SCAS_ASSIGNED"></set>
            <set field="newInput.userLogin" from-field="userLogin"/>
            <call-service service-name="assignPartyToWorkEffort" in-map-name="newInput"/>
            <!--  Assigned party for sprint -->
            <if-not-empty field="projectAndTaskList">
                <entity-condition entity-name="WorkEffortPartyAssignment" list="sprintAssigneds">
                    <condition-list combine="and">
                        <condition-expr field-name="partyId" from-field="assignedMap.partyId"/>
                        <condition-expr field-name="statusId" value="PRTYASGN_ASSIGNED"/>
                        <condition-expr field-name="workEffortId" from-field="projectAndTaskList[0].sprintId"/>
                    </condition-list>
                </entity-condition>
                <if-empty field="sprintAssigneds">
                    <set field="sprintInput.partyId" from-field="assignedMap.partyId"></set>
                    <set field="sprintInput.workEffortId" from-field="projectAndTaskList[0].sprintId"></set>
                    <set field="sprintInput.roleTypeId" from-field="assignedMap.roleTypeId"></set>
                    <set field="sprintInput.statusId" value="PRTYASGN_ASSIGNED"></set>
                    <set field="sprintInput.userLogin" from-field="userLogin"/>
                    <call-service service-name="assignPartyToWorkEffort" in-map-name="sprintInput"/>
                </if-empty>
             </if-not-empty>
        </if-not-empty>
    </simple-method>
    
    <simple-method method-name="scrumCreatePartyRole" short-description="Scrum Create Party Role">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <map-to-map map="parameters" to-map="partyRoleMap"/>
        <set field="partyRoleMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="createPartyRole" in-map-name="partyRoleMap"/>
        <field-to-request field="parameters.partyId" request-name="partyId"/>
    </simple-method>
    
    <simple-method method-name="scrumDeletePartyRole" short-description="Scrum Delete Party Role">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <map-to-map map="parameters" to-map="partyRoleMap"/>
        <set field="partyRoleMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="deletePartyRole" in-map-name="partyRoleMap"/>
        <field-to-request field="parameters.partyId" request-name="partyId"/>
    </simple-method>
    
    <simple-method method-name="scrumUpdatePartyRate" short-description="Scrum UpdatePartyRate">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set-service-fields service-name="updatePartyRate" map="parameters" to-map="partyRateMap"/>
        <set field="partyRateMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="updatePartyRate" in-map-name="partyRateMap"/>
        <field-to-request field="parameters.partyId" request-name="partyId"/>
    </simple-method>
    
    <simple-method method-name="scrumDeletePartyRate" short-description="Scrum Delete Party Rate">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set-service-fields service-name="deletePartyRate" map="parameters" to-map="partyRateMap"/>
        <set field="partyRateMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="deletePartyRate" in-map-name="partyRateMap"/>
        <field-to-request field="parameters.partyId" request-name="partyId"/>
    </simple-method>
    
    <simple-method method-name="createQuickAddPartyRelationship" short-description="create Quick Add Add Party Relationship">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set-service-fields service-name="createPartyRelationshipContactAccount" map="parameters" to-map="partyRelationshipMap"/>
        <set field="partyRelationshipMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="createPartyRelationshipContactAccount" in-map-name="partyRelationshipMap">
            <default-message>Successfully created party relationship.</default-message>
        </call-service>
    </simple-method>
    
    <simple-method method-name="createQuickAddParty" short-description="create Quick Add Party" login-required="false">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <property-to-field resource="security" property="username.lowercase" default="false" field="username_lowercase"/>
        <property-to-field resource="security" property="password.lowercase" default="false" field="password_lowercase"/>
        
        <call-simple-method method-name="validateQuickAddPartyInfo"/>
        <check-errors/>
        
        <call-service service-name="createPerson" in-map-name="personMap">
            <result-to-field result-name="partyId" field="tempMap.partyId"/>
        </call-service>
        
        <set field="roleMap.roleTypeId" from-field="parameters.roleTypeId"/>
        <set field="roleMap.partyId" from-field="tempMap.partyId"/>
        <set field="roleMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="createPartyRole" in-map-name="roleMap"/>
        
        <!-- create the email address -->
        <set from-field="tempMap.partyId" field="partyId"/>
        <if-not-empty field="parameters.emailAddress">
            <set from-field="partyId" field="emailMap.partyId"/>
            <set field="emailMap.contactMechPurposeTypeId" value="PRIMARY_EMAIL"/>
            <set field="emailMap.userLogin" from-field="systemUserLogin"/>
            <call-service service-name="createPartyEmailAddress" in-map-name="emailMap"/>
        </if-not-empty>
        
        <!-- create userLogin -->
        <if-not-empty field="userLoginContext.userLoginId">
            <set field="userLoginContext.passwordHint" value="No hint set"/>
            
            <if-compare field="username_lowercase" operator="equals" value="true">
                <call-object-method obj-field="userLoginContext.userLoginId" method-name="toLowerCase" ret-field="userLoginContext.userLoginId"/>
            </if-compare>
            <if-compare field="password_lowercase" operator="equals" value="true">
                <call-object-method obj-field="userLoginContext.currentPassword" method-name="toLowerCase" ret-field="userLoginContext.currentPassword"/>
                <call-object-method obj-field="userLoginContext.currentPasswordVerify" method-name="toLowerCase" ret-field="userLoginContext.currentPasswordVerify"/>
            </if-compare>
            
            <if-not-empty field="userLoginContext.userLoginId">
                <set field="userLoginExistsMap.userLoginId"  from-field="userLoginContext.userLoginId"/>
                <find-by-primary-key entity-name="UserLogin" map="userLoginExistsMap" value-field="existingUserLogin"/>
                <if-not-empty field="existingUserLogin">
                    <property-to-field field="tempErrorMessage" property="PartyUserNameInUse" resource="PartyUiLabels"/>
                    <field-to-list field="tempErrorMessage" list="error_list"/>
                </if-not-empty>
            </if-not-empty>
            
            <make-value entity-name="UserLogin" value-field="newUserLogin"/>
            <set field="newUserLogin.userLoginId" from-field="userLoginContext.userLoginId"/>
            <set field="newUserLogin.currentPassword" from-field="userLoginContext.currentPassword"/>
            <set field="newUserLogin.passwordHint" from-field="userLoginContext.passwordHint"/>

            <!-- Check the password, etc for validity -->
            <script>groovy:
                String password = (String) userLoginContext.get("currentPassword")
                String confirmPassword = (String) userLoginContext.get("currentPasswordVerify")
                String passwordHint = (String) userLoginContext.get("passwordHint")
                org.apache.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin, null, password, confirmPassword, passwordHint, error_list, true, locale)
            </script>
             <!-- If password encryption is enabled, encrpyt it now -->
            <script>groovy:
                boolean useEncryption = "true".equals(org.apache.ofbiz.base.util.UtilProperties.getPropertyValue("security", "password.encrypt"))
                if (useEncryption) {
                    String hashType = org.apache.ofbiz.common.login.LoginServices.getHashType()
                    newUserLogin.set("currentPassword", org.apache.ofbiz.base.crypto.HashCrypt.digestHash(hashType, null, (String) newUserLogin.get("currentPassword")))
                }
            </script>

            <!-- create the UserLogin -->
            <set field="newUserLogin.partyId" from-field="tempMap.partyId"/>
            <create-value value-field="newUserLogin"/>
        </if-not-empty>
        
        <!-- Create Party Relation -->
        <set field="partyRelationMap.contactPartyId" from-field="tempMap.partyId"/>
        <set field="partyRelationMap.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="createPartyRelationshipContactAccount" in-map-name="partyRelationMap"/>
        <!-- Creste security group -->
        <if-not-empty field="parameters.roleTypeId">
            <set field="parameters.partyId" from-field="partyId"/>
            <set field="parameters.userLoginIdDesc" value="|${userLoginContext.userLoginId}"/>
            <if-compare operator="equals" value="PRODUCT_OWNER" field="parameters.roleTypeId">
                <set field="parameters.groupId" value="SCRUM_PRODUCT_OWNER"/>
            </if-compare>
            <if-compare operator="equals" value="PRODUCT_OWNER_COMP" field="parameters.roleTypeId">
                <set field="parameters.groupId" value="SCRUM_PRODUCT_OWNER"/>
            </if-compare>
            <if-compare operator="equals" value="SCRUM_MASTER" field="parameters.roleTypeId">
                <set field="parameters.groupId" value="SCRUM_MASTER"/>
            </if-compare>
            <if-compare operator="equals" value="SCRUM_TEAM" field="parameters.roleTypeId">
                <set field="parameters.groupId" value="SCRUM_TEAM"/>
            </if-compare>
            <if-compare operator="equals" value="STAKEHOLDER" field="parameters.roleTypeId">
                <set field="parameters.groupId" value="SCRUM_STAKEHOLDER"/>
            </if-compare>
            <call-simple-method method-name="addScrumResource"/>
        </if-not-empty>
    </simple-method>
    <simple-method method-name="validateQuickAddPartyInfo" short-description="validateQuickAddPartyInfo" login-required="false">
        <!-- setup the party/person -->
        <call-map-processor in-map-name="parameters" out-map-name="personMap">
            <simple-map-processor name="newPerson">
                <process field="personalTitle"><copy/></process>
                <process field="firstName">
                    <copy/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyFirstNameMissing"/></not-empty>
                </process>
                <process field="middleName"><copy/></process>
                <process field="lastName">
                    <copy/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyLastNameMissingError"/></not-empty>
                </process>
            </simple-map-processor>
        </call-map-processor>
        <!-- setup the email -->
        <call-map-processor in-map-name="parameters" out-map-name="emailMap">
            <simple-map-processor name="newEmail">
                <process field="emailAddress">
                    <copy/>
                    <validate-method method="isEmail"><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></validate-method>
                </process>
                <process field="emailSol"><copy to-field="allowSolicitation"/></process>
            </simple-map-processor>
        </call-map-processor>
        <!-- setup the User Login -->
         <call-map-processor in-map-name="parameters" out-map-name="userLoginContext">
            <simple-map-processor name="newUserLogin">
                <process field="userLoginId"><copy to-field="userLoginId"/><not-empty><fail-property resource="PartyUiLabels" property="PartyUserNameMissing"/></not-empty></process>
                 <process field="password"><copy to-field="currentPassword"/><not-empty><fail-property resource="PartyUiLabels" property="PartyPasswordMissing"/></not-empty></process>
                 <process field="confirmPassword">
                        <compare-field operator="equals" field="password"><fail-property resource="PartyUiLabels" property="PartyPasswordMatchError"/></compare-field>
                        <copy to-field="currentPasswordVerify"/>
                 </process>
            </simple-map-processor>
        </call-map-processor>
        <!-- setup the PartyRelationship -->
        <call-map-processor in-map-name="parameters" out-map-name="partyRelationMap">
            <simple-map-processor name="newPartyRelation">
                <process field="company">
                    <copy to-field="accountPartyId"/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyCompanyNameMissingError"/></not-empty>
                </process>
            </simple-map-processor>
        </call-map-processor>
    </simple-method>
    <simple-method method-name="addProductMember" short-description="Add Product Member">
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <entity-and entity-name="ProductRole" list="productRoleList">
            <field-map field-name="partyId" from-field="parameters.partyId"/>
            <field-map field-name="productId" from-field="parameters.productId"/>
            <field-map field-name="roleTypeId" from-field="parameters.roleTypeId"/>
            <field-map field-name="thruDate" value=""/>
        </entity-and>
        <if-empty field="productRoleList">
            <entity-and entity-name="PartyRole" list="partyRoleList">
                <field-map field-name="partyId" from-field="parameters.partyId"/>
                <field-map field-name="roleTypeId" from-field="parameters.roleTypeId"/>
            </entity-and>  
            <if-empty field="partyRoleList">
                <make-value entity-name="PartyRole" value-field="partyRole"/>
                <set field="partyRole.partyId" from-field="parameters.partyId"/>
                <set field="partyRole.roleTypeId" from-field="parameters.roleTypeId"/>
                <create-value value-field="partyRole"/>
            </if-empty>
            <now-timestamp field="nowTimestamp"/>
            <make-value entity-name="ProductRole" value-field="productRoleMap"/>
            <set field="productRoleMap.productId" from-field="parameters.productId" />
            <set field="productRoleMap.partyId" from-field="parameters.partyId"/>
            <set field="productRoleMap.roleTypeId" from-field="parameters.roleTypeId"/>
            <set field="productRoleMap.fromDate" from-field="nowTimestamp"/>
            <create-value value-field="productRoleMap"/>
            <else>
                <add-error>
                    <fail-message message="There are partyId : ${parameters.partyId} and roleTypeId : ${parameters.roleTypeId} already exist."/>
                </add-error>
            <check-errors/>
            </else>
        </if-empty>
    </simple-method>
    <simple-method method-name="removeProductMember" short-description="Remove Product Member">
        <set field="parameters.fromDate" from-field="parameters.fromDate" type="Timestamp"/>
        <entity-one entity-name="ProductRole" value-field="productRoleMap"/>
        <remove-value value-field="productRoleMap"/>
    </simple-method>
    <simple-method method-name="updateNotBilledBacklog" short-description="Update Not Billed Backlog">
       <call-class-method method-name="getParameterMap" class-name="org.apache.ofbiz.base.util.UtilHttp" ret-field="paramMap">
           <field field="request" type="javax.servlet.http.HttpServletRequest"/>
       </call-class-method>
       <call-class-method method-name="getMultiFormRowCount" class-name="org.apache.ofbiz.base.util.UtilHttp" ret-field="rowCount">
           <field field="paramMap" type="java.util.Map"/>
       </call-class-method>
       <loop count="${rowCount}" field="i">
           <set field="billed" from-field="paramMap[&quot;billed_o_${i}&quot;]"/>
           <set field="custRequestId" from-field="paramMap[&quot;custRequestId_o_${i}&quot;]"/>
           <entity-one entity-name="CustRequest" value-field="custRequestMap"/>
           <set field="custRequestMap.billed" from-field="billed"/>
           <store-value value-field="custRequestMap"/>
       </loop>
    </simple-method>
    <simple-method method-name="getWebSiteId" short-description="Get WebSite Id">
        <!-- for notification -->
        <if-not-empty field="request">
            <call-class-method method-name="getWebSiteId" class-name="org.apache.ofbiz.webapp.website.WebSiteWorker" ret-field="webSiteId">
                <field field="request" type="javax.servlet.ServletRequest"/>
            </call-class-method>
        </if-not-empty>
        <if-not-empty field="webSiteId">
            <set field="parameters.webSiteId" from-field="webSiteId"/>
        </if-not-empty>
    </simple-method>
</simple-methods>
