[OFBiz] SVN: r6770 - in trunk/applications/content: src/org/ofbiz/content src/org/ofbiz/content/compdoc src/org/ofbiz/content/view webapp/content/WEB-INF widget/compdoc

byersa@svn.ofbiz.org byersa at svn.ofbiz.org
Fri Feb 17 16:14:48 CST 2006


Author: byersa
Date: 2006-02-17 16:14:40 -0600 (Fri, 17 Feb 2006)
New Revision: 6770

Added:
   trunk/applications/content/src/org/ofbiz/content/compdoc/
   trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java
   trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java
Modified:
   trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java
   trunk/applications/content/webapp/content/WEB-INF/controller.xml
   trunk/applications/content/widget/compdoc/CompDocScreens.xml
Log:
Committing services and events



Added: trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java	2006-02-17 20:58:47 UTC (rev 6769)
+++ trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocEvents.java	2006-02-17 22:14:40 UTC (rev 6770)
@@ -0,0 +1,138 @@
+package org.ofbiz.content.compdoc;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.security.Security;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.webapp.event.CoreEvents;
+import org.ofbiz.service.GenericServiceException;
+
+
+/**
+ * CompDocEvents Class
+ *
+ * @author     <a href="mailto:byersa at automationgroups.com">Al Byers</a>
+ * @version    $Rev: 5462 $
+ * @since      3.0
+ *
+ * 
+ */
+
+public class CompDocEvents {
+
+    public static final String module = CompDocEvents.class.getName();
+    
+    /** 
+     * 
+     * @param request
+     * @param response
+     * @return
+     * 
+     * Creates the topmost Content entity of a Composite Document tree.
+     * Also creates an "empty" Composite Document Instance Content entity.
+     * Creates ContentRevision/Item records for each, as well.
+     */
+
+    public static String persistRootCompDoc(HttpServletRequest request, HttpServletResponse response) {
+        Map paramMap = UtilHttp.getParameterMap(request);
+        GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
+        LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");
+        Locale locale = UtilHttp.getLocale(request);
+        HttpSession session = request.getSession();
+        Security security = (Security)request.getAttribute("security");
+        GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
+        String contentId = (String)paramMap.get("contentId");
+        String instanceContentId = null;
+        
+        boolean contentExists = true;
+        if (UtilValidate.isEmpty(contentId)) {
+            contentExists = false;
+        } else {
+            try {
+                GenericValue val = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));
+                if (val == null)  contentExists = false;
+            } 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);
+                request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + " [" + "persistContentAndAssoc" + "]: " + e.toString());
+                return "error";
+           }
+        }
+        
+        ModelService modelService = null;
+        try {
+            modelService = dispatcher.getDispatchContext().getModelService("persistContentAndAssoc");
+        } catch (GenericServiceException e) {
+            String errMsg = "Error getting model service for serviceName, 'persistContentAndAssoc'. " + e.getMessage();
+            Debug.logError(errMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + "</li>");
+            return "error";
+        }
+        Map persistMap = modelService.makeValid(paramMap, ModelService.IN_PARAM);
+        persistMap.put("userLogin", userLogin);
+        try {
+            Map persistResult = dispatcher.runSync("persistContentAndAssoc", persistMap);
+            contentId = (String)persistResult.get("contentId");
+            //request.setAttribute("contentId", contentId);
+            Set keySet = persistResult.keySet();
+            Iterator iter = keySet.iterator();
+            while (iter.hasNext()) {
+                Object obj = iter.next();
+                Object val = persistResult.get(obj);
+                request.setAttribute(obj.toString(), val);
+            }
+            // Update ContentRevision and ContentRevisonItem
+            Map contentRevisionMap = new HashMap();
+            contentRevisionMap.put("itemContentId", contentId);
+            contentRevisionMap.put("contentId", contentId);
+            contentRevisionMap.put("userLogin", userLogin);
+            Map result = dispatcher.runSync("persistContentRevisionAndItem", contentRevisionMap);
+            keySet = result.keySet();
+            iter = keySet.iterator();
+            while (iter.hasNext()) {
+                Object obj = iter.next();
+                Object val = persistResult.get(obj);
+                request.setAttribute(obj.toString(), val);
+            }
+            String errorMsg = ServiceUtil.getErrorMessage(result);
+            if (UtilValidate.isNotEmpty(errorMsg)) {
+                String errMsg = "Error running serviceName, 'persistContentRevisionAndItem'. " + errorMsg;
+                Debug.logError(errMsg, module);
+                request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + "</li>");
+                return "error";
+            }
+            
+        } catch(GenericServiceException e) {
+            String errMsg = "Error running serviceName, 'persistContentAndAssoc'. " + e.getMessage();
+            Debug.logError(errMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + "</li>");
+            return "error";
+        }
+        return "success";
+    }
+    
+    public static String padNumberWithLeadingZeros(Long num, Integer padLen) {
+        String s = UtilFormatOut.formatPaddedNumber(num.longValue(), padLen.intValue());
+        return s;
+    }
+}

Added: trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java	2006-02-17 20:58:47 UTC (rev 6769)
+++ trunk/applications/content/src/org/ofbiz/content/compdoc/CompDocServices.java	2006-02-17 22:14:40 UTC (rev 6770)
@@ -0,0 +1,118 @@
+package org.ofbiz.content.compdoc;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.security.Security;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.webapp.event.CoreEvents;
+import org.ofbiz.service.GenericServiceException;
+
+
+/**
+ * CompDocEvents Class
+ *
+ * @author     <a href="mailto:byersa at automationgroups.com">Al Byers</a>
+ * @version    $Rev: 5462 $
+ * @since      3.0
+ *
+ * 
+ */
+
+public class CompDocServices {
+
+    public static final String module = CompDocServices.class.getName();
+    
+    /** 
+     * 
+     * @param request
+     * @param response
+     * @return
+     * 
+     * Creates the topmost Content entity of a Composite Document tree.
+     * Also creates an "empty" Composite Document Instance Content entity.
+     * Creates ContentRevision/Item records for each, as well.
+     */
+
+    public static Map persistRootCompDoc(DispatchContext dctx, Map context) {
+        
+        Map result = new HashMap();
+        GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Locale locale = (Locale)context.get("locale");
+        GenericValue userLogin = (GenericValue)context.get("userLogin");
+        String contentId = (String)context.get("contentId");
+        String instanceContentId = null;
+        
+        boolean contentExists = true;
+        if (UtilValidate.isEmpty(contentId)) {
+            contentExists = false;
+        } else {
+            try {
+                GenericValue val = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));
+                if (val == null)  contentExists = false;
+            } 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);
+                return ServiceUtil.returnError(errMsg);
+           }
+        }
+        
+        ModelService modelService = null;
+        try {
+            modelService = dispatcher.getDispatchContext().getModelService("persistContentAndAssoc");
+        } catch (GenericServiceException e) {
+            String errMsg = "Error getting model service for serviceName, 'persistContentAndAssoc'. " + e.getMessage();
+            Debug.logError(errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+        Map persistMap = modelService.makeValid(context, ModelService.IN_PARAM);
+        persistMap.put("userLogin", userLogin);
+        try {
+            Map persistResult = dispatcher.runSync("persistContentAndAssoc", persistMap);
+            contentId = (String)persistResult.get("contentId");
+            result.putAll(persistResult);
+            //request.setAttribute("contentId", contentId);
+            // Update ContentRevision and ContentRevisonItem
+            Map contentRevisionMap = new HashMap();
+            contentRevisionMap.put("itemContentId", contentId);
+            contentRevisionMap.put("contentId", contentId);
+            contentRevisionMap.put("userLogin", userLogin);
+            persistResult = dispatcher.runSync("persistContentRevisionAndItem", contentRevisionMap);
+            result.putAll(persistResult);
+            String errorMsg = ServiceUtil.getErrorMessage(result);
+            if (UtilValidate.isNotEmpty(errorMsg)) {
+                String errMsg = "Error running serviceName, 'persistContentRevisionAndItem'. " + errorMsg;
+                Debug.logError(errMsg, module);
+                return ServiceUtil.returnError(errMsg);
+            }
+            
+        } catch(GenericServiceException e) {
+            String errMsg = "Error running serviceName, 'persistContentAndAssoc'. " + e.getMessage();
+            Debug.logError(errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+        return result;
+    }
+    
+}

Modified: trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java	2006-02-17 20:58:47 UTC (rev 6769)
+++ trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java	2006-02-17 22:14:40 UTC (rev 6770)
@@ -95,18 +95,24 @@
             https = (String) servletContext.getAttribute("https");
         }
     	try {
-    		GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
+            Debug.logInfo("SCVH(0a)- dataResourceId:" + dataResourceId, module);
+GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
             if (UtilValidate.isEmpty(dataResourceId)) {
                 if (UtilValidate.isEmpty(contentRevisionSeqId)) {
                    GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
                    dataResourceId = content.getString("dataResourceId");
+                   Debug.logInfo("SCVH(0b)- dataResourceId:" + dataResourceId, module);
                 } else {
                    GenericValue contentRevisionItem = delegator.findByPrimaryKeyCache("ContentRevisionItem", UtilMisc.toMap("contentId", rootContentId, "itemContentId", contentId, "contentRevisionSeqId", contentRevisionSeqId));
                    if (contentRevisionItem == null) {
                        throw new ViewHandlerException("ContentRevisionItem record not found for contentId=" + rootContentId
                                                       + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId);
                    }
+                   Debug.logInfo("SCVH(1)- contentRevisionItem:" + contentRevisionItem, module);
+                   Debug.logInfo("SCVH(2)-contentId=" + rootContentId
+                           + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId, module);
                    dataResourceId = contentRevisionItem.getString("newDataResourceId");
+                   Debug.logInfo("SCVH(3)- dataResourceId:" + dataResourceId, module);
                 }
     		}
 			GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));

Modified: trunk/applications/content/webapp/content/WEB-INF/controller.xml
===================================================================
--- trunk/applications/content/webapp/content/WEB-INF/controller.xml	2006-02-17 20:58:47 UTC (rev 6769)
+++ trunk/applications/content/webapp/content/WEB-INF/controller.xml	2006-02-17 22:14:40 UTC (rev 6770)
@@ -1010,6 +1010,11 @@
         <response name="success" type="view" value="AddChildCompDocTemplate"/>
     </request-map>
    
+    <request-map uri="ViewCompDocContentBinary">
+        <security auth="true" https="true"/>
+        <response name="success" type="view" value="ViewCompDocContentBinary"/>
+    </request-map>
+   
     <request-map uri="createCompDocTemplate">
         <security auth="true" https="true"/>
         <event invoke="persistContentAndAssoc" path="" type="service"/>
@@ -1751,7 +1756,7 @@
     <view-map name="EditRootCompDocContent" page="component://content/widget/compdoc/CompDocScreens.xml#EditRootCompDocContent" type="screen"/>
     <view-map name="EditCompDocContentRole" page="component://content/widget/compdoc/CompDocScreens.xml#EditCompDocContentRole" type="screen"/>
     <view-map name="ViewInstances" page="component://content/widget/compdoc/CompDocScreens.xml#ViewInstances" type="screen"/>
-    <view-map name="ViewCompDocContent" page="component://content/widget/compdoc/CompDocScreens.xml#ViewCompDocContent" type="screen"/>
+    <view-map name="ViewCompDocContentBinary" page="" type="simplecontent"/>
 
     <view-map name="ViewSimpleContent" page="" type="simplecontent"/>
     <!-- end of view mappings -->

Modified: trunk/applications/content/widget/compdoc/CompDocScreens.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocScreens.xml	2006-02-17 20:58:47 UTC (rev 6769)
+++ trunk/applications/content/widget/compdoc/CompDocScreens.xml	2006-02-17 22:14:40 UTC (rev 6770)
@@ -400,7 +400,7 @@
                                         <set from-field="dummy.rootTemplateContentId" field="dummy.rootContentId" />
                                     </actions>
                                     <widgets>
-                                        <link target="ViewCompDocContent?contentId=${content.contentId}&amp;contentRevisionSeqId=${contentRevisionSeqId}&amp;rootTemplateContentId=${rootTemplateContentId}&amp;rootTemplateRevSeqId=${rootTemplateRevSeqId}&amp;rootInstanceContentId=${rootInstanceContentId}&amp;rootInstanceRevSeqId=${rootInstanceRevSeqId}" text="View CompDoc Content" style="buttontext"/>
+                                        <include-screen name="ContentViewLink"/>
                                         <include-form name="UploadCompDocContent" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                     </widgets>
                                 </section>
@@ -445,7 +445,6 @@
                                     </actions>
                                     <widgets>
                                         <include-screen name="ContentViewLink"/>
-                                        <link target="ViewCompDocContent?contentId=${content.contentId}&amp;contentRevisionSeqId=${contentRevisionSeqId}&amp;rootTemplateContentId=${rootTemplateContentId}&amp;rootTemplateRevSeqId=${rootTemplateRevSeqId}&amp;rootInstanceContentId=${rootInstanceContentId}&amp;rootInstanceRevSeqId=${rootInstanceRevSeqId}" text="View CompDoc Content" style="buttontext"/>
                                         <include-form name="UploadCompDocContent" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                     </widgets>
                                 </section>
@@ -480,7 +479,7 @@
                     <actions>
                     </actions>
                     <widgets>
-                        <link target="ViewCompDocContentBinary?contentId=${content.contentId}&amp;contentRevisionSeqId=${contentRevisionSeqId}&amp;rootContentId=${rootContentId}" text="View CompDoc Content" style="buttontext"/>
+                        <link target="ViewCompDocContentBinary?contentId=${content.contentId}&amp;contentRevisionSeqId=${contentRevisionSeqId}&amp;rootContentId=${dummy.rootContentId}" text="View CompDoc Content" style="buttontext"/>
                     </widgets>
                 </section>
                 <section>
@@ -823,7 +822,7 @@
                    <select-field field-name="fromDate"/>
                    <select-field field-name="sequenceNum"/>
 
-                   <order-by field-name="-sequenceNum"/>
+                   <order-by field-name="-maxRevisionSeqId"/>
                 </entity-condition>
                 <set from-field="assocRevisionItemViewList[0]" field="assocRevisionItemView"/>
             </actions>



More information about the Svn mailing list