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
commit 8af7cf877583acf100d1229260e62fe7f4c92563 Author: Wiebke Pätzold <wiebke.paetz...@ecomify.de> AuthorDate: Thu Apr 16 09:08:36 2020 +0200 Improved: Converted AccountServices from mini lang to groovy (OFBIZ-11413) Added ServiceDefs createPartyContactMechs and createPartyGroupRoleAndContactMechs. Also converted createPartyGroupRoleAndContactMechs because it is used in AccountServies and needed more return values. --- .../sfa/account/AccountServices.groovy | 44 ++++++++++ .../minilang/sfa/account/AccountServices.xml | 36 -------- applications/marketing/servicedef/services.xml | 4 +- .../groovyScripts/party/PartySimpleMethods.groovy | 97 ++++++++++++++++++++++ applications/party/servicedef/services.xml | 37 +++++++++ 5 files changed, 180 insertions(+), 38 deletions(-) diff --git a/applications/marketing/groovyScripts/sfa/account/AccountServices.groovy b/applications/marketing/groovyScripts/sfa/account/AccountServices.groovy new file mode 100644 index 0000000..d659bd2 --- /dev/null +++ b/applications/marketing/groovyScripts/sfa/account/AccountServices.groovy @@ -0,0 +1,44 @@ +/* + * 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. + */ + + +/** + * create Account Group + */ +def createAccount() { + parameters.roleTypeId = "ACCOUNT" + + Map serviceResult = run service: "createPartyGroupRoleAndContactMechs", with: parameters + String partyId = serviceResult.partyId + + Map result = success() + result.successMessage = serviceResult.successMessage + result.partyId = partyId + + run service: "ensurePartyRole", with: [partyId: userLogin.partyId, + roleTypeId: "OWNER"] + + run service: "createPartyRelationship", with: [partyIdFrom: userLogin.partyId, + partyIdTo: partyId, + roleTypeIdFrom: "OWNER", + roleTypeIdTo: "ACCOUNT", + partyRelationshipTypeId: "ACCOUNT"] + + return result +} diff --git a/applications/marketing/minilang/sfa/account/AccountServices.xml b/applications/marketing/minilang/sfa/account/AccountServices.xml deleted file mode 100644 index b4284f8..0000000 --- a/applications/marketing/minilang/sfa/account/AccountServices.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <simple-method method-name="createAccount" short-description="create Account Group"> - <set field="parameters.roleTypeId" value="ACCOUNT"/> - <call-simple-method method-name="createPartyGroupRoleAndContactMechs" xml-resource="component://party/minilang/party/PartySimpleMethods.xml"/> - <field-to-result field="partyId"/> - <set field="ensurePartyRoleCtx.partyId" from-field="userLogin.partyId"/> - <set field="ensurePartyRoleCtx.roleTypeId" value="OWNER"/> - <call-service service-name="ensurePartyRole" in-map-name="ensurePartyRoleCtx"/> - <set field="partyRelationshipCtx.partyIdFrom" from-field="userLogin.partyId"/> - <set field="partyRelationshipCtx.partyIdTo" from-field="partyId"/> - <set field="partyRelationshipCtx.roleTypeIdFrom" value="OWNER"/> - <set field="partyRelationshipCtx.roleTypeIdTo" value="ACCOUNT"/> - <set field="partyRelationshipCtx.partyRelationshipTypeId" value="ACCOUNT"/> - <call-service service-name="createPartyRelationship" in-map-name="partyRelationshipCtx"/> - </simple-method> -</simple-methods> diff --git a/applications/marketing/servicedef/services.xml b/applications/marketing/servicedef/services.xml index 7825290..ec5d244 100644 --- a/applications/marketing/servicedef/services.xml +++ b/applications/marketing/servicedef/services.xml @@ -547,8 +547,8 @@ under the License. <attribute name="useEmail2" type="String" mode="IN" optional="true"/> </service> <!-- Account services --> - <service name="createAccount" engine="simple" - location="component://marketing/minilang/sfa/account/AccountServices.xml" invoke="createAccount"> + <service name="createAccount" engine="groovy" + location="component://marketing/groovyScripts/sfa/account/AccountServices.groovy" invoke="createAccount"> <description>Create an Account Group</description> <auto-attributes entity-name="PartyGroup" mode="IN" optional="true"> <exclude field-name="partyId"/> diff --git a/applications/party/groovyScripts/party/PartySimpleMethods.groovy b/applications/party/groovyScripts/party/PartySimpleMethods.groovy new file mode 100644 index 0000000..7e934ec --- /dev/null +++ b/applications/party/groovyScripts/party/PartySimpleMethods.groovy @@ -0,0 +1,97 @@ +/* + * 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. + */ + +import org.apache.ofbiz.base.util.UtilProperties +import org.apache.ofbiz.base.util.UtilValidate +import org.apache.ofbiz.minilang.SimpleMapProcessor +import org.apache.ofbiz.service.GenericServiceException +import org.apache.ofbiz.service.ServiceUtil + +// Simple method to create a party group, its role and basic contact mechs + +/** + * Creates a party group, role and contactMechs + * @return + */ +def createPartyGroupRoleAndContactMechs() { + try { + parameters.partyGroupContext = resolvePartyGroupMap(parameters) + if (parameters.address1) { + parameters.postalAddressContext = resolvePostalAddressMap() + } + if (parameters.contactNumber) { + parameters.telecomNumberContext = resolveTelecomNumberMap() + } + } catch (GenericServiceException e) { + return error(e.toString()) + } + + if (parameters.emailAddress) { + Map emailAddressContext = [:] + if (!UtilValidate.isEmail(parameters.emailAddress)) { + return error(UtilProperties.getMessage('PartyUiLabels', + 'PartyEmailAddressNotFormattedCorrectly', parameters.locale)) + } else { + emailAddressContext.emailAddress = parameters.emailAddress + } + parameters.emailAddressContext = emailAddressContext + } + + parameters.partyGroupContext.partyTypeId = "PARTY_GROUP" + Map serviceResult = run service: "createPartyGroup", with: parameters.partyGroupContext + if (ServiceUtil.isError(serviceResult)) { + return serviceResult + } + Map result = success() + result.partyId = serviceResult.partyId + + if (parameters.roleTypeId) { + Map serviceResultCPR = run service: "createPartyRole", with: [partyId: serviceResult.partyId, + roleTypeId: parameters.roleTypeId] + if (ServiceUtil.isError(serviceResultCPR)) { + return serviceResultCPR + } + } + + run service:"createPartyContactMechs", with: parameters + + return result +} + +// TODO need to convert from MapProcessor +def resolvePartyGroupMap() { + return resolvePartyProcessMap('partyGroup') +} +def resolvePostalAddressMap() { + return resolvePartyProcessMap('postalAddress') +} +def resolveTelecomNumberMap() { + return resolvePartyProcessMap('telecomNumber') +} +def resolvePartyProcessMap(String processMapName) { + List messages = [] + Map resultMap = [:] + SimpleMapProcessor.runSimpleMapProcessor('component://party/minilang/party/PartyMapProcs.xml', + processMapName, parameters, resultMap, messages, context.locale) + // Check errors + if (messages) { + throw new GenericServiceException(messages.join(',')) + } + return resultMap +} \ No newline at end of file diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml index c3c15ed..07337ec 100644 --- a/applications/party/servicedef/services.xml +++ b/applications/party/servicedef/services.xml @@ -91,6 +91,43 @@ under the License. </type-validate> </attribute> </service> + + <service name="createPartyGroupRoleAndContactMechs" engine="groovy" default-entity-name="PartyGroupRoleAndContactMechs" + location="component://party/groovyScripts/party/PartySimpleMethods.groovy" invoke="createPartyGroupRoleAndContactMechs"> + <description>Create Party Group Role and Contact Mechs</description> + <auto-attributes entity-name="PartyGroup" mode="IN" optional="true"> + <exclude field-name="partyId"/> + </auto-attributes> + <auto-attributes entity-name="PostalAddress" mode="IN" optional="true"> + <exclude field-name="contactMechId"/> + </auto-attributes> + <auto-attributes entity-name="TelecomNumber" mode="IN" optional="true"> + <exclude field-name="contactMechId"/> + </auto-attributes> + <attribute name="groupName" type="String" mode="IN" optional="false"/> + <attribute name="address1" type="String" mode="IN" optional="true"/> + <attribute name="contactNumber" type="String" mode="IN" optional="true"/> + <attribute name="emailAddress" type="String" mode="IN" optional="true"/> + <attribute name="postalAddContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + <attribute name="phoneContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + <attribute name="emailContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + <attribute name="roleTypeId" type="String" mode="IN" optional="true"/> + <attribute name="partyId" type="String" mode="OUT" optional="false"/> + </service> + + <service name="createPartyContactMechs" engine="simple" default-entity-name="createPartyContactMechs" + location="component://party/minilang/party/PartySimpleMethods.xml" invoke="createPartyContactMechs"> + <description>Create Party Group Role and Contact Mechs</description> + <attribute name="partyGroupContext" type="Map" mode="IN" optional="true"/> + <attribute name="postalAddressContext" type="Map" mode="IN" optional="true"/> + <attribute name="telecomNumberContext" type="Map" mode="IN" optional="true"/> + <attribute name="postalAddContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + <attribute name="contactNumber" type="String" mode="IN" optional="true"/> + <attribute name="phoneContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + <attribute name="emailAddress" type="String" mode="IN" optional="true"/> + <attribute name="emailContactMechPurpTypeId" type="String" mode="IN" optional="true"/> + </service> + <service name="updatePerson" engine="java" default-entity-name="Person" location="org.apache.ofbiz.party.party.PartyServices" invoke="updatePerson" auth="true"> <description>Update a Person</description>