svn commit: r1840296 - in /ofbiz/ofbiz-framework/trunk/applications: party/groovyScripts/test/ party/src/main/java/org/apache/ofbiz/party/contact/ party/testdef/data/ workeffort/entitydef/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1840296 - in /ofbiz/ofbiz-framework/trunk/applications: party/groovyScripts/test/ party/src/main/java/org/apache/ofbiz/party/contact/ party/testdef/data/ workeffort/entitydef/

nmalin
Author: nmalin
Date: Fri Sep  7 13:11:01 2018
New Revision: 1840296

URL: http://svn.apache.org/viewvc?rev=1840296&view=rev
Log:
Fixed: Warning in console logs related to entity definitions
(OFBIZ-10540)
Improve the previous fix at r183834 where an error has been introduce with the entity WorkEffortContactMech who is different than OrderContactMech (no purpose but fromDate, thruDate) where at the beginning I thinking, wrongly, that they was the same pattern.
I completed the generic function *getEntityContactMechValueMaps* to analyze on the fly what element have the entityview. To complete, I added unit test for WorkEffortContactMech.

Thanks to Deepak Nigam for the control.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/party/groovyScripts/test/ContactMechWorkerTests.groovy
    ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java
    ofbiz/ofbiz-framework/trunk/applications/party/testdef/data/PartyContactMechTestData.xml
    ofbiz/ofbiz-framework/trunk/applications/workeffort/entitydef/entitymodel_view.xml

Modified: ofbiz/ofbiz-framework/trunk/applications/party/groovyScripts/test/ContactMechWorkerTests.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/groovyScripts/test/ContactMechWorkerTests.groovy?rev=1840296&r1=1840295&r2=1840296&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/party/groovyScripts/test/ContactMechWorkerTests.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/applications/party/groovyScripts/test/ContactMechWorkerTests.groovy Fri Sep  7 13:11:01 2018
@@ -133,4 +133,44 @@ class ContactMechWorkerTests extends Gro
         }
         assert foundBillingAddress && foundShippingAddress && foundOrderEmail
     }
+
+    void testWorkEffortContactMechResolution() {
+        List workEffortContactMechValueMaps = ContactMechWorker.getWorkEffortContactMechValueMaps(delegator, "TEST_CM_WORKER")
+        assert workEffortContactMechValueMaps
+        assert workEffortContactMechValueMaps.size() == 3
+
+        boolean foundPostalAddress, foundPhone, foundEmail = false
+        workEffortContactMechValueMaps.forEach {
+            Map workEffortContactMechValueMap ->
+                switch (workEffortContactMechValueMap.contactMech?.contactMechId) {
+                    case '9015':
+                        assert workEffortContactMechValueMap.contactMech.contactMechTypeId == 'POSTAL_ADDRESS'
+                        assert workEffortContactMechValueMap.contactMechType
+                        assert workEffortContactMechValueMap.workEffortContactMech
+                        assert workEffortContactMechValueMap.postalAddress
+                        assert workEffortContactMechValueMap.postalAddress.contactMechId == '9015'
+                        assert workEffortContactMechValueMap.postalAddress.address1 == '2004 Factory Blvd'
+                        foundPostalAddress = true
+                        break
+                    case '9126':
+                        assert workEffortContactMechValueMap.contactMech.contactMechTypeId == 'EMAIL_ADDRESS'
+                        assert workEffortContactMechValueMap.contactMech.infoString == '[hidden email]'
+                        assert workEffortContactMechValueMap.workEffortContactMech
+                        assert workEffortContactMechValueMap.contactMechType
+                        foundEmail = true
+                        break
+                    case '9125':
+                        assert workEffortContactMechValueMap.contactMech.contactMechTypeId == 'TELECOM_NUMBER'
+                        assert workEffortContactMechValueMap.workEffortContactMech
+                        assert workEffortContactMechValueMap.contactMechType
+                        assert workEffortContactMechValueMap.telecomNumber.contactNumber == '555-5555'
+                        foundPhone = true
+                        break
+                    default:
+                        assert false
+                        break
+                }
+        }
+        assert foundPostalAddress && foundEmail && foundPhone
+    }
 }

Modified: ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java?rev=1840296&r1=1840295&r2=1840296&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java Fri Sep  7 13:11:01 2018
@@ -44,6 +44,7 @@ import org.apache.ofbiz.entity.GenericEn
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.condition.EntityOperator;
+import org.apache.ofbiz.entity.model.ModelEntity;
 import org.apache.ofbiz.entity.model.ModelUtil;
 import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.entity.util.EntityUtil;
@@ -223,13 +224,26 @@ public class ContactMechWorker {
         String downCaseEntityName = ModelUtil.lowerFirstChar(entityName);
 
         List<GenericValue> allEntityContactMechs = null;
+        String entityViewName = entityName + "AndContactMech";
 
+        ModelEntity contactMechViewModel = delegator.getModelEntity(entityViewName);
+        if (contactMechViewModel == null) {
+            Debug.logError("Entity view " + entityViewName + " not exist, please check your call. We return empty list", module);
+            return entityContactMechValueMaps;
+        }
+        boolean contactMechPurposeTypeIdFieldPresent = contactMechViewModel.isField("contactMechPurposeTypeId");
+        boolean fromDateFieldPresent = contactMechViewModel.isField("fromDate");
         try {
-            allEntityContactMechs = EntityQuery.use(delegator).from(entityName + "AndContactMech")
-                    .where(downCaseEntityName + "Id", entityId)
-                    .orderBy("contactMechPurposeTypeId")
-                    .filterByDate(date)
-                    .queryList();
+            EntityQuery contactMechQuery = EntityQuery.use(delegator)
+                    .from(entityViewName)
+                    .where(downCaseEntityName + "Id", entityId);
+            if (contactMechPurposeTypeIdFieldPresent) {
+                contactMechQuery.orderBy("contactMechPurposeTypeId");
+            }
+            if (fromDateFieldPresent) {
+                contactMechQuery.filterByDate(date);
+            }
+            allEntityContactMechs = contactMechQuery.cache().queryList();
         } catch (GenericEntityException e) {
             Debug.logWarning(e, module);
         }
@@ -245,8 +259,10 @@ public class ContactMechWorker {
             entityContactMechValueMaps.add(entityContactMechValueMap);
             entityContactMechValueMap.put("contactMech", delegator.makeValidValue("ContactMech", fields));
             entityContactMechValueMap.put(downCaseEntityName + "ContactMech", delegator.makeValidValue(entityName + "ContactMech", fields));
-            entityContactMechValueMap.put("contactMechType", delegator.makeValidValue("ContactMechType",fields));
-            entityContactMechValueMap.put("contactMechPurposeType", delegator.makeValidValue("ContactMechPurposeType", fields));
+            entityContactMechValueMap.put("contactMechType", delegator.makeValidValue("ContactMechType", fields));
+            if (contactMechPurposeTypeIdFieldPresent) {
+                entityContactMechValueMap.put("contactMechPurposeType", delegator.makeValidValue("ContactMechPurposeType", fields));
+            }
             insertRelatedContactElement(delegator, UtilGenerics.checkMap(entityContactMechValueMap), fields);
         }
 

Modified: ofbiz/ofbiz-framework/trunk/applications/party/testdef/data/PartyContactMechTestData.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/testdef/data/PartyContactMechTestData.xml?rev=1840296&r1=1840295&r2=1840296&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/party/testdef/data/PartyContactMechTestData.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/party/testdef/data/PartyContactMechTestData.xml Fri Sep  7 13:11:01 2018
@@ -32,4 +32,11 @@ under the License.
     <ContactMech contactMechId="9127" contactMechTypeId="FTP_ADDRESS"/>
     <FtpAddress contactMechId="9127" hostname="ftp://apacheofbiz.foo.com" port="" username="ofbiz" password="apache" binaryTransfer="Y" passiveMode="Y" path="public"/>
     <PartyContactMech partyId="DemoCustomer" contactMechId="9127" fromDate="2001-05-13 00:00:00.000" allowSolicitation="Y"/>
+
+    <!--Data use by ContactMechWorkerTests.testWorkEffortContactMechResolution-->
+    <WorkEffort workEffortId="TEST_CM_WORKER" />
+    <WorkEffortContactMech workEffortId="TEST_CM_WORKER" contactMechId="9015" fromDate="2001-05-13 00:00:00.000"/>
+    <WorkEffortContactMech workEffortId="TEST_CM_WORKER" contactMechId="9127" fromDate="2001-05-13 00:00:00.000" thruDate="2001-05-14 00:00:00.000"/>
+    <WorkEffortContactMech workEffortId="TEST_CM_WORKER" contactMechId="9126" fromDate="2001-05-13 00:00:00.000"/>
+    <WorkEffortContactMech workEffortId="TEST_CM_WORKER" contactMechId="9125" fromDate="2001-05-13 00:00:00.000"/>
 </entity-engine-xml>

Modified: ofbiz/ofbiz-framework/trunk/applications/workeffort/entitydef/entitymodel_view.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/entitydef/entitymodel_view.xml?rev=1840296&r1=1840295&r2=1840296&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/workeffort/entitydef/entitymodel_view.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/workeffort/entitydef/entitymodel_view.xml Fri Sep  7 13:11:01 2018
@@ -942,7 +942,7 @@ under the License.
     </view-entity>
     <view-entity entity-name="WorkEffortAndContactMech"
                                    package-name="org.apache.ofbiz.workeffort.workeffort"
-                 title="Order Contact Detail View">
+                 title="WorkEffort Contact Detail View">
         <member-entity entity-alias="WCM" entity-name="WorkEffortContactMech"/>
         <member-entity entity-alias="CMD" entity-name="ContactMechDetail"/>
         <alias-all entity-alias="WCM"/>
@@ -957,8 +957,8 @@ under the License.
         <relation type="one-nofk" rel-entity-name="ContactMech">
             <key-map field-name="contactMechId"/>
         </relation>
-        <relation type="one-nofk" rel-entity-name="ContactMechPurposeType">
-            <key-map field-name="contactMechPurposeTypeId"/>
+        <relation type="one-nofk" rel-entity-name="ContactMechType">
+            <key-map field-name="contactMechTypeId"/>
         </relation>
         <relation type="one-nofk" rel-entity-name="PostalAddress">
             <key-map field-name="contactMechId"/>