This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2c370a6c35 Improved: Convert WorkEffortServices.xml mini-lang to 
groovyDSL (OFBIZ-12965)
2c370a6c35 is described below

commit 2c370a6c356776f0098ab815185978ef44433d58
Author: Nicolas Malin <nicolas.ma...@nereide.fr>
AuthorDate: Tue Mar 26 18:31:15 2024 +0100

    Improved: Convert WorkEffortServices.xml mini-lang to groovyDSL 
(OFBIZ-12965)
    
    Convert the following service :
       * createWorkEffort
       * updateWorkEffort
       * deleteWorkEffort
       * copyWorkEffort
       * createWorkEffortAndPartyAssign
    
    createWorkEffort contains too functionnal logic on the base code so split 
it on different services and introduce :
       * assocAcceptedCustRequestToWorkEffort, run throught seca
       * createWorkEffortStatus
    
    createWorkEffortAndPartyAssign use the entity-auto logic so create services 
createWorkEffortPartyAssignment, updateWorkEffortPartyAssignment and 
expireWorkEffortPartyAssignment to make them more generic
---
 .../workeffort/config/WorkEffortUiLabels.xml       |  14 +-
 .../workeffort/WorkEffortSimpleServices.xml        | 276 ---------------------
 applications/workeffort/servicedef/secas.xml       |   8 +
 applications/workeffort/servicedef/services.xml    |  56 +++--
 .../workeffort/WorkEffortServicesScript.groovy     | 195 +++++++++++++++
 5 files changed, 251 insertions(+), 298 deletions(-)

diff --git a/applications/workeffort/config/WorkEffortUiLabels.xml 
b/applications/workeffort/config/WorkEffortUiLabels.xml
index e341db024a..08c7957e59 100644
--- a/applications/workeffort/config/WorkEffortUiLabels.xml
+++ b/applications/workeffort/config/WorkEffortUiLabels.xml
@@ -4870,13 +4870,13 @@
         <value xml:lang="zh-TW">狀態</value>
     </property>
     <property key="WorkEffortStatusChangeNotValid">
-        <value xml:lang="ar">إن تحويل الحالة من 
${lookedUpValue.currentStatusId} الى ${parameters.currentStatusId} هو تحويل غير 
مسموح به</value>
-        <value xml:lang="en">The status change from 
${lookedUpValue.currentStatusId} to ${parameters.currentStatusId} is not a 
valid change</value>
-        <value xml:lang="it">Il cambio di stato da 
${lookedUpValue.currentStatusId} a ${parameters.currentStatusId} non è 
consentito</value>
-        <value xml:lang="ja">ステータス ${lookedUpValue.currentStatusId} から 
${parameters.currentStatusId} へ変更は正しくありません。</value>
-        <value xml:lang="vi">Trạng thái thay đổi từ 
${lookedUpValue.currentStatusId} đến ${parameters.currentStatusId} là không hợp 
lệ</value>
-        <value xml:lang="zh">从 ${lookedUpValue.currentStatusId} 到 
${parameters.currentStatusId} 不是一个有效的状态改变</value>
-        <value xml:lang="zh-TW">從 ${lookedUpValue.currentStatusId} 到 
${parameters.currentStatusId} 不是一個有效的狀態改變</value>
+        <value xml:lang="ar">إن تحويل الحالة من ${statusId} الى ${statusIdTo} 
هو تحويل غير مسموح به</value>
+        <value xml:lang="en">The status change from ${statusId} to 
${statusIdTo} is not a valid change</value>
+        <value xml:lang="it">Il cambio di stato da ${statusId} a ${statusIdTo} 
non è consentito</value>
+        <value xml:lang="ja">ステータス ${statusId} から ${statusIdTo} 
へ変更は正しくありません。</value>
+        <value xml:lang="vi">Trạng thái thay đổi từ ${statusId} đến 
${statusIdTo} là không hợp lệ</value>
+        <value xml:lang="zh">从 ${statusId} 到 ${statusIdTo} 不是一个有效的状态改变</value>
+        <value xml:lang="zh-TW">從 ${statusId} 到 ${statusIdTo} 
不是一個有效的狀態改變</value>
     </property>
     <property key="WorkEffortStatusIdMissing">
         <value xml:lang="en">Current Status ID is missing.</value>
diff --git 
a/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml 
b/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml
index cf65e6ea41..26c221207e 100644
--- a/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml
+++ b/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml
@@ -21,282 +21,6 @@ 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="createWorkEffortAndPartyAssign" 
short-description="Create Work Effort and assign to a party with a role">
-        <entity-one entity-name="PartyRole" value-field="partyRole">
-            <field-map field-name="partyId" from-field="parameters.partyId"/>
-            <field-map field-name="roleTypeId" value="CAL_OWNER"/>
-        </entity-one>
-        <if-empty field="partyRole">
-            <entity-one entity-name="RoleType" value-field="roleType">
-                <field-map field-name="roleTypeId" value="CAL_OWNER"/>
-            </entity-one>
-            <if-not-empty field="roleType">
-                <set field="roleDescription" 
from-field="roleType.description"/>
-            </if-not-empty>
-            <set field="partyId" from-field="parameters.partyId"></set>
-            <add-error>
-                <fail-property resource="PartyErrorUiLabels" 
property="PartyRoleAssociationRequired" />
-            </add-error>
-        </if-empty>
-        <set-service-fields service-name="createWorkEffort" map="parameters" 
to-map="create"/>
-        <call-service service-name="createWorkEffort" in-map-name="create">
-            <result-to-field result-name="workEffortId"/>
-        </call-service>
-        <check-errors />
-        <make-value entity-name="WorkEffortPartyAssignment" 
value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <set field="newEntity.workEffortId" from-field="workEffortId"/>
-        <if-empty field="newEntity.fromDate">
-            <now-timestamp field="newEntity.fromDate"/>
-        </if-empty>
-        <set field="newEntity.assignedByUserLoginId" 
from-field="userLogin.userLoginId"/>
-        <create-value value-field="newEntity"/>
-        <field-to-result field="workEffortId"/>
-    </simple-method>
-
-    <simple-method method-name="createWorkEffort" short-description="Create 
Work Effort">
-        <make-value entity-name="WorkEffort" value-field="newEntity"/>
-        <if-empty field="parameters.workEffortId">
-            <sequenced-id sequence-name="WorkEffort" 
field="newEntity.workEffortId"/>
-            <else>
-                <check-id field="parameters.workEffortId"/>
-                <check-errors/>            
-                <set field="newEntity.workEffortId" 
from-field="parameters.workEffortId"/>
-            </else>
-        </if-empty>
-        <field-to-result field="newEntity.workEffortId" 
result-name="workEffortId"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-
-        <now-timestamp field="nowTimestamp"/>
-        <set from-field="nowTimestamp" field="newEntity.lastStatusUpdate"/>
-        <set from-field="nowTimestamp" field="newEntity.lastModifiedDate"/>
-        <set from-field="nowTimestamp" field="newEntity.createdDate"/>
-        <set field="newEntity.revisionNumber" value="1" type="Long"/>
-        <set from-field="userLogin.userLoginId" 
field="newEntity.lastModifiedByUserLogin"/>
-        <set from-field="userLogin.userLoginId" 
field="newEntity.createdByUserLogin"/>
-        <create-value value-field="newEntity"/>
-
-        <!-- create new status entry, and set lastStatusUpdate date -->
-        <make-value entity-name="WorkEffortStatus" 
value-field="newWorkEffortStatus"/>
-        <set from-field="newEntity.workEffortId" 
field="newWorkEffortStatus.workEffortId"/>
-        <set from-field="newEntity.currentStatusId" 
field="newWorkEffortStatus.statusId"/>
-        <set from-field="nowTimestamp" 
field="newWorkEffortStatus.statusDatetime"/>
-        <set from-field="userLogin.userLoginId" 
field="newWorkEffortStatus.setByUserLogin"/>
-        <create-value value-field="newWorkEffortStatus"/>
-
-        <!-- Attach the workeffort to a requirement if passed -->
-        <if-not-empty field="parameters.requirementId">
-            <make-value entity-name="WorkRequirementFulfillment" 
value-field="workFullfillment"/>
-            <set from-field="newEntity.workEffortId" 
field="workFullfillment.workEffortId"/>
-            <set from-field="parameters.requirementId" 
field="workFullfillment.requirementId"/>
-            <create-value value-field="workFullfillment"/>
-        </if-not-empty>
-
-        <!-- attach to a customer request if passed and copy attached docs -->
-        <if-not-empty field="parameters.custRequestId">
-            <!-- check status of customer request if valid -->
-            <entity-one entity-name="CustRequest" value-field="lookedUpValue"/>
-            <set field="goodStatusId" value="CRQ_ACCEPTED"/>
-            <if-compare-field operator="not-equals" 
field="lookedUpValue.statusId" to-field="goodStatusId" >
-                <set field="entity" value="Customer request"/>
-                <add-error>
-                    <fail-property resource="CommonUiLabels" 
property="CommonErrorStatusNotValid"/>
-                </add-error>
-                <check-errors/>
-            </if-compare-field>
-            <!-- create customer request / work effort relation -->
-            <make-value entity-name="CustRequestWorkEffort" 
value-field="custRequestWorkEffort"/>
-            <set field="custRequestWorkEffort.workEffortId" 
from-field="newEntity.workEffortId"/>
-            <set field="custRequestWorkEffort.custRequestId" 
from-field="parameters.custRequestId"/>
-            <create-value value-field="custRequestWorkEffort"/>
-            <!-- update status of customer request -->
-            <set field="updCustReq.custRequestId" 
from-field="parameters.custRequestId"/>
-            <set field="updCustReq.statusId" value="CRQ_REVIEWED"/>
-            <set field="updCustReq.webSiteId" 
from-field="parameters.webSiteId"/>
-            <call-service service-name="setCustRequestStatus" 
in-map-name="updCustReq"/>
-            <entity-and entity-name="CustRequestContent" 
list="custRequestContents">
-                <field-map field-name="custRequestId" 
from-field="parameters.custRequestId"/>
-            </entity-and>
-            <iterate list="custRequestContents" entry="custRequestContent">
-                <set field="newWorkEffortContent.workEffortId" 
from-field="newEntity.workEffortId"/>
-                <set field="newWorkEffortContent.contentId" 
from-field="custRequestContent.contentId"/>
-                <set field="newWorkEffortContent.workEffortContentTypeId" 
value="SUPPORTING_MEDIA"/>
-                <call-service service-name="createWorkEffortContent" 
in-map-name="newWorkEffortContent"/>
-            </iterate>
-        </if-not-empty>
-    </simple-method>
-    <simple-method method-name="updateWorkEffort" short-description="Update 
Work Effort">
-        <!-- check permissions before moving on: if update or delete logged in 
user must be associated OR have the corresponding UPDATE or DELETE permissions 
-->
-
-        <!-- temporarily commented out, because users assigned to a project or 
phase should
-              have the capability to modify status on sub-tasks, right? 
Hmmmm.... -->
-
-<!--        <set from-field="workEffortId" map-name="parameters" 
to-map-name="findWepaMap"/>
-        <set from-field="partyId" map-name="userLogin" 
to-map-name="findWepaMap"/>
-        <find-by-and entity-name="WorkEffortPartyAssignment" map="findWepaMap" 
list="wepaList"/>
-        <if-empty field="wepaList">
-            <check-permission permission="WORKEFFORTMGR" action="_UPDATE">
-                <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortUpdatePermissionError"/>
-            </check-permission>
-            <check-errors/>
-        </if-empty>-->
-
-        <entity-one entity-name="WorkEffort" value-field="lookedUpValue"/>
-        <clone-value value-field="lookedUpValue" new-value-field="savedValue"/>
-
-        <now-timestamp field="nowTimestamp"/>
-
-        <!-- if necessary create new status entry, and set lastStatusUpdate 
date -->
-        <if>
-            <condition>
-                <and>
-                    <not><if-empty field="parameters.currentStatusId"/></not>
-                    <if-compare-field field="parameters.currentStatusId" 
to-field="lookedUpValue.currentStatusId" operator="not-equals"/>
-                </and>
-            </condition>
-            <then>
-                <if-not-empty field="lookedUpValue.currentStatusId">
-                    <!-- check if the status change is a valid change -->
-                    <entity-and entity-name="StatusValidChange" 
list="validChange">
-                        <field-map field-name="statusId" 
from-field="lookedUpValue.currentStatusId"/>
-                        <field-map field-name="statusIdTo" 
from-field="parameters.currentStatusId"/>
-                    </entity-and>
-
-                    <if-empty field="validChange">
-                        <add-error>
-                            <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortStatusChangeNotValid"/>
-                        </add-error>
-                        <log level="error" message="The status change from 
${lookedUpValue.currentStatusId} to ${parameters.currentStatusId} is not a 
valid change"/>
-                        <check-errors/>
-                    </if-empty>
-                </if-not-empty>
-
-                <set from-field="nowTimestamp" 
field="lookedUpValue.lastStatusUpdate"/>
-                <make-value entity-name="WorkEffortStatus" 
value-field="newWorkEffortStatus"/>
-                <set from-field="lookedUpValue.workEffortId" 
field="newWorkEffortStatus.workEffortId"/>
-                <set from-field="parameters.currentStatusId" 
field="newWorkEffortStatus.statusId"/>
-                <set from-field="parameters.reason" 
field="newWorkEffortStatus.reason"/>
-                <set from-field="nowTimestamp" 
field="newWorkEffortStatus.statusDatetime"/>
-                <set from-field="userLogin.userLoginId" 
field="newWorkEffortStatus.setByUserLogin"/>
-                <create-value value-field="newWorkEffortStatus"/>
-            </then>
-        </if>
-        <!-- after checking status change, set all parameters -->
-        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
-
-        <!-- only save if something has changed -->
-        <if-compare-field field="lookedUpValue" to-field="savedValue" 
operator="not-equals" type="Object">
-            <!-- only set lastModifiedDate after comparing new & old to see if 
anything has changed -->
-            <set from-field="nowTimestamp" 
field="lookedUpValue.lastModifiedDate"/>
-            <set from-field="userLogin.userLoginId" 
field="lookedUpValue.lastModifiedByUserLogin"/>
-            <if-not-empty field="lookedUpValue.revisionNumber">
-                <set field="lookedUpValue.revisionNumber" 
value="${lookedUpValue.revisionNumber + 1}" type="Long"/>
-            <else>
-                <set field="lookedUpValue.revisionNumber" value="1" 
type="Long"/>
-            </else>
-            </if-not-empty>
-            <store-value value-field="lookedUpValue"/>
-        </if-compare-field>
-    </simple-method>
-    <simple-method method-name="deleteWorkEffort" short-description="Delete 
Work Effort">
-        <!-- check permissions before moving on: if update or delete logged in 
user must be associated OR have the corresponding UPDATE or DELETE permissions 
-->
-        <entity-and entity-name="WorkEffortPartyAssignment" list="wepaList">
-            <field-map field-name="workEffortId" 
from-field="parameters.workEffortId"/>
-            <field-map field-name="partyId" from-field="userLogin.partyId"/>
-        </entity-and>
-        <if-empty field="wepaList">
-            <check-permission permission="WORKEFFORTMGR" action="_DELETE">
-                <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortDeletePermissionError"/>
-            </check-permission>
-            <check-errors/>
-        </if-empty>
-
-        <entity-one entity-name="WorkEffort" value-field="lookedUpValue"/>
-
-        <!-- Remove associated/dependent entries from other entities here -->
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortKeyword"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortAttribute"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkOrderItemFulfillment"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="FromWorkEffortAssoc"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="ToWorkEffortAssoc"/>
-        <remove-related value-field="lookedUpValue" relation-name="NoteData"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="RecurrenceInfo"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="RuntimeData"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortPartyAssignment"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortFixedAssetAssign"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortSkillStandard"/>
-        <remove-related value-field="lookedUpValue" 
relation-name="WorkEffortStatus"/>
-
-        <!-- Delete actual main entity last -->
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-
-    <simple-method method-name="copyWorkEffort" short-description="Copy a 
WorkEffort">
-        <entity-one entity-name="WorkEffort" value-field="sourceWorkEffort">
-            <field-map field-name="workEffortId" 
from-field="parameters.sourceWorkEffortId" />
-        </entity-one>
-        <if-empty field="sourceWorkEffort">
-            <set field="errorString" value="sourceWorkEffortId = 
${parameters.sourceWorkEffortId}" />
-            <add-error>
-                <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortNotFound" />
-            </add-error>
-            <check-errors />
-        </if-empty>
-        <set field="targetWorkEffortId" 
from-field="parameters.targetWorkEffortId" />
-        <if-empty field="targetWorkEffortId">
-            <sequenced-id sequence-name="WorkEffort" 
field="targetWorkEffortId" />
-        </if-empty>
-        <set-service-fields service-name="createWorkEffort" 
map="sourceWorkEffort" to-map="createWorkEffortCtx"/>
-        <set field="createWorkEffortCtx.workEffortId" 
from-field="targetWorkEffortId" />
-        <set field="createWorkEffortCtx.userLogin" 
from-field="parameters.userLogin" />
-        <call-service service-name="createWorkEffort" 
in-map-name="createWorkEffortCtx" />
-        <check-errors />
-        <entity-one entity-name="WorkEffort" value-field="targetWorkEffort">
-            <field-map field-name="workEffortId" 
from-field="targetWorkEffortId" />
-        </entity-one>
-        <set field="copyWorkEffortAssocs" 
from-field="parameters.copyWorkEffortAssocs" default-value="N" />
-        <if-compare field="copyWorkEffortAssocs" operator="equals" value="Y">
-            <set-service-fields service-name="copyWorkEffortAssocs" 
map="parameters" to-map="copyWorkEffortAssocsCtx"/>
-            <set field="copyWorkEffortAssocsCtx.targetWorkEffortId" 
from-field="targetWorkEffortId" />
-            <call-service service-name="copyWorkEffortAssocs" 
in-map-name="copyWorkEffortAssocsCtx" />
-            <check-errors />
-        </if-compare>
-        <set field="copyRelatedValues" 
from-field="parameters.copyRelatedValues" default-value="N" />
-        <if-compare field="copyRelatedValues" operator="equals" value="Y">
-            <set field="excludeExpiredRelations" 
from-field="parameters.excludeExpiredRelations" default-value="N" />
-            <set field="modelRelationList" 
from-field="groovy:delegator.getModelEntity('WorkEffort').getRelationsManyList();"
 />
-            <iterate list="modelRelationList" entry="modelRelation">
-                <set field="relatedEntityName" 
from-field="groovy:modelRelation.getRelEntityName();" />
-                <if-compare field="relatedEntityName" operator="not-equals" 
value="WorkEffortAssoc">
-                    <set field="relationName" 
from-field="groovy:modelRelation.getCombinedName();" />
-                    <set field="keyMap" 
from-field="groovy:modelRelation.findKeyMap('workEffortId');" 
set-if-null="true" />
-                    <if-not-empty field="keyMap">
-                        <set field="relatedIdFieldName" 
from-field="groovy:keyMap.getRelFieldName();" />
-                        <get-related relation-name="${relationName}" 
list="relationValues" value-field="sourceWorkEffort" />
-                        <if-compare field="excludeExpiredRelations" 
operator="equals" value="Y">
-                            <set field="fromDateModelField" 
from-field="groovy:delegator.getModelEntity(relatedEntityName).getField('fromDate');"
 set-if-null="true" />
-                            <if-not-empty field="fromDateModelField">
-                                <filter-list-by-date list="relationValues" />
-                            </if-not-empty>
-                        </if-compare>
-                        <iterate list="relationValues" entry="relatedValue">
-                            <clone-value value-field="relatedValue" 
new-value-field="newRelatedValue" />
-                            <set field="newRelatedValue[relatedIdFieldName]" 
from-field="targetWorkEffortId" />
-                            <make-value entity-name="${relatedEntityName}" 
value-field="newRelatedPks" />
-                            <set-pk-fields value-field="newRelatedPks" 
map="newRelatedValue" />
-                            <find-by-primary-key 
entity-name="${relatedEntityName}" map="newRelatedPks" 
value-field="duplicateCheck" />
-                            <if-empty field="duplicateCheck">
-                                <create-value value-field="newRelatedValue" />
-                            </if-empty>
-                        </iterate>
-                    </if-not-empty>
-                </if-compare>
-            </iterate>
-        </if-compare>
-        <field-to-result field="targetWorkEffortId" result-name="workEffortId" 
/>
-    </simple-method>
-
     <!-- communication event workeffort -->
     <simple-method method-name="makeCommunicationEventWorkEffort" 
short-description="Make a Communication Event WorkEffort">
         <make-value entity-name="CommunicationEventWorkEff" 
value-field="lookupMap"/>
diff --git a/applications/workeffort/servicedef/secas.xml 
b/applications/workeffort/servicedef/secas.xml
index 4c05f5b9c2..80e08c3fcb 100644
--- a/applications/workeffort/servicedef/secas.xml
+++ b/applications/workeffort/servicedef/secas.xml
@@ -29,6 +29,14 @@ under the License.
         <condition field-name="custRequestId" operator="is-empty"/><!-- 
otherwise link is made over the customer request -->
         <action service="makeCommunicationEventWorkEffort" mode="sync"/>
     </eca>
+    <eca service="createWorkEffort" event="commit">
+        <condition field-name="custRequestId" operator="is-not-empty"/>
+        <action service="assocAcceptedCustRequestToWorkEffort" mode="sync"/>
+    </eca>
+    <eca service="createWorkEffort" event="commit">
+        <condition field-name="requirementId" operator="is-not-empty"/>
+        <action service="createWorkRequirementFulfillment" mode="sync"/>
+    </eca>
 
     <eca service="updateWorkEffort" event="commit">
         <condition field-name="communicationEventId" operator="is-not-empty"/>
diff --git a/applications/workeffort/servicedef/services.xml 
b/applications/workeffort/servicedef/services.xml
index bf90f16753..45207a8d0d 100644
--- a/applications/workeffort/servicedef/services.xml
+++ b/applications/workeffort/servicedef/services.xml
@@ -38,8 +38,8 @@ under the License.
         <override name="workEffortName" allow-html="safe"/>
         <override name="description" allow-html="safe"/>
     </service>
-    <service name="createWorkEffort" default-entity-name="WorkEffort" 
engine="simple"
-        
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="createWorkEffort">
+    <service name="createWorkEffort" default-entity-name="WorkEffort" 
engine="groovy" invoke="createWorkEffort"
+            
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
         <description>Create a WorkEffort Entity</description>
         <permission-service service-name="workEffortGenericPermission" 
main-action="CREATE"/>
         <implements service="interfaceWorkEffort"/>
@@ -54,23 +54,23 @@ under the License.
         <override name="currentStatusId" optional="false"/>
         <override name="description" allow-html="safe"/>
     </service>
-    <service name="createWorkEffortAndPartyAssign" 
default-entity-name="WorkEffort" engine="simple"
-        
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="createWorkEffortAndPartyAssign">
+    <service name="createWorkEffortAndPartyAssign" 
default-entity-name="WorkEffort" engine="groovy" 
invoke="createWorkEffortAndPartyAssign"
+             
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
         <description>Create a WorkEffort Entity and assign to a 
party</description>
         <permission-service service-name="workEffortGenericPermission" 
main-action="CREATE"/>
         <implements service="interfaceWorkEffort"/>
         <auto-attributes mode="INOUT" include="pk" optional="true"/>
-        <attribute name="partyId" type="String" mode="IN" optional="false">
+        <attribute name="partyId" type="String" mode="IN">
             <type-validate>
                 <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortRequiredFieldMissingPartyId"/>
             </type-validate>
         </attribute>
-        <attribute name="roleTypeId" type="String" mode="IN" optional="false">
+        <attribute name="roleTypeId" type="String" mode="IN" 
default-value="CAL_OWNER">
             <type-validate>
                 <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortRequiredFieldMissingRoleTypeId"/>
             </type-validate>
         </attribute>
-        <attribute name="statusId" type="String" mode="IN" optional="false">
+        <attribute name="statusId" type="String" mode="IN">
             <type-validate>
                 <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortRequiredFieldMissingStatusId"/>
             </type-validate>
@@ -82,12 +82,12 @@ under the License.
         <override name="workEffortName" optional="false"/>
         <override name="currentStatusId" optional="false"/>
     </service>
-    <service name="updateWorkEffort" default-entity-name="WorkEffort" 
engine="simple"
-            
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="updateWorkEffort">
+    <service name="updateWorkEffort" default-entity-name="WorkEffort" 
engine="groovy" invoke="updateWorkEffort"
+             
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
         <description>Update a WorkEffort Entity</description>
         <permission-service service-name="workEffortGenericPermission" 
main-action="UPDATE"/>
         <implements service="interfaceWorkEffort"/>
-        <auto-attributes mode="IN" include="pk" optional="false"/>
+        <auto-attributes mode="IN" include="pk"/>
         <attribute name="communicationEventId" type="String" mode="IN" 
optional="true"/>
         <attribute name="reason" type="String" mode="IN" optional="true"/>
         <attribute name="webSiteId" type="String" mode="IN" 
optional="true"/><!-- for notification services -->
@@ -97,19 +97,24 @@ under the License.
             </type-validate>
         </override>
     </service>
-    <service name="deleteWorkEffort" default-entity-name="WorkEffort" 
engine="simple"
-            
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="deleteWorkEffort">
+    <service name="deleteWorkEffort" default-entity-name="WorkEffort" 
engine="groovy" invoke="deleteWorkEffort"
+             
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
         <description>Delete a WorkEffort Entity</description>
-        <auto-attributes mode="IN" include="pk" optional="false"/>
+        <auto-attributes mode="IN" include="pk"/>
         <override name="workEffortId" optional="false">
             <type-validate>
                 <fail-property resource="WorkEffortUiLabels" 
property="WorkEffortRequiredFieldMissingWorkEffortId"/>
             </type-validate>
         </override>
     </service>
+    <service name="createWorkEffortStatus" 
default-entity-name="WorkEffortStatus" engine="entity-auto"
+             invoke="create" auth="true">
+        <auto-attributes include="pk" mode="IN"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+    </service>
 
-    <service name="copyWorkEffort" engine="simple" auth="true" 
transaction-timeout="300"
-            
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="copyWorkEffort">
+    <service name="copyWorkEffort" engine="groovy" auth="true" 
transaction-timeout="300" invoke="copyWorkEffort"
+             
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
         <description>Copies an existing WorkEffort to a new 
WorkEffort.</description>
         <permission-service service-name="workEffortGenericPermission" 
main-action="CREATE"/>
         <attribute name="sourceWorkEffortId" mode="IN" type="String" 
optional="false">
@@ -178,6 +183,22 @@ under the License.
     </service>
 
     <!-- WorkEffortPartyAssignment services -->
+    <service name="createWorkEffortPartyAssignment" 
default-entity-name="WorkEffortPartyAssignment" engine="entity-auto"
+             invoke="create" auth="true">
+        <auto-attributes include="pk" mode="IN"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+        <override name="fromDate" optional="true"/>
+    </service>
+    <service name="updateWorkEffortPartyAssignment" 
default-entity-name="WorkEffortPartyAssignment" engine="entity-auto"
+             invoke="update" auth="true">
+        <auto-attributes include="pk" mode="IN"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+    </service>
+    <service name="expireWorkEffortPartyAssignment" 
default-entity-name="WorkEffortPartyAssignment" engine="entity-auto"
+             invoke="expire" auth="true">
+        <auto-attributes include="pk" mode="IN"/>
+        <attribute name="thruDate" type="Timestamp" mode="IN" optional="true"/>
+    </service>
     <service name="assignPartyToWorkEffort" 
default-entity-name="WorkEffortPartyAssignment" engine="simple"
             
location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"
 invoke="assignPartyToWorkEffort">
         <description>Create a WorkEffortPartyAssignment Entity</description>
@@ -878,6 +899,11 @@ under the License.
         <auto-attributes include="pk" mode="IN" optional="true" 
entity-name="CustRequestItem"/>
         <attribute name="custRequestItemExists" type="java.lang.String" 
mode="OUT" optional="true"/>
     </service>
+    <service name="assocAcceptedCustRequestToWorkEffort" engine="groovy" 
default-entity-name="CustRequestWorkEffort" 
invoke="assocAcceptedCustRequestToWorkEffort" auth="true"
+             
location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy">
+        <description>For a custRequest approved, link it to a workEffort and 
copy associate content</description>
+        <auto-attributes include="pk" mode="IN"/>
+    </service>
 
     <service name="createWorkEffortQuote" engine="entity-auto" 
default-entity-name="QuoteWorkEffort" invoke="create" auth="true">
         <description>Creates a QuoteWorkEffort</description>
diff --git 
a/applications/workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy
 
b/applications/workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy
index d16ab5eddc..32c7a239fe 100644
--- 
a/applications/workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy
+++ 
b/applications/workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy
@@ -18,9 +18,15 @@
 */
 package org.apache.ofbiz.workeffort.workeffort.workeffort
 
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.base.util.UtilValidate
 import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.model.ModelKeyMap
+import org.apache.ofbiz.entity.util.EntityUtil
 import org.apache.ofbiz.service.ServiceUtil
 
+import java.sql.Timestamp
+
 Map checkAndCreateWorkEffort() {
     Map result = success()
     /*
@@ -84,6 +90,7 @@ Map checkAndCreateWorkEffort() {
     lookedUpValue.store()
     return result
 }
+
 Map checkAndUpdateWorkEffort() {
     Map result = success()
     GenericValue lookedUpValue = from('Shipment').where(parameters).queryOne()
@@ -175,3 +182,191 @@ Map checkAndUpdateWorkEffort() {
     }
     return result
 }
+
+/**
+ * Create Work Effort and assign to a party with a role
+ */
+Map createWorkEffortAndPartyAssign() {
+    GenericValue partyRole = 
from('PartyRole').where(parameters).cache().queryOne()
+    if (!partyRole) {
+        GenericValue roleType = 
from('RoleType').where(parameters).cache().queryOne()
+        return error(label('PartyErrorUiLabels', 
'PartyRoleAssociationRequired', [partyId: parameters.partyId,
+                                                                               
   roleDescription: roleType.get('description', locale)]))
+    }
+    Map serviceResult = run service: 'createWorkEffort', with: parameters
+    String workEffortId  = serviceResult.workEffortId
+
+    run service: 'createWorkEffortPartyAssignment', with: [*: parameters,
+                                                           workEffortId: 
workEffortId,
+                                                           
assignedByUserLoginId: userLogin.userLoginId]
+    return success([workEffortId: workEffortId])
+}
+
+/**
+ * Create Work Effort
+ * @return
+ */
+Map createWorkEffort() {
+    GenericValue workEffort = makeValue('WorkEffort', parameters)
+    if (!workEffort.workEffortId) {
+        workEffort.workEffortId = delegator.getNextSeqId('WorkEffort')
+    } else {
+        String errMsg = 
UtilValidate.checkValidDatabaseId(workEffort.workEffortId)
+        if (errMsg) {
+            return error(errMsg)
+        }
+    }
+    Timestamp now = UtilDateTime.nowTimestamp()
+    workEffort.setFields([lastStatusUpdate: now,
+                          lastModifiedDate: now,
+                          createdDate: now,
+                          revisionNumber: 1,
+                          lastModifiedByUserLogin: userLogin.userLoginId,
+                          createdByUserLogin: userLogin.userLoginId])
+    workEffort.create()
+
+    // create new status entry, and set lastStatusUpdate date
+    run service: 'createWorkEffortStatus', with: [workEffortId: 
workEffort.workEffortId,
+                                                  statusId: 
workEffort.currentStatusId,
+                                                  statusDatetime: now,
+                                                  setByUserLogin: 
userLogin.userLoginId]
+
+    return success([workEffortId: workEffort.workEffortId])
+}
+
+/**
+ * Update Work Effort
+ * @return
+ */
+Map updateWorkEffort() {
+    GenericValue workEffort = from('WorkEffort').where(parameters).queryOne()
+    Timestamp now = UtilDateTime.nowTimestamp()
+
+    // check if the status change is a valid change
+    if (parameters.currentStatusId && workEffort.currentStatusId &&
+            parameters.currentStatusId != workEffort.currentStatusId) {
+        Map statusValidChange = [statusId  : workEffort.currentStatusId,
+                                 statusIdTo: parameters.currentStatusId]
+        if (from('StatusValidChange').where(statusValidChange).queryCount() == 
0) {
+            return error(label('WorkEffortUiLabels', 
'WorkEffortStatusChangeNotValid', statusValidChange))
+        }
+        run service: 'createWorkEffortStatus', with: [*: parameters,
+                                                      statusId: 
parameters.currentStatusId,
+                                                      statusDatetime: now,
+                                                      setByUserLogin: 
userLogin.userLoginId]
+    }
+
+    // only save if something has changed
+    GenericValue workEffortOrigin = workEffort.clone()
+    workEffort.setNonPKFields(parameters)
+    if (workEffortOrigin != workEffort) {
+        workEffort.lastModifiedDate = now
+        workEffort.lastModifiedByUserLogin = userLogin.userLoginId
+        workEffort.revisionNumber = (workEffort.revisionNumber ?: 0) + 1
+        workEffort.store()
+    }
+    return success()
+}
+
+/**
+ * Delete Work Effort
+ * @return
+ */
+Map deleteWorkEffort() {
+
+    // check permissions before moving on: if update or delete logged in user 
must be associated OR have the corresponding UPDATE or DELETE permissions -->
+    if (from('WorkEffortPartyAssignment')
+            .where(workEffortId: parameters.workEffortId,
+                    partyId: userLogin.partyId)
+            .queryCount() == 0 &&
+            security.hasPermission('WORKEFFORTMGR_DELETE', userLogin)) {
+                return error(label('WorkEffortUiLabels', 
'WorkEffortDeletePermissionError'))
+            }
+
+    GenericValue workEffort = from('WorkEffort').where(parameters).queryOne()
+
+    // Remove associated/dependent entries from other entities here
+    ['WorkEffortKeyword', 'WorkEffortAttribute',
+     'WorkOrderItemFulfillment', 'FromWorkEffortAssoc',
+     'ToWorkEffortAssoc', 'NoteData', 'RecurrenceInfo',
+     'RuntimeData', 'WorkEffortPartyAssignment',
+     'WorkEffortFixedAssetAssign', 'WorkEffortSkillStandard',
+     'WorkEffortStatus', 'WorkEffortContent'].each {
+        workEffort.removeRelated(it)
+    }
+    workEffort.remove()
+    return success()
+}
+
+/**
+ * Copy Work Effort
+ * @return
+ */
+Map copyWorkEffort() {
+    GenericValue sourceWorkEffort = from('WorkEffort').where(workEffortId: 
parameters.sourceWorkEffortId).queryOne()
+    if (!sourceWorkEffort) {
+        return error(label('WorkEffortUiLabels', 'WorkEffortNotFound', 
[errorString: parameters.sourceWorkEffortId]))
+    }
+    Map serviceResult = run service: 'createWorkEffort', with: [*           : 
sourceWorkEffort.getAllFields(),
+                                                                workEffortId: 
parameters.targetWorkEffortId]
+    GenericValue targetWorkEffort = from('WorkEffort').where(workEffortId: 
serviceResult.workEffortId).queryOne()
+    if (parameters.copyWorkEffortAssocs == 'Y') {
+        run service: 'copyWorkEffortAssocs', with: [*                 : 
parameters,
+                                                    targetWorkEffortId: 
targetWorkEffort.workEffortId]
+    }
+
+    if (parameters.copyRelatedValues == 'Y') {
+        excludeExpiredRelations = parameters.excludeExpiredRelations
+        delegator.getModelEntity('WorkEffort').getRelationsManyList().each {
+            if (it.getRelEntityName() != 'WorkEffortAssoc') {
+                String relationName = it.getCombinedName()
+                ModelKeyMap keyMap = it.findKeyMap('workEffortId')
+                if (keyMap) {
+                    String relationWorkEffortId = keyMap.getRelFieldName()
+                    List<GenericValue> relationValues = 
sourceWorkEffort.getRelated(relationName, null, null, false)
+                    if (parameters.excludeExpiredRelations == 'Y') {
+                        relationValues = 
EntityUtil.filterByDate(relationValues)
+                    }
+                    relationValues.each { relationValue ->
+                        GenericValue targetRelationValue = 
relationValue.clone()
+                        targetRelationValue[relationWorkEffortId] = 
targetWorkEffort.workEffortId
+                        if 
(!from(targetRelationValue.getEntityName()).where(targetRelationValue.getAllFields()).queryOne())
 {
+                            targetRelationValue.create()
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return success(workEffortId: targetWorkEffort.workEffortId)
+}
+
+/**
+ * For a custRequest accepted link it to a workEffort and duplicate content
+ * @return
+ */
+Map assocAcceptedCustRequestToWorkEffort() {
+    // check status of customer request if valid
+    GenericValue custRequet = 
from("CustRequest").where(parameters).cache().queryOne()
+    if (custRequet.statusId != 'CRQ_ACCEPTED') {
+        return error(label('CommonUiLabels', 'CommonErrorStatusNotValid'))
+    }
+
+    // create customer request / work effort relation
+    run service: 'createWorkEffortRequest', with: parameters
+
+    // update status of customer request
+    run service: 'setCustRequestStatus', with: [*: parameters,
+                                                statusId: 'CRQ_REVIEWED']
+
+    // duplicate content on the workEffort
+    from('CustRequestContent')
+            .where(custRequestId: parameters.custRequestId)
+            .getFieldList('contentId')
+            .each {
+                run service: 'createWorkEffortContent', with: [*: parameters,
+                                                               contentId: it,
+                                                               
workEffortContentTypeId: 'SUPPORTING_MEDIA']
+            }
+    return success()
+}


Reply via email to