You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ha...@apache.org on 2011/06/03 05:05:23 UTC
svn commit: r1130890 - in /ofbiz/trunk/applications/content: config/
src/org/ofbiz/content/content/ webapp/content/WEB-INF/ widget/content/
Author: hansbak
Date: Fri Jun 3 03:05:23 2011
New Revision: 1130890
URL: http://svn.apache.org/viewvc?rev=1130890&view=rev
Log:
add a button to content to (re) generate the keywords for all content. The whole keyword implementation was done by Antwebsystems employee Tom
Modified:
ofbiz/trunk/applications/content/config/ContentErrorUiLabels.xml
ofbiz/trunk/applications/content/config/ContentUiLabels.xml
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentEvents.java
ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml
ofbiz/trunk/applications/content/widget/content/ContentMenus.xml
ofbiz/trunk/applications/content/widget/content/ContentScreens.xml
Modified: ofbiz/trunk/applications/content/config/ContentErrorUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/config/ContentErrorUiLabels.xml?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/config/ContentErrorUiLabels.xml (original)
+++ ofbiz/trunk/applications/content/config/ContentErrorUiLabels.xml Fri Jun 3 03:05:23 2011
@@ -19,6 +19,27 @@
under the License.
-->
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <property key="contentevents.error_getting_content_list">
+ <value xml:lang="en">Error getting the content list to index: ${gee}.</value>
+ </property>
+ <property key="contentevents.keyword_creation_complete_for_contents">
+ <value xml:lang="en">Keyword creation complete for ${numConts} contents.</value>
+ </property>
+ <property key="contentevents.keyword_creation_complete_for_contents_with_errors">
+ <value xml:lang="en">Keyword creation complete for ${numConts} contents, with errors in ${errConts} contents (see the log for more details).</value>
+ </property>
+ <property key="contentevents.not_sufficient_permissions">
+ <value xml:lang="de">Sie haben nicht genügend Berechtigungen um ${updateMode} CONTENTMGR (CONTENTMGR_${updateMode} oder CONTENTMGR_ADMIN benötigt).</value>
+ <value xml:lang="en">You do not have sufficient permissions to ${updateMode} CONTENTMGR (CONTENTMGR_${updateMode} or CONTENTMGR_ADMIN needed).</value>
+ <value xml:lang="es">No tiene suficientes permisos para ${updateMode} se necesitan permisos de CONTENTMGR (CONTENTMGR_${updateMode} o CONTENTMGR_ADMIN).</value>
+ <value xml:lang="fr">Vous n'avez pas les autorisations suffisantes pour ${updatemode} le CONTENTMGR (CONTENTMGR_${updateMode} ou CONTENTMGR_ADMIN requis).</value>
+ <value xml:lang="it">Non hai permessi sufficienti per ${updateMode} CONTENTMGR (permesso CONTENTMGR_${updateMode} o CONTENTMGR_ADMIN necessario).</value>
+ <value xml:lang="ro">Nu aidestule permise pentru ${updateMode} CONTENTMGR (este necesar permisul CONTENTMGR_${updateMode} sau CONTENTMGR_ADMIN).</value>
+ <value xml:lang="ru">У Ð²Ð°Ñ Ð½ÐµÑ Ð´Ð¾ÑÑаÑоÑнÑÑ
пÑав Ð´Ð»Ñ ${updateMode} CONTENTMGR (необÑ
Ð¾Ð´Ð¸Ð¼Ñ Ð¿Ñава CONTENTMGR_${updateMode} или CONTENTMGR_ADMIN).</value>
+ <value xml:lang="th">à¸à¸¸à¸à¹à¸¡à¹à¸¡à¸µà¸à¸²à¸£à¸à¸à¸¸à¸à¸²à¸à¹à¸à¸µà¸¢à¸à¸à¸à¸à¸¶à¸ ${updateMode} CONTENTMGR (CONTENTMGR_${updateMode} หรืภCONTENTMGR_ADMIN à¸à¹à¸à¸à¸à¸²à¸£).</value>
+ <value xml:lang="zh">ä½ æ²¡æè¶³å¤çæé ${updateMode} ç®å½ (éè¦CONTENTMGR_${updateMode} æ CONTENTMGR_ADMIN)ã</value>
+ <value xml:lang="zh_TW">ä½ æ²æè¶³å¤ çæ¬é ${updateMode} ç®é (éè¦CONTENTMGR_${updateMode} æ CONTENTMGR_ADMIN)ã</value>
+ </property>
<property key="dataEvents.error_call_create_service">
<value xml:lang="da">Fejl ved kald af service createDataResource</value>
<value xml:lang="de">Fehler beim Aufruf createDataResource Service</value>
Modified: ofbiz/trunk/applications/content/config/ContentUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/config/ContentUiLabels.xml?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/config/ContentUiLabels.xml (original)
+++ ofbiz/trunk/applications/content/config/ContentUiLabels.xml Fri Jun 3 03:05:23 2011
@@ -27,6 +27,9 @@
<value xml:lang="zh">ç»å¯¹å°åæä»¶</value>
<value xml:lang="zh_TW">çµå°ä½åæä»¶</value>
</property>
+ <property key="ContentAutoCreateKeywords">
+ <value xml:lang="en">Auto Create Keywords</value>
+ </property>
<property key="ContentAnswer">
<value xml:lang="ar">Ø§ÙØ¬Ùاب</value>
<value xml:lang="da">Svar</value>
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentEvents.java?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentEvents.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentEvents.java Fri Jun 3 03:05:23 2011
@@ -18,6 +18,23 @@
*******************************************************************************/
package org.ofbiz.content.content;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.transaction.TransactionUtil;
+import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.content.content.ContentKeywordIndex;
+import org.ofbiz.security.Security;
+
/**
* ContentEvents Class
@@ -25,6 +42,113 @@ package org.ofbiz.content.content;
public class ContentEvents {
public static final String module = ContentEvents.class.getName();
+ public static final String resource = "ContentErrorUiLabels";
+
+ /**
+ * Updates/adds keywords for all contents
+ *
+ * @param request HTTPRequest object for the current request
+ * @param response HTTPResponse object for the current request
+ * @return String specifying the exit status of this event
+ */
+ public static String updateAllContentKeywords(HttpServletRequest request, HttpServletResponse response) {
+ //String errMsg = "";
+ Delegator delegator = (Delegator) request.getAttribute("delegator");
+ Security security = (Security) request.getAttribute("security");
+
+ String updateMode = "CREATE";
+ String errMsg=null;
+
+ String doAll = request.getParameter("doAll");
+
+ // check permissions before moving on...
+ if (!security.hasEntityPermission("CONTENTMGR", "_" + updateMode, request.getSession())) {
+ Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode);
+ errMsg = UtilProperties.getMessage(resource,"contentevents.not_sufficient_permissions", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+
+ EntityListIterator entityListIterator = null;
+ int numConts = 0;
+ int errConts = 0;
+
+ boolean beganTx = false;
+ try {
+ // begin the transaction
+ beganTx = TransactionUtil.begin(7200);
+ try {
+ if (Debug.infoOn()) {
+ long count = delegator.findCountByCondition("Content", null, null, null);
+ Debug.logInfo("========== Found " + count + " contents to index ==========", module);
+ }
+ entityListIterator = delegator.find("Content", null, null, null, null, null);
+ } catch (GenericEntityException gee) {
+ Debug.logWarning(gee, gee.getMessage(), module);
+ Map<String, String> messageMap = UtilMisc.toMap("gee", gee.toString());
+ errMsg = UtilProperties.getMessage(resource,"contentevents.error_getting_content_list", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ throw gee;
+ }
+
+ GenericValue content;
+ while ((content = entityListIterator.next()) != null) {
+ try {
+ ContentKeywordIndex.indexKeywords(content, "Y".equals(doAll));
+ } catch (GenericEntityException e) {
+ //request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ Debug.logWarning("[ContentEvents.updateAllContentKeywords] Could not create content-keyword (write error); message: " + e.getMessage(), module);
+ errConts++;
+ }
+ numConts++;
+ if (numConts % 500 == 0) {
+ Debug.logInfo("Keywords indexed for " + numConts + " so far", module);
+ }
+ }
+ } catch (GenericEntityException e) {
+ try {
+ TransactionUtil.rollback(beganTx, e.getMessage(), e);
+ } catch (Exception e1) {
+ Debug.logError(e1, module);
+ }
+ return "error";
+ } catch (Throwable t) {
+ Debug.logError(t, module);
+ request.setAttribute("_ERROR_MESSAGE_", t.getMessage());
+ try {
+ TransactionUtil.rollback(beganTx, t.getMessage(), t);
+ } catch (Exception e2) {
+ Debug.logError(e2, module);
+ }
+ return "error";
+ } finally {
+ if (entityListIterator != null) {
+ try {
+ entityListIterator.close();
+ } catch (GenericEntityException gee) {
+ Debug.logError(gee, "Error closing EntityListIterator when indexing content keywords.", module);
+ }
+ }
+ // commit the transaction
+ try {
+ TransactionUtil.commit(beganTx);
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ }
+ }
+ if (errConts == 0) {
+ Map<String, String> messageMap = UtilMisc.toMap("numConts", Integer.toString(numConts));
+ errMsg = UtilProperties.getMessage(resource,"contentevents.keyword_creation_complete_for_contents", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_EVENT_MESSAGE_", errMsg);
+ return "success";
+ } else {
+ Map<String, String> messageMap = UtilMisc.toMap("numConts", Integer.toString(numConts));
+ messageMap.put("errConts", Integer.toString(errConts));
+ errMsg = UtilProperties.getMessage(resource,"contentevents.keyword_creation_complete_for_contents_with_errors", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ }
}
Modified: ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml Fri Jun 3 03:05:23 2011
@@ -1864,6 +1864,12 @@ under the License.
<response name="success" type="view" value="EditContentKeywords"/>
<response name="error" type="view" value="EditContentKeywords"/>
</request-map>
+ <request-map uri="updateContentAllKeywords">
+ <security https="true" auth="true"/>
+ <event type="java" path="org.ofbiz.content.content.ContentEvents" invoke="updateAllContentKeywords"/>
+ <response name="success" type="view" value="FindContent"/>
+ <response name="error" type="view" value="FindContent"/>
+ </request-map>
<!-- View Mappings -->
<view-map name="main" type="screen" page="component://content/widget/CommonScreens.xml#main"/>
Modified: ofbiz/trunk/applications/content/widget/content/ContentMenus.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/widget/content/ContentMenus.xml?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/widget/content/ContentMenus.xml (original)
+++ ofbiz/trunk/applications/content/widget/content/ContentMenus.xml Fri Jun 3 03:05:23 2011
@@ -260,4 +260,15 @@ under the License.
<link target="showHelp?helpTopic=navigateHelp"/>
</menu-item>
</menu>
+ <menu name="contentMenu" menu-container-style="button-bar button-style-2" default-selected-style="selected">
+ <menu-item name="EditContent" title="${uiLabelMap.CommonCreateNew}" widget-style="buttontext create">
+ <link target="EditContent"/>
+ </menu-item>
+ <menu-item name="ContentSearchOptions" title="${uiLabelMap.CommonAdvancedSearch}" widget-style="buttontext">
+ <link target="ContentSearchOptions"/>
+ </menu-item>
+ <menu-item name="UpdateContentAllKeywords" title="${uiLabelMap.ContentAutoCreateKeywords}" widget-style="buttontext">
+ <link target="updateContentAllKeywords"/>
+ </menu-item>
+ </menu>
</menus>
Modified: ofbiz/trunk/applications/content/widget/content/ContentScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/widget/content/ContentScreens.xml?rev=1130890&r1=1130889&r2=1130890&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/widget/content/ContentScreens.xml (original)
+++ ofbiz/trunk/applications/content/widget/content/ContentScreens.xml Fri Jun 3 03:05:23 2011
@@ -43,8 +43,9 @@ under the License.
<decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
<decorator-section name="menu-bar">
<container style="button-bar">
- <link target="EditContent" text="${uiLabelMap.CommonCreateNew}" style="buttontext create"/>
- <link text="${uiLabelMap.CommonAdvancedSearch}" target="ContentSearchOptions" style="buttontext"/>
+ <!--<link target="EditContent" text="${uiLabelMap.CommonCreateNew}" style="buttontext create"/>
+ <link target="ContentSearchOptions" text="${uiLabelMap.CommonAdvancedSearch}" style="buttontext"/>-->
+ <include-menu name="contentMenu" location="component://content/widget/content/ContentMenus.xml"/>
</container>
</decorator-section>
<decorator-section name="search-options">