Author: sohil.shah(a)jboss.com
Date: 2008-05-04 02:49:23 -0400 (Sun, 04 May 2008)
New Revision: 10735
Added:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CommandFactory.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCommandFactory.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/StoreArchiveCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/main.jsp
Log:
[JBPORTAL-1899] - Uploading large archives into Portal CMS results in Transaction timeout
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CommandFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CommandFactory.java 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CommandFactory.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -25,6 +25,7 @@
import org.jboss.portal.cms.model.Content;
import org.jboss.portal.cms.model.File;
import org.jboss.portal.cms.model.Folder;
+import org.jboss.portal.cms.CMS;
import org.jboss.portal.search.impl.jcr.JCRQuery;
import java.io.InputStream;
@@ -74,6 +75,8 @@
Command createContentCreateNewVersionCommand(List contents, boolean bMakeLive);
Command createStoreArchiveCommand(String sRootPath, InputStream is, String
sLanguage);
+
+ Command createAsyncStoreArchiveCommand(CMS cms, String sRootPath, InputStream is,
String sLanguage);
Command createItemExistsCommand(String sPath);
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCommandFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCommandFactory.java 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCommandFactory.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -50,8 +50,11 @@
import org.jboss.portal.cms.model.Content;
import org.jboss.portal.cms.model.File;
import org.jboss.portal.cms.model.Folder;
+import org.jboss.portal.cms.CMS;
import org.jboss.portal.search.impl.jcr.JCRQuery;
+import org.jboss.portal.cms.impl.jcr.command.AsyncStoreArchiveCommand;
+
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
@@ -153,8 +156,13 @@
public Command createStoreArchiveCommand(String sRootPath, InputStream is, String
sLanguage)
{
- return new StoreArchiveCommand(sRootPath, is, sLanguage);
+ return new StoreArchiveCommand(sRootPath, is, sLanguage);
}
+
+ public Command createAsyncStoreArchiveCommand(CMS cms, String sRootPath, InputStream
is, String sLanguage)
+ {
+ return new AsyncStoreArchiveCommand(cms,sRootPath, is, sLanguage);
+ }
public Command createItemExistsCommand(String sPath)
{
Added:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -0,0 +1,127 @@
+/******************************************************************************
+ * 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.jcr.command;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.portal.cms.impl.jcr.JCRCMS;
+import org.jboss.portal.cms.impl.jcr.JCRCommand;
+import org.jboss.portal.cms.impl.jcr.JCRCommandContext;
+import org.jboss.portal.cms.CMSException;
+
+
+import java.io.InputStream;
+
+import org.jboss.portal.cms.CMS;
+
+/**
+ * Saves an uploaded archive to the repo.
+ *
+ * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class AsyncStoreArchiveCommand extends JCRCommand
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1568453649437987499L;
+ private static Logger log = Logger.getLogger(AsyncStoreArchiveCommand.class);
+
+ String msRootPath;
+ InputStream mIS;
+ String msLanguage;
+ CMS cms = null;
+
+ private Object user = null;
+ private Object approvePublishWorkflow = null;
+
+
+ /**
+ * @param sRootPath
+ * @param is
+ * @param sLanguage
+ */
+ public AsyncStoreArchiveCommand(CMS cms, String sRootPath, InputStream is, String
sLanguage)
+ {
+ this.msRootPath = sRootPath;
+ this.mIS = is;
+ this.msLanguage = sLanguage;
+ this.cms = cms;
+ }
+
+ /**
+ *
+ */
+ public Object execute()
+ {
+ try
+ {
+ //Capture context information to be passed to the Async processor
+ this.user = context.getAttribute(JCRCommandContext.scope, "user");
+ this.approvePublishWorkflow = context.getAttribute(JCRCommandContext.scope,
"approvePublishWorkflow");
+
+ Thread t = new Thread(new AsyncProcessor());
+ t.start();
+
+ return null;
+ }
+ catch(Exception e)
+ {
+ throw new CMSException(e);
+ }
+ }
+
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ private class AsyncProcessor implements Runnable
+ {
+ /**
+ *
+ */
+ public void run()
+ {
+ try
+ {
+ log.info("Async Processing started....................");
+
+ //Setup context information to be propagated to the new CMS Service Command
call
+ JCRCMS.getUserInfo().set(user);
+ if(approvePublishWorkflow != null)
+ {
+ JCRCMS.turnOnWorkflow();
+ }
+
+ JCRCommand storeArchiveCommand =
(JCRCommand)cms.getCommandFactory().createStoreArchiveCommand(msRootPath, mIS,
msLanguage);
+ cms.execute(storeArchiveCommand);
+
+ log.info("Async Processing finished..................");
+ }
+ catch(Exception e)
+ {
+ log.error("Asynchronous Processing of archive
failed------------------------------------");
+ log.error(this, e);
+
log.error("-----------------------------------------------------------------------------");
+ }
+ }
+ }
+}
\ No newline at end of file
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/StoreArchiveCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/StoreArchiveCommand.java 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/StoreArchiveCommand.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.cms.impl.jcr.command;
+import org.apache.log4j.Logger;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.jboss.portal.cms.CMSException;
@@ -37,10 +38,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
-import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
@@ -54,6 +53,8 @@
{
/** The serialVersionUID */
private static final long serialVersionUID = 1568453649437987499L;
+ private static Logger log = Logger.getLogger(StoreArchiveCommand.class);
+
String msRootPath;
InputStream mIS;
String msLanguage;
@@ -75,7 +76,6 @@
*/
public Object execute()
{
- List contents = new ArrayList();
File tmpFile = null;
try
{
@@ -128,8 +128,10 @@
JCRCommand saveContentCMD =
(JCRCommand)context.getCommandFactory().createContentSaveCommand(file);
context.execute(saveContentCMD);
-
- contents.add(content);
+
+ //Add this content to the repository
+ JCRCommand createContent =
(JCRCommand)context.getCommandFactory().createContentCreateNewVersionCommand(content,
true);
+ context.execute(createContent);
}
else // isDirectory
{
@@ -168,11 +170,11 @@
}
}
}
- return contents;
+ return null;
}
catch (Exception e)
{
- e.printStackTrace();
+ throw new CMSException(e);
}
finally
{
@@ -181,7 +183,6 @@
tmpFile.delete();
}
}
- return null;
}
/** @param parentPath */
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -80,13 +80,9 @@
service.setDefaultLocale(Locale.ENGLISH.getLanguage());
InputStream is = IOTools.safeBufferedWrapper(new FileInputStream(sZipFile));
Command storearchiveCMD =
service.getCommandFactory().createStoreArchiveCommand("", is, "en");
- List contentsToVersion = (List)service.execute(storearchiveCMD);
- is.close();
+ service.execute(storearchiveCMD);
+ is.close();
- Command createVersions = service.getCommandFactory()
- .createContentCreateNewVersionCommand(contentsToVersion, true);
- service.execute(createVersions);
-
// retrieve list
Command listCMD =
service.getCommandFactory().createFolderGetListCommand("/ziptest/poop");
Folder whopper = (Folder)service.execute(listCMD);
@@ -107,13 +103,6 @@
Command listCMD3 =
service.getCommandFactory().createFolderGetListCommand("/");
Folder whopper3 = (Folder)service.execute(listCMD3);
List folders3 = whopper3.getFolders();
- List files3 = whopper3.getFiles();
-
- //Create and Test an archive containing foreign files
- is = IOTools.safeBufferedWrapper(new FileInputStream(this.foreignArchive));
- storearchiveCMD =
service.getCommandFactory().createStoreArchiveCommand("", is, "en");
- contentsToVersion = (List)service.execute(storearchiveCMD);
- assertTrue("Foreign Archive Creation Failed", (contentsToVersion != null
&& !contentsToVersion.isEmpty() && contentsToVersion.size() == 2));
- is.close();
+ List files3 = whopper3.getFiles();
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-05-04
06:49:23 UTC (rev 10735)
@@ -68,6 +68,7 @@
import org.jboss.portlet.JBossRenderResponse;
import javax.naming.InitialContext;
+import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
@@ -85,6 +86,7 @@
import java.util.Locale;
import java.util.Set;
import java.util.Vector;
+import java.util.ResourceBundle;
/**
* @author <a href="mailto:roy@jboss.org">Roy Russo</a>
@@ -99,6 +101,7 @@
private MembershipModule membershipModule;
private ApprovePublish approvePublish;
private AuthorizationManager authorizationManager;
+ private ResourceBundle resources = null;
public void init() throws PortletException
@@ -130,9 +133,22 @@
throw new PortletException("Authorization Service not found");
}
- this.initializeApprovePublishWorkflow();
+ this.initializeApprovePublishWorkflow();
}
+
+ /**
+ *
+ */
+ public void init(PortletConfig config) throws PortletException
+ {
+ super.init(config);
+
+ //Get the Resource Bundle for this Portlet
+ this.resources = config.getResourceBundle(Locale.getDefault());
+ }
+
+
protected void doView(final JBossRenderRequest rReq, final JBossRenderResponse rRes)
throws PortletException, IOException, UnavailableException
{
@@ -222,6 +238,14 @@
{
rReq.setAttribute("manageWorkflowAccessible", new Boolean(false));
}
+
+ //Messages
+ if(rReq.getPortletSession().getAttribute("messages") != null)
+ {
+ Object messages =
rReq.getPortletSession().getAttribute("messages");
+ rReq.getPortletSession().removeAttribute("messages");
+ rReq.setAttribute("messages", messages);
+ }
javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMSAdminConstants.CMS_JSP_PATH +
"/main.jsp");
prd.include(rReq, rRes);
@@ -852,12 +876,14 @@
if (!item.isFormField())
{
InputStream is = item.getInputStream();
- Command storearchiveCMD =
CMSService.getCommandFactory().createStoreArchiveCommand(sPath, is, sLanguage);
- List contentstoVersion = (List)CMSService.execute(storearchiveCMD);
+
+ Command storearchiveCMD =
CMSService.getCommandFactory().createAsyncStoreArchiveCommand(CMSService, sPath, is,
sLanguage);
+ CMSService.execute(storearchiveCMD);
+
+ List messages = new ArrayList();
+
messages.add(this.resources.getObject("CMS_MSG_UPLOADARCHIVE_ASYNC"));
+ aReq.getPortletSession().setAttribute("messages",
messages);
- Command createVersions =
CMSService.getCommandFactory().createContentCreateNewVersionCommand(contentstoVersion,
true);
- CMSService.execute(createVersions);
-
aRes.setRenderParameter("path",
FileUtil.cleanDoubleSlashes(sPath));
}
else
@@ -870,13 +896,13 @@
else if ("language".equals(fieldName))
{
sLanguage = item.getString(aReq.getCharacterEncoding());
- }
+ }
}
}
}
catch (Exception e)
{
- throw new PortletException(e);
+ throw new PortletException("CMS_ERROR_UPLOADARCHIVE_ASYNC");
}
aRes.setRenderParameter("op", CMSAdminConstants.OP_MAIN);
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2008-05-04
06:49:23 UTC (rev 10735)
@@ -58,6 +58,7 @@
CMS_CREATEFOLDER= Create Folder
CMS_CREATEFILE=Create File
CMS_UPLOADARCHIVE=Upload Archive
+CMS_UPLOADARCHIVE_ASYNC=Process Asynchronously
CMS_BACKTOBROWSER=Back to Directory Browser
CMS_TRANSFER=Import/Export
CMS_EXPORTARCHIVE=Export Folder
@@ -96,4 +97,6 @@
CMS_PATH=Location
CMS_EMPTY_FOLDER=This folder is empty.
-
\ No newline at end of file
+
+CMS_ERROR_UPLOADARCHIVE_ASYNC=An error occurred while processing your archive. Please try
again with 'Asynchronous Processing' activated
+CMS_MSG_UPLOADARCHIVE_ASYNC=Your archive has been accepted for processing. The resources
will appear in your Folder once the processing is finished
\ No newline at end of file
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/main.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/main.jsp 2008-05-02
05:08:09 UTC (rev 10734)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/main.jsp 2008-05-04
06:49:23 UTC (rev 10735)
@@ -21,6 +21,7 @@
String createDate = "";
String modifiedDate = "";
Boolean manageWorkflowAccessible =
(Boolean)request.getAttribute("manageWorkflowAccessible");
+ List messages = (List)request.getAttribute("messages");
%>
<div class="admin-ui">
@@ -31,6 +32,23 @@
<div class="cms-tab-container">
+<!-- Displaying any messages that may have occurred during this request -->
+<%if(messages != null && !messages.isEmpty()){%>
+<table width="100%">
+ <th colspan="2"><h3
class="sectionTitle-blue">Messages:</h3></th>
+ <%for(int i=0; i<messages.size(); i++){%>
+ <tr colspan="2" align="center">
+ <td colspan="2">
+ <font color="red">
+ <%=(String)messages.get(i)%>
+ </font>
+ </td>
+ </tr>
+ <%}%>
+</table>
+<br/><br/>
+<%}%>
+
<!-- Currently browsing -->
<ul class="objectpath">
<li class="pathItem"><a href="<portlet:renderURL>