Author: sohil.shah(a)jboss.com
Date: 2008-07-25 16:13:04 -0400 (Fri, 25 Jul 2008)
New Revision: 11591
Modified:
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/cms/workflow/FinalizePublish.java
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/test/cms/workflow/TestDeniedPublish.java
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
Log:
JBPORTAL-2088 - uploading a file shows up in list when it's not approved
Modified:
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/cms/workflow/FinalizePublish.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/cms/workflow/FinalizePublish.java 2008-07-25
20:12:03 UTC (rev 11590)
+++
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/cms/workflow/FinalizePublish.java 2008-07-25
20:13:04 UTC (rev 11591)
@@ -34,6 +34,7 @@
import javax.naming.InitialContext;
import java.util.List;
import java.util.Locale;
+import java.util.ArrayList;
/**
* Created on : Dec 20, 2006
@@ -58,16 +59,15 @@
long processId = executionContext.getProcessInstance().getId();
CMS cms = this.getCMSService();
+ int lastIndex = content.getPath().lastIndexOf('/');
+ String path = content.getPath().substring(0, lastIndex);
+ String language = content.getPath().substring(lastIndex + 1);
if (approved)
{
ACLInterceptor.turnOff();
JCRCMS.turnOffWorkflow();
//create this content in the CMS and make it live
- int lastIndex = content.getPath().lastIndexOf('/');
- String path = content.getPath().substring(0, lastIndex);
- String language = content.getPath().substring(lastIndex + 1);
-
Command command =
cms.getCommandFactory().createContentGetVersionsCommand(content.getPath());
List versions = (List)cms.execute(command);
org.jboss.portal.cms.model.Content processContent =
this.findProcessContent(processId, versions);
@@ -100,6 +100,27 @@
JCRCMS.turnOnWorkflow();
ACLInterceptor.turnOn();
}
+ else
+ {
+ ACLInterceptor.turnOff();
+ JCRCMS.turnOffWorkflow();
+
+ //Check if there are any published versions of this file. If not, this is a new
file that was denied publishing
+ //hence delete the file itself
+ Command command =
cms.getCommandFactory().createContentGetVersionsCommand(content.getPath());
+ List versions = (List)cms.execute(command);
+ List filtered = this.filterPending(versions);
+ if(filtered == null || filtered.isEmpty())
+ {
+ //Delete this file
+ Command deleteCommand = cms.getCommandFactory().createDeleteCommand(path);
+ cms.execute(deleteCommand);
+ }
+
+
+ JCRCMS.turnOnWorkflow();
+ ACLInterceptor.turnOn();
+ }
}
/**
@@ -130,6 +151,30 @@
return content;
}
+
+ /**
+ *
+ * @param versions
+ * @return
+ */
+ private List filterPending(List versions)
+ {
+ List filtered = new ArrayList();
+
+ if(versions != null)
+ {
+ for(int i=0; i<versions.size(); i++)
+ {
+ org.jboss.portal.cms.model.Content content =
(org.jboss.portal.cms.model.Content)versions.get(i);
+ if(!content.isWaitingForPublishApproval())
+ {
+ filtered.add(content);
+ }
+ }
+ }
+
+ return filtered;
+ }
/** @return */
private CMS getCMSService()
Modified:
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/test/cms/workflow/TestDeniedPublish.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/test/cms/workflow/TestDeniedPublish.java 2008-07-25
20:12:03 UTC (rev 11590)
+++
branches/JBoss_Portal_Branch_2_7/cms/src/main/org/jboss/portal/test/cms/workflow/TestDeniedPublish.java 2008-07-25
20:13:04 UTC (rev 11591)
@@ -91,60 +91,22 @@
/** @throws Exception */
- public void test() throws Exception
+ public void testPublishExistingFile() throws Exception
{
- //Execute file creation as a regular user/non-manager
- this.runAs("user");
-
- //Add a new file to the CMS
- File file = new FileImpl();
- file.setBasePath(this.newFile);
-
- Content content = new ContentImpl();
- content.setEncoding("UTF-8");
- content.setTitle("English Title");
- content.setDescription("English Description");
- content.setBasePath(this.newFile + "/" + Locale.ENGLISH.getLanguage());
- content.setBytes("newdata".getBytes());
- content.setMimeType("text/html");
- file.setContent(Locale.ENGLISH, content);
-
- Command newFileCommand =
this.service.getCommandFactory().createNewFileCommand(file, content);
- this.service.execute(newFileCommand);
-
- //Make sure this resource is not published into the CMS yet
- Command fileGet =
this.service.getCommandFactory().createFileGetCommand(this.newFile, Locale.ENGLISH);
- File assertFile = (File)this.service.execute(fileGet);
- assertNull(assertFile.getContent());
-
- //Check the pending queue for this file
ApprovePublish approvePublish = this.service.getApprovePublishWorkflow();
- Collection queueItems = approvePublish.getPendingQueue(this.newFile);
- assertNotNull(queueItems);
- assertEquals(1, queueItems.size());
-
- //Deny the publish of this file into the CMS
Set managers = approvePublish.getManagers();
String manager = (String)managers.iterator().next();
- org.jboss.portal.cms.workflow.Content pendingItem =
(org.jboss.portal.cms.workflow.Content)queueItems.iterator().next();
- approvePublish.processManagerResponse(Long.parseLong(pendingItem.getProcessId()),
manager.toLowerCase(), false);
-
- //Make sure this resource is not published into the CMS, and removed from the
pending queue
- assertFile = (File)this.service.execute(fileGet);
- assertNull(assertFile.getContent());
- queueItems = approvePublish.getPendingQueue(this.newFile);
- if (queueItems != null)
- {
- assertTrue(queueItems.isEmpty());
- }
-
+
+ //Execute file creation as a regular user/non-manager
+ this.createNewFile();
+
//Check for the existence of a file to be updated first
Command existsCommand =
this.service.getCommandFactory().createItemExistsCommand(this.updateFile);
Boolean exists = (Boolean)this.service.execute(existsCommand);
assertTrue(exists.booleanValue());
//Get the file to be updated
- fileGet = this.service.getCommandFactory().createFileGetCommand(this.updateFile,
new Locale(this.service.getDefaultLocale()));
+ Command fileGet =
this.service.getCommandFactory().createFileGetCommand(this.updateFile, new
Locale(this.service.getDefaultLocale()));
File updateFile = (File)this.service.execute(fileGet);
assertNotNull(updateFile);
assertNotNull(updateFile.getContent());
@@ -163,19 +125,19 @@
this.service.execute(updateFileCommand);
//Make sure a new LIVE version of this resource is not published into the CMS
- assertFile = (File)this.service.execute(fileGet);
+ File assertFile = (File)this.service.execute(fileGet);
versions = (List)this.service.execute(getVersions);
assertEquals(new String(assertFile.getContent().getBytes()), oldContent);
assertEquals(assertFile.getContent().getVersionNumber(), oldLiveVersion);
assertEquals(2, versions.size());
//Checking pending queue for a version of this file to be approved
- queueItems = approvePublish.getPendingQueue(this.updateFile);
+ Collection queueItems = approvePublish.getPendingQueue(this.updateFile);
assertNotNull(queueItems);
assertEquals(1, queueItems.size());
//Deny publishing of this new version into the CMS
- pendingItem = (org.jboss.portal.cms.workflow.Content)queueItems.iterator().next();
+ org.jboss.portal.cms.workflow.Content pendingItem =
(org.jboss.portal.cms.workflow.Content)queueItems.iterator().next();
approvePublish.processManagerResponse(Long.parseLong(pendingItem.getProcessId()),
manager.toLowerCase(), false);
//Check for the success of this denial, and removal from the pending queue
@@ -189,5 +151,87 @@
{
assertTrue(queueItems.isEmpty());
}
- }
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testPublishNewFile() throws Exception
+ {
+ //Execute file creation as a regular user/non-manager
+ this.runAs("user");
+
+ //Add a new file to the CMS
+ File file = new FileImpl();
+ file.setBasePath(this.newFile);
+
+ Content content = new ContentImpl();
+ content.setEncoding("UTF-8");
+ content.setTitle("English Title");
+ content.setDescription("English Description");
+ content.setBasePath(this.newFile + "/" + Locale.ENGLISH.getLanguage());
+ content.setBytes("newdata".getBytes());
+ content.setMimeType("text/html");
+ file.setContent(Locale.ENGLISH, content);
+
+ Command newFileCommand =
this.service.getCommandFactory().createNewFileCommand(file, content);
+ this.service.execute(newFileCommand);
+
+ //Make sure this resource is not published into the CMS yet
+ Command fileGet =
this.service.getCommandFactory().createFileGetCommand(this.newFile, Locale.ENGLISH);
+ File assertFile = (File)this.service.execute(fileGet);
+ assertNull(assertFile.getContent());
+
+ //Check the pending queue for this file
+ ApprovePublish approvePublish = this.service.getApprovePublishWorkflow();
+ Collection queueItems = approvePublish.getPendingQueue(this.newFile);
+ assertNotNull(queueItems);
+ assertEquals(1, queueItems.size());
+
+ //Deny the publish of this file into the CMS
+ Set managers = approvePublish.getManagers();
+ String manager = (String)managers.iterator().next();
+ org.jboss.portal.cms.workflow.Content pendingItem =
(org.jboss.portal.cms.workflow.Content)queueItems.iterator().next();
+ approvePublish.processManagerResponse(Long.parseLong(pendingItem.getProcessId()),
manager.toLowerCase(), false);
+
+ //Make sure the file/content does not exist in the CMS, and removed from the
pending queue
+ assertFile = (File)this.service.execute(fileGet);
+ assertNull(assertFile);
+ queueItems = approvePublish.getPendingQueue(this.newFile);
+ if (queueItems != null)
+ {
+ assertTrue(queueItems.isEmpty());
+ }
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ private void createNewFile() throws Exception
+ {
+ JCRCMS.turnOffWorkflow();
+
+ //Execute file creation as a regular user/non-manager
+ this.runAs("user");
+
+ //Add a new file to the CMS
+ File file = new FileImpl();
+ file.setBasePath(this.newFile);
+
+ Content content = new ContentImpl();
+ content.setEncoding("UTF-8");
+ content.setTitle("English Title");
+ content.setDescription("English Description");
+ content.setBasePath(this.newFile + "/" + Locale.ENGLISH.getLanguage());
+ content.setBytes("newdata".getBytes());
+ content.setMimeType("text/html");
+ file.setContent(Locale.ENGLISH, content);
+
+ Command newFileCommand =
this.service.getCommandFactory().createNewFileCommand(file, content);
+ this.service.execute(newFileCommand);
+
+ JCRCMS.turnOnWorkflow();
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-07-25
20:12:03 UTC (rev 11590)
+++
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-07-25
20:13:04 UTC (rev 11591)
@@ -1421,8 +1421,31 @@
}
return;
}
- aRes.setRenderParameter("path",
aReq.getParameter("path"));
- aRes.setRenderParameter("op", CMSAdminConstants.OP_VIEWFILE);
+
+ String filePath = aReq.getParameter("path");
+ String parentPath = null;
+ try
+ {
+ parentPath = NodeUtil.getParentPath(filePath);
+ }
+ catch(Exception e)
+ {
+ parentPath = "/";
+ }
+
+ //Check if this file still exists
+ Command existsCmd =
this.CMSService.getCommandFactory().createItemExistsCommand(filePath);
+ boolean exists =
((Boolean)this.CMSService.execute(existsCmd)).booleanValue();
+ if(exists)
+ {
+ aRes.setRenderParameter("path", filePath);
+ aRes.setRenderParameter("op", CMSAdminConstants.OP_VIEWFILE);
+ }
+ else
+ {
+ aRes.setRenderParameter("path", parentPath);
+ aRes.setRenderParameter("op", CMSAdminConstants.OP_MAIN);
+ }
}
else if(CMSAdminConstants.OP_MODIFYANDAPPROVE.equals(op))
{