Author: sohil.shah(a)jboss.com
Date: 2008-07-01 15:59:35 -0400 (Tue, 01 Jul 2008)
New Revision: 11239
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/test/cms/commands/TestFileArchiveUpload.java
Log:
JBPORTAL-2002 - VersionException thrown when you try to upload an archive (ZIP) that
contains files that already exists in the repository
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-07-01
19:55:44 UTC (rev 11238)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/StoreArchiveCommand.java 2008-07-01
19:59:35 UTC (rev 11239)
@@ -113,25 +113,23 @@
content.setBasePath(sBasePath + "/" + this.msLanguage);
content.setBytes(zipBytes);
file.setContent(new Locale(this.msLanguage), content);
-
- // in case folder does not exist, yet.
- String sParentPath = NodeUtil.getParentPath(sBasePath);
- JCRCommand nodeExists =
(JCRCommand)context.getCommandFactory().createItemExistsCommand(sParentPath);
+
+ //Store the file
+ JCRCommand nodeExists =
(JCRCommand)context.getCommandFactory().createItemExistsCommand(file.getBasePath());
Boolean bExists = (Boolean)context.execute(nodeExists);
if (!bExists.booleanValue())
{
- this.createParentHierarchy(sParentPath);
+ //Create new file
+ JCRCommand newFile =
(JCRCommand)context.getCommandFactory().createNewFileCommand(file, content);
+ context.execute(newFile);
}
-
- JCRCommand fileSave =
(JCRCommand)context.getCommandFactory().createFileSaveCommand(file);
- context.execute(fileSave);
-
- JCRCommand saveContentCMD =
(JCRCommand)context.getCommandFactory().createContentSaveCommand(file);
- context.execute(saveContentCMD);
-
- //Add this content to the repository
- JCRCommand createContent =
(JCRCommand)context.getCommandFactory().createContentCreateNewVersionCommand(content,
true);
- context.execute(createContent);
+ else
+ {
+ //Update the existing one, and make the new version created
+ //in return as live
+ JCRCommand updateFile =
(JCRCommand)context.getCommandFactory().createUpdateFileCommand(file, content, true);
+ context.execute(updateFile);
+ }
}
else // isDirectory
{
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-07-01
19:55:44 UTC (rev 11238)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2008-07-01
19:59:35 UTC (rev 11239)
@@ -26,6 +26,7 @@
import org.jboss.portal.cms.CMSException;
import org.jboss.portal.cms.Command;
import org.jboss.portal.cms.model.Folder;
+import org.jboss.portal.cms.model.File;
import org.jboss.portal.common.io.IOTools;
import java.io.FileInputStream;
@@ -77,13 +78,76 @@
public void testArchiveUpload() throws CMSException, IOException
{
+ //create archive
+ this.runArchive();
+ this.assertArchiveUploadCreate();
+
+ //update archive
+ this.runArchive();
+ this.assertArchiveUploadUpdate();
+
+ }
+
+ private void runArchive() throws IOException
+ {
service.setDefaultLocale(Locale.ENGLISH.getLanguage());
- InputStream is = IOTools.safeBufferedWrapper(new FileInputStream(sZipFile));
- Command storearchiveCMD =
service.getCommandFactory().createStoreArchiveCommand("", is, "en");
- service.execute(storearchiveCMD);
- is.close();
+ InputStream is = null;
+ try
+ {
+ is = IOTools.safeBufferedWrapper(new FileInputStream(sZipFile));
+ Command storearchiveCMD =
service.getCommandFactory().createStoreArchiveCommand("", is, "en");
+ service.execute(storearchiveCMD);
+ }
+ finally
+ {
+ if(is != null)
+ {
+ is.close();
+ }
+ }
+ }
+
+ private void assertArchiveUploadCreate()
+ {
+ //retrieve list
+ Command listCMD =
service.getCommandFactory().createFolderGetListCommand("/ziptest/poop");
+ Folder whopper = (Folder)service.execute(listCMD);
+ List folders = whopper.getFolders();
+ List files = whopper.getFiles();
+ assertEquals("Folder Size incorrect", folders.size(), 1);
+ assertEquals("File Size incorrect", files.size(), 1);
// retrieve list
+ Command listCMD2 =
service.getCommandFactory().createFolderGetListCommand("/ziptest/poop/music");
+ Folder whopper2 = (Folder)service.execute(listCMD2);
+ List folders2 = whopper2.getFolders();
+ List files2 = whopper2.getFiles();
+ assertEquals("Folder Size incorrect", folders2.size(), 0);
+ assertEquals("File Size incorrect", files2.size(), 1);
+
+ //Look for single versions of files
+ for(int i=0; i<files.size(); i++)
+ {
+ File file = (File)files.get(i);
+
+ Command versionsCMD =
service.getCommandFactory().createContentGetVersionsCommand(file.getBasePath()+"/en");
+ List versions = (List)service.execute(versionsCMD);
+ assertEquals("Multiple Versions not Found", versions.size(), 1);
+ }
+
+ for(int i=0; i<files2.size(); i++)
+ {
+ File file = (File)files2.get(i);
+
+ Command versionsCMD =
service.getCommandFactory().createContentGetVersionsCommand(file.getBasePath()+"/en");
+ List versions = (List)service.execute(versionsCMD);
+ assertEquals("Multiple Versions not Found", versions.size(), 1);
+ }
+ }
+
+ private void assertArchiveUploadUpdate()
+ {
+ //retrieve list
Command listCMD =
service.getCommandFactory().createFolderGetListCommand("/ziptest/poop");
Folder whopper = (Folder)service.execute(listCMD);
List folders = whopper.getFolders();
@@ -98,11 +162,24 @@
List files2 = whopper2.getFiles();
assertEquals("Folder Size incorrect", folders2.size(), 0);
assertEquals("File Size incorrect", files2.size(), 1);
-
- // retrieve list
- Command listCMD3 =
service.getCommandFactory().createFolderGetListCommand("/");
- Folder whopper3 = (Folder)service.execute(listCMD3);
- List folders3 = whopper3.getFolders();
- List files3 = whopper3.getFiles();
+
+ //Look for multiple versions of files
+ for(int i=0; i<files.size(); i++)
+ {
+ File file = (File)files.get(i);
+
+ Command versionsCMD =
service.getCommandFactory().createContentGetVersionsCommand(file.getBasePath()+"/en");
+ List versions = (List)service.execute(versionsCMD);
+ assertEquals("Multiple Versions not Found", versions.size(), 2);
+ }
+
+ for(int i=0; i<files2.size(); i++)
+ {
+ File file = (File)files2.get(i);
+
+ Command versionsCMD =
service.getCommandFactory().createContentGetVersionsCommand(file.getBasePath()+"/en");
+ List versions = (List)service.execute(versionsCMD);
+ assertEquals("Multiple Versions not Found", versions.size(), 2);
+ }
}
}
Show replies by date