[portal-commits] JBoss Portal SVN: r6112 - in trunk: cms/src/main/org/jboss/portal/cms/impl/interceptors and 5 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Jan 29 11:32:27 EST 2007


Author: sohil.shah at jboss.com
Date: 2007-01-29 11:32:27 -0500 (Mon, 29 Jan 2007)
New Revision: 6112

Added:
   trunk/cms/src/main/org/jboss/portal/cms/impl/interceptors/ApprovalWorkflowInterceptor.java
Modified:
   trunk/cms/src/main/org/jboss/portal/cms/CMS.java
   trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
   trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateNewVersionCommand.java
   trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/NewFileCommand.java
   trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/UpdateFileCommand.java
   trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
   trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
Log:
JBPORTAL-1186: Refactor Workflow integration from CMS Command to a CMS Interceptor

Modified: trunk/cms/src/main/org/jboss/portal/cms/CMS.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/CMS.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/cms/src/main/org/jboss/portal/cms/CMS.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -37,4 +37,10 @@
 
    /** Return default locale */
    String getDefaultLocale();
+   
+   /**
+    * 
+    * @return
+    */
+   public boolean isWorkflowActivated();
 }

Added: trunk/cms/src/main/org/jboss/portal/cms/impl/interceptors/ApprovalWorkflowInterceptor.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/interceptors/ApprovalWorkflowInterceptor.java	                        (rev 0)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/interceptors/ApprovalWorkflowInterceptor.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.jboss.portal.cms.impl.interceptors;
+
+import java.util.Date;
+import java.lang.reflect.Method;
+
+import org.jboss.portal.cms.CMSInterceptor;
+import org.jboss.portal.cms.impl.jcr.JCRCommand;
+import org.jboss.portal.cms.impl.jcr.JCRCommandContext;
+
+import org.jboss.portal.cms.impl.jcr.composite.NewFileCommand;
+import org.jboss.portal.cms.impl.jcr.composite.UpdateFileCommand;
+
+import org.jboss.portal.common.invocation.InvocationException;
+
+import org.jboss.portal.identity.User;
+
+import org.jboss.portal.workflow.cms.ApprovePublish;
+import org.jboss.portal.workflow.cms.Content;
+
+
+/**
+ * 
+ * Created on : Jan 29, 2007
+ * @author Sohil Shah - sohil.shah at jboss.com
+ *
+ */
+public class ApprovalWorkflowInterceptor extends CMSInterceptor
+{
+	/**
+	 * 
+	 */
+	protected Object invoke(JCRCommand invocation) throws Exception, InvocationException
+	{
+		//pre-processing
+		if(invocation instanceof NewFileCommand || invocation instanceof UpdateFileCommand)
+		{			
+			ApprovePublish approvePublishWorkflow = (ApprovePublish)invocation.getContext().
+			getAttribute(JCRCommandContext.scope, "approvePublishWorkflow");
+			
+			if(approvePublishWorkflow!=null)
+	    	{
+				User user = (User)invocation.getContext().getAttribute(JCRCommandContext.scope,"user");
+				org.jboss.portal.cms.model.Content content = null;
+				Method getContentMethod = invocation.getClass().getMethod("getContent", null);
+				content = (org.jboss.portal.cms.model.Content)getContentMethod.invoke(invocation, null);
+				
+	        	//call the workflow service here
+	        	Content workflowContent = new Content();
+	        	workflowContent.setPath(content.getBasePath());	            		            		            	
+	        	workflowContent.setUserName(user.getUserName());
+	        	workflowContent.setMimeType(content.getMimeType());
+	        	if(content.getBytes()!=null)
+	        	{
+	        		workflowContent.setSize(content.getBytes().length);
+	        	}
+	        	workflowContent.setCreationDate(new Date());
+	        	
+	        	long processId = approvePublishWorkflow.requestApproval(workflowContent);
+	        	
+	        	//save the processId in the context
+	        	invocation.setAttribute(JCRCommandContext.scope, "processid", String.valueOf(processId));
+	    	}
+		}
+		
+		Object returnVal = invocation.invokeNext();
+		
+		//post-processing
+		
+		//no post-processing needed for this interceptor
+		
+		return returnVal;
+	}
+}

Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -640,6 +640,15 @@
       }
       return obj;
    }
+   
+   /**
+    * 
+    * @return
+    */
+   public boolean isWorkflowActivated()
+   {
+	   return (this.approvePublishWorkflow!=null);
+   }
 
    public void setStackFactory(InterceptorStackFactory stackFactory)
    {

Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateNewVersionCommand.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateNewVersionCommand.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateNewVersionCommand.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -30,12 +30,9 @@
 
 import org.jboss.portal.identity.User;
 
-import org.jboss.portal.workflow.cms.ApprovePublish;
-
 import javax.jcr.Node;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Date;
 
 /**
  * Creates a new version of the content and labels it "LIVE".
@@ -76,6 +73,7 @@
       try
       {
     	  Scope scope = this.context.scope;
+    	  
          // create versions
          for (int i = 0; i < mContents.size(); i++)
          {
@@ -92,50 +90,21 @@
             contentNode.setProperty("portalcms:size", new StringValue(String.valueOf(content.getBytes().length)));
             context.getSession().save();
             
-            ApprovePublish approvePublishWorkflow = (ApprovePublish)this.context.getAttribute(scope, "approvePublishWorkflow");
-            
+            String processId = (String)context.getAttribute(scope, "processid");
+                                    
             //integration of publish/approval workflow
-            if(this.bMakeLive)
-            {
-            	if(approvePublishWorkflow!=null)
-            	{	            		            		            	            		            	
-	            	//call the workflow service here
-	            	org.jboss.portal.workflow.cms.Content workflowContent =
-	            	new org.jboss.portal.workflow.cms.Content();
-	            	workflowContent.setPath(content.getBasePath());	            		            		            	
-	            	workflowContent.setUserName(user.getUserName());
-	            	workflowContent.setMimeType(content.getMimeType());
-	            	if(content.getBytes()!=null)
-	            	{
-	            		workflowContent.setSize(content.getBytes().length);
-	            	}
-	            	workflowContent.setCreationDate(new Date());
-	            	
-	            	long processId = approvePublishWorkflow.requestApproval(workflowContent);
-	            	
-	            	if(processId > 0)
-	            	{
-		            	//now save workflow related meta data on this version 
-		            	//so that this version can be processed later in the execution
-		            	//of the workflow
-		            	contentNode.setProperty("portalcms:processid",String.valueOf(processId));
-		            	
-		            	//save
-		            	context.getSession().save();
-		            	
-		            	//create a new version, but dont make it live
-		            	VersionUtil.createVersion(contentNode,false);
-	            	}
-            	}
-            	else
-            	{
-            		//remove any processid if they are present on the node
-            		contentNode.setProperty("portalcms:processid",(String)null);
-            		contentNode.save();
-            		
-            		//no workflow is activated....just publish the content straight up
-            		VersionUtil.createVersion(contentNode, this.bMakeLive);
-            	}
+            if(this.bMakeLive && processId != null && processId.trim().length() != 0)
+            {	                        	
+            	//now save workflow related meta data on this version 
+            	//so that this version can be processed later in the execution
+            	//of the workflow
+            	contentNode.setProperty("portalcms:processid",processId);
+            	
+            	//save
+            	context.getSession().save();
+            	
+            	//create a new version, but dont make it live
+            	VersionUtil.createVersion(contentNode,false);
             }
             else
             {
@@ -148,6 +117,8 @@
             	VersionUtil.createVersion(contentNode, this.bMakeLive);
             }
          }
+         
+         
          context.getSession().save();
       }
       catch (Exception e)

Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/NewFileCommand.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/NewFileCommand.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/NewFileCommand.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -41,6 +41,7 @@
    
    //
    private String path = null;
+   private Content content = null;
    
    /**
     * 
@@ -50,12 +51,22 @@
    {
        return this.path;
    }
+   
+   /**
+    * 
+    * @return
+    */
+   public Content getContent()
+   {
+	   return this.content;
+   }
 
    public NewFileCommand(File file, Content content)
    {
       // setAttribute("file", file);
       // setAttribute("content", content);
        this.path = file.getBasePath();
+       this.content = content;
        
       Command saveFileCMD = new FileCreateCommand(file);
       commands.add(saveFileCMD);

Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/UpdateFileCommand.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/UpdateFileCommand.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/composite/UpdateFileCommand.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -39,6 +39,7 @@
 
    /** . */
    private String path;
+   private Content content;
 
    /** . */
    private Locale locale;
@@ -47,6 +48,15 @@
    {
       return path;
    }
+   
+   /**
+    * 
+    * @return
+    */
+   public Content getContent()
+   {
+	   return this.content;
+   }
 
    public Locale getLocale()
    {
@@ -57,6 +67,7 @@
    {
       path = file.getBasePath();
       locale = content.getLocale();
+      this.content = content;
 
       //
       FileUpdateCommand fileUpdateCMD = new FileUpdateCommand(file);

Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java	2007-01-29 16:32:27 UTC (rev 6112)
@@ -205,7 +205,16 @@
          rReq.setAttribute("currpath", sPath);
          
          //manage workflow accessibility check
-         rReq.setAttribute("manageWorkflowAccessible", new Boolean(this.isWorkflowManagementAccessible(rReq)));
+         boolean isWorkflowManagementAccessible = this.isWorkflowManagementAccessible(rReq);
+         boolean isWorkflowActivated = this.CMSService.isWorkflowActivated();
+         if(isWorkflowManagementAccessible && isWorkflowActivated)
+         {
+        	 rReq.setAttribute("manageWorkflowAccessible", new Boolean(true));
+         }
+         else
+         {
+        	 rReq.setAttribute("manageWorkflowAccessible", new Boolean(false));
+         }
          
          javax.portlet.PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(CMSAdminConstants.CMS_JSP_PATH + "/main.jsp");
          prd.include(rReq, rRes);
@@ -276,7 +285,16 @@
          rReq.setAttribute("contents", contents);
          
          //manage workflow accessibility check
-         rReq.setAttribute("manageWorkflowAccessible", new Boolean(this.isWorkflowManagementAccessible(rReq)));
+         boolean isWorkflowManagementAccessible = this.isWorkflowManagementAccessible(rReq);
+         boolean isWorkflowActivated = this.CMSService.isWorkflowActivated();
+         if(isWorkflowManagementAccessible && isWorkflowActivated)
+         {
+        	 rReq.setAttribute("manageWorkflowAccessible", new Boolean(true));
+         }
+         else
+         {
+        	 rReq.setAttribute("manageWorkflowAccessible", new Boolean(false));
+         }
          
          javax.portlet.PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(CMSAdminConstants.CMS_JSP_PATH + "/viewfile.jsp");
          prd.include(rReq, rRes);

Modified: trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml	2007-01-29 15:24:19 UTC (rev 6111)
+++ trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml	2007-01-29 16:32:27 UTC (rev 6112)
@@ -59,7 +59,9 @@
       <depends>portal:service=Hibernate,type=CMS</depends>
       <depends optional-attribute-name="IdentityServiceController" proxy-type="attribute">portal:service=Module,type=IdentityServiceController</depends>
       <!-- Add this to activate publish/approval workflow integration -->
-      <!--<depends optional-attribute-name="ApprovePublishWorkflow" proxy-type="attribute">portal:service=ApprovePublish,type=Workflow</depends>-->
+      <!--
+      <depends optional-attribute-name="ApprovePublishWorkflow" proxy-type="attribute">portal:service=ApprovePublish,type=Workflow</depends>
+      -->
       <depends optional-attribute-name="StackFactory" proxy-type="attribute">portal:service=InterceptorStackFactory,type=Cms</depends>
       <attribute name="DoChecking">true</attribute>
       <attribute name="DefaultContentLocation">portal/cms/conf/default-content/default/</attribute>
@@ -432,6 +434,7 @@
       <xmbean/>
       <depends-list optional-attribute-name="InterceptorNames">
          <depends-list-element>portal:service=Interceptor,type=Cms,name=ACL</depends-list-element>
+         <depends-list-element>portal:service=Interceptor,type=Cms,name=ApprovalWorkflow</depends-list-element>
       </depends-list>
    </mbean> 
     
@@ -507,6 +510,16 @@
       <depends>portal:service=Module,type=IdentityServiceController</depends>      
    </mbean>
    
+   <!-- Approval Workflow Interceptor -->
+   <mbean
+      code="org.jboss.portal.cms.impl.interceptors.ApprovalWorkflowInterceptor"
+      name="portal:service=Interceptor,type=Cms,name=ApprovalWorkflow"
+      xmbean-dd=""
+      xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+      <xmbean/>                  
+      <depends>portal:service=Hibernate,type=CMS</depends>      
+   </mbean>
+   
    <!--  logging interceptor -->
    <!--mbean
       code="org.jboss.portal.cms.impl.interceptors.LogInterceptor"




More information about the portal-commits mailing list