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 55d33436d8 Improved: Convert WorkEffortServices.xml mini-lang to groovyDSL (OFBIZ-12968) 55d33436d8 is described below commit 55d33436d87950c7623536b70d297ca770ff5bc9 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Thu Mar 28 10:22:39 2024 +0100 Improved: Convert WorkEffortServices.xml mini-lang to groovyDSL (OFBIZ-12968) Convert the following services : * assignPartyToWorkEffort * updatePartyToWorkEffortAssignment * deletePartyToWorkEffortAssignment -> deprecated suggest to use expireWorkEffortPartyAssignment * quickAssignPartyToWorkEffort * quickAssignPartyToWorkEffortRole * duplicateWorkEffort * createWorkEffortContactMech * updateWorkEffortContactMech * createWorkEffortPostalAddress * updateWorkEffortPostalAddress * createWorkEffortTelecomNumber * updateWorkEffortTelecomNumber * createWorkEffortEmailAddress * updateWorkEffortEmailAddress For all WorkEffortContactMech service like, use only two generic functions. --- .../workeffort/WorkEffortSimpleServices.xml | 428 --------------------- applications/workeffort/servicedef/services.xml | 186 ++++----- .../workeffort/WorkEffortServicesScript.groovy | 216 +++++++++++ 3 files changed, 281 insertions(+), 549 deletions(-) diff --git a/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml b/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml index 26c221207e..b8cc8e02d8 100644 --- a/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml +++ b/applications/workeffort/minilang/workeffort/WorkEffortSimpleServices.xml @@ -69,316 +69,6 @@ under the License. <remove-value value-field="communicationEventWorkEff"/> </simple-method> - - <!-- WorkEffortPartyAssignment --> - <simple-method method-name="assignPartyToWorkEffort" short-description="Assign Party to Work Effort"> - <!-- check if the requested party Assignment already exist --> - <entity-and entity-name="WorkEffortPartyAssignment" list="currentAssignments" filter-by-date="true"> - <field-map field-name="workEffortId" from-field="parameters.workEffortId"/> - <field-map field-name="partyId" from-field="parameters.partyId"/> - <field-map field-name="roleTypeId" from-field="parameters.roleTypeId"/> - </entity-and> - <if-not-empty field="currentAssignments"> - <first-from-list list="currentAssignments" entry="firstAssignment"/> - <add-error> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortPartyAssignmentError"/> - </add-error> - </if-not-empty> - <check-errors/> - - <set field="ensurePartyRoleCtx.partyId" from-field="parameters.partyId"/> - <set field="ensurePartyRoleCtx.roleTypeId" from-field="parameters.roleTypeId"/> - <call-service service-name="ensurePartyRole" in-map-name="ensurePartyRoleCtx"/> - <make-value entity-name="WorkEffortPartyAssignment" value-field="newEntity"/> - - <set-pk-fields map="parameters" value-field="newEntity"/> - <set-nonpk-fields map="parameters" value-field="newEntity"/> - - <if-empty field="newEntity.fromDate"> - <now-timestamp field="newEntity.fromDate"/> - </if-empty> - <field-to-result field="newEntity.fromDate" result-name="fromDate"/> - <set field="newEntity.assignedByUserLoginId" from-field="userLogin.userLoginId"/> - - <if-not-empty field="parameters.statusId"> - <now-timestamp field="newEntity.statusDateTime"/> - <call-class-method class-name="org.apache.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" method-name="updateWorkflowEngine"> - <field field="newEntity" type="org.apache.ofbiz.entity.GenericValue"/> - <field field="userLogin" type="org.apache.ofbiz.entity.GenericValue"/> - <field field="dispatcher" type="org.apache.ofbiz.service.LocalDispatcher"/> - </call-class-method> - </if-not-empty> - <create-value value-field="newEntity"/> - </simple-method> - <simple-method method-name="updatePartyToWorkEffortAssignment" short-description="Update WorkEffortPartyAssignment entity"> - <entity-one entity-name="WorkEffortPartyAssignment" value-field="workEffortPartyAssignment"/> - <!-- to be dropped later (use now workEffortGenericPermission) - <if-compare-field field="userLogin.partyId" to-field="workEffortPartyAssignment.partyId" operator="not-equals"> - <check-permission permission="WORKEFFORTMGR" action="_UPDATE"/> - <check-errors/> - </if-compare-field> - --> - <set from-field="workEffortPartyAssignment.statusId" field="oldStatusId"/> - <set-nonpk-fields map="parameters" value-field="workEffortPartyAssignment"/> - - <if-compare-field field="parameters.statusId" to-field="oldStatusId" operator="not-equals"> - <now-timestamp field="workEffortPartyAssignment.statusDateTime"/> - <call-class-method class-name="org.apache.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" method-name="updateWorkflowEngine" > - <field field="workEffortPartyAssignment" type="org.apache.ofbiz.entity.GenericValue"/> - <field field="userLogin" type="org.apache.ofbiz.entity.GenericValue"/> - <field field="dispatcher" type="org.apache.ofbiz.service.LocalDispatcher"/> - </call-class-method> - </if-compare-field> - <store-value value-field="workEffortPartyAssignment"/> - </simple-method> - <simple-method method-name="deletePartyToWorkEffortAssignment" short-description="Update WorkEffortPartyAssignment entity"> - <set-service-fields service-name="updatePartyToWorkEffortAssignment" map="parameters" to-map="del"/> - <now-timestamp field="del.thruDate"/> - <call-service service-name="updatePartyToWorkEffortAssignment" in-map-name="del"/> - </simple-method> - - <!-- Create a WorkEffortContactMech --> - <simple-method method-name="createWorkEffortContactMech" short-description="Create a WorkEffortContactMech"> - <make-value entity-name="WorkEffortContactMech" value-field="newValue"/> - <if-empty field="parameters.contactMechId"> - <if-empty field="parameters.contactMechTypeId"> - <add-error> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingContactMechIdOrContactMechTypeId"/> - </add-error> - </if-empty> - <check-errors/> - - <if-not-empty field="parameters.partyId"> - <set-service-fields service-name="createPartyContactMech" map="parameters" to-map="context"/> - <call-service service-name="createPartyContactMech" in-map-name="context"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - <log level="info" message="Party ContactMech created"/> - <else> - <set-service-fields service-name="createContactMech" map="parameters" to-map="context"/> - <call-service service-name="createContactMech" in-map-name="context"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - <log level="info" message="ContactMech created"/> - </else> - </if-not-empty> - <else> - <set from-field="parameters.contactMechId" field="newValue.contactMechId"/> - </else> - </if-empty> - <log level="info" message="Creating a WorkEffortContactMech"/> - <set from-field="parameters.workEffortId" field="newValue.workEffortId"/> - <set-nonpk-fields map="parameters" value-field="newValue"/> - <field-to-result field="newValue.contactMechId" result-name="contactMechId"/> - <field-to-request field="newValue.contactMechId" request-name="contactMechId"/> - <now-timestamp field="newValue.fromDate"/> - <create-value value-field="newValue"/> - </simple-method> - - <simple-method method-name="updateWorkEffortContactMech" short-description="Update a WorkEffortContactMech"> - <make-value entity-name="WorkEffortContactMech" value-field="newWorkEffortContactMech"/> - <!-- Find old value --> - <entity-one entity-name="WorkEffortContactMech" value-field="workEffortContactMech"/> - <if-empty field="workEffortContactMech"> - <add-error> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortCannotUpdateContactInfo"/> - </add-error> - </if-empty> - <check-errors/> - - <clone-value value-field="workEffortContactMech" new-value-field="newWorkEffortContactMech"/> - - <!-- If we already have a new contactMechId don't update ContactMech --> - <if-empty field="parameters.newContactMechId"> - <log level="info" message="Calling map procs"/> - <log level="info" message="Calling generic updateContactMech method"/> - <set-service-fields service-name="updateContactMech" map="parameters" to-map="context"/> - <call-service service-name="updateContactMech" in-map-name="context"> - <default-message property="PartyContactMechanismSuccessfullyUpdated" resource="PartyUiLabels"/> - <result-to-field result-name="contactMechId" field="newWorkEffortContactMech.contactMechId"/> - </call-service> - <else> - <set from-field="parameters.newContactMechId" field="newWorkEffortContactMech.contactMechId"/> - </else> - </if-empty> - - <if-compare-field to-field="newWorkEffortContactMech.contactMechId" field="parameters.contactMechId" operator="not-equals"> - <set-nonpk-fields map="parameters" value-field="newWorkEffortContactMech"/> - <now-timestamp field="newWorkEffortContactMech.fromDate"/> - <now-timestamp field="workEffortContactMech.thruDate"/> - <create-value value-field="newWorkEffortContactMech"/> - <store-value value-field="workEffortContactMech"/> - </if-compare-field> - - <field-to-result field="newWorkEffortContactMech.contactMechId" result-name="contactMechId"/> - <field-to-request field="newWorkEffortContactMech.contactMechId" request-name="contactMechId"/> - </simple-method> - - <simple-method method-name="createWorkEffortPostalAddress" short-description="Create a PostalAddress for WorkEffort"> - <make-value entity-name="WorkEffortContactMech" value-field="newValue"/> - <log level="info" message="Creating postal address"/> - <if-not-empty field="parameters.partyId"> - <call-map-processor xml-resource="component://party/minilang/contact/PartyContactMechMapProcs.xml" - processor-name="postalAddress" in-map-name="parameters" out-map-name="context"/> - <call-service service-name="createPartyPostalAddress" in-map-name="context"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - <log level="info" message="Party ContactMech created"/> - <else> - <set-service-fields service-name="createPostalAddress" map="parameters" to-map="context"/> - <call-service in-map-name="context" service-name="createPostalAddress"> - <default-message resource="PartyUiLabels" property="PartyPostalAddressSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - </else> - </if-not-empty> - <log level="info" message="ContactMech for postal address was ${newValue.contactMechId}, now creating work effort contact mech"/> - <call-map-processor xml-resource="component://workeffort/minilang/workeffort/WorkflowMapProcessors.xml" - processor-name="workEffortContactMech" in-map-name="parameters" out-map-name="context2"/> - <set from-field="newValue.contactMechId" field="context2.contactMechId"/> - <log level="info" message="Copied id to context2: ${context2.contactMechId}"/> - <call-service in-map-name="context2" break-on-error="true" service-name="createWorkEffortContactMech"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - </call-service> - <field-to-request field="newValue.contactMechId" request-name="contactMechId"/> - <field-to-result field="newValue.contactMechId" result-name="contactMechId"/> - </simple-method> - - <simple-method method-name="updateWorkEffortPostalAddress" short-description="Update a PostalAddress for WorkEffort"> - <make-value entity-name="WorkEffortContactMech" value-field="newValue"/> - <set-service-fields service-name="updatePostalAddress" map="parameters" to-map="context"/> - <call-service in-map-name="context" service-name="updatePostalAddress"> - <default-message resource="PartyUiLabels" property="PartyPostalAddressSuccessfullyUpdated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - <result-to-field result-name="oldContactMechId" field="oldContactMechId"/> - </call-service> - <call-map-processor xml-resource="component://workeffort/minilang/workeffort/WorkflowMapProcessors.xml" - processor-name="workEffortContactMech" in-map-name="parameters" out-map-name="context2"/> - <set from-field="newValue.contactMechId" field="context2.newContactMechId"/> - <set field="context2.contactMechTypeId" value="POSTAL_ADDRESS"/> - <set field="context2.fromDate" from-field="parameters.fromDate"/> - <log level="info" message="Copied id to context2: ${context2.newContactMechId}"/> - <call-service in-map-name="context2" service-name="updateWorkEffortContactMech"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyUpdated"/> - </call-service> - <field-to-request field="newValue.contactMechId" request-name="contactMechId"/> - <field-to-result field="newValue.contactMechId" result-name="contactMechId"/> - <field-to-result field="oldContactMechId" result-name="oldContactMechId"/> - </simple-method> - - <simple-method method-name="createWorkEffortTelecomNumber" short-description="Create a TelecomNumber for WorkEffort"> - <make-value entity-name="WorkEffortContactMech" value-field="newValue"/> - <log level="info" message="Creating telecom number"/> - <if-not-empty field="parameters.partyId"> - <call-map-processor xml-resource="component://party/minilang/contact/PartyContactMechMapProcs.xml" - processor-name="telecomNumber" in-map-name="parameters" out-map-name="context"/> - <call-service service-name="createPartyTelecomNumber" in-map-name="context"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - <log level="info" message="Party ContactMech created"/> - <else> - <set-service-fields service-name="createTelecomNumber" map="parameters" to-map="context"/> - <call-service in-map-name="context" service-name="createTelecomNumber"> - <default-message resource="PartyUiLabels" property="PartyTelecomNumberSuccessfullyCreated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - </call-service> - </else> - </if-not-empty> - <call-map-processor xml-resource="component://workeffort/minilang/workeffort/WorkflowMapProcessors.xml" - processor-name="workEffortContactMech" in-map-name="parameters" out-map-name="context2"/> - <set from-field="newValue.contactMechId" field="context2.contactMechId"/> - <log level="info" message="Copied id to context2: ${context2.contactMechId}"/> - <call-service in-map-name="context2" break-on-error="true" service-name="createWorkEffortContactMech"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - </call-service> - <field-to-request field="newValue.contactMechId" request-name="contactMechId"/> - <field-to-result field="newValue.contactMechId" result-name="contactMechId"/> - </simple-method> - - <simple-method method-name="updateWorkEffortTelecomNumber" short-description="Update a TelecomNumber for WorkEffort"> - <make-value entity-name="WorkEffortContactMech" value-field="newValue"/> - <set-service-fields service-name="updateTelecomNumber" map="parameters" to-map="context"/> - <call-service in-map-name="context" service-name="updateTelecomNumber"> - <default-message resource="PartyUiLabels" property="PartyTelecomNumberSuccessfullyUpdated"/> - <result-to-field result-name="contactMechId" field="newValue.contactMechId"/> - <result-to-field result-name="oldContactMechId" field="oldContactMechId"/> - </call-service> - - <call-map-processor xml-resource="component://workeffort/minilang/workeffort/WorkflowMapProcessors.xml" - processor-name="workEffortContactMech" in-map-name="parameters" out-map-name="context2"/> - <set from-field="newValue.contactMechId" field="context2.newContactMechId"/> - <set field="context2.contactMechTypeId" value="TELECOM_NUMBER"/> - <set field="context2.fromDate" from-field="parameters.fromDate"/> - <log level="info" message="Copied id to context2: ${context2.newContactMechId}"/> - <call-service in-map-name="context2" service-name="updateWorkEffortContactMech"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyUpdated"/> - </call-service> - <log level="info" message="Setting result id: ${newValue.contactMechId}"/> - <field-to-request field="newValue.contactMechId" request-name="contactMechId"/> - <field-to-result field="newValue.contactMechId" result-name="contactMechId"/> - <field-to-result field="oldContactMechId" result-name="oldContactMechId"/> - </simple-method> - - <simple-method method-name="createWorkEffortEmailAddress" short-description="Create an email address for WorkEffort"> - <set-service-fields service-name="createWorkEffortContactMech" map="parameters" to-map="cwecmMap"/> - <set field="cwecmMap.contactMechTypeId" value="EMAIL_ADDRESS"/> - <call-service service-name="createWorkEffortContactMech" in-map-name="cwecmMap"> - <default-message resource="PartyUiLabels" property="PartyContactMechanismSuccessfullyCreated"/> - <result-to-result result-name="contactMechId"/> - <result-to-request result-name="contactMechId"/> - </call-service> - </simple-method> - <simple-method method-name="updateWorkEffortEmailAddress" short-description="Update an email address for WorkEffort"> - <set-service-fields service-name="createWorkEffortContactMech" map="parameters" to-map="uwecmMap"/> - <set field="uwecmMap.contactMechTypeId" value="EMAIL_ADDRESS"/> - <call-service service-name="updateWorkEffortContactMech" in-map-name="uwecmMap"> - <default-message resource="PartyUiLabels" property="PartyTelecomNumberSuccessfullyUpdated"/> - <result-to-result result-name="contactMechId"/> - <result-to-request result-name="contactMechId"/> - </call-service> - </simple-method> - - <simple-method method-name="quickAssignPartyToWorkEffort" short-description="Quick Assign Party To WorkEffort as Owner"> - <if-not-empty field="parameters.quickAssignPartyId"> - <now-timestamp field="nowTimestamp"/> - <!-- add a party assignment for the creator of the event, use the list method and let the EE do the update or create... --> - <make-value entity-name="PartyRole" value-field="newPartyRole"/> - <set from-field="parameters.quickAssignPartyId" field="newPartyRole.partyId"/> - <set value="CAL_OWNER" field="newPartyRole.roleTypeId"/> - <field-to-list field="newPartyRole" list="newPartyRoleList"/> - <store-list list="newPartyRoleList"/> - - <make-value entity-name="WorkEffortPartyAssignment" value-field="newWorkEffortPartyAssignment"/> - <set from-field="parameters.workEffortId" field="newWorkEffortPartyAssignment.workEffortId"/> - <set from-field="parameters.quickAssignPartyId" field="newWorkEffortPartyAssignment.partyId"/> - <set value="CAL_OWNER" field="newWorkEffortPartyAssignment.roleTypeId"/> - <set value="PRTYASGN_ASSIGNED" field="newWorkEffortPartyAssignment.statusId"/> - <set from-field="nowTimestamp" field="newWorkEffortPartyAssignment.fromDate"/> - <create-value value-field="newWorkEffortPartyAssignment"/> - </if-not-empty> - </simple-method> - <simple-method method-name="quickAssignPartyToWorkEffortWithRole" short-description="Quick Assign Party To WorkEffort"> - <if-not-empty field="parameters.quickAssignPartyId"> - <!-- add a party assignment for the creator of the event, use the list method and let the EE do the update or create... --> - <make-value entity-name="PartyRole" value-field="newPartyRole"/> - <set from-field="parameters.quickAssignPartyId" field="newPartyRole.partyId"/> - <set from-field="parameters.roleTypeId" field="newPartyRole.roleTypeId"/> - <set field="newPartyRoleList[]" from-field="newPartyRole"/> - <store-list list="newPartyRoleList"/> - - <make-value entity-name="WorkEffortPartyAssignment" value-field="newWorkEffortPartyAssignment"/> - <set from-field="parameters.workEffortId" field="newWorkEffortPartyAssignment.workEffortId"/> - <set from-field="parameters.quickAssignPartyId" field="newWorkEffortPartyAssignment.partyId"/> - <set from-field="parameters.roleTypeId" field="newWorkEffortPartyAssignment.roleTypeId"/> - <set value="CAL_ACCEPTED" field="newWorkEffortPartyAssignment.statusId"/> - <now-timestamp field="newWorkEffortPartyAssignment.fromDate"/> - <create-value value-field="newWorkEffortPartyAssignment"/> - </if-not-empty> - </simple-method> <simple-method method-name="createWorkEffortNote" short-description="Create Work Effort Note"> <make-value entity-name="NoteData" value-field="newEntity"/> <sequenced-id sequence-name="NoteData" field="newEntity.noteId"/> @@ -655,124 +345,6 @@ under the License. <check-errors/> </simple-method> - <simple-method method-name="duplicateWorkEffort" short-description="Duplicate a WorkEffort"> - <set field="removeWorkEffortAssocs" from-field="parameters.removeWorkEffortAssocs" default-value="N" /> - <set field="removeWorkEffortContents" from-field="parameters.removeWorkEffortContents" default-value="N" /> - <set field="removeWorkEffortNotes" from-field="parameters.removeWorkEffortNotes" default-value="N" /> - <set field="removeWorkEffortAssignmentRates" from-field="parameters.removeWorkEffortAssignmentRates" default-value="N" /> - <if> - <condition> - <or> - <if-compare field="removeWorkEffortAssocs" operator="equals" value="Y" /> - <if-compare field="removeWorkEffortContents" operator="equals" value="Y" /> - <if-compare field="removeWorkEffortNotes" operator="equals" value="Y" /> - <if-compare field="removeWorkEffortAssignmentRates" operator="equals" value="Y" /> - </or> - </condition> - <then> - <check-permission permission="WORKEFFORTMGR" action="_DELETE"> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortDeletePermissionError" /> - </check-permission> - <check-errors /> - </then> - </if> - - <!-- Get the old WorkEffort --> - <set field="workEffortId" from-field="parameters.workEffortId"/> - <if-empty field="workEffortId"> - <sequenced-id sequence-name="WorkEffort" field="workEffortId"/> - </if-empty> - <entity-one entity-name="WorkEffort" value-field="oldWorkEffort"> - <field-map field-name="workEffortId" from-field="parameters.oldWorkEffortId"/> - </entity-one> - - <!-- Check the status to give to the new WorkEffort --> - <if-empty field="parameters.statusId"> - <entity-one entity-name="StatusItem" value-field="oldStatus"> - <field-map field-name="statusId" from-field="oldWorkEffort.currentStatusId"/> - </entity-one> - <entity-and entity-name="StatusItem" list="statusList"> - <field-map field-name="statusTypeId" from-field="oldStatus.statusTypeId"/> - <order-by field-name="sequenceId"/> - </entity-and> - <set field="oldWorkEffort.currentStatusId" from-field="statusList[0].statusId"/> - <else> - <set field="oldWorkEffort.currentStatusId" from-field="parameters.statusId"/> - </else> - </if-empty> - - <!-- Create the new WorkEffort from the old one and the status --> - <set-service-fields service-name="createWorkEffort" map="oldWorkEffort" to-map="createWorkEffortCtx"/> - <set field="createWorkEffortCtx.workEffortId" from-field="workEffortId"/> - <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="newWorkEffort" /> - <set field="workEffortAssocFindContext.workEffortIdFrom" from-field="parameters.oldWorkEffortId" /> - <set field="reverseWorkEffortFindContext.workEffortIdTo" from-field="parameters.oldWorkEffortId" /> - <set field="duplicateWorkEffortAssocs" from-field="parameters.duplicateWorkEffortAssocs" default-value="N" /> - <if-compare field="duplicateWorkEffortAssocs" operator="equals" value="Y"> - <find-by-and entity-name="WorkEffortAssoc" map="workEffortAssocFindContext" list="foundValues" /> - <iterate list="foundValues" entry="foundValue"> - <clone-value value-field="foundValue" new-value-field="newTempValue" /> - <set from-field="workEffortId" field="newTempValue.workEffortIdFrom" /> - <create-value value-field="newTempValue" /> - </iterate> - <entity-and entity-name="WorkEffortAssoc" list="foundValues"> - <field-map field-name="workEffortIdTo" from-field="parameters.oldWorkEffortId" /> - </entity-and> - <iterate list="foundValues" entry="foundValue"> - <clone-value value-field="foundValue" new-value-field="newTempValue" /> - <set from-field="workEffortId" field="newTempValue.workEffortIdTo" /> - <create-value value-field="newTempValue" /> - </iterate> - </if-compare> - <set field="workEffortFindContext.workEffortId" from-field="parameters.oldWorkEffortId" /> - <set field="duplicateWorkEffortNotes" from-field="parameters.duplicateWorkEffortNotes" default-value="N" /> - <if-compare field="duplicateWorkEffortNotes" operator="equals" value="Y"> - <find-by-and entity-name="WorkEffortNote" map="workEffortFindContext" list="foundValues" /> - <iterate list="foundValues" entry="foundValue"> - <clone-value value-field="foundValue" new-value-field="newTempValue" /> - <set from-field="workEffortId" field="newTempValue.workEffortId" /> - <create-value value-field="newTempValue" /> - </iterate> - </if-compare> - <set field="duplicateWorkEffortContents" from-field="parameters.duplicateWorkEffortContents" default-value="N" /> - <if-compare field="duplicateWorkEffortContents" operator="equals" value="Y"> - <find-by-and entity-name="WorkEffortContent" map="workEffortFindContext" list="foundValues" /> - <iterate list="foundValues" entry="foundValue"> - <clone-value value-field="foundValue" new-value-field="newTempValue" /> - <set from-field="workEffortId" field="newTempValue.workEffortId" /> - <create-value value-field="newTempValue" /> - </iterate> - </if-compare> - <set field="duplicateWorkEffortAssignmentRates" from-field="parameters.duplicateWorkEffortAssignmentRates" default-value="N" /> - <if-compare field="duplicateWorkEffortAssignmentRates" operator="equals" value="Y"> - <find-by-and entity-name="RateAmount" map="workEffortFindContext" list="foundValuesAll" /> - <filter-list-by-date list="foundValuesAll" to-list="foundValues" /> - <iterate list="foundValues" entry="foundValue"> - <clone-value value-field="foundValue" new-value-field="newTempValue" /> - <set from-field="workEffortId" field="newTempValue.workEffortId" /> - <create-value value-field="newTempValue" /> - </iterate> - </if-compare> - <if-compare field="removeWorkEffortAssocs" operator="equals" value="Y"> - <remove-by-and entity-name="WorkEffortAssoc" map="workEffortAssocFindContext" /> - <!-- small difference here, also do the reverse assocs... --> - <remove-by-and entity-name="WorkEffortAssoc" map="reverseWorkEffortFindContext" /> - </if-compare> - <if-compare field="removeWorkEffortContents" operator="equals" value="Y"> - <remove-by-and entity-name="WorkEffortContent" map="workEffortFindContext" /> - </if-compare> - <if-compare field="removeWorkEffortNotes" operator="equals" value="Y"> - <remove-by-and entity-name="WorkEffortNote" map="workEffortFindContext" /> - </if-compare> - <if-compare field="removeWorkEffortAssignmentRates" operator="equals" value="Y"> - <remove-by-and entity-name="RateAmount" map="workEffortFindContext" /> - </if-compare> - <field-to-result field="workEffortId"/> - </simple-method> - <!-- WorkEffort ServiceTest Services --> <simple-method method-name="testCreateEventService" short-description="test to create new event (workeffort) service" login-required="false"> <log level="info" message="====================Create an event test case=========================================="/> diff --git a/applications/workeffort/servicedef/services.xml b/applications/workeffort/servicedef/services.xml index 45207a8d0d..e35d0e7662 100644 --- a/applications/workeffort/servicedef/services.xml +++ b/applications/workeffort/servicedef/services.xml @@ -148,18 +148,19 @@ under the License. </attribute> </service> - <service name="duplicateWorkEffort" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="duplicateWorkEffort" auth="true"> + <service name="duplicateWorkEffort" engine="groovy" invoke="duplicateWorkEffort" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Duplicate a Work Effort. If workEffortId is empty a new workEffortId will be generated. Set the statusId of the new WorkEffort to this status, otherwise, set the status to the first of the sequenceId of the statusTypeId</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> - <attribute name="workEffortId" type="String" mode="IN" optional="true"/> - <attribute name="oldWorkEffortId" type="String" mode="IN" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingOldWorkEffortTypeId"/> - </type-validate> + <attribute name="oldWorkEffortId" type="String" mode="IN"> + <type-validate> + <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingOldWorkEffortTypeId"/> + </type-validate> </attribute> + <attribute name="workEffortId" type="String" mode="IN" optional="true"/> + <attribute name="statusId" type="String" mode="IN" optional="true"/> <attribute name="duplicateWorkEffortAssocs" type="String" mode="IN" optional="true"/> <attribute name="duplicateWorkEffortContents" type="String" mode="IN" optional="true"/> <attribute name="duplicateWorkEffortNotes" type="String" mode="IN" optional="true"/> @@ -168,8 +169,7 @@ under the License. <attribute name="removeWorkEffortContents" type="String" mode="IN" optional="true"/> <attribute name="removeWorkEffortNotes" type="String" mode="IN" optional="true"/> <attribute name="removeWorkEffortAssignmentRates" type="String" mode="IN" optional="true"/> - <attribute name="workEffortId" type="String" mode="OUT" optional="false"/> - <attribute name="statusId" type="String" mode="IN" optional="true"/> + <attribute name="workEffortId" type="String" mode="OUT"/> </service> <!-- Communication Event WorkEffort --> @@ -185,104 +185,37 @@ under the License. <!-- WorkEffortPartyAssignment services --> <service name="createWorkEffortPartyAssignment" default-entity-name="WorkEffortPartyAssignment" engine="entity-auto" invoke="create" auth="true"> + <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <auto-attributes include="pk" mode="IN"/> <auto-attributes include="nonpk" mode="IN" optional="true"/> - <override name="fromDate" optional="true"/> + <override name="fromDate" mode="INOUT" optional="true"/> </service> <service name="updateWorkEffortPartyAssignment" default-entity-name="WorkEffortPartyAssignment" engine="entity-auto" invoke="update" auth="true"> + <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <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"> + <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <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"> + <service name="assignPartyToWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="groovy" invoke="assignPartyToWorkEffort" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Create a WorkEffortPartyAssignment Entity</description> - <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> - <auto-attributes mode="IN" include="pk" optional="false"/> - <auto-attributes mode="IN" include="nonpk" optional="true"> - <exclude field-name="statusDateTime"/> - </auto-attributes> - <override name="fromDate" mode="INOUT" optional="true"/> - <override name="partyId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingPartyId"/> - </type-validate> - </override> - <override name="roleTypeId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingRoleTypeId"/> - </type-validate> - </override> - <override name="statusId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingStatusId"/> - </type-validate> - </override> - <override name="workEffortId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> - </type-validate> - </override> + <implements service="createWorkEffortPartyAssignment"/> </service> - <service name="updatePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="updatePartyToWorkEffortAssignment"> + <service name="updatePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="groovy" invoke="updatePartyToWorkEffortAssignment" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Update a WorkEffortPartyAssignment Entity</description> - <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> - <auto-attributes mode="IN" include="pk" optional="false"/> - <auto-attributes mode="IN" include="nonpk" optional="true"> - <exclude field-name="statusDateTime"/> - </auto-attributes> - <override name="fromDate" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingFromDate"/> - </type-validate> - </override> - <override name="partyId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingPartyId"/> - </type-validate> - </override> - <override name="roleTypeId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingRoleTypeId"/> - </type-validate> - </override> - <override name="workEffortId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> - </type-validate> - </override> + <implements service="updateWorkEffortPartyAssignment"/> </service> - <service name="deletePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="deletePartyToWorkEffortAssignment"> + <service name="deletePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="entity-auto" invoke="expire"> <description>delete/set the thrudate on the WorkEffortPartyAssignment Entity to today</description> - <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> - <auto-attributes mode="IN" include="pk" optional="false"/> - <override name="fromDate" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingFromDate"/> - </type-validate> - </override> - <override name="partyId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingPartyId"/> - </type-validate> - </override> - <override name="roleTypeId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingRoleTypeId"/> - </type-validate> - </override> - <override name="workEffortId" optional="false"> - <type-validate> - <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> - </type-validate> - </override> + <deprecated use-instead="expireWorkEffortPartyAssignment" since="UpComingBranch"/> + <implements service="expireWorkEffortPartyAssignment"/> </service> <service name="unassignPartyFromWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="entity-auto" invoke="delete"> <description>Delete a WorkEffortPartyAssignment Entity</description> @@ -310,34 +243,35 @@ under the License. </override> </service> - <service name="quickAssignPartyToWorkEffort" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="quickAssignPartyToWorkEffort"> + <service name="quickAssignPartyToWorkEffort" engine="groovy" invoke="quickAssignPartyToWorkEffort" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Quick Assign Party To WorkEffort as Owner</description> - <attribute name="workEffortId" type="String" mode="IN" optional="false"> + <attribute name="workEffortId" type="String" mode="IN"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> </type-validate> </attribute> - <attribute name="quickAssignPartyId" type="String" mode="IN" optional="false"> + <attribute name="roleTypeId" type="String" mode="IN" default-value="CAL_OWNER"/> + <attribute name="quickAssignPartyId" type="String" mode="IN"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingQuickAssignPartyId"/> </type-validate> </attribute> </service> - <service name="quickAssignPartyToWorkEffortWithRole" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="quickAssignPartyToWorkEffortWithRole"> + <service name="quickAssignPartyToWorkEffortWithRole" engine="groovy" invoke="quickAssignPartyToWorkEffort" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Quick Assign Party To WorkEffort as Owner</description> - <attribute name="workEffortId" type="String" mode="IN" optional="false"> + <attribute name="workEffortId" type="String" mode="IN"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> </type-validate> </attribute> - <attribute name="quickAssignPartyId" type="String" mode="IN" optional="false"> + <attribute name="quickAssignPartyId" type="String" mode="IN"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingQuickAssignPartyId"/> </type-validate> </attribute> - <attribute name="roleTypeId" type="String" mode="IN" optional="false"> + <attribute name="roleTypeId" type="String" mode="IN"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingRoleTypeId"/> </type-validate> @@ -1485,31 +1419,31 @@ under the License. </service> <!-- WorkEffort Contact Mech Services --> - <service name="createWorkEffortContactMech" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="createWorkEffortContactMech" auth="true"> + <service name="createWorkEffortContactMech" engine="groovy" invoke="createWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Create WorkEffortContactMech; if contactMechId is not provided, a new contact mech is created (if partyId is set then the new contact mech is also associated to the party)</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <auto-attributes entity-name="WorkEffortContactMech" mode="IN" include="nonpk" optional="true"/> - <auto-attributes entity-name="PartyContactMech" include="all" mode="IN" optional="true"/> - <attribute name="workEffortId" mode="IN" type="String" optional="false"> + <auto-attributes entity-name="PartyContactMech" mode="IN" optional="true"/> + <attribute name="workEffortId" mode="IN" type="String"> <type-validate> <fail-property resource="WorkEffortUiLabels" property="WorkEffortRequiredFieldMissingWorkEffortId"/> </type-validate> </attribute> <attribute name="contactMechTypeId" mode="IN" type="String" optional="true"/> - <attribute name="infoString" mode="IN" type="String" optional="true"></attribute> + <attribute name="infoString" mode="IN" type="String" optional="true"/> <attribute name="contactMechPurposeTypeId" type="String" mode="IN" optional="true"/> <attribute name="contactMechId" type="String" mode="INOUT" optional="true"/> </service> - <service name="updateWorkEffortContactMech" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="updateWorkEffortContactMech" auth="true"> + <service name="updateWorkEffortContactMech" engine="groovy" invoke="updateWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Update WorkEffortContactMech</description> <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <auto-attributes entity-name="WorkEffortContactMech" mode="IN" include="nonpk" optional="true"/> - <auto-attributes entity-name="PartyContactMech" include="all" mode="IN" optional="true"/> - <attribute name="workEffortId" mode="IN" type="String" optional="false"></attribute> - <attribute name="contactMechTypeId" mode="IN" type="String" optional="true"></attribute> - <attribute name="infoString" mode="IN" type="String" optional="true"></attribute> + <auto-attributes entity-name="PartyContactMech" mode="IN" optional="true"/> + <attribute name="workEffortId" mode="IN" type="String"/> + <attribute name="contactMechTypeId" mode="IN" type="String" optional="true"/> + <attribute name="infoString" mode="IN" type="String" optional="true"/> <attribute name="contactMechPurposeTypeId" type="String" mode="IN" optional="true"/> <attribute name="newContactMechId" type="String" mode="IN" optional="true"/> <attribute name="contactMechId" type="String" mode="INOUT" optional="true"/> @@ -1519,47 +1453,57 @@ under the License. <permission-service service-name="workEffortGenericPermission" main-action="DELETE"/> <auto-attributes mode="IN" include="pk" optional="false"/> </service> - <service name="createWorkEffortPostalAddress" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="createWorkEffortPostalAddress"> + <service name="createWorkEffortPostalAddress" engine="groovy" invoke="createWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Create WorkEffort PostalAddress</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <implements service="createPostalAddress"/> <implements service="createPartyPostalAddress"/> <implements service="createWorkEffortContactMech"/> + <attribute name="relationEntityName" type="String" mode="IN" default-value="PostalAddress"/> + <override name="contactMechTypeId" default-value="POSTAL_ADDRESS"/> </service> - <service name="updateWorkEffortPostalAddress" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="updateWorkEffortPostalAddress"> + <service name="updateWorkEffortPostalAddress" engine="groovy" invoke="updateWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Update WorkEffort PostalAddress</description> <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <implements service="updatePostalAddress"/> <implements service="updateWorkEffortContactMech"/> + <attribute name="relationEntityName" type="String" mode="IN" default-value="PostalAddress"/> + <override name="contactMechTypeId" default-value="POSTAL_ADDRESS"/> </service> - <service name="createWorkEffortTelecomNumber" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="createWorkEffortTelecomNumber"> + <service name="createWorkEffortTelecomNumber" engine="groovy" invoke="createWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Create WorkEffort TelecomNumber</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <implements service="createTelecomNumber"/> <implements service="createPartyTelecomNumber"/> <implements service="createWorkEffortContactMech"/> + <attribute name="relationEntityName" type="String" mode="IN" default-value="TelecomNumber"/> + <override name="contactMechTypeId" default-value="TELECOM_NUMBER"/> </service> - <service name="updateWorkEffortTelecomNumber" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="updateWorkEffortTelecomNumber"> + <service name="updateWorkEffortTelecomNumber" engine="groovy" invoke="updateWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Update WorkEffort TelecomNumber</description> <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <implements service="updateTelecomNumber"/> <implements service="updateWorkEffortContactMech"/> + <attribute name="relationEntityName" type="String" mode="IN" default-value="PostalAddress"/> + <override name="contactMechTypeId" default-value="TELECOM_NUMBER"/> </service> - <service name="createWorkEffortEmailAddress" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="createWorkEffortEmailAddress"> + <service name="createWorkEffortEmailAddress" engine="groovy" invoke="createWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Create WorkEffort Email Address</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <implements service="createWorkEffortContactMech"/> + <override name="contactMechTypeId" default-value="EMAIL_ADDRESS"/> </service> - <service name="updateWorkEffortEmailAddress" engine="simple" - location="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml" invoke="updateWorkEffortEmailAddress"> + <service name="updateWorkEffortEmailAddress" engine="groovy" invoke="updateWorkEffortContactMech" auth="true" + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> <description>Update WorkEffort Email Address</description> <permission-service service-name="workEffortGenericPermission" main-action="UPDATE"/> <implements service="updateWorkEffortContactMech"/> + <override name="contactMechTypeId" default-value="EMAIL_ADDRESS"/> </service> <!--WorkEffortInventoryProduced Services --> 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 a0b8fe6cdc..f1b94f9d24 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,6 +18,10 @@ */ package org.apache.ofbiz.workeffort.workeffort.workeffort +import org.apache.ofbiz.entity.model.ModelEntity +import org.apache.ofbiz.entity.util.EntityQuery +import org.apache.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices + import java.sql.Timestamp import org.apache.ofbiz.base.util.UtilDateTime @@ -337,6 +341,92 @@ Map copyWorkEffort() { return success(workEffortId: targetWorkEffort.workEffortId) } +/** + * Duplicate a WorkEffort + * @return Success response containing the workEffortId, error response otherwise. + */ +Map duplicateWorkEffort() { + if ((parameters.removeWorkEffortAssocs == 'Y' || + parameters.removeWorkEffortContents == 'Y' || + parameters.removeWorkEffortNotes == 'Y' || + parameters.removeWorkEffortAssignmentRates == 'Y') && + security.hasPermission('WORKEFFORTMGR_DELETE', userLogin)) { + return error(label('WorkEffortUiLabels', 'WorkEffortDeletePermissionError')) + } + String workEffortId = parameters.workEffortId ?: delegator.getNextSeqId('WorkEffort') + GenericValue oldWorkEffort = from('WorkEffort').where(workEffortId: parameters.oldWorkEffortId).queryOne() + GenericValue duplicateWorkEffort = oldWorkEffort.clone() + duplicateWorkEffort.workEffortId = workEffortId + + // Check the status to give to the new WorkEffort + if (!parameters.statusId) { + GenericValue oldStatus = from('StatusItem').where(statusId: oldWorkEffort.currentStatusId).cache().queryOne() + GenericValue firstStatus = from('StatusItem') + .where(statusTypeId: oldStatus.statusTypeId) + .orderBy('sequenceId') + .queryFirst() + duplicateWorkEffort.currentStatusId = firstStatus.statusId + } else { + duplicateWorkEffort.currentStatusId = parameters.statusId + } + + // Create the new WorkEffort from the old one and the status + run service: 'createWorkEffort', with: duplicateWorkEffort.getAllFields() + + if (parameters.duplicateWorkEffortAssocs == 'Y') { + ['From', 'To'].each { + duplicateWorkEffortAssoc('WorkEffortAssoc', oldWorkEffort.workEffortId, workEffortId, "workEffortId$it") + } + } + + if (parameters.duplicateWorkEffortNotes == 'Y') { + duplicateWorkEffortAssoc('WorkEffortNote', oldWorkEffort.workEffortId, workEffortId) + } + if (parameters.duplicateWorkEffortContents == 'Y') { + duplicateWorkEffortAssoc('WorkEffortContent', oldWorkEffort.workEffortId, workEffortId) + } + if (parameters.duplicateWorkEffortAssignmentRates == 'Y') { + duplicateWorkEffortAssoc('RateAmount', oldWorkEffort.workEffortId, workEffortId) + } + Map removeWorkEffortMap = [workEffortId: oldWorkEffort.workEffortId] + if (parameters.removeWorkEffortAssocs == 'Y') { + delegator.removeByAnd('WorkEffortAssoc', removeWorkEffortMap) + } + if (parameters.removeWorkEffortNotes == 'Y') { + delegator.removeByAnd('WorkEffortNote', removeWorkEffortMap) + } + if (parameters.removeWorkEffortContents == 'Y') { + delegator.removeByAnd('WorkEffortContent', removeWorkEffortMap) + } + if (parameters.removeWorkEffortAssignmentRates == 'Y') { + delegator.removeByAnd('RateAmount', removeWorkEffortMap) + } + return success([workEffortId: workEffortId]) +} + +/** + * duplicate entity relation during a workEffort duplication process + * @param relationEntityName + * @param oldWorkEffortId + * @param workEffortId + * @param relationFieldName + */ +void duplicateWorkEffortAssoc(String relationEntityName, String oldWorkEffortId, + String workEffortId, String relationFieldName = 'workEffortId') { + ModelEntity modelEntity = delegator.getModelEntity(relationFieldName) + EntityQuery entities = from(relationEntityName) + .where((relationFieldName): oldWorkEffortId) + if (modelEntity.getField('fromDate')) { + entities.filterByDate() + } + entities.queryList() + .each { oldAssoc -> + GenericValue duplicateAssoc = oldAssoc.clone() + duplicateAssoc.(relationFieldName) = workEffortId + duplicateAssoc.create() + } +} + /** * For a custRequest accepted link it to a workEffort and duplicate content * @return Success, error response otherwise. @@ -366,3 +456,129 @@ Map assocAcceptedCustRequestToWorkEffort() { } return success() } + +/** + * Assign Party to Work Effort + * @return Success, error response otherwise. + */ +Map assignPartyToWorkEffort() { + // check if the requested party Assignment already exist + GenericValue assignment = from('WorkEffortPartyAssignment') + .where(workEffortId: parameters.workEffortId, + partyId: parameters.partyId, + roleTypeId: parameters.roleTypeId) + .filterByDate() + .queryFirst() + if (assignment) { + return error(label('WorkEffortUiLabels', 'WorkEffortPartyAssignmentError', parameters)) + } + + run service: 'ensurePartyRole', with: parameters + Timestamp now = UtilDateTime.nowTimestamp() + parameters.fromDate = parameters.fromDate ?: now + Map result = run service: 'createWorkEffortPartyAssignment', with: [*: parameters, + statusDatetime: parameters.statusId? now: null, + assignedByUserLoginId: userLogin.userLoginId] + assignment = from('WorkEffortPartyAssignment').where(parameters).queryOne() + if (parameters.statusId) { + WorkEffortPartyAssignmentServices.updateWorkflowEngine(assignment, userLogin, dispatcher) + } + return success([fromDate: result.fromDate]) +} + +/** + * Update WorkEffortPartyAssignment entity + * @return Success, error response otherwise. + */ +Map updatePartyToWorkEffortAssignment() { + Map assignment = from('WorkEffortPartyAssignment').where(parameters).queryOne() + if (assignment && parameters.statusId + && parameters.statusId != assignment.statusId) { + WorkEffortPartyAssignmentServices.updateWorkflowEngine(assignment, userLogin, dispatcher) + parameters.statusDatetime = UtilDateTime.nowTimestamp() + } + Map result = run service: 'updateWorkEffortPartyAssignment', with: parameters + return result +} + +/** + * Quick Assign Party To WorkEffort + * @return Success, error response otherwise. + */ +Map quickAssignPartyToWorkEffort() { + + // add a party assignment for the creator of the event, use the list method and let the EE do the update or create... + run service: 'ensurePartyRole', with: [partyId: parameters.quickAssignPartyId, + roleTypeId: parameters.roleTypeId] + run service: 'createWorkEffortPartyAssignment', with: [*: parameters, + partyId: parameters.quickAssignPartyId, + statusId: 'PRTYASGN_ASSIGNED'] + return success() +} + +/** + * Quick Assign Party To WorkEffort + * if relationEntityName is present create the contactMech type related + * and if partyId is also present, link it + * @return Success response containing the contactMechId, error response otherwise. + */ +Map createWorkEffortContactMech() { + String contactMechId = parameters.contactMechId + if (!contactMechId && parameters.relationEntityName) { + String serviceName = 'create' + (parameters.partyId ? 'Party' : '') + parameters.relationEntityName + Map serviceResult = run service: serviceName, with: parameters + contactMechId = serviceResult.contactMechId + } + + if (!contactMechId) { + if (!parameters.contactMechTypeId) { + return error(label('WorkEffortUiLabels', 'WorkEffortRequiredFieldMissingContactMechIdOrContactMechTypeId')) + } + String serviceName = 'create' + (parameters.relationEntityName ?: 'ContactMech') + Map serviceResult = run service: serviceName, with: parameters + contactMechId = serviceResult.contactMechId + } + + GenericValue workEffortContactMech = makeValue('WorkEffortContactMech', [*: parameters, + fromDate: UtilDateTime.nowTimestamp(), + contactMechId: contactMechId]) + workEffortContactMech.create() + return success([contactMechId: contactMechId]) +} + +/** + * Update a WorkEffortContactMech and ContactMech related + * @return Successs response containing the contactMechId and oldContactMechId,, error response otherwise. + */ +Map updateWorkEffortContactMech() { + GenericValue workEffortContactMech = from('WorkEffortContactMech') + .where(workEffortId: parameters.workEffortId, + contactMechId: parameters.contactMechId) + .filterByDate() + .queryFirst() + if (!workEffortContactMech) { + return error(label('WorkEffortUiLabels', 'WorkEffortCannotUpdateContactInfo')) + } + GenericValue newWorkEffortContactMech = workEffortContactMech.clone() + // If we already have a new contactMechId don't update ContactMech + String newContactMechId = parameters.newContactMechId + if (!newContactMechId && parameters.relationEntityName) { + String serviceName = 'update' + parameters.relationEntityName + Map serviceResult = run service: serviceName, with: parameters + newContactMechId = serviceResult.contactMechId + } + if (!newContactMechId) { + Map serviceResult = run service: 'updateContactMech', with: parameters + newContactMechId = serviceResult.contactMechId + } + + if (newContactMechId != parameters.contactMechId) { + Timestamp now = UtilDateTime.nowTimestamp() + newWorkEffortContactMech.fromDate = now + workEffortContactMech.thruDate = now + newWorkEffortContactMech.contactMechId = newContactMechId + newWorkEffortContactMech.create() + workEffortContactMech.store() + } + return success([contactMechId: newContactMechId, oldContactMechId: workEffortContactMech.contactMechId]) +} \ No newline at end of file