Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java Fri Oct 24 08:22:56 2014 @@ -36,6 +36,7 @@ import org.ofbiz.content.data.DataResour import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; /** * Does indexing in preparation for a keyword search. @@ -77,22 +78,22 @@ public class ContentKeywordIndex { addWeightedKeywordSourceString(content, "description", strings); // ContentAttribute - List<GenericValue> contentAttributes = delegator.findByAnd("ContentAttribute", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> contentAttributes = EntityQuery.use(delegator).from("ContentAttribute").where("contentId", contentId).queryList(); for (GenericValue contentAttribute: contentAttributes) { addWeightedKeywordSourceString(contentAttribute, "attrName", strings); addWeightedKeywordSourceString(contentAttribute, "attrValue", strings); } // ContentMetaData - List<GenericValue> contentMetaDatas = delegator.findByAnd("ContentMetaData", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> contentMetaDatas = EntityQuery.use(delegator).from("ContentMetaData").where("contentId", contentId).queryList(); for (GenericValue contentMetaData: contentMetaDatas) { addWeightedKeywordSourceString(contentMetaData, "metaDataValue", strings); } // ContentRole - List<GenericValue> contentRoles = delegator.findByAnd("ContentRole", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> contentRoles = EntityQuery.use(delegator).from("ContentRole").where("contentId", contentId).queryList(); for (GenericValue contentRole: contentRoles) { - GenericValue party = delegator.findOne("PartyNameView", UtilMisc.toMap("partyId", contentRole.getString("partyId")), false); + GenericValue party = EntityQuery.use(delegator).from("PartyNameView").where("partyId", contentRole.get("partyId")).queryOne(); if (party != null) { addWeightedKeywordSourceString(party, "description", strings); addWeightedKeywordSourceString(party, "firstName", strings); @@ -103,9 +104,9 @@ public class ContentKeywordIndex { } // DataResourceRole - List<GenericValue> dataResourceRoles = delegator.findByAnd("DataResourceRole", UtilMisc.toMap("dataResourceId", content.getString("dataResourceId")), null, false); + List<GenericValue> dataResourceRoles = EntityQuery.use(delegator).from("DataResourceRole").where("dataResourceId", content.get("dataResourceId")).queryList(); for (GenericValue dataResourceRole: dataResourceRoles) { - GenericValue party = delegator.findOne("PartyNameView", UtilMisc.toMap("partyId", dataResourceRole.getString("partyId")), false); + GenericValue party = EntityQuery.use(delegator).from("PartyNameView").where("partyId", dataResourceRole.get("partyId")).queryOne(); if (party != null) { addWeightedKeywordSourceString(party, "description", strings); addWeightedKeywordSourceString(party, "firstName", strings); @@ -116,9 +117,9 @@ public class ContentKeywordIndex { } // Product - List<GenericValue> productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> productContentList = EntityQuery.use(delegator).from("ProductContent").where("contentId", contentId).queryList(); for (GenericValue productContent: productContentList) { - GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productContent.getString("productId")), false); + GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productContent.get("productId")).queryOne(); if (product != null) { addWeightedKeywordSourceString(product, "productName", strings); addWeightedKeywordSourceString(product, "internalName", strings); @@ -129,9 +130,9 @@ public class ContentKeywordIndex { } // ProductCategory - List<GenericValue> productCategoryContentList = delegator.findByAnd("ProductCategoryContent", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> productCategoryContentList = EntityQuery.use(delegator).from("ProductCategoryContent").where("contentId", contentId).queryList(); for (GenericValue productCategoryContent: productCategoryContentList) { - GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryContent.getString("productCategoryId")), false); + GenericValue productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", productCategoryContent.getString("productCategoryId")).queryOne(); if (productCategory != null) { addWeightedKeywordSourceString(productCategory, "categoryName", strings); addWeightedKeywordSourceString(productCategory, "description", strings); @@ -140,9 +141,9 @@ public class ContentKeywordIndex { } // PartyContent - List<GenericValue> partyContents = delegator.findByAnd("PartyContent", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> partyContents = EntityQuery.use(delegator).from("PartyContent").where("contentId", contentId).queryList(); for (GenericValue partyContent: partyContents) { - GenericValue party = delegator.findOne("PartyNameView", UtilMisc.toMap("partyId", partyContent.getString("partyId")), false); + GenericValue party = EntityQuery.use(delegator).from("PartyNameView").where("partyId", partyContent.get("partyId")).queryOne(); if (party != null) { addWeightedKeywordSourceString(party, "description", strings); addWeightedKeywordSourceString(party, "firstName", strings); @@ -153,9 +154,9 @@ public class ContentKeywordIndex { } // WebSiteContent - List<GenericValue> webSiteContents = delegator.findByAnd("WebSiteContent", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> webSiteContents = EntityQuery.use(delegator).from("WebSiteContent").where("contentId", contentId).queryList(); for (GenericValue webSiteContent: webSiteContents) { - GenericValue webSite = delegator.findOne("WebSite", UtilMisc.toMap("webSiteId", webSiteContent.getString("webSiteId")), false); + GenericValue webSite = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteContent.get("webSiteId")).queryOne(); if (webSite != null) { addWeightedKeywordSourceString(webSite, "siteName", strings); addWeightedKeywordSourceString(webSite, "httpHost", strings); @@ -164,21 +165,21 @@ public class ContentKeywordIndex { } // WorkEffortContent - List<GenericValue> workEffortContents = delegator.findByAnd("WorkEffortContent", UtilMisc.toMap("contentId", contentId), null, false); + List<GenericValue> workEffortContents = EntityQuery.use(delegator).from("WorkEffortContent").where("contentId", contentId).queryList(); for (GenericValue workEffortContent: workEffortContents) { - GenericValue workEffort = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", workEffortContent.getString("workEffortId")), false); + GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortContent.get("workEffortId")).queryOne(); if (workEffort != null) { addWeightedKeywordSourceString(workEffort, "workEffortName", strings); } } // DataResource - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", content.getString("dataResourceId")), false); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", content.get("dataResourceId")).queryOne(); if (dataResource != null) { addWeightedKeywordSourceString(dataResource, "dataResourceName", strings); addWeightedKeywordSourceString(dataResource, "objectInfo", strings); } - /*List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId), null, false); + /*List<GenericValue> contentDataResourceViews = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", contentId).queryList(); for (GenericValue contentDataResourceView: contentDataResourceViews) { int weight = 1; addWeightedDataResourceString(contentDataResourceView, weight, strings, delegator, content);
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java Fri Oct 24 08:22:56 2014 @@ -42,6 +42,7 @@ 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.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.webapp.control.RequestHandler; @@ -112,9 +113,9 @@ public class ContentMapFacade implements this.cache = cache; try { if (cache) { - this.value = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); + this.value = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache().queryOne(); } else { - this.value = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + this.value = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } } catch (GenericEntityException e) { Debug.logError(e, module); @@ -232,11 +233,11 @@ public class ContentMapFacade implements return fields; } try { + EntityQuery contentQuery = EntityQuery.use(delegator).from("Content").where("contentId", contentId); if (cache) { - this.fields = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); - } else { - this.fields = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + contentQuery.cache(); } + this.fields = contentQuery.queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -257,16 +258,12 @@ public class ContentMapFacade implements // Try and find a WebSitePathAlias record to use, it isn't very feasible to find an alias by (parent)contentId/mapKey // so we're only looking for a direct alias using contentId if (webSiteId != null && delegator != null) { - EntityCondition condition = EntityCondition.makeCondition( - UtilMisc.toMap( - "mapKey", null, - "webSiteId", webSiteId, - "contentId", this.contentId - ) - ); try { - List<GenericValue> webSitePathAliases = delegator.findList("WebSitePathAlias", condition, null, null, null, true); - GenericValue webSitePathAlias = EntityUtil.getFirst(webSitePathAliases); + GenericValue webSitePathAlias = EntityQuery.use(delegator).from("WebSitePathAlias") + .where("mapKey", null, + "webSiteId", webSiteId, + "contentId", this.contentId) + .cache().queryFirst(); if (webSitePathAlias != null) { contentUri = webSitePathAlias.getString("pathAlias"); } @@ -297,13 +294,15 @@ public class ContentMapFacade implements expressions.put("statusId", this.statusFilter); } - subs = delegator.findByAnd("ContentAssocViewTo", expressions, UtilMisc.toList(this.sortOrder), cache); + subs = EntityQuery.use(delegator).from("ContentAssocViewTo") + .where(expressions) + .orderBy(this.sortOrder) + .filterByDate() + .cache(cache).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } if (subs != null) { - subs = EntityUtil.filterByDate(subs); - for (GenericValue v: subs) { subContent.add(new ContentMapFacade(dispatcher, delegator, v.getString("contentId"), context, locale, mimeType, cache)); } @@ -429,9 +428,9 @@ public class ContentMapFacade implements GenericValue content = null; try { if (cache) { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", name), true); + content = EntityQuery.use(delegator).from("Content").where("contentId", name).cache().queryOne(); } else { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", name), false); + content = EntityQuery.use(delegator).from("Content").where("contentId", name).queryOne(); } } catch (GenericEntityException e) { Debug.logError(e, module); @@ -459,7 +458,7 @@ public class ContentMapFacade implements } // key is the mapKey - List<GenericValue> subs = null; + GenericValue sub = null; try { Map<String, Object> expressions = FastMap.newInstance(); expressions.put("contentIdStart", contentId); @@ -467,16 +466,16 @@ public class ContentMapFacade implements if(!this.statusFilter.equals("")) { expressions.put("statusId", this.statusFilter); } - subs = delegator.findByAnd("ContentAssocViewTo", expressions, UtilMisc.toList(this.sortOrder), cache); + sub = EntityQuery.use(delegator).from("ContentAssocViewTo") + .where(expressions) + .orderBy(this.sortOrder) + .cache(cache) + .filterByDate().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } - if (subs != null) { - subs = EntityUtil.filterByDate(subs); - GenericValue v = EntityUtil.getFirst(subs); - if (v != null) { - return new ContentMapFacade(dispatcher, delegator, v.getString("contentId"), context, locale, mimeType, cache); - } + if (sub != null) { + return new ContentMapFacade(dispatcher, delegator, sub.getString("contentId"), context, locale, mimeType, cache); } return null; @@ -507,7 +506,9 @@ public class ContentMapFacade implements String name = (String) key; List<GenericValue> metaData = null; try { - metaData = delegator.findByAnd("ContentMetaData", UtilMisc.toMap("contentId", contentId, "metaDataPredicateId", name), null, cache); + metaData = EntityQuery.use(delegator).from("ContentMetaData") + .where("contentId", contentId, "metaDataPredicateId", name) + .cache(cache).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java Fri Oct 24 08:22:56 2014 @@ -34,6 +34,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.util.EntityQuery; import org.ofbiz.entityext.permission.EntityPermissionChecker; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; @@ -121,7 +122,7 @@ public class ContentPermissionServices { String passedUserLoginId = (String)context.get("userLoginId"); if (UtilValidate.isNotEmpty(passedUserLoginId)) { try { - userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", passedUserLoginId), true); + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", passedUserLoginId).cache().queryOne(); if (userLogin != null) { partyId = userLogin.getString("partyId"); } @@ -276,8 +277,8 @@ public class ContentPermissionServices { GenericValue contentTo = null; GenericValue contentFrom = null; try { - contentTo = delegator.findOne("Content", UtilMisc.toMap("contentId", contentIdTo), true); - contentFrom = delegator.findOne("Content", UtilMisc.toMap("contentId", contentIdFrom), true); + contentTo = EntityQuery.use(delegator).from("Content").where("contentId", contentIdTo).cache().queryOne(); + contentFrom = EntityQuery.use(delegator).from("Content").where("contentId", contentIdFrom).cache().queryOne(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentContentToOrFromErrorRetriving", locale)); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentSearch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentSearch.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentSearch.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentSearch.java Fri Oct 24 08:22:56 2014 @@ -39,7 +39,6 @@ import org.ofbiz.common.KeywordSearchUti import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.condition.EntityComparisonOperator; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; @@ -50,8 +49,8 @@ import org.ofbiz.entity.model.ModelViewE import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasField; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; -import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; public class ContentSearch { @@ -79,7 +78,7 @@ public class ContentSearch { // now find all sub-categories, filtered by effective dates, and call this routine for them try { - List<GenericValue> contentAssocList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentIdFrom", contentId), null, true); + List<GenericValue> contentAssocList = EntityQuery.use(delegator).from("ContentAssoc").where("contentIdFrom", contentId).cache().queryList(); for (GenericValue contentAssoc: contentAssocList) { String subContentId = contentAssoc.getString("contentIdTo"); if (contentIdSet.contains(subContentId)) { @@ -94,8 +93,10 @@ public class ContentSearch { } // Find Content where current contentId = contentParentId; only select minimal fields to keep the size low - List<GenericValue> childContentList = delegator.findList("Content", EntityCondition.makeCondition("contentParentId", EntityComparisonOperator.EQUALS, contentId), - UtilMisc.toSet("contentId", "contentParentId"), null, null, true); + List<GenericValue> childContentList = EntityQuery.use(delegator) + .select("contentId", "contentParentId").from("Content") + .where("contentParentId", contentId) + .cache().queryList(); for (GenericValue childContent: childContentList) { String subContentId = childContent.getString("contentId"); if (contentIdSet.contains(subContentId)) { @@ -115,7 +116,7 @@ public class ContentSearch { public int index = 1; public List<EntityCondition> entityConditionList = FastList.newInstance(); public List<String> orderByList = FastList.newInstance(); - public List<String> fieldsToSelect = UtilMisc.toList("contentId"); + public Set<String> fieldsToSelect = UtilMisc.toSet("contentId"); public DynamicViewEntity dynamicViewEntity = new DynamicViewEntity(); public boolean contentIdGroupBy = false; public boolean includedKeywordSearch = false; @@ -286,16 +287,15 @@ public class ContentSearch { // Debug.logInfo("ContentSearch, whereCondition = " + whereCondition.toString(), module); - EntityFindOptions efo = new EntityFindOptions(); - efo.setDistinct(true); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - if (maxResults != null) { - efo.setMaxRows(maxResults); - } - EntityListIterator eli = null; try { - eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, orderByList, efo); + eli = EntityQuery.use(delegator) + .select(fieldsToSelect).from(dynamicViewEntity) + .where(whereCondition) + .cursorScrollInsensitive() + .distinct() + .maxRows(maxResults) + .queryIterator(); } catch (GenericEntityException e) { Debug.logError(e, "Error in content search", module); return null; @@ -555,8 +555,8 @@ public class ContentSearch { GenericValue content = null; GenericValue contentAssocType = null; try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", this.contentId), true); - contentAssocType = delegator.findOne("ContentAssocType", UtilMisc.toMap("contentAssocTypeId", this.contentAssocTypeId), true); + content = EntityQuery.use(delegator).from("Content").where("contentId", this.contentId).cache().queryOne(); + contentAssocType = EntityQuery.use(delegator).from("ContentAssocType").where("contentAssocTypeId", this.contentAssocTypeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up ContentAssocConstraint pretty print info: " + e.toString(), module); } Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java Fri Oct 24 08:22:56 2014 @@ -46,7 +46,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; 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; @@ -186,7 +186,7 @@ public class ContentServices { GenericValue content = null; try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Entity Error:" + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentNoContentFound", UtilMisc.toMap("contentId", contentId), locale)); @@ -277,9 +277,11 @@ public class ContentServices { // get first statusId for content out of the statusItem table if not provided if (UtilValidate.isEmpty(context.get("statusId"))) { try { - List<GenericValue> statusItems = delegator.findByAnd("StatusItem",UtilMisc.toMap("statusTypeId", "CONTENT_STATUS"), UtilMisc.toList("sequenceId"), false); - if (!UtilValidate.isEmpty(statusItems)) { - content.put("statusId", (statusItems.get(0)).getString("statusId")); + GenericValue statusItem = EntityQuery.use(delegator).from("StatusItem") + .where("statusTypeId", "CONTENT_STATUS") + .orderBy("sequenceId").queryFirst(); + if (statusItem != null) { + content.put("statusId", statusItem.get("statusId")); } } catch (GenericEntityException e) { return ServiceUtil.returnError(e.getMessage()); @@ -398,7 +400,7 @@ public class ContentServices { } if (Debug.infoOn()) Debug.logInfo("DEACTIVATING CONTENTASSOC andMap: " + andMap, null); - List assocList = delegator.findByAnd("ContentAssoc", andMap); + List assocList = EntityQuery.use(delegator).from("ContentAssoc").where(andMap).queryList(); Iterator iter = assocList.iterator(); while (iter.hasNext()) { GenericValue val = (GenericValue) iter.next(); @@ -536,7 +538,7 @@ public class ContentServices { Locale locale = (Locale) context.get("locale"); String contentId = (String) context.get("contentId"); try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentNoContentFound", UtilMisc.toMap("contentId", contentId), locale)); @@ -624,7 +626,7 @@ public class ContentServices { GenericValue contentAssoc = null; try { - contentAssoc = delegator.findOne("ContentAssoc", UtilMisc.toMap("contentId", contentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate), false); + contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Entity Error:" + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentAssocRetrievingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); @@ -738,8 +740,8 @@ public class ContentServices { GenericValue contentAssoc = null; try { - //contentAssoc = delegator.findOne("ContentAssoc", UtilMisc.toMap("contentId", contentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate), false); - contentAssoc = delegator.findOne("ContentAssoc", pk, false); + //contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate).queryOne(); + contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where(pk).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Entity Error:" + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentAssocRetrievingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); @@ -808,7 +810,7 @@ public class ContentServices { try { GenericValue activeAssoc = null; if (fromDate != null) { - activeAssoc = delegator.findOne("ContentAssoc", UtilMisc.toMap("contentId", activeContentId, "contentIdTo", contentIdTo, "fromDate", fromDate, "contentAssocTypeId", contentAssocTypeId), false); + activeAssoc = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", activeContentId, "contentIdTo", contentIdTo, "fromDate", fromDate, "contentAssocTypeId", contentAssocTypeId).queryOne(); if (activeAssoc == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentAssocNotFound", UtilMisc.toMap("activeContentId", activeContentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate), locale)); } @@ -833,17 +835,17 @@ public class ContentServices { } EntityConditionList<EntityCondition> assocExprList = EntityCondition.makeCondition(exprList, EntityOperator.AND); - List<GenericValue> relatedAssocs = delegator.findList("ContentAssoc", assocExprList, null, UtilMisc.toList("fromDate"), null, false); + List<GenericValue> relatedAssocs = EntityQuery.use(delegator).from("ContentAssoc") + .where(assocExprList) + .orderBy("fromDate").filterByDate().queryList(); //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, relatedAssocs:" + relatedAssocs, module); - List<GenericValue> filteredAssocs = EntityUtil.filterByDate(relatedAssocs); - //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, filteredAssocs:" + filteredAssocs, module); - for (GenericValue val : filteredAssocs) { + for (GenericValue val : relatedAssocs) { val.set("thruDate", nowTimestamp); val.store(); //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, val:" + val, module); } - results.put("deactivatedList", filteredAssocs); + results.put("deactivatedList", relatedAssocs); } catch (GenericEntityException e) { return ServiceUtil.returnError(e.getMessage()); } @@ -989,7 +991,7 @@ public class ContentServices { isPublished = true; if (Debug.infoOn()) Debug.logInfo("in publishContent, contentId:" + contentId + " contentIdTo:" + contentIdTo + " contentAssocTypeId:" + contentAssocTypeId + " publish:" + publish + " isPublished:" + isPublished, module); if (UtilValidate.isNotEmpty(publish) && publish.equalsIgnoreCase("Y")) { - GenericValue content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); String contentStatusId = (String) content.get("statusId"); String contentPrivilegeEnumId = (String) content.get("privilegeEnumId"); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java Fri Oct 24 08:22:56 2014 @@ -19,6 +19,7 @@ package org.ofbiz.content.content; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -39,6 +40,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMapProcessor; @@ -135,7 +137,7 @@ public class ContentServicesComplex { EntityConditionList<EntityCondition> assocExprList = EntityCondition.makeCondition(exprList, EntityOperator.AND); List<GenericValue> relatedAssocs = null; try { - relatedAssocs = delegator.findList(viewName, assocExprList, null,UtilMisc.toList("caFromDate"), null, false); + relatedAssocs = EntityQuery.use(delegator).from(viewName).where(assocExprList).orderBy("caFromDate").queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(e.getMessage()); } @@ -220,49 +222,31 @@ public class ContentServicesComplex { viewName = "ContentAssocDataResourceViewTo"; } //if (Debug.infoOn()) Debug.logInfo("in getAssocAndContent...Cache, assocTypes:" + assocTypes, module); - Map<String, Object> fieldMap = UtilMisc.<String, Object>toMap(contentFieldName, contentId); - if (assocTypes != null && assocTypes.size() == 1) { - fieldMap.putAll(UtilMisc.<String, Object>toMap("contentAssocTypeId", assocTypes.get(0))); - } + List<EntityCondition> conditionList = new ArrayList<EntityCondition>(); if (UtilValidate.isNotEmpty(mapKey)) { - if (mapKey.equalsIgnoreCase("is null")) - fieldMap.putAll(UtilMisc.<String, Object>toMap("mapKey", null)); - else - fieldMap.putAll(UtilMisc.<String, Object>toMap("mapKey", mapKey)); + String mapKeyValue = "is null".equalsIgnoreCase(mapKey) ? null : mapKey; + conditionList.add(EntityCondition.makeCondition("mapKey", mapKeyValue)); } if (UtilValidate.isNotEmpty(contentAssocPredicateId)) { - if (contentAssocPredicateId.equalsIgnoreCase("is null")) - fieldMap.putAll(UtilMisc.<String, Object>toMap("contentAssocPredicateId", null)); - else - fieldMap.putAll(UtilMisc.<String, Object>toMap("contentAssocPredicateId", contentAssocPredicateId)); + String contentAssocPredicateIdValue = "is null".equalsIgnoreCase(contentAssocPredicateId) ? null : contentAssocPredicateId; + conditionList.add(EntityCondition.makeCondition("mapKey", contentAssocPredicateIdValue)); } - if (nullThruDatesOnly != null && nullThruDatesOnly.booleanValue()) { - fieldMap.putAll(UtilMisc.<String, Object>toMap("thruDate", null)); + if (nullThruDatesOnly != null && nullThruDatesOnly) { + conditionList.add(EntityCondition.makeCondition("thruDate", null)); } - List<GenericValue> contentAssocsUnfiltered = null; - //if (Debug.infoOn()) Debug.logInfo("in getAssocAndContent...Cache, fieldMap:" + fieldMap, module); - contentAssocsUnfiltered = delegator.findByAnd("ContentAssoc", fieldMap, UtilMisc.toList("-fromDate"), true); + if (UtilValidate.isNotEmpty(assocTypes)) { + conditionList.add(EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.IN, assocTypes)); + } - //if (Debug.infoOn()) Debug.logInfo("in getAssocAndContent...Cache, contentAssocsUnfiltered:" + contentAssocsUnfiltered, module); if (fromDate == null && fromDateStr != null) { fromDate = UtilDateTime.toTimestamp(fromDateStr); } - List<GenericValue> contentAssocsDateFiltered2 = EntityUtil.filterByDate(contentAssocsUnfiltered, fromDate); - List<GenericValue> contentAssocsDateFiltered = EntityUtil.orderBy(contentAssocsDateFiltered2, UtilMisc.toList("sequenceNum", "fromDate DESC")); - String contentAssocTypeId = null; - List<GenericValue> contentAssocsTypeFiltered = FastList.newInstance(); - if (assocTypes != null && assocTypes.size() > 1) { - for (GenericValue contentAssoc : contentAssocsDateFiltered) { - contentAssocTypeId = (String)contentAssoc.get("contentAssocTypeId"); - if (assocTypes.contains(contentAssocTypeId)) { - contentAssocsTypeFiltered.add(contentAssoc); - } - } - } else { - contentAssocsTypeFiltered = contentAssocsDateFiltered; - } + List<GenericValue> contentAssocsTypeFiltered = EntityQuery.use(delegator).from("ContentAssoc") + .where(conditionList).orderBy("sequenceNum", "-fromDate") + .filterByDate(fromDate).cache().queryList(); + String assocRelationName = null; if (direction != null && direction.equalsIgnoreCase("To")) { Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java Fri Oct 24 08:22:56 2014 @@ -44,6 +44,7 @@ import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.webapp.control.ContextFilter; import org.owasp.esapi.errors.EncodingException; @@ -72,13 +73,15 @@ public class ContentUrlFilter extends Co String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf("/")); if (alternativeUrl.endsWith("-content")) { try { - List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("drObjectInfo", alternativeUrl), null, false); - if (contentDataResourceViews.size() > 0) { - contentDataResourceViews = EntityUtil.orderBy(contentDataResourceViews, UtilMisc.toList("createdDate DESC")); - GenericValue contentDataResourceView = EntityUtil.getFirst(contentDataResourceViews); - List<GenericValue> contents = EntityUtil.filterByDate(delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentAssocTypeId", "ALTERNATIVE_URL", "contentIdTo", contentDataResourceView.getString("contentId")), null, false)); - if (contents.size() > 0) { - GenericValue content = EntityUtil.getFirst(contents); + GenericValue contentDataResourceView = EntityQuery.use(delegator).from("ContentDataResourceView") + .where("drObjectInfo", alternativeUrl) + .orderBy("createdDate DESC").queryFirst(); + if (contentDataResourceView != null) { + GenericValue content = EntityQuery.use(delegator).from("ContentAssoc") + .where("contentAssocTypeId", "ALTERNATIVE_URL", + "contentIdTo", contentDataResourceView.get("contentId")) + .filterByDate().queryFirst(); + if (content != null) { urlContentId = content.getString("contentId"); } } @@ -113,14 +116,15 @@ public class ContentUrlFilter extends Co Delegator delegator = (Delegator) request.getAttribute("delegator"); String url = null; try { - List<EntityCondition> expr = FastList.newInstance(); - expr.add(EntityCondition.makeCondition("caContentAssocTypeId", EntityOperator.EQUALS, "ALTERNATIVE_URL")); - expr.add(EntityCondition.makeCondition("caThruDate", EntityOperator.EQUALS, null)); - expr.add(EntityCondition.makeCondition("contentIdStart", EntityOperator.EQUALS, contentId)); - Set<String> fieldsToSelect = UtilMisc.toSet("contentIdStart", "drObjectInfo", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate"); - List<GenericValue> contentAssocDataResources = delegator.findList("ContentAssocDataResourceViewTo", EntityCondition.makeCondition(expr), fieldsToSelect, UtilMisc.toList("-caFromDate"), null, true); - if (contentAssocDataResources.size() > 0) { - GenericValue contentAssocDataResource = EntityUtil.getFirst(contentAssocDataResources); + GenericValue contentAssocDataResource = EntityQuery.use(delegator) + .select("contentIdStart", "drObjectInfo", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate") + .from("ContentAssocDataResourceViewTo") + .where("caContentAssocTypeId", "ALTERNATIVE_URL", + "caThruDate", null, + "contentIdStart", contentId) + .orderBy("-caFromDate") + .queryFirst(); + if (contentAssocDataResource != null) { url = contentAssocDataResource.getString("drObjectInfo"); try { url = StringUtil.defaultWebEncoder.decodeFromURL(url); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Fri Oct 24 08:22:56 2014 @@ -51,6 +51,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMapProcessor; @@ -107,28 +108,31 @@ public class ContentWorker implements or // Content rendering methods // ------------------------------------- public static GenericValue findContentForRendering(Delegator delegator, String contentId, Locale locale, String partyId, String roleTypeId, boolean cache) throws GeneralException, IOException { - GenericValue content; if (UtilValidate.isEmpty(contentId)) { Debug.logError("No content ID found.", module); return null; } - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), cache); + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache(cache).queryOne(); if (content == null) { throw new GeneralException("No content found for content ID [" + contentId + "]"); } // if the content is a PUBLISH_POINT and the data resource is not defined; get the related content if ("WEB_SITE_PUB_PT".equals(content.get("contentTypeId")) && content.get("dataResourceId") == null) { - List<GenericValue> relContentIds = delegator.findByAnd("ContentAssocDataResourceViewTo", - UtilMisc.toMap("contentIdStart", content.get("contentId"),"statusId","CTNT_PUBLISHED", - "caContentAssocTypeId", "PUBLISH_LINK"), UtilMisc.toList("caFromDate"), true); + GenericValue relContent = EntityQuery.use(delegator) + .from("ContentAssocDataResourceViewTo") + .where("contentIdStart", content.get("contentId"), + "statusId","CTNT_PUBLISHED", + "caContentAssocTypeId", "PUBLISH_LINK") + .orderBy("caFromDate") + .filterByDate("caFromDate", "caThruDate") + .cache().queryFirst(); - relContentIds = EntityUtil.filterByDate(relContentIds, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true); - if (UtilValidate.isNotEmpty(relContentIds)) { - content = EntityUtil.getFirst(relContentIds); + if (relContent != null) { + content = relContent; } - if (content == null) { + if (relContent == null) { throw new GeneralException("No related content found for publish point [" + contentId + "]"); } } @@ -178,7 +182,7 @@ public class ContentWorker implements or String serviceName = content.getString("serviceName"); //Kept for backward compatibility GenericValue custMethod = null; if (UtilValidate.isNotEmpty(content.getString("customMethodId"))) { - custMethod = delegator.findOne("CustomMethod", UtilMisc.toMap("customMethodId", content.get("customMethodId")), true); + custMethod = EntityQuery.use(delegator).from("CustomMethod").where("customMethodId", content.get("customMethodId")).cache().queryOne(); } if (custMethod != null) serviceName = custMethod.getString("customMethodName"); if (dispatcher != null && UtilValidate.isNotEmpty(serviceName)) { @@ -227,7 +231,7 @@ public class ContentWorker implements or if (!isDecorated && UtilValidate.isNotEmpty(contentDecoratorId)) { // if there is a decorator content; do not render this content; // instead render the decorator - GenericValue decorator = delegator.findOne("Content", UtilMisc.toMap("contentId", contentDecoratorId), cache); + GenericValue decorator = EntityQuery.use(delegator).from("Content").where("contentId", contentDecoratorId).cache(cache).queryOne(); if (decorator == null) { throw new GeneralException("No decorator content found for decorator contentId [" + contentDecoratorId + "]"); } @@ -286,8 +290,8 @@ public class ContentWorker implements or // This part is using an xml file as the input data and an ftl or xsl file to present it. if (UtilValidate.isNotEmpty(mimeType)) { if (mimeType.toLowerCase().indexOf("xml") >= 0) { - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); - GenericValue templateDataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", templateDataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); + GenericValue templateDataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", templateDataResourceId).cache().queryOne(); if ("FTL".equals(templateDataResource.getString("dataTemplateTypeId"))) { StringReader sr = new StringReader(textData); try { @@ -346,16 +350,14 @@ public class ContentWorker implements or Map<String,Object> templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException { // find the sub-content with matching mapKey - List<String> orderBy = UtilMisc.toList("-fromDate"); - List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, contentId)); + List<EntityCondition> exprs = UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, contentId)); if (UtilValidate.isNotEmpty(mapKey)) { exprs.add(EntityCondition.makeCondition("mapKey", EntityOperator.EQUALS, mapKey)); } - List<GenericValue> assocs; - assocs = delegator.findList("ContentAssoc", EntityCondition.makeCondition(exprs, EntityOperator.AND), null, orderBy, null, cache); - assocs = EntityUtil.filterByDate(assocs); - GenericValue subContent = EntityUtil.getFirst(assocs); + GenericValue subContent = EntityQuery.use(delegator).from("ContentAssoc") + .where(exprs) + .orderBy("-fromDate").cache(cache).filterByDate().queryFirst(); if (subContent == null) { //throw new GeneralException("No sub-content found with map-key [" + mapKey + "] for content [" + contentId + "]"); @@ -762,7 +764,7 @@ public class ContentWorker implements or for (GenericValue assoc : assocList) { String contentId = (String) assoc.get(contentIdName); if (Debug.infoOn()) Debug.logInfo("contentId:" + contentId, ""); - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); if (UtilValidate.isNotEmpty(contentTypes)) { contentTypeId = content.getString("contentTypeId"); if (contentTypes.contains(contentTypeId)) { @@ -810,10 +812,8 @@ public class ContentWorker implements or expr = EntityCondition.makeCondition("thruDate", EntityOperator.LESS_THAN, tsThru); exprListAnd.add(expr); } - EntityConditionList<EntityExpr> contentCondList = EntityCondition.makeCondition(exprListAnd, EntityOperator.AND); Delegator delegator = currentContent.getDelegator(); - contentList = delegator.findList(contentAssocViewName, contentCondList, null, null, null, false); - return contentList; + return EntityQuery.use(delegator).from(contentAssocViewName).where(exprListAnd).queryList(); } public static List<GenericValue> getAssociations(GenericValue currentContent, String linkDir, List<String> assocTypes, String strFromDate, String strThruDate) throws GenericEntityException { @@ -844,13 +844,7 @@ public class ContentWorker implements or } exprList.add(joinExpr); if (UtilValidate.isNotEmpty(assocTypes)) { - List<EntityExpr> exprListOr = FastList.newInstance(); - for (String assocType : assocTypes) { - expr = EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.EQUALS, assocType); - exprListOr.add(expr); - } - EntityConditionList assocExprList = EntityCondition.makeCondition(exprListOr, EntityOperator.OR); - exprList.add(assocExprList); + exprList.add(EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.IN, assocTypes)); } if (fromDate != null) { EntityExpr fromExpr = EntityCondition.makeCondition("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, fromDate); @@ -864,7 +858,7 @@ public class ContentWorker implements or thruList.add(thruExpr); EntityExpr thruExpr2 = EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null); thruList.add(thruExpr2); - EntityConditionList thruExprList = EntityCondition.makeCondition(thruList, EntityOperator.OR); + EntityConditionList<EntityExpr> thruExprList = EntityCondition.makeCondition(thruList, EntityOperator.OR); exprList.add(thruExprList); } else if (fromDate != null) { List<EntityExpr> thruList = FastList.newInstance(); @@ -873,25 +867,19 @@ public class ContentWorker implements or thruList.add(thruExpr); EntityExpr thruExpr2 = EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null); thruList.add(thruExpr2); - EntityConditionList thruExprList = EntityCondition.makeCondition(thruList, EntityOperator.OR); + EntityConditionList<EntityExpr> thruExprList = EntityCondition.makeCondition(thruList, EntityOperator.OR); exprList.add(thruExprList); } else { EntityExpr thruExpr2 = EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null); exprList.add(thruExpr2); } - EntityConditionList assocExprList = EntityCondition.makeCondition(exprList, EntityOperator.AND); - //if (Debug.infoOn()) Debug.logInfo(" assocExprList:" + assocExprList , ""); - List<GenericValue> relatedAssocs = delegator.findList("ContentAssoc", assocExprList, null, UtilMisc.toList("-fromDate"), null, false); - //if (Debug.infoOn()) Debug.logInfo(" relatedAssoc:" + relatedAssocs.size() , ""); - //for (int i = 0; i < relatedAssocs.size(); i++) { - //GenericValue a = (GenericValue) relatedAssocs.get(i); - //} - return relatedAssocs; + + return EntityQuery.use(delegator).from("ContentAssoc").where(exprList).orderBy("-fromDate").queryList(); } public static void getContentTypeAncestry(Delegator delegator, String contentTypeId, List<String> contentTypes) throws GenericEntityException { contentTypes.add(contentTypeId); - GenericValue contentTypeValue = delegator.findOne("ContentType", UtilMisc.toMap("contentTypeId", contentTypeId), false); + GenericValue contentTypeValue = EntityQuery.use(delegator).from("ContentType").where("contentTypeId", contentTypeId).queryOne(); if (contentTypeValue == null) return; String parentTypeId = (String) contentTypeValue.get("parentTypeId"); @@ -922,12 +910,8 @@ public class ContentWorker implements or andMap = UtilMisc.<String, Object>toMap(contentIdField, contentId, "contentAssocTypeId", contentAssocTypeId); } try { - List<GenericValue> lst = delegator.findByAnd("ContentAssoc", andMap, null, true); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst:" + lst, ""); - List<GenericValue> lst2 = EntityUtil.filterByDate(lst); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst2:" + lst2, ""); - if (lst2.size() > 0) { - GenericValue contentAssoc = lst2.get(0); + GenericValue contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where(andMap).cache().filterByDate().queryFirst(); + if (contentAssoc != null) { getContentAncestry(delegator, contentAssoc.getString(contentIdOtherField), contentAssocTypeId, direction, contentAncestorList); contentAncestorList.add(contentAssoc); } @@ -949,18 +933,17 @@ public class ContentWorker implements or } if (Debug.infoOn()) Debug.logInfo("getContentAncestry, contentId:" + contentId, ""); - Map<String, Object> andMap = UtilMisc.<String, Object>toMap(contentIdField, contentId); try { - List<GenericValue> lst = delegator.findByAnd("ContentAssoc", andMap, null, true); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst:" + lst, ""); - List<GenericValue> lst2 = EntityUtil.filterByDate(lst); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst2:" + lst2, ""); - for (GenericValue contentAssoc : lst2) { + List<GenericValue> contentAssocs = EntityQuery.use(delegator).from("ContentAssoc") + .where(contentIdField, contentId) + .cache().filterByDate().queryList(); + for (GenericValue contentAssoc : contentAssocs) { String contentIdOther = contentAssoc.getString(contentIdOtherField); if (!contentAncestorList.contains(contentIdOther)) { getContentAncestryAll(delegator, contentIdOther, passedContentTypeId, direction, contentAncestorList); if (!contentAncestorList.contains(contentIdOther)) { - GenericValue contentTo = delegator.findOne("Content", UtilMisc.toMap("contentId", contentIdOther), true); + GenericValue contentTo = EntityQuery.use(delegator).from("Content").where("contentId", contentIdOther).cache().queryOne(); + String contentTypeId = contentTo.getString("contentTypeId"); if (contentTypeId != null && contentTypeId.equals(passedContentTypeId)) contentAncestorList.add(contentIdOther); @@ -1004,14 +987,14 @@ public class ContentWorker implements or //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, contentId:" + contentId, ""); try { - List<GenericValue> lst = delegator.findByAnd("ContentAssoc", UtilMisc.toMap(contentIdField, contentId, "contentAssocTypeId", contentAssocTypeId), null, true); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst:" + lst, ""); - List<GenericValue> lst2 = EntityUtil.filterByDate(lst); - //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst2:" + lst2, ""); - if (lst2.size() > 0) { - GenericValue contentAssoc = lst2.get(0); + GenericValue contentAssoc = EntityQuery.use(delegator).from("ContentAssoc") + .where(contentIdField, contentId, "contentAssocTypeId", contentAssocTypeId) + .cache().filterByDate().queryFirst(); + if (contentAssoc != null) { getContentAncestryValues(delegator, contentAssoc.getString(contentIdOtherField), contentAssocTypeId, direction, contentAncestorList); - GenericValue content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentAssoc.getString(contentIdOtherField)), true); + GenericValue content = EntityQuery.use(delegator).from("Content") + .where("contentId", contentAssoc.getString(contentIdOtherField)) + .cache().queryOne(); contentAncestorList.add(content); } @@ -1082,11 +1065,11 @@ public class ContentWorker implements or view = entityList.get(0); } } else { - List<GenericValue> lst = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", subContentId), null, false); - if (UtilValidate.isEmpty(lst)) { + view = EntityQuery.use(delegator).from("ContentDataResourceView") + .where("contentId", subContentId).queryFirst(); + if (view == null) { throw new IOException("No subContent found for subContentId=." + subContentId); } - view = lst.get(0); } } catch (GenericEntityException e) { throw new IOException(e.getMessage()); @@ -1131,13 +1114,9 @@ public class ContentWorker implements or } public static GenericValue getContentCache(Delegator delegator, String contentId) throws GenericEntityException { - GenericValue view = null; - List<GenericValue> lst = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId), null, true); - //if (Debug.infoOn()) Debug.logInfo("getContentCache, lst(2):" + lst, ""); - if (UtilValidate.isNotEmpty(lst)) { - view = lst.get(0); - } - return view; + return EntityQuery.use(delegator).from("ContentDataResourceView") + .where("contentId", contentId) + .cache().queryFirst(); } public static GenericValue getCurrentContent(Delegator delegator, List<Map<String, ? extends Object>> trail, GenericValue userLogin, Map<String, Object> ctx, Boolean nullThruDatesOnly, String contentAssocPredicateId) throws GeneralException { @@ -1227,7 +1206,7 @@ public class ContentWorker implements or ctx.put("contentIdTo", assocContentId); } if (thisContent == null) - thisContent = delegator.findOne("Content", UtilMisc.toMap("contentId", assocContentId), true); + thisContent = EntityQuery.use(delegator).from("Content").where("contentId", assocContentId).cache().queryOne(); ctx.put("content", thisContent); List<Object> purposes = getPurposes(thisContent); ctx.put("purposes", purposes); @@ -1393,10 +1372,10 @@ public class ContentWorker implements or exprListAnd.add(expr); } - EntityConditionList<EntityExpr> contentCondList = EntityCondition.makeCondition(exprListAnd, EntityOperator.AND); - List<GenericValue> contentList = delegator.findList("ContentAssocDataResourceViewFrom", contentCondList, null, null, null, false); - List<GenericValue> filteredList = EntityUtil.filterByDate(contentList, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true); - return filteredList; + return EntityQuery.use(delegator).from("ContentAssocDataResourceViewFrom") + .where(exprListAnd) + .filterByDate("caFromDate", "caThruDate") + .queryList(); } public static GenericValue getContentAssocViewFrom(Delegator delegator, String contentIdTo, String contentId, String contentAssocTypeId, String statusId, String privilegeEnumId) throws GenericEntityException { @@ -1458,7 +1437,7 @@ public class ContentWorker implements or List<String> values = null; for (String contentId : contentIdList) { try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); return FastList.newInstance(); @@ -1481,7 +1460,7 @@ public class ContentWorker implements or GenericValue content = null; for (String contentId : contentIdList) { try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); return FastList.newInstance(); @@ -1512,7 +1491,7 @@ public class ContentWorker implements or String parentContentId = (String)ctx.get("contentId"); if (UtilValidate.isEmpty(mimeTypeId) && UtilValidate.isNotEmpty(parentContentId)) { // will need these below try { - GenericValue parentContent = delegator.findOne("Content", UtilMisc.toMap("contentId", parentContentId), false); + GenericValue parentContent = EntityQuery.use(delegator).from("Content").where("contentId", parentContentId).queryOne(); if (parentContent != null) { mimeTypeId = (String) parentContent.get("mimeTypeId"); ctx.put("parentContent", parentContent); @@ -1549,7 +1528,7 @@ public class ContentWorker implements or if (UtilValidate.isEmpty(mimeTypeId)) { if (UtilValidate.isNotEmpty(contentId) && UtilValidate.isNotEmpty(dataResourceId)) { - view = delegator.findOne("SubContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceId", dataResourceId), false); + view = EntityQuery.use(delegator).from("SubContentDataResourceView").where("contentId", contentId, "drDataResourceId", dataResourceId).queryOne(); if (view != null) { mimeTypeId = view.getString("mimeTypeId"); String drMimeTypeId = view.getString("drMimeTypeId"); @@ -1568,7 +1547,7 @@ public class ContentWorker implements or if (UtilValidate.isEmpty(mimeTypeId)) { if (UtilValidate.isNotEmpty(parentContentId)) { - parentContent = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + parentContent = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); if (parentContent != null) { mimeTypeId = parentContent.getString("mimeTypeId"); } Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java Fri Oct 24 08:22:56 2014 @@ -47,7 +47,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; -import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMapProcessor; import org.ofbiz.service.GenericServiceException; @@ -294,12 +294,13 @@ public class UploadContentAndImage { // Check for existing AUTHOR link String userLoginId = userLogin.getString("userLoginId"); - GenericValue authorContent = delegator.findOne("Content", UtilMisc.toMap("contentId", userLoginId), true); + GenericValue authorContent = EntityQuery.use(delegator).from("Content").where("contentId", userLoginId).cache().queryOne(); if (authorContent != null) { - List<GenericValue> authorAssocList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", ftlContentId, "contentIdTo", userLoginId, "contentAssocTypeId", "AUTHOR"), null, false); - List<GenericValue> currentAuthorAssocList = EntityUtil.filterByDate(authorAssocList); + long currentAuthorAssocCount = EntityQuery.use(delegator).from("ContentAssoc") + .where("contentId", ftlContentId, "contentIdTo", userLoginId, "contentAssocTypeId", "AUTHOR") + .filterByDate().queryCount(); //if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]currentAuthorAssocList " + currentAuthorAssocList, module); - if (currentAuthorAssocList.size() == 0) { + if (currentAuthorAssocCount == 0) { // Don't want to bother with permission checking on this association GenericValue authorAssoc = delegator.makeValue("ContentAssoc"); authorAssoc.set("contentId", ftlContentId); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java Fri Oct 24 08:22:56 2014 @@ -21,7 +21,6 @@ package org.ofbiz.content.data; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.List; import java.util.Locale; import java.util.Map; @@ -39,6 +38,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.util.EntityQuery; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; @@ -81,7 +81,7 @@ public class DataEvents { // get the content record GenericValue content; try { - content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); @@ -108,7 +108,7 @@ public class DataEvents { // get the data resource GenericValue dataResource; try { - dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), false); + dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); @@ -244,7 +244,7 @@ public class DataEvents { } try { - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); if (!"Y".equals(dataResource.getString("isPublic"))) { // now require login... GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); @@ -257,9 +257,11 @@ public class DataEvents { // make sure the logged in user can download this content; otherwise is a pretty big security hole for DataResource records... // TODO: should we restrict the roleTypeId? - List<GenericValue> contentAndRoleList = delegator.findByAnd("ContentAndRole", - UtilMisc.toMap("partyId", userLogin.get("partyId"), "dataResourceId", dataResourceId), null, false); - if (contentAndRoleList.size() == 0) { + long contentAndRoleCount = EntityQuery.use(delegator).from("ContentAndRole") + .where("partyId", userLogin.get("partyId"), + "dataResourceId", dataResourceId) + .queryCount(); + if (contentAndRoleCount == 0) { String errorMsg = "You do not have permission to download the Data Resource with ID [" + dataResourceId + "], ie you are not associated with it."; Debug.logError(errorMsg, module); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=1634024&r1=1634023&r2=1634024&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Fri Oct 24 08:22:56 2014 @@ -72,6 +72,7 @@ import org.ofbiz.content.content.UploadC 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.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -114,15 +115,12 @@ public class DataResourceWorker impleme } // Find all the categoryTypes that are children of the categoryNode. - String matchValue = null; - if (parentCategoryId != null) { - matchValue = parentCategoryId; - } - List<GenericValue> categoryValues = delegator.findByAnd("DataCategory", UtilMisc.toMap("parentCategoryId", matchValue), null, true); + List<GenericValue> categoryValues = EntityQuery.use(delegator).from("DataCategory") + .where("parentCategoryId", parentCategoryId) + .cache().queryList(); categoryNode.put("count", Integer.valueOf(categoryValues.size())); List<Map<String, Object>> subCategoryIds = FastList.newInstance(); - for (int i = 0; i < categoryValues.size(); i++) { - GenericValue category = categoryValues.get(i); + for (GenericValue category : categoryValues) { String id = (String) category.get("dataCategoryId"); String categoryName = (String) category.get("categoryName"); Map<String, Object> newNode = FastMap.newInstance(); @@ -154,7 +152,7 @@ public class DataResourceWorker impleme */ public static void getDataCategoryAncestry(Delegator delegator, String dataCategoryId, List<String> categoryTypeIds) throws GenericEntityException { categoryTypeIds.add(dataCategoryId); - GenericValue dataCategoryValue = delegator.findOne("DataCategory", UtilMisc.toMap("dataCategoryId", dataCategoryId), false); + GenericValue dataCategoryValue = EntityQuery.use(delegator).from("DataCategory").where("dataCategoryId", dataCategoryId).queryOne(); if (dataCategoryValue == null) return; String parentCategoryId = (String) dataCategoryValue.get("parentCategoryId"); @@ -310,7 +308,7 @@ public class DataResourceWorker impleme String ownerContentId = (String) context.get("ownerContentId"); if (UtilValidate.isNotEmpty(ownerContentId)) { try { - GenericValue content = delegator.findOne("Content", UtilMisc.toMap("contentId", ownerContentId), false); + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", ownerContentId).queryOne(); if (content != null) serviceInMap.put("currentContent", content); } catch (GenericEntityException e) { @@ -334,7 +332,7 @@ public class DataResourceWorker impleme public static byte[] acquireImage(Delegator delegator, String dataResourceId) throws GenericEntityException { byte[] b = null; - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); if (dataResource == null) return b; @@ -345,7 +343,7 @@ public class DataResourceWorker impleme public static byte[] acquireImage(Delegator delegator, GenericValue dataResource) throws GenericEntityException { byte[] b = null; String dataResourceId = dataResource.getString("dataResourceId"); - GenericValue imageDataResource = delegator.findOne("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId), false); + GenericValue imageDataResource = EntityQuery.use(delegator).from("ImageDataResource").where("dataResourceId", dataResourceId).queryOne(); if (imageDataResource != null) { //b = (byte[]) imageDataResource.get("imageData"); b = imageDataResource.getBytes("imageData"); @@ -461,7 +459,7 @@ public class DataResourceWorker impleme mimeType = view.getString("drMimeTypeId"); //if (Debug.infoOn()) Debug.logInfo("getDataResourceMimeType, mimeType(2):" + mimeType, ""); if (UtilValidate.isEmpty(mimeType) && UtilValidate.isNotEmpty(dataResourceId)) { - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); //if (Debug.infoOn()) Debug.logInfo("getDataResourceMimeType, dataResource(2):" + dataResource, ""); mimeType = dataResource.getString("mimeTypeId"); @@ -586,7 +584,7 @@ public class DataResourceWorker impleme throw new GeneralException("Cannot clear dataResource related cache for a null dataResourceId"); } - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); if (dataResource != null) { String dataTemplateTypeId = dataResource.getString("dataTemplateTypeId"); if ("FTL".equals(dataTemplateTypeId)) { @@ -652,7 +650,9 @@ public class DataResourceWorker impleme } // get the data resource object - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource") + .where("dataResourceId", dataResourceId) + .cache(cache).queryOne(); if (dataResource == null) { throw new GeneralException("No data resource object found for dataResourceId: [" + dataResourceId + "]"); @@ -707,7 +707,7 @@ public class DataResourceWorker impleme } else { String defaultVisualThemeId = EntityUtilProperties.getPropertyValue("general", "VISUAL_THEME", delegator); if (defaultVisualThemeId != null) { - GenericValue themeValue = delegator.findOne("VisualThemeResource", UtilMisc.toMap("visualThemeId", defaultVisualThemeId, "resourceTypeEnumId", "VT_DOCBOOKSTYLESHEET", "sequenceId", "01"), true); + GenericValue themeValue = EntityQuery.use(delegator).from("VisualThemeResource").where("visualThemeId", defaultVisualThemeId, "resourceTypeEnumId", "VT_DOCBOOKSTYLESHEET", "sequenceId", "01").cache().queryOne(); sourceFileLocation = new File(System.getProperty("ofbiz.home") + "/themes" + themeValue.get("resourceValue")); UtilMisc.copyFile(sourceFileLocation,targetFileLocation); } @@ -827,7 +827,9 @@ public class DataResourceWorker impleme String text = dataResource.getString("objectInfo"); writeText(dataResource, text, templateContext, mimeTypeId, locale, out); } else if ("ELECTRONIC_TEXT".equals(dataResourceTypeId)) { - GenericValue electronicText = delegator.findOne("ElectronicText", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + GenericValue electronicText = EntityQuery.use(delegator).from("ElectronicText") + .where("dataResourceId", dataResourceId) + .cache(cache).queryOne(); if (electronicText != null) { String text = electronicText.getString("textData"); writeText(dataResource, text, templateContext, mimeTypeId, locale, out); @@ -902,7 +904,7 @@ public class DataResourceWorker impleme if ("text/html".equals(targetMimeTypeId)) { // get the default mime type template - GenericValue mimeTypeTemplate = delegator.findOne("MimeTypeHtmlTemplate", UtilMisc.toMap("mimeTypeId", dataResourceMimeTypeId), true); + GenericValue mimeTypeTemplate = EntityQuery.use(delegator).from("MimeTypeHtmlTemplate").where("mimeTypeId", dataResourceMimeTypeId).cache().queryOne(); if (mimeTypeTemplate != null && mimeTypeTemplate.get("templateLocation") != null) { // prepare the context @@ -1008,7 +1010,9 @@ public class DataResourceWorker impleme if ("SHORT_TEXT".equals(dataResourceTypeId) || "LINK".equals(dataResourceTypeId)) { text = dataResource.getString("objectInfo"); } else if ("ELECTRONIC_TEXT".equals(dataResourceTypeId)) { - GenericValue electronicText = delegator.findOne("ElectronicText", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + GenericValue electronicText = EntityQuery.use(delegator).from("ElectronicText") + .where("dataResourceId", dataResourceId) + .cache(cache).queryOne(); if (electronicText != null) { text = electronicText.getString("textData"); } @@ -1025,22 +1029,22 @@ public class DataResourceWorker impleme GenericValue valObj; if ("IMAGE_OBJECT".equals(dataResourceTypeId)) { - valObj = delegator.findOne("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + valObj = EntityQuery.use(delegator).from("ImageDataResource").where("dataResourceId", dataResourceId).cache(cache).queryOne(); if (valObj != null) { bytes = valObj.getBytes("imageData"); } } else if ("VIDEO_OBJECT".equals(dataResourceTypeId)) { - valObj = delegator.findOne("VideoDataResource", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + valObj = EntityQuery.use(delegator).from("VideoDataResource").where("dataResourceId", dataResourceId).cache(cache).queryOne(); if (valObj != null) { bytes = valObj.getBytes("videoData"); } } else if ("AUDIO_OBJECT".equals(dataResourceTypeId)) { - valObj = delegator.findOne("AudioDataResource", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + valObj = EntityQuery.use(delegator).from("AudioDataResource").where("dataResourceId", dataResourceId).cache(cache).queryOne(); if (valObj != null) { bytes = valObj.getBytes("audioData"); } } else if ("OTHER_OBJECT".equals(dataResourceTypeId)) { - valObj = delegator.findOne("OtherDataResource", UtilMisc.toMap("dataResourceId", dataResourceId), cache); + valObj = EntityQuery.use(delegator).from("OtherDataResource").where("dataResourceId", dataResourceId).cache(cache).queryOne(); if (valObj != null) { bytes = valObj.getBytes("dataResourceContent"); } @@ -1088,7 +1092,7 @@ public class DataResourceWorker impleme // TODO: remove this method in favor of getDataResourceStream public static void streamDataResource(OutputStream os, Delegator delegator, String dataResourceId, String https, String webSiteId, Locale locale, String rootDir) throws IOException, GeneralException { try { - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne(); if (dataResource == null) { throw new GeneralException("Error in streamDataResource: DataResource with ID [" + dataResourceId + "] was not found."); } @@ -1105,7 +1109,7 @@ public class DataResourceWorker impleme String text = dataResource.getString("objectInfo"); os.write(text.getBytes()); } else if (dataResourceTypeId.equals("ELECTRONIC_TEXT")) { - GenericValue electronicText = delegator.findOne("ElectronicText", UtilMisc.toMap("dataResourceId", dataResourceId), true); + GenericValue electronicText = EntityQuery.use(delegator).from("ElectronicText").where("dataResourceId", dataResourceId).cache().queryOne(); if (electronicText != null) { String text = electronicText.getString("textData"); if (text != null) os.write(text.getBytes());