Author: lektran
Date: Thu Oct 30 04:16:39 2014
New Revision: 1635381
URL: http://svn.apache.org/r1635381
Log:
Convert marketing component's java files to EntityQuery
Modified:
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java
ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
Modified:
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java?rev=1635381&r1=1635380&r2=1635381&view=diff
==============================================================================
---
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
(original)
+++
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
Thu Oct 30 04:16:39 2014
@@ -19,7 +19,6 @@
package org.ofbiz.marketing.marketing;
import java.sql.Timestamp;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -31,9 +30,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
@@ -67,33 +64,32 @@ public class MarketingServices {
try {
// locate the contact list
- Map<String, Object> input = UtilMisc.<String,
Object>toMap("contactListId", contactListId);
- GenericValue contactList = delegator.findOne("ContactList", input,
false);
+ GenericValue contactList =
EntityQuery.use(delegator).from("ContactList").where("contactListId",
contactListId).queryOne();
if (contactList == null) {
- String error = UtilProperties.getMessage(resourceMarketing,
"MarketingContactListNotFound", input, locale);
+ String error = UtilProperties.getMessage(resourceMarketing,
"MarketingContactListNotFound", UtilMisc.<String, Object>toMap("contactListId",
contactListId), locale);
return ServiceUtil.returnError(error);
}
// perform actions as the system user
- GenericValue userLogin = delegator.findOne("UserLogin",
UtilMisc.toMap("userLoginId", "system"), true);
+ GenericValue userLogin =
EntityQuery.use(delegator).from("UserLogin").where("userLoginId",
"system").cache().queryOne();
// associate the email with anonymous user TODO: do we need a
custom contact mech purpose type, say MARKETING_EMAIL?
if (partyId == null) {
// Check existing email
- List<EntityCondition> conds =
UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("infoString",
EntityOperator.EQUALS, email));
- conds.add(EntityCondition.makeCondition("contactMechTypeId",
EntityOperator.EQUALS, "EMAIL_ADDRESS"));
-
conds.add(EntityCondition.makeCondition("contactMechPurposeTypeId",
EntityOperator.EQUALS, "PRIMARY_EMAIL"));
- conds.add(EntityUtil.getFilterByDateExpr("purposeFromDate",
"purposeThruDate"));
- conds.add(EntityUtil.getFilterByDateExpr());
- List<GenericValue> contacts =
delegator.findList("PartyContactDetailByPurpose",
EntityCondition.makeCondition(conds), null, UtilMisc.toList("-fromDate"), null,
false);
- if (UtilValidate.isNotEmpty(contacts)) {
- GenericValue contact = EntityUtil.getFirst(contacts);
+ GenericValue contact =
EntityQuery.use(delegator).from("PartyContactDetailByPurpose")
+ .where("infoString", email,
+ "contactMechTypeId", "EMAIL_ADDRESS",
+ "contactMechPurposeTypeId", "PRIMARY_EMAIL")
+ .orderBy("-fromDate")
+ .filterByDate("fromDate", "thruDate",
"purposeFromDate", "purposeThruDate")
+ .queryFirst();
+ if (contact != null) {
partyId = contact.getString("partyId");
} else {
partyId = "_NA_";
}
}
- input = UtilMisc.toMap("userLogin", userLogin, "emailAddress",
email, "partyId", partyId, "fromDate", fromDate, "contactMechPurposeTypeId",
"OTHER_EMAIL");
+ Map<String, Object> input = UtilMisc.toMap("userLogin", userLogin,
"emailAddress", email, "partyId", partyId, "fromDate", fromDate,
"contactMechPurposeTypeId", "OTHER_EMAIL");
Map<String, Object> serviceResults =
dispatcher.runSync("createPartyEmailAddress", input);
if (ServiceUtil.isError(serviceResults)) {
throw new
GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));
Modified:
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java?rev=1635381&r1=1635380&r2=1635381&view=diff
==============================================================================
---
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java
(original)
+++
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java
Thu Oct 30 04:16:39 2014
@@ -38,6 +38,7 @@ import org.ofbiz.webapp.website.WebSiteW
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.entity.util.EntityUtilProperties;
import org.ofbiz.product.category.CategoryWorker;
@@ -61,7 +62,7 @@ public class TrackingCodeEvents {
Delegator delegator = (Delegator)
request.getAttribute("delegator");
GenericValue trackingCode;
try {
- trackingCode = delegator.findOne("TrackingCode",
UtilMisc.toMap("trackingCodeId", trackingCodeId), true);
+ trackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up TrackingCode with
trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module);
return "error";
@@ -98,7 +99,7 @@ public class TrackingCodeEvents {
Delegator delegator = (Delegator)
request.getAttribute("delegator");
GenericValue trackingCode;
try {
- trackingCode = delegator.findOne("TrackingCode",
UtilMisc.toMap("trackingCodeId", trackingCodeId), true);
+ trackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up TrackingCode with
trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module);
return "error";
@@ -114,7 +115,7 @@ public class TrackingCodeEvents {
if (UtilValidate.isNotEmpty(dtc)) {
GenericValue defaultTrackingCode = null;
try {
- defaultTrackingCode =
delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", dtc), true);
+ defaultTrackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
dtc).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up Default values
TrackingCode with trackingCodeId [" + dtc + "], not using the dtc value for new
TrackingCode defaults", module);
}
@@ -209,7 +210,7 @@ public class TrackingCodeEvents {
String webSiteId = WebSiteWorker.getWebSiteId(request);
if (webSiteId != null) {
try {
- GenericValue webSite = delegator.findOne("WebSite",
UtilMisc.toMap("webSiteId", webSiteId), true);
+ GenericValue webSite =
EntityQuery.use(delegator).from("WebSite").where("webSiteId",
webSiteId).cache().queryOne();
if (webSite != null) {
cookieDomain = webSite.getString("cookieDomain");
}
@@ -320,7 +321,7 @@ public class TrackingCodeEvents {
String trackingCodeId = cookies[i].getValue();
GenericValue trackingCode;
try {
- trackingCode = delegator.findOne("TrackingCode",
UtilMisc.toMap("trackingCodeId", trackingCodeId), true);
+ trackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up TrackingCode
with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId",
module);
continue;
@@ -382,7 +383,7 @@ public class TrackingCodeEvents {
// find the tracking code object
GenericValue trackingCode = null;
try {
- trackingCode = delegator.findOne("TrackingCode",
UtilMisc.toMap("trackingCodeId", trackingCodeId), true);
+ trackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up TrackingCode with
trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module);
}
@@ -480,7 +481,7 @@ public class TrackingCodeEvents {
}
GenericValue trackingCode = null;
try {
- trackingCode = delegator.findOne("TrackingCode",
UtilMisc.toMap("trackingCodeId", trackingCodeId), true);
+ trackingCode =
EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up TrackingCode with
trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module);
}
Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java?rev=1635381&r1=1635380&r2=1635381&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
(original)
+++ ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Thu
Oct 30 04:16:39 2014
@@ -27,12 +27,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import javolution.util.FastMap;
-
import net.wimpi.pim.Pim;
import net.wimpi.pim.contact.basicimpl.AddressImpl;
import net.wimpi.pim.contact.basicimpl.EmailAddressImpl;
@@ -61,7 +59,7 @@ import org.ofbiz.entity.GenericEntityExc
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.party.party.PartyHelper;
import org.ofbiz.party.party.PartyWorker;
import org.ofbiz.service.DispatchContext;
@@ -116,23 +114,19 @@ public class VCard {
serviceCtx.put("city", workAddress.getCity());
serviceCtx.put("postalCode", workAddress.getPostalCode());
- List<GenericValue> countryGeoList = null;
- List<GenericValue> stateGeoList = null;
- EntityCondition cond =
EntityCondition.makeCondition(UtilMisc.toList(
-
EntityCondition.makeCondition("geoTypeId", EntityOperator.EQUALS, "COUNTRY"),
-
EntityCondition.makeCondition("geoName", EntityOperator.LIKE,
workAddress.getCountry())), EntityOperator.AND);
- countryGeoList = delegator.findList("Geo", cond, null,
null, null, true);
- if (!countryGeoList.isEmpty()) {
- GenericValue countryGeo =
EntityUtil.getFirst(countryGeoList);
+ GenericValue countryGeo =
EntityQuery.use(delegator).from("Geo")
+ .where(EntityCondition.makeCondition("geoTypeId",
EntityOperator.EQUALS, "COUNTRY"),
+ EntityCondition.makeCondition("geoName",
EntityOperator.LIKE, workAddress.getCountry()))
+ .cache().queryFirst();
+ if (countryGeo != null) {
serviceCtx.put("countryGeoId",
countryGeo.get("geoId"));
}
- EntityCondition condition =
EntityCondition.makeCondition(UtilMisc.toList(
- EntityCondition.makeCondition("geoTypeId",
EntityOperator.EQUALS, "STATE"),
- EntityCondition.makeCondition("geoName",
EntityOperator.LIKE, workAddress.getRegion())), EntityOperator.AND);
- stateGeoList = delegator.findList("Geo", condition, null,
null, null, true);
- if (!stateGeoList.isEmpty()) {
- GenericValue stateGeo =
EntityUtil.getFirst(stateGeoList);
+ GenericValue stateGeo =
EntityQuery.use(delegator).from("Geo")
+ .where(EntityCondition.makeCondition("geoTypeId",
EntityOperator.EQUALS, "STATE"),
+ EntityCondition.makeCondition("geoName",
EntityOperator.LIKE, workAddress.getRegion()))
+ .cache().queryFirst();
+ if (stateGeo != null) {
serviceCtx.put("stateProvinceGeoId",
stateGeo.get("geoId"));
}
}