Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/cms/CmsEvents.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/cms/CmsEvents.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/cms/CmsEvents.java Tue Oct 28 08:56:02 2014 @@ -35,7 +35,6 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.collections.MapStack; @@ -43,6 +42,7 @@ import org.ofbiz.content.content.Content 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.EntityUtil; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.webapp.control.RequestHandler; @@ -116,15 +116,14 @@ public class CmsEvents { // if path info is null; check for a default content if (pathInfo == null) { - List<GenericValue> defaultContents = null; + GenericValue defaultContent = null; try { - defaultContents = delegator.findByAnd("WebSiteContent", UtilMisc.toMap("webSiteId", webSiteId, - "webSiteContentTypeId", "DEFAULT_PAGE"), UtilMisc.toList("-fromDate"), true); + defaultContent = EntityQuery.use(delegator).from("WebSiteContent") + .where("webSiteId", webSiteId, "webSiteContentTypeId", "DEFAULT_PAGE") + .orderBy("-fromDate").filterByDate().cache().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } - defaultContents = EntityUtil.filterByDate(defaultContents); - GenericValue defaultContent = EntityUtil.getFirst(defaultContents); if (defaultContent != null) { pathInfo = defaultContent.getString("contentId"); } @@ -143,7 +142,7 @@ public class CmsEvents { GenericValue pathAlias = null; try { - pathAlias = delegator.findOne("WebSitePathAlias", UtilMisc.toMap("webSiteId", webSiteId, "pathAlias", pathInfo), true); + pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -197,30 +196,32 @@ public class CmsEvents { // We try to find a specific Error page for this website concerning the status code if (statusCode != HttpServletResponse.SC_OK) { - List<GenericValue> errorContainers = null; + GenericValue errorContainer = null; try { - errorContainers = delegator.findByAnd("WebSiteContent", - UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "ERROR_ROOT"), - UtilMisc.toList("-fromDate"), true); + errorContainer = EntityQuery.use(delegator).from("WebSiteContent") + .where("webSiteId", webSiteId, "webSiteContentTypeId", "ERROR_ROOT") + .orderBy("fromDate").filterByDate().cache().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } - errorContainers = EntityUtil.filterByDate(errorContainers); - if (UtilValidate.isNotEmpty(errorContainers)) { - if (Debug.verboseOn()) Debug.logVerbose("Found error containers: " + errorContainers, module); - GenericValue errorContainer = EntityUtil.getFirst(errorContainers); + if (errorContainer != null) { + if (Debug.verboseOn()) Debug.logVerbose("Found error containers: " + errorContainer, module); - List<GenericValue> errorPages = null; + GenericValue errorPage = null; try { - errorPages = delegator.findByAnd("ContentAssocViewTo", UtilMisc.toMap("contentIdStart", errorContainer.getString("contentId"), "caContentAssocTypeId", "TREE_CHILD", "contentTypeId", "DOCUMENT", "caMapKey", String.valueOf(statusCode)), null, false); + errorPage = EntityQuery.use(delegator).from("ContentAssocViewTo") + .where("contentIdStart", errorContainer.getString("contentId"), + "caContentAssocTypeId", "TREE_CHILD", + "contentTypeId", "DOCUMENT", + "caMapKey", String.valueOf(statusCode)) + .filterByDate().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } - errorPages = EntityUtil.filterByDate(errorPages); - if (UtilValidate.isNotEmpty(errorPages)) { - if (Debug.verboseOn()) Debug.logVerbose("Found error pages " + statusCode + " : " + errorPages, module); - contentId = EntityUtil.getFirst(errorPages).getString("contentId"); + if (errorPage != null) { + if (Debug.verboseOn()) Debug.logVerbose("Found error pages " + statusCode + " : " + errorPage, module); + contentId = errorPage.getString("contentId"); } else { if (Debug.verboseOn()) Debug.logVerbose("No specific error page, falling back to the Error Container for " + statusCode, module); contentId = errorContainer.getString("contentId"); @@ -231,7 +232,7 @@ public class CmsEvents { // We try to find a generic content Error page concerning the status code if (!hasErrorPage) { try { - GenericValue errorPage = delegator.findOne("Content", UtilMisc.toMap("contentId", "CONTENT_ERROR_" + statusCode), true); + GenericValue errorPage = EntityQuery.use(delegator).from("Content").where("contentId", "CONTENT_ERROR_" + statusCode).cache().queryOne(); if (errorPage != null) { Debug.logVerbose("Found generic page " + statusCode, module); contentId = errorPage.getString("contentId"); @@ -269,8 +270,7 @@ public class CmsEvents { templateMap.put("formStringRenderer", formStringRenderer); // if use web analytics - List<GenericValue> webAnalytics = delegator.findByAnd("WebAnalyticsConfig", UtilMisc.toMap("webSiteId", webSiteId), null, false); - + List<GenericValue> webAnalytics = EntityQuery.use(delegator).from("WebAnalyticsConfig").where("webSiteId", webSiteId).queryList(); // render if (UtilValidate.isNotEmpty(webAnalytics) && hasErrorPage) { ContentWorker.renderContentAsText(dispatcher, delegator, contentId, writer, templateMap, locale, "text/html", null, null, true, webAnalytics); @@ -293,14 +293,14 @@ public class CmsEvents { String contentName = null; String siteName = null; try { - GenericValue content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache().queryOne(); if (content != null && UtilValidate.isNotEmpty(content)) { contentName = content.getString("contentName"); } else { request.setAttribute("_ERROR_MESSAGE_", "Content: " + contentName + " [" + contentId + "] is not a publish point for the current website: [" + webSiteId + "]"); return "error"; } - siteName = delegator.findOne("WebSite", UtilMisc.toMap("webSiteId", webSiteId), true).getString("siteName"); + siteName = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteId).cache().queryOne().getString("siteName"); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -311,7 +311,7 @@ public class CmsEvents { String siteName = null; GenericValue webSite = null; try { - webSite = delegator.findOne("WebSite", UtilMisc.toMap("webSiteId", webSiteId), true); + webSite = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteId).cache().queryOne(); if (webSite != null) { siteName = webSite.getString("siteName"); } @@ -334,9 +334,9 @@ public class CmsEvents { List<GenericValue> publishPoints = null; boolean hadContent = false; try { - publishPoints = delegator.findByAnd("WebSiteContent", - UtilMisc.toMap("webSiteId", webSiteId, "contentId", contentId, "webSiteContentTypeId", "PUBLISH_POINT"), - UtilMisc.toList("-fromDate"), true); + publishPoints = EntityQuery.use(delegator).from("WebSiteContent") + .where("webSiteId", webSiteId, "contentId", contentId, "webSiteContentTypeId", "PUBLISH_POINT") + .orderBy("-fromDate").cache().queryList(); } catch (GenericEntityException e) { throw e; } @@ -350,9 +350,9 @@ public class CmsEvents { } else { // the passed in contentId is not a publish point for the web site; // however we will publish its content if it is a node of one of the trees that have a publish point as the root - List<GenericValue> topLevelContentValues = delegator.findByAnd("WebSiteContent", - UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT"), UtilMisc.toList("-fromDate"), true); - topLevelContentValues = EntityUtil.filterByDate(topLevelContentValues); + List<GenericValue> topLevelContentValues = EntityQuery.use(delegator).from("WebSiteContent") + .where("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT") + .orderBy("-fromDate").cache().filterByDate().queryList(); if (topLevelContentValues != null) { for (GenericValue point: topLevelContentValues) { @@ -376,15 +376,17 @@ public class CmsEvents { } protected static int verifySubContent(Delegator delegator, String contentId, String contentIdFrom) throws GeneralException { - List<GenericValue> contentAssoc = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom, "contentIdTo", contentId, "contentAssocTypeId", "SUB_CONTENT"), null, true); + List<GenericValue> contentAssoc = EntityQuery.use(delegator).from("ContentAssoc") + .where("contentId", contentIdFrom, "contentIdTo", contentId, "contentAssocTypeId", "SUB_CONTENT") + .cache().queryList(); + boolean hadContent = false; if (UtilValidate.isNotEmpty(contentAssoc)) { hadContent = true; } contentAssoc = EntityUtil.filterByDate(contentAssoc); if (UtilValidate.isEmpty(contentAssoc)) { - List<GenericValue> assocs = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom), null, true); - assocs = EntityUtil.filterByDate(assocs); + List<GenericValue> assocs = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentIdFrom).cache().filterByDate().queryList(); if (assocs != null) { for (GenericValue assoc : assocs) { int subContentStatusCode = verifySubContent(delegator, contentId, assoc.getString("contentIdTo")); Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java Tue Oct 28 08:56:02 2014 @@ -34,12 +34,12 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; 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.ModelService; @@ -79,7 +79,7 @@ public class CompDocEvents { if (UtilValidate.isNotEmpty(contentId)) { try { - delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error running serviceName persistContentAndAssoc", module); String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.error_modelservice_for_srv_name", locale); Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java Tue Oct 28 08:56:02 2014 @@ -21,17 +21,14 @@ package org.ofbiz.content.compdoc; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.sql.Timestamp; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import javolution.util.FastList; import javolution.util.FastMap; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -40,8 +37,8 @@ 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.EntityConditionList; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -85,7 +82,7 @@ public class CompDocServices { if (UtilValidate.isNotEmpty(contentId)) { try { - delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false); + EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error running serviceName persistContentAndAssoc", module); return ServiceUtil.returnError(UtilProperties.getMessage(CoreEvents.err_resource, "ContentNoContentFound", UtilMisc.toMap("contentId", contentId), locale)); @@ -147,27 +144,19 @@ public class CompDocServices { GenericValue userLogin = (GenericValue) context.get("userLogin"); try { - Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); List<EntityCondition> exprList = FastList.newInstance(); exprList.add(EntityCondition.makeCondition("contentIdTo", EntityOperator.EQUALS, contentId)); + exprList.add(EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.EQUALS, "COMPDOC_PART")); exprList.add(EntityCondition.makeCondition("rootRevisionContentId", EntityOperator.EQUALS, contentId)); if (UtilValidate.isNotEmpty(contentRevisionSeqId)) { exprList.add(EntityCondition.makeCondition("contentRevisionSeqId", EntityOperator.LESS_THAN_EQUAL_TO, contentRevisionSeqId)); } - exprList.add(EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.EQUALS, "COMPDOC_PART")); - exprList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp)); - List<EntityCondition> thruList = FastList.newInstance(); - thruList.add(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null)); - thruList.add(EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, nowTimestamp)); - exprList.add(EntityCondition.makeCondition(thruList, EntityOperator.OR)); - - EntityConditionList<EntityCondition> conditionList = EntityCondition.makeCondition(exprList, EntityOperator.AND); - - String [] fields = {"rootRevisionContentId", "itemContentId", "maxRevisionSeqId", "contentId", "dataResourceId", "contentIdTo", "contentAssocTypeId", "fromDate", "sequenceNum"}; - Set<String> selectFields = UtilMisc.toSetArray(fields); - List<String> orderByFields = UtilMisc.toList("sequenceNum"); - List<GenericValue> compDocParts = delegator.findList("ContentAssocRevisionItemView", conditionList, selectFields, orderByFields, null, false); + List<GenericValue> compDocParts = EntityQuery.use(delegator) + .select("rootRevisionContentId", "itemContentId", "maxRevisionSeqId", "contentId", "dataResourceId", "contentIdTo", "contentAssocTypeId", "fromDate", "sequenceNum") + .from("ContentAssocRevisionItemView") + .where(exprList) + .orderBy("sequenceNum").filterByDate().queryList(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); @@ -176,12 +165,12 @@ public class CompDocServices { //PdfWriter writer = PdfWriter.getInstance(document, baos); PdfCopy writer = new PdfCopy(document, baos); document.open(); - int pgCnt =0; + int pgCnt = 0; for (GenericValue contentAssocRevisionItemView : compDocParts) { //String thisContentId = contentAssocRevisionItemView.getString("contentId"); //String thisContentRevisionSeqId = contentAssocRevisionItemView.getString("maxRevisionSeqId"); String thisDataResourceId = contentAssocRevisionItemView.getString("dataResourceId"); - GenericValue dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", thisDataResourceId), false); + GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", thisDataResourceId).queryOne(); String inputMimeType = null; if (dataResource != null) { inputMimeType = dataResource.getString("mimeTypeId"); @@ -204,13 +193,13 @@ public class CompDocServices { String acroFormContentId = null; GenericValue surveyResponse = null; if (UtilValidate.isNotEmpty(surveyResponseId)) { - surveyResponse = delegator.findOne("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId), false); + surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("surveyResponseId", surveyResponseId).queryOne(); if (surveyResponse != null) { surveyId = surveyResponse.getString("surveyId"); } } if (UtilValidate.isNotEmpty(surveyId)) { - GenericValue survey = delegator.findOne("Survey", UtilMisc.toMap("surveyId", surveyId), false); + GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne(); if (survey != null) { acroFormContentId = survey.getString("acroFormContentId"); if (UtilValidate.isNotEmpty(acroFormContentId)) { @@ -314,12 +303,12 @@ public class CompDocServices { GenericValue dataResource = null; if (UtilValidate.isEmpty(contentRevisionSeqId)) { - GenericValue content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), true); + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).cache().queryOne(); dataResourceId = content.getString("dataResourceId"); Debug.logInfo("SCVH(0b)- dataResourceId:" + dataResourceId, module); - dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), false); + dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne(); } else { - GenericValue contentRevisionItem = delegator.findOne("ContentRevisionItem", UtilMisc.toMap("contentId", contentId, "itemContentId", contentId, "contentRevisionSeqId", contentRevisionSeqId), true); + GenericValue contentRevisionItem = EntityQuery.use(delegator).from("ContentRevisionItem").where("contentId", contentId, "itemContentId", contentId, "contentRevisionSeqId", contentRevisionSeqId).cache().queryOne(); if (contentRevisionItem == null) { throw new ViewHandlerException("ContentRevisionItem record not found for contentId=" + contentId + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId); @@ -329,7 +318,7 @@ public class CompDocServices { + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId, module); dataResourceId = contentRevisionItem.getString("newDataResourceId"); Debug.logInfo("SCVH(3)- dataResourceId:" + dataResourceId, module); - dataResource = delegator.findOne("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId), false); + dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne(); } String inputMimeType = null; if (dataResource != null) { @@ -350,13 +339,13 @@ public class CompDocServices { String acroFormContentId = null; GenericValue surveyResponse = null; if (UtilValidate.isNotEmpty(surveyResponseId)) { - surveyResponse = delegator.findOne("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId), false); + surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("surveyResponseId", surveyResponseId).queryOne(); if (surveyResponse != null) { surveyId = surveyResponse.getString("surveyId"); } } if (UtilValidate.isNotEmpty(surveyId)) { - GenericValue survey = delegator.findOne("Survey", UtilMisc.toMap("surveyId", surveyId), false); + GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne(); if (survey != null) { acroFormContentId = survey.getString("acroFormContentId"); if (UtilValidate.isNotEmpty(acroFormContentId)) { Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentEvents.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentEvents.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentEvents.java Tue Oct 28 08:56:02 2014 @@ -32,6 +32,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.content.content.ContentKeywordIndex; import org.ofbiz.security.Security; @@ -78,11 +79,12 @@ public class ContentEvents { // begin the transaction beganTx = TransactionUtil.begin(7200); try { + EntityQuery contentQuery = EntityQuery.use(delegator).from("Content"); if (Debug.infoOn()) { - long count = delegator.findCountByCondition("Content", null, null, null); + long count = contentQuery.queryCount(); Debug.logInfo("========== Found " + count + " contents to index ==========", module); } - entityListIterator = delegator.find("Content", null, null, null, null, null); + entityListIterator = contentQuery.queryIterator(); } catch (GenericEntityException gee) { Debug.logWarning(gee, gee.getMessage(), module); Map<String, String> messageMap = UtilMisc.toMap("gee", gee.toString()); Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentKeywordIndex.java Tue Oct 28 08:56:02 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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java Tue Oct 28 08:56:02 2014 @@ -36,13 +36,11 @@ import javolution.util.FastSet; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.content.data.DataResourceWorker; 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.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.webapp.control.RequestHandler; import org.ofbiz.webapp.website.WebSiteWorker; @@ -112,9 +110,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 +230,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 +255,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 +291,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 +425,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 +455,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 +463,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 +503,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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentPermissionServices.java Tue Oct 28 08:56:02 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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentSearch.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentSearch.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentSearch.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentSearch.java Tue Oct 28 08:56:02 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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServices.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServices.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServices.java Tue Oct 28 08:56:02 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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentServicesComplex.java Tue Oct 28 08:56:02 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; @@ -30,7 +31,6 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -39,6 +39,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 +136,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 +221,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/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java?rev=1634818&r1=1634817&r2=1634818&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java Tue Oct 28 08:56:02 2014 @@ -20,8 +20,6 @@ package org.ofbiz.content.content; import java.io.IOException; -import java.util.List; -import java.util.Set; import javax.servlet.FilterChain; import javax.servlet.RequestDispatcher; @@ -32,19 +30,14 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javolution.util.FastList; - import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.common.UrlServletHelper; 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.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.webapp.control.ContextFilter; import org.owasp.esapi.errors.EncodingException; @@ -72,13 +65,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 +108,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); |
Free forum by Nabble | Edit this page |