This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git
The following commit(s) were added to refs/heads/trunk by this push: new 40e3263b9 Improved: convert createProject service (OFBIZ-12983) (#104) 40e3263b9 is described below commit 40e3263b990bd1e71150901904ee80aa2189475e Author: Pierre Smits <pierre.sm...@somonar.com> AuthorDate: Fri Apr 12 18:27:19 2024 +0200 Improved: convert createProject service (OFBIZ-12983) (#104) * Improved: convert createProject service (OFBIZ-12983) convert createProject service code from mini-lang to groovy DSL modified: services.xml: changed engine, location and description ProjectServices.xml: removed simple-method added: ProjectServices.groovy: having createProject * Improved: convert createProject service (OFBIZ-12983) codenarc corrections corrections suggested by Michael. * Updates ProjectServices.groovy Uses Groovy thruth rather than !=null. It also checks for non empty jleroux: works locally --------- Co-authored-by: Jacques Le Roux <jacques.le.r...@les7arts.com> --- projectmgr/minilang/ProjectServices.xml | 40 ------------- projectmgr/servicedef/services.xml | 7 +-- .../apache/ofbiz/projectmgr/ProjectServices.groovy | 69 ++++++++++++++++++++++ 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/projectmgr/minilang/ProjectServices.xml b/projectmgr/minilang/ProjectServices.xml index f11a3014b..bb756b28b 100644 --- a/projectmgr/minilang/ProjectServices.xml +++ b/projectmgr/minilang/ProjectServices.xml @@ -21,46 +21,6 @@ <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="createProject" short-description="Create a project"> - <if-not-empty field="parameters.templateId"> - <set field="parameters.projectId" from-field="parameters.templateId"/> - <call-simple-method method-name="copyProject"/> - <else> - <set field="parameters.currentStatusId" value="PRJ_ACTIVE"/> - <call-simple-method method-name="createWorkEffort" xml-resource="component://workeffort/minilang/workeffort/WorkEffortSimpleServices.xml"/> - </else> - </if-not-empty> - <set field="parameters.workEffortId" from-field="newEntity.workEffortId"/> - <if-not-empty field="parameters.organizationPartyId"> - <set field="updProjectRole.newPartyId" from-field="parameters.organizationPartyId"/> - <set field="updProjectRole.roleTypeId" value="INTERNAL_ORGANIZATIO"/> - <call-simple-method method-name="updProjectRole"/> - </if-not-empty> - <if-not-empty field="parameters.clientBillingPartyId"> - <set field="updProjectRole.newPartyId" from-field="parameters.clientBillingPartyId"/> - <set field="updProjectRole.roleTypeId" value="CLIENT_BILLING"/> - <call-simple-method method-name="updProjectRole"/> - </if-not-empty> - <if-not-empty field="parameters.emailAddress"> - <if-validate-method field="parameters.emailAddress" method="isEmail"> - <else><add-error><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></add-error></else> - </if-validate-method> - <check-errors/> - - <!-- create new work effort's e-mail address --> - <set field="emailAddressIn.emailAddress" from-field="parameters.emailAddress"/> - <set field="emailAddressIn.contactMechTypeId" value="EMAIL_ADDRESS"/> - <call-service service-name="createEmailAddress" in-map-name="emailAddressIn"> - <result-to-field result-name="contactMechId"/> - </call-service> - <set field="workEffortContactMechIn.workEffortId" from-field="parameters.workEffortId"/> - <set field="workEffortContactMechIn.contactMechId" from-field="contactMechId"/> - <set field="workEffortContactMechIn.contactMechTypeId" value="EMAIL_ADDRESS"/> - <set field="workEffortContactMechIn.infoString" from-field="parameters.emailAddress"/> - <call-service service-name="createWorkEffortContactMech" in-map-name="workEffortContactMechIn"/> - </if-not-empty> - </simple-method> - <simple-method method-name="updateProject" short-description="Update a project"> <set-service-fields service-name="updateWorkEffort" map="parameters" to-map="updWorkEffort"/> <call-service service-name="updateWorkEffort" in-map-name="updWorkEffort"/> diff --git a/projectmgr/servicedef/services.xml b/projectmgr/servicedef/services.xml index bd94179ab..038ceb565 100644 --- a/projectmgr/servicedef/services.xml +++ b/projectmgr/servicedef/services.xml @@ -90,9 +90,9 @@ under the License. <attribute name="projectInfo" type="java.util.Map" mode="OUT" optional="true"/> </service> - <service name="createProject" engine="simple" default-entity-name="WorkEffort" - location="component://projectmgr/minilang/ProjectServices.xml" invoke="createProject"> - <description>Copy a project planning from a template.</description> + <service name="createProject" engine="groovy" default-entity-name="WorkEffort" + location="component://projectmgr/src/main/groovy/org/apache/ofbiz/projectmgr/ProjectServices.groovy" invoke="createProject"> + <description>Create a new Project</description> <permission-service service-name="projectMgrPermission" main-action="CREATE"/> <implements service="interfaceWorkEffort"/> <auto-attributes mode="INOUT" include="pk" optional="true"/> @@ -110,7 +110,6 @@ under the License. <override name="workEffortName" optional="false"/> <override name="currentStatusId" optional="false"/> </service> - <service name="updateProject" default-entity-name="WorkEffort" engine="simple" location="component://projectmgr/minilang/ProjectServices.xml" invoke="updateProject"> <description>Update a Project</description> diff --git a/projectmgr/src/main/groovy/org/apache/ofbiz/projectmgr/ProjectServices.groovy b/projectmgr/src/main/groovy/org/apache/ofbiz/projectmgr/ProjectServices.groovy new file mode 100644 index 000000000..cef83254f --- /dev/null +++ b/projectmgr/src/main/groovy/org/apache/ofbiz/projectmgr/ProjectServices.groovy @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +*/ +package org.apache.ofbiz.projectmgr + +/** +* service to create project +*/ +Map createProject() { + Map result = success() + wepaInMap = [:] + emailInMap = [:] + if (parameters.templateId) { + parameters.projectId = parameters.templateId + pc = run service: 'copyProject', with: parameters + workEffortId = pc.workEffortId + } else { + parameters.currentStatusId = 'PRJ_ACTIVE' + we = run service: 'createWorkEffort', with: parameters + workEffortId = we.workEffortId + } + wepaInMap.workEffortId = workEffortId + // create project role for the internal organisation + if (parameters.organizationPartyId) { + wepaInMap.partyId = parameters.organizationPartyId + wepaInMap.roleTypeId = 'INTERNAL_ORGANIZATIO' + wepa = run service: 'createWorkEffortPartyAssignment', with: wepaInMap + } + // create project role for the client + if (parameters.clientBillingPartyId) { + wepaInMap.partyId = parameters.clientBillingPartyId + wepaInMap.roleTypeId = 'CLIENT_BILLING' + wepa = run service: 'createWorkEffortPartyAssignment', with: wepaInMap + } + // create email address for the project + emailInMap.contactMechTypeId = 'EMAIL_ADDRESS' + emailAddress = parameters.emailAddress + if (emailAddress) { + emailInMap.emailAddress = emailAddress + } else { + emailAddress = 'project.' + workEffortId + '@example.com' + emailInMap.emailAddress = emailAddress + } + email = run service: 'createEmailAddress', with: emailInMap + // create the contact mech regarding the project's email address + wecmInMap = [:] + wecmInMap.workEffortId = workEffortId + wecmInMap.contactMechId = email.contactMechId + wecmInMap.contactMechTypeId = 'EMAIL_ADDRESS' + wecmInMap.infoString = emailAddress + weContactMech = run service: 'createWorkEffortContactMech', with: wecmInMap + result.put('projectId', workEffortId) + return result +}