svn commit: r1780800 - in /ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt: BirtWorker.java flexible/BirtMasterReportServices.java flexible/BirtServices.java flexible/BirtUtil.java

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

svn commit: r1780800 - in /ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt: BirtWorker.java flexible/BirtMasterReportServices.java flexible/BirtServices.java flexible/BirtUtil.java

nmalin
Author: nmalin
Date: Sun Jan 29 14:27:27 2017
New Revision: 1780800

URL: http://svn.apache.org/viewvc?rev=1780800&view=rev
Log:
Fixed: Convert delegator.find to EntityQuery (OFBIZ-9189)
The code came from a project under ofbiz 13.07 and is still using deprecated delegator.find calls, so I converted them to EntityQuery

Modified:
    ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/BirtWorker.java
    ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtMasterReportServices.java
    ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtServices.java
    ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtUtil.java

Modified: ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/BirtWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/BirtWorker.java?rev=1780800&r1=1780799&r2=1780800&view=diff
==============================================================================
--- ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/BirtWorker.java (original)
+++ ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/BirtWorker.java Sun Jan 29 14:27:27 2017
@@ -43,6 +43,7 @@ import org.apache.ofbiz.birt.flexible.Bi
 import org.apache.ofbiz.entity.Delegator;
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.condition.EntityCondition;
+import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.service.GenericServiceException;
 import org.apache.ofbiz.service.LocalDispatcher;
 import org.apache.ofbiz.service.ServiceUtil;
@@ -240,7 +241,7 @@ public final class BirtWorker {
             EntityCondition entityConditionOnName = EntityCondition.makeCondition("drObjectInfo", templateFileLocation);
             ecl = EntityCondition.makeCondition(UtilMisc.toList(entityConditionRpt, entityConditionOnName));
             i++;
-        } while (delegator.findCountByCondition("ContentDataResourceView", ecl, null, null) > 0);
+        } while (EntityQuery.use(delegator).from("ContentDataResourceView").where(ecl).queryCount() > 0);
 
         //resolve the initial form structure from master content
         Map<String, Object> resultElectronicText = dispatcher.runSync("getElectronicText", UtilMisc.toMap("contentId", masterContentId, "locale", locale, "userLogin", userLogin));

Modified: ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtMasterReportServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtMasterReportServices.java?rev=1780800&r1=1780799&r2=1780800&view=diff
==============================================================================
--- ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtMasterReportServices.java (original)
+++ ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtMasterReportServices.java Sun Jan 29 14:27:27 2017
@@ -19,6 +19,7 @@ import org.apache.ofbiz.entity.GenericVa
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.condition.EntityExpr;
 import org.apache.ofbiz.entity.condition.EntityOperator;
+import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.entity.util.EntityUtil;
 import org.apache.ofbiz.party.party.PartyHelper;
 import org.apache.ofbiz.service.DispatchContext;
@@ -75,7 +76,7 @@ public class BirtMasterReportServices {
                 listConditions.add(conditionLastName);
             }
             EntityCondition ecl = EntityCondition.makeCondition(listConditions, EntityOperator.AND);
-            listPersons = delegator.findList("Person", ecl, UtilMisc.toSet("partyId", "firstName", "lastName"), null, null, true);
+            listPersons = EntityQuery.use(delegator).from("Person").where(ecl).select("partyId", "firstName", "lastName").queryList();
             GenericValue person = null;
             if (listPersons.size() > 1) {
                 return ServiceUtil.returnError("Your criteria match with several people");
@@ -106,7 +107,7 @@ public class BirtMasterReportServices {
             EntityExpr conditionParty = EntityCondition.makeCondition("partyId", partyId);
             listConditionsWorkEffort.add(conditionParty);
             ecl = EntityCondition.makeCondition(listConditionsWorkEffort, EntityOperator.AND);
-            listWorkEffortTime = delegator.findList("WorkEffortAndTimeEntry", ecl, UtilMisc.toSet("hours", "fromDate", "thruDate"), null, null, true);
+            listWorkEffortTime = EntityQuery.use(delegator).from("WorkEffortAndTimeEntry").where(ecl).select("hours", "fromDate", "thruDate").queryList();
         } catch (GenericEntityException e) {
             e.printStackTrace();
             ServiceUtil.returnError("Error getting party from person name.");
@@ -184,7 +185,9 @@ public class BirtMasterReportServices {
                 EntityExpr conditionBeforeDate = EntityCondition.makeCondition("thruDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp());
                 EntityExpr conditionNull = EntityCondition.makeCondition("thruDate", null);
                 EntityCondition conditionThroughDate = EntityCondition.makeCondition(EntityOperator.OR, UtilMisc.toList(conditionBeforeDate, conditionNull));
-                List<GenericValue> listProductIds = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(UtilMisc.toList(conditionProductCategory, conditionFromDate, conditionThroughDate)), UtilMisc.toSet("productId"), null, null, true);
+                List<GenericValue> listProductIds = EntityQuery.use(delegator).from("ProductCategoryMember")
+                    .where(EntityCondition.makeCondition(UtilMisc.toList(conditionProductCategory, conditionFromDate, conditionThroughDate)))
+                    .select("productId").queryList();
                 List<String> listProductIdsString = EntityUtil.getFieldListFromEntityList(listProductIds, "productId", true);
 
                 EntityExpr conditionProductCat = EntityCondition.makeCondition("productId", EntityOperator.IN, listProductIdsString);
@@ -202,10 +205,10 @@ public class BirtMasterReportServices {
                 }
                 // getting list of invoice Ids linked to these productStore
                 EntityExpr conditionProductStoreId = EntityCondition.makeCondition("productStoreId", EntityOperator.IN, productStoreList);
-                List<GenericValue> listOrderAndProductStores = delegator.findList("OrderAndProductStore", conditionProductStoreId, UtilMisc.toSet("orderId"), null, null, true);
+                List<GenericValue> listOrderAndProductStores = EntityQuery.use(delegator).from("OrderAndProductStore").where(conditionProductStoreId).select("orderId").queryList();
                 List<String> listOrderIds = EntityUtil.getFieldListFromEntityList(listOrderAndProductStores, "orderId", true);
                 EntityExpr conditionOrderId = EntityCondition.makeCondition("orderId", EntityOperator.IN, listOrderIds);
-                List<GenericValue> listInvoices = delegator.findList("OrderItemBilling", conditionOrderId, UtilMisc.toSet("invoiceId"), null, null, false);
+                List<GenericValue> listInvoices = EntityQuery.use(delegator).from("OrderItemBilling").where(conditionOrderId).select("invoiceId").queryList();
                 List<String> listInvoiceString = EntityUtil.getFieldListFromEntityList(listInvoices, "invoiceId", true);
 
                 EntityExpr conditionInvoiceIdProductStore = EntityCondition.makeCondition("invoiceId", EntityOperator.IN, listInvoiceString);
@@ -252,7 +255,7 @@ public class BirtMasterReportServices {
             fieldsToSelect.add("productId");
             fieldsToSelect.add("partyId");
             fieldsToSelect.add("primaryProductCategoryId");
-            listTurnOver = delegator.findList("InvoiceItemProductAndParty", EntityCondition.makeCondition(listAllConditions), fieldsToSelect, null, null, true);
+            listTurnOver = EntityQuery.use(delegator).from("InvoiceItemProductAndParty").where(EntityCondition.makeCondition(listAllConditions)).select(fieldsToSelect).queryList();
 
             // adding missing fields
             for (GenericValue invoice : listTurnOver) {
@@ -266,12 +269,10 @@ public class BirtMasterReportServices {
                 EntityExpr conditionInvoiceId = EntityCondition.makeCondition("invoiceId", invoice.getString("invoiceId"));
 //                EntityExpr conditionInvoiceItemSeqId = EntityCondition.makeCondition("invoiceItemSeqId", invoice.getString("invoiceItemSeqId"));
 //                List<GenericValue> listOrderBilling = delegator.findList("OrderItemBilling", EntityCondition.makeCondition(UtilMisc.toList(conditionInvoiceId, conditionInvoiceItemSeqId)), UtilMisc.toSet("orderId"), null, null, false);
-                List<GenericValue> listOrderBilling = delegator.findList("OrderItemBilling", conditionInvoiceId, UtilMisc.toSet("orderId"), null, null, false);
-                if (UtilValidate.isNotEmpty(listOrderBilling)) {
-                    GenericValue orderBilling = EntityUtil.getFirst(listOrderBilling);
+                GenericValue orderBilling = EntityQuery.use(delegator).from("OrderItemBilling").where(conditionInvoiceId).select("orderId").queryFirst();
+                if (orderBilling != null) {
                     EntityExpr conditionOrderId = EntityCondition.makeCondition("orderId", orderBilling.getString("orderId"));
-                    List<GenericValue> listProductStore = delegator.findList("OrderAndProductStore", conditionOrderId, null, null, null, true);
-                    GenericValue productStore = EntityUtil.getFirst(listProductStore);
+                    GenericValue productStore = EntityQuery.use(delegator).from("OrderAndProductStore").where(conditionOrderId).cache().queryFirst();
                     if (UtilValidate.isNotEmpty(productStoreList) && ! productStoreList.contains(productStore.getString("productStoreId"))) {
                         continue; // pretty ugly... but had problems with the rare case where an invoice matches with several orders with more than one productStore
                     }

Modified: ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtServices.java?rev=1780800&r1=1780799&r2=1780800&view=diff
==============================================================================
--- ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtServices.java (original)
+++ ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtServices.java Sun Jan 29 14:27:27 2017
@@ -34,6 +34,7 @@ import java.util.Locale;
 import java.util.Map;
 
 import javax.xml.parsers.ParserConfigurationException;
+import org.apache.ofbiz.entity.util.EntityQuery;
 import org.xml.sax.SAXException;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
@@ -221,7 +222,7 @@ public class BirtServices {
         GenericValue masterContentAttribute = null;
         try {
             EntityCondition entityCondition = EntityCondition.makeCondition("contentId", masterContentId);
-            masterContentAttribute = EntityUtil.getFirst(delegator.findList("ContentAttribute", entityCondition, null, null, null, false));
+            masterContentAttribute = EntityQuery.use(delegator).from("ContentAttribute").where(entityCondition).queryFirst();
         } catch (GenericEntityException e) {
             e.printStackTrace();
             return ServiceUtil.returnError(e.getMessage());
@@ -302,7 +303,7 @@ public class BirtServices {
         }
 
         try {
-            GenericValue content = delegator.findOne("Content", true, UtilMisc.toMap("contentId", reportContentId));
+            GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", reportContentId).queryOne();
             String dataResourceId = content.getString("dataResourceId");
             StringBuffer newForm = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <forms xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://ofbiz.apache.org/dtds/widget-form.xsd\">");
             newForm.append(overrideFilters);
@@ -351,10 +352,10 @@ public class BirtServices {
             contentId = BirtWorker.recordReportContent(delegator, dispatcher, context);
             // callPerformFindFromBirt is the customMethod for Entity workflow
             String rptDesignFileName = BirtUtil.resolveRptDesignFilePathFromContent(delegator, contentId);
-            GenericValue content = delegator.findOne("Content", true, "contentId", contentId);
+            GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
             String customMethodId = content.getString("customMethodId");
             if (UtilValidate.isEmpty(customMethodId)) customMethodId = "CM_FB_PERFORM_FIND";
-            GenericValue customMethod = delegator.findOne("CustomMethod", true, "customMethodId", customMethodId);
+            GenericValue customMethod = EntityQuery.use(delegator).from("CustomMethod").where("customMethodId", customMethodId).cache().queryOne();
             if (customMethod == null) {
                 return ServiceUtil.returnError("CustomMethod not exist : " + customMethodId); //todo labelise
             }
@@ -394,12 +395,12 @@ public class BirtServices {
         Map<String, Object> result = ServiceUtil.returnSuccess();
 
         try {
-            GenericValue masterContent = delegator.findOne("Content", true, "contentId", masterContentId);
+            GenericValue masterContent = EntityQuery.use(delegator).from("Content").where("contentId", masterContentId).cache().queryOne();
             String customMethodId = masterContent.getString("customMethodId");
             if (UtilValidate.isEmpty(customMethodId)) {
                 throw new GeneralException("The master content " + masterContentId + " haven't a customMethod");
             }
-            GenericValue customMethod = delegator.findOne("CustomMethod", true, "customMethodId", customMethodId);
+            GenericValue customMethod = EntityQuery.use(delegator).from("CustomMethod").where("customMethodId", customMethodId).cache().queryOne();
             if (customMethod == null) {
                 return ServiceUtil.returnError("CustomMethod not exist : " + customMethodId); //todo labelise
             }
@@ -518,9 +519,9 @@ public class BirtServices {
 
         String textData = null;
         try {
-            GenericValue content = delegator.findOne("Content", true, "contentId", reportContentId);
+            GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", reportContentId).cache().queryOne();
             String dataResourceId = content.getString("dataResourceId");
-            GenericValue electronicText = delegator.findOne("ElectronicText", true, "dataResourceId", dataResourceId);
+            GenericValue electronicText = EntityQuery.use(delegator).from("ElectronicText").where("dataResourceId", dataResourceId).cache().queryOne();
             textData = electronicText.getString("textData");
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError(e.getMessage());
@@ -551,7 +552,7 @@ public class BirtServices {
         List<GenericValue> listContent = null;
         EntityCondition entityConditionContent = EntityCondition.makeCondition("contentTypeId", "FLEXIBLE_REPORT");
         try {
-            listContent = delegator.findList("Content", entityConditionContent, UtilMisc.toSet("contentId"), null, null, false);
+            listContent = EntityQuery.use(delegator).from("Content").where(entityConditionContent).select("contentId").queryList();
         } catch (GenericEntityException e) {
             e.printStackTrace();
             return ServiceUtil.returnError(e.getMessage());
@@ -587,11 +588,11 @@ public class BirtServices {
         List<GenericValue> listRptDesignFileGV = null;
         String contentIdRpt;
         try {
-            listContentRpt = delegator.findList("ContentAssoc", EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, contentId), UtilMisc.toSet("contentIdTo"), null, null, false);
+            listContentRpt = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId).select("contentIdTo").queryList();
             contentIdRpt = listContentRpt.get(0).getString("contentIdTo");
             List<EntityExpr> listConditions = UtilMisc.toList(EntityCondition.makeCondition("contentTypeId", EntityOperator.EQUALS, "RPTDESIGN"), EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, contentIdRpt));
             EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(listConditions, EntityOperator.AND);
-            listRptDesignFileGV = delegator.findList("ContentDataResourceView", ecl, UtilMisc.toSet("drObjectInfo"), null, null, false);
+            listRptDesignFileGV = EntityQuery.use(delegator).from("ContentDataResourceView").where(ecl).select("drObjectInfo").queryList();
         } catch (GenericEntityException e1) {
             e1.printStackTrace();
             return ServiceUtil.returnError(e1.getMessage());
@@ -656,7 +657,7 @@ public class BirtServices {
 
         GenericValue dataResource = null;
         try {
-            dataResource = delegator.findOne("DataResource", false, "dataResourceId", dataResourceId);
+            dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne();
         } catch (GenericEntityException e1) {
             e1.printStackTrace();
             return ServiceUtil.returnError(e1.getMessage());

Modified: ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtUtil.java?rev=1780800&r1=1780799&r2=1780800&view=diff
==============================================================================
--- ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtUtil.java (original)
+++ ofbiz/trunk/plugins/birt/src/main/java/org/apache/ofbiz/birt/flexible/BirtUtil.java Sun Jan 29 14:27:27 2017
@@ -43,6 +43,7 @@ import org.apache.ofbiz.entity.GenericVa
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.condition.EntityConditionList;
 import org.apache.ofbiz.entity.condition.EntityExpr;
+import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.entity.util.EntityUtil;
 import org.apache.ofbiz.security.Security;
 import org.apache.ofbiz.service.GenericServiceException;
@@ -234,16 +235,16 @@ public final class BirtUtil {
      * @throws GenericEntityException
      */
     public static String resolveRptDesignFilePathFromContent(Delegator delegator, String contentId) throws GenericEntityException {
-        List<GenericValue> listContentRpt = delegator.findList("ContentAssoc", EntityCondition.makeCondition("contentId", contentId), UtilMisc.toSet("contentIdTo"), null, null, true);
-        if (UtilValidate.isNotEmpty(listContentRpt)) {
-            String contentIdRpt = EntityUtil.getFirst(listContentRpt).getString("contentIdTo");
+        GenericValue contentRpt = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId).select("contentIdTo").cache().queryFirst();
+        if (contentRpt != null) {
+            String contentIdRpt = contentRpt.getString("contentIdTo");
             List<EntityExpr> listConditions = UtilMisc.toList(
                     EntityCondition.makeCondition("contentTypeId", "RPTDESIGN"),
                     EntityCondition.makeCondition("contentId", contentIdRpt));
             EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(listConditions);
-            List<GenericValue> listDataRessouceRptDesignFile = delegator.findList("ContentDataResourceView", ecl, UtilMisc.toSet("drObjectInfo"), null, null, true);
-            if (UtilValidate.isNotEmpty(listDataRessouceRptDesignFile)) {
-                return EntityUtil.getFirst(listDataRessouceRptDesignFile).getString("drObjectInfo");
+            GenericValue dataRessouceRptDesignFile = EntityQuery.use(delegator).from("ContentDataResourceView").where(ecl).select("drObjectInfo").cache().queryFirst();
+            if (dataRessouceRptDesignFile != null) {
+                return dataRessouceRptDesignFile.getString("drObjectInfo");
             }
         }
         return "";