You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/09/30 12:35:19 UTC

[ofbiz-framework] 03/03: Fixed: createPartyGroupRoleAndContactMechs service not working (OFBIZ-11986)

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-framework.git

commit 70ff1c500665ae400c077f0e0c9f875afa6d4b3d
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Wed Sep 30 14:27:13 2020 +0200

    Fixed: createPartyGroupRoleAndContactMechs service not working (OFBIZ-11986)
    
    As Akash Jain reported:
    
    <<While researched on ticket OFBIZ-11896 identified that groovy version of
    createPartyGroupRoleAndContactMechs service (converted from mini lang at rev
    8af7cf877583acf100d1229260e62fe7f4c92563 ) is not working.
    Identify these two reasons,
        resolvePartyGroupMap called incorrectly
        resolvePostalAddressMap and resolveTelecomNumberMap implemented incorrectly
    as 'postalAddress' and 'telecomNumber' map processor
    not available into PartyMapProcs.xml.
    
    There may be more reasons along with these two reasons.>>
    
    He was so true to say the later!
    
    There are also some intentionally or automated formattings.
    
    Thanks: Akash for report, Sourabh Jain for shy tentative :)
---
 .../groovyScripts/sfa/lead/LeadServices.groovy     |  8 ++--
 applications/marketing/servicedef/services.xml     | 15 ++++---
 .../groovyScripts/party/PartySimpleMethods.groovy  | 47 ++++++++++++----------
 .../party/minilang/party/PartySimpleMethods.xml    | 19 ++++++---
 applications/party/servicedef/services.xml         |  6 +--
 5 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/applications/marketing/groovyScripts/sfa/lead/LeadServices.groovy b/applications/marketing/groovyScripts/sfa/lead/LeadServices.groovy
index 61d1e93..7594ce5 100644
--- a/applications/marketing/groovyScripts/sfa/lead/LeadServices.groovy
+++ b/applications/marketing/groovyScripts/sfa/lead/LeadServices.groovy
@@ -32,11 +32,9 @@ def createLead() {
     String partyGroupPartyId
     // Check if Person or PartyGroup name is supplied
     if ((!parameters.firstName || !parameters.lastName) && !parameters.groupName) {
-        return error(UtilProperties.getMessage("MarketingUiLabels",
-                "SfaFirstNameLastNameAndCompanyNameMissingError", locale))
+        return error(UtilProperties.getMessage("MarketingUiLabels", "SfaFirstNameLastNameAndCompanyNameMissingError", locale))
     }
-    run service: "ensurePartyRole", with: [partyId: userLogin.partyId,
-                                           roleTypeId: "OWNER"]
+    run service: "ensurePartyRole", with: [partyId: userLogin.partyId, roleTypeId: "OWNER"]
     // PartyRole check end
     parameters.roleTypeId = "LEAD"
 
@@ -202,4 +200,4 @@ def resolvePartyProcessMap() {
         throw new GenericServiceException(messages.join(','))
     }
     return resultMap
-}
\ No newline at end of file
+}
diff --git a/applications/marketing/servicedef/services.xml b/applications/marketing/servicedef/services.xml
index 28a646b..55e1281 100644
--- a/applications/marketing/servicedef/services.xml
+++ b/applications/marketing/servicedef/services.xml
@@ -289,21 +289,21 @@ under the License.
     <service name="updateCommStatusFromCommEvent" engine="simple"
             location="component://marketing/minilang/marketing/contact/ContactListServices.xml" invoke="updateCommStatusFromCommEvent">
         <attribute name="communicationEventId" type="String" mode="IN"/>
-        <attribute name="statusId" type="String" mode="IN"/>        
-    </service> 
+        <attribute name="statusId" type="String" mode="IN"/>
+    </service>
     
     <!-- WebSiteContactList services -->
-    <service name="createWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList" 
+    <service name="createWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList"
         location="component://marketing/minilang/marketing/contact/ContactListServices.xml" invoke="createWebSiteContactList">
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true"/>
     </service>
-    <service name="updateWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList" 
+    <service name="updateWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList"
         location="component://marketing/minilang/marketing/contact/ContactListServices.xml" invoke="updateWebSiteContactList">
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true"/>
     </service>
-    <service name="deleteWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList" 
+    <service name="deleteWebSiteContactList" engine="simple" default-entity-name="WebSiteContactList"
         location="component://marketing/minilang/marketing/contact/ContactListServices.xml" invoke="deleteWebSiteContactList">
         <auto-attributes mode="IN" include="pk" optional="false"/>
     </service>
@@ -484,7 +484,10 @@ under the License.
     <service name="createLead" engine="groovy" location="component://marketing/groovyScripts/sfa/lead/LeadServices.groovy" invoke="createLead">
         <description>
             Sales Lead can be just a person or a person representing a company or a company (party group).
-            createLead works 1) If person information is passed. 2) If company (party group) information is passed. 3) If Person and company (party group) information is passed. 
+            createLead works
+            1) If person information is passed.
+            2) If company (party group) information is passed.
+            3) If Person and company (party group) information is passed.
         </description>
         <auto-attributes entity-name="Person" mode="IN" optional="true">
             <exclude field-name="partyId"/>
diff --git a/applications/party/groovyScripts/party/PartySimpleMethods.groovy b/applications/party/groovyScripts/party/PartySimpleMethods.groovy
index 20605cb..a261b3f 100644
--- a/applications/party/groovyScripts/party/PartySimpleMethods.groovy
+++ b/applications/party/groovyScripts/party/PartySimpleMethods.groovy
@@ -23,36 +23,18 @@ 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
+ * @return result
  */
 def createPartyGroupRoleAndContactMechs() {
     try {
         parameters.partyGroupContext = resolvePartyGroupMap()
-        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)) {
@@ -60,7 +42,8 @@ def createPartyGroupRoleAndContactMechs() {
     }
     Map result = success()
     result.partyId = serviceResult.partyId
-
+    parameters.partyId = serviceResult.partyId
+    
     if (parameters.roleTypeId) {
         Map serviceResultCPR = run service: "createPartyRole", with: [partyId: serviceResult.partyId,
                                                                      roleTypeId: parameters.roleTypeId]
@@ -68,9 +51,26 @@ def createPartyGroupRoleAndContactMechs() {
             return serviceResultCPR
         }
     }
+    try {
+        if (parameters.address1) {
+            parameters.postalAddressContext = resolvePostalAddressMap()
+        }
+        if (parameters.contactNumber) {
+            parameters.telecomNumberContext = resolveTelecomNumberMap()
+        }
+        if (parameters.emailAddress) {
+            resolveEmailAddressMap()
+            Map emailAddressContext = [:]
+            emailAddressContext.partyId = parameters.partyId
+            emailAddressContext.emailAddress = parameters.emailAddress
+            parameters.emailAddressContext = emailAddressContext
+        }
+    } catch (GenericServiceException e) {
+        return error(e.toString())
+    }
+    
 
-    run service:"createPartyContactMechs", with: parameters
-
+    run service: "createPartyContactMechs", with: parameters
     return result
 }
 
@@ -84,6 +84,9 @@ def resolvePostalAddressMap() {
 def resolveTelecomNumberMap() {
     return resolvePartyProcessMap("party/minilang/contact/PartyContactMechMapProcs.xml", 'telecomNumber')
 }
+def resolveEmailAddressMap() {
+    return resolvePartyProcessMap("party/minilang/contact/PartyContactMechMapProcs.xml", 'emailAddress')
+}
 def resolvePartyProcessMap(String mapProcessorPath, String processMapName) {
     List messages = []
     Map resultMap = [:]
diff --git a/applications/party/minilang/party/PartySimpleMethods.xml b/applications/party/minilang/party/PartySimpleMethods.xml
index ed7922a..91fb7c8 100644
--- a/applications/party/minilang/party/PartySimpleMethods.xml
+++ b/applications/party/minilang/party/PartySimpleMethods.xml
@@ -131,21 +131,23 @@ under the License.
             </call-map-processor>
         </if-not-empty>
         <check-errors/>
-
+        
         <call-service service-name="createPerson" in-map-name="personContext">
             <result-to-field result-name="partyId" field="partyId"/>
         </call-service>
-
+        <check-errors/>
+        <set field="emailAddressContext.partyId" from="partyId"/>
+        
         <if-not-empty field="parameters.roleTypeId">
             <set field="createPartyRoleCtx.partyId" from-field="partyId"/>
             <set field="createPartyRoleCtx.roleTypeId" from-field="parameters.roleTypeId"/>
             <call-service service-name="createPartyRole" in-map-name="createPartyRoleCtx"/>
         </if-not-empty>
-
+        <check-errors/>
         <set field="postalAddContactMechPurpTypeId" from-field="parameters.postalAddContactMechPurpTypeId"/>
         <set field="contactNumber" from-field="parameters.contactNumber"/>
         <set field="phoneContactMechPurpTypeId" from-field="parameters.phoneContactMechPurpTypeId"/>
-        <set field="emailAddress" from-field="parameters.emailAddress"/>
+        <set field="emailAddress" from-field="emailAddressContext"/>
         <set field="emailContactMechPurpTypeId" from-field="parameters.emailContactMechPurpTypeId"/>
         <call-simple-method method-name="createPartyContactMechs"/>
         <field-to-result field="partyId"/>
@@ -198,6 +200,12 @@ under the License.
     <!-- Simple method to create Party Postal Address, Telecom Number and Email Address, to be used by
          createPersonRoleAndContactMechs and createPartyGroupRoleAndContactMechs simple methods -->
     <simple-method method-name="createPartyContactMechs" short-description="Create Contact Mechs">
+        <set field="postalAddressContext" from-field="parameters.postalAddressContext"/>
+        <set field="postalAddContactMechPurpTypeId" from-field="parameters.postalAddContactMechPurpTypeId"/>
+        <set field="telecomNumberContext" from-field="parameters.telecomNumberContext" />
+        <set field="phoneContactMechPurpTypeId" from-field="parameters.phoneContactMechPurpTypeId"/>
+        <set field="emailAddressContext" from-field="parameters.emailAddressContext"/>
+        <set field="emailContactMechPurpTypeId" from-field="parameters.emailContactMechPurpTypeId"/>
         <!-- postal address -->
         <if-not-empty field="postalAddressContext">
             <set field="postalAddressContext.partyId" from-field="partyId"/>
@@ -225,12 +233,11 @@ under the License.
 
         <!-- email address -->
         <if-not-empty field="emailAddressContext">
-            <set field="emailAddressContext.partyId" from-field="partyId"/>
             <set field="emailAddressContext.contactMechPurposeTypeId" value="PRIMARY_EMAIL"/>
             <if-not-empty field="emailContactMechPurpTypeId"> <!-- override with purpose present in parameters, if any (This field is not used now, just here for future implementations) -->
                 <set field="emailAddressContext.contactMechPurposeTypeId" from-field="emailContactMechPurpTypeId"/>
             </if-not-empty>
-            <call-service service-name="createPartyEmailAddress" in-map-name="emailAddressContext"/>
+            <call-service service-name="createPartyEmailAddress" in-map-name="emailAddressContext" />
         </if-not-empty>
     </simple-method>
 
diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml
index 8a1f8ad..66ee5f2 100644
--- a/applications/party/servicedef/services.xml
+++ b/applications/party/servicedef/services.xml
@@ -73,7 +73,7 @@ under the License.
         <attribute name="description" type="String" mode="IN" optional="true"/>
         <attribute name="externalId" type="String" mode="IN" optional="true"/>
         <attribute name="statusId" type="String" mode="IN" optional="true"/>
-        <!-- First and Last names are here optional. This allows to implement simple create user login screen where user is able create account 
+        <!-- First and Last names are here optional. This allows to implement simple create user login screen where user is able create account
             in system with username and password and then later populate rest of the account information. -->
 <!--        <override name="firstName" optional="false"/>
         <override name="lastName" optional="false"/>
@@ -124,7 +124,7 @@ under the License.
         <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="emailAddressContext" type="Map" mode="IN" optional="true"/>
         <attribute name="emailContactMechPurpTypeId" type="String" mode="IN" optional="true"/>
     </service>
     <service name="createPersonRoleAndContactMechs" engine="simple"
@@ -1271,7 +1271,7 @@ under the License.
         </description>
         <implements service="permissionInterface"/>
     </service>
-    <service name="basePermissionCheck" engine="groovy" 
+    <service name="basePermissionCheck" engine="groovy"
             location="component://party/groovyScripts/party/PartyPermissionServices.groovy" invoke="basePermissionCheck">
         <description>
             Performs a basic security check. The user must have the base PARTYMGR  permission.