Merged DEV/WCM_SERVICES2 to HEAD

12236: Implementation of Sandbox Revert REST API
  12305: WCM Services - "asset service" initial checkpoint (more tests to be added)
  12334: placeholder for WCM Asset implementation
  12338: Check in to get server working ...
  12341: WCM Services - "asset service" checkpoint (locking fixes, bulk import, more tests added)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12544 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-12-23 14:48:34 +00:00
parent c4e9d6f97b
commit eb906a0d52
23 changed files with 2709 additions and 334 deletions

View File

@@ -227,7 +227,7 @@ public final class SandboxFactory extends WCMUtil
* @param sandboxId
* @return SandboxInfo returns sandbox info or null if sandbox does not exist or is not visible
*/
public SandboxInfo getSandbox(String sandboxId)
/* package */ SandboxInfo getSandbox(String sandboxId)
{
AVMStoreDescriptor storeDesc = avmService.getStore(sandboxId);
if (storeDesc == null)
@@ -680,6 +680,12 @@ public final class SandboxFactory extends WCMUtil
this.avmService.setStoreProperty(workflowStoreName, QName.createQName(null, dnsProp),
new PropertyValue(DataTypeDefinition.TEXT, path));
// TODO review above and replace with common call to ...
/*
// tag the store with the DNS name property
tagStoreDNSPath(avmService, workflowStoreName, storeId, packageName);
*/
// the main workflow store depends on the main user store (dist=1)
String prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + userStore;
this.avmService.setStoreProperty(workflowStoreName, QName.createQName(null, prop_key),
@@ -721,6 +727,12 @@ public final class SandboxFactory extends WCMUtil
dnsProp = SandboxConstants.PROP_DNS + DNSNameMangler.MakeDNSName(userStore, packageName, "preview");
this.avmService.setStoreProperty(previewStoreName, QName.createQName(null, dnsProp),
new PropertyValue(DataTypeDefinition.TEXT, path));
// TODO review above and replace with common call to ...
/*
// tag the store with the DNS name property
tagStoreDNSPath(avmService, previewStoreName, storeId, packageName, "preview");
*/
// The preview worfkflow store depends on the main workflow store (dist=1)
prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + workflowStoreName;

View File

@@ -28,9 +28,9 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.VersionDescriptor;
import org.alfresco.service.namespace.QName;
import org.alfresco.wcm.asset.AssetInfo;
/**
@@ -156,7 +156,7 @@ public interface SandboxService
* @param includeDeleted if true, include deleted assets as well as new/modified assets
* @return List<AVMNodeDescriptor> list of all changed assets
*/
public List<AVMNodeDescriptor> listChangedAll(String sbStoreId, boolean includeDeleted);
public List<AssetInfo> listChangedAll(String sbStoreId, boolean includeDeleted);
/**
* List changed assets for given sandbox and web app (eg. in user sandbox)
@@ -168,7 +168,7 @@ public interface SandboxService
* @param includeDeleted if true, include deleted assets as well as new/modified assets
* @return List<AVMNodeDescriptor> list of changed assets
*/
public List<AVMNodeDescriptor> listChangedWebApp(String sbStoreId, String webApp, boolean includeDeleted);
public List<AssetInfo> listChangedWebApp(String sbStoreId, String webApp, boolean includeDeleted);
/**
* List changed assets for given sandbox path (eg. between user sandbox and staging sandbox)
@@ -180,7 +180,7 @@ public interface SandboxService
* @param includeDeleted if true, include deleted assets as well as new/modified assets
* @return List<AVMNodeDescriptor> list of changed assets
*/
public List<AVMNodeDescriptor> listChanged(String sbStoreId, String relativePath, boolean includeDeleted);
public List<AssetInfo> listChanged(String sbStoreId, String relativePath, boolean includeDeleted);
/**
* List changed (new/modified/deleted) assets between any two sandbox paths
@@ -192,7 +192,7 @@ public interface SandboxService
* @param includeDeleted if true, include deleted assets as well as new/modified assets
* @return List<AVMNodeDescriptor> list of changed assets
*/
public List<AVMNodeDescriptor> listChanged(String srcSandboxStoreId, String srcRelativePath, String dstSandboxStoreId, String dstRelativePath, boolean includeDeleted);
public List<AssetInfo> listChanged(String srcSandboxStoreId, String srcRelativePath, String dstSandboxStoreId, String dstRelativePath, boolean includeDeleted);
/**
* Submit all changed assets for given sandbox (eg. from user sandbox to staging sandbox)
@@ -239,15 +239,16 @@ public interface SandboxService
*/
public void submitList(String sbStoreId, List<String> relativePaths, String submitLabel, String submitComment);
public void submitList(String sbStoreId, List<String> relativePaths, Map<String, Date> expirationDates, String submitLabel, String submitComment);
/**
* Submit list of changed assets for given sandbox (eg. from user sandbox to staging sandbox)
*
* @param sbStoreId sandbox store id
* @param assetNodes list of assets, as AVM node descriptors
* @param assetNodes list of assets, as AVM node descriptors
* @param submitLabel label for submitted snapshot
* @param submitComment comment for submitted snapshot
*/
public void submitListNodes(String sbStoreId, List<AVMNodeDescriptor> assets, String submitLabel, String submitComment);
public void submitListAssets(String sbStoreId, List<AssetInfo> assets, String submitLabel, String submitComment);
/**
* Submit list of changed assets for given sandbox (eg. from user sandbox to staging sandbox)
@@ -258,7 +259,7 @@ public interface SandboxService
* @param submitLabel label for submitted snapshot
* @param submitComment comment for submitted snapshot
*/
public void submitListNodes(String sbStoreId, List<AVMNodeDescriptor> assets, Map<String, Date> expirationDates, String submitLabel, String submitComment);
public void submitListAssets(String sbStoreId, List<AssetInfo> assets, Map<String, Date> expirationDates, String submitLabel, String submitComment);
/**
* Revert all changed assets for given sandbox (eg. in user sandbox)
@@ -302,7 +303,7 @@ public interface SandboxService
*
* @param assets list of AVM node descriptors
*/
public void revertListNodes(String sbStoreId, List<AVMNodeDescriptor> assets);
public void revertListNodes(String sbStoreId, List<AssetInfo> assets);
/**
* Revert sandbox to a specific snapshot version ID (ie. for staging sandbox)

View File

@@ -61,6 +61,8 @@ import org.alfresco.util.NameMatcher;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.VirtServerUtils;
import org.alfresco.wcm.asset.AssetInfo;
import org.alfresco.wcm.asset.AssetService;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.wcm.util.WCMWorkflowUtil;
import org.alfresco.wcm.webproject.WebProjectInfo;
@@ -76,7 +78,7 @@ import org.apache.commons.logging.LogFactory;
*
* @author janv
*/
public class SandboxServiceImpl extends WCMUtil implements SandboxService
public class SandboxServiceImpl implements SandboxService
{
/** Logger */
private static Log logger = LogFactory.getLog(SandboxServiceImpl.class);
@@ -90,6 +92,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
private VirtServerRegistry virtServerRegistry;
private ActionService actionService;
private WorkflowService workflowService;
private AssetService assetService;
public void setWebProjectService(WebProjectService wpService)
{
@@ -135,7 +138,11 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
{
this.workflowService = workflowService;
}
public void setAssetService(AssetService assetService)
{
this.assetService = assetService;
}
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#createAuthorSandbox(java.lang.String)
@@ -350,7 +357,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#listChangedAll(java.lang.String, boolean)
*/
public List<AVMNodeDescriptor> listChangedAll(String sbStoreId, boolean includeDeleted)
public List<AssetInfo> listChangedAll(String sbStoreId, boolean includeDeleted)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
@@ -361,7 +368,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#listChangedWebApp(java.lang.String, java.lang.String, boolean)
*/
public List<AVMNodeDescriptor> listChangedWebApp(String sbStoreId, String webApp, boolean includeDeleted)
public List<AssetInfo> listChangedWebApp(String sbStoreId, String webApp, boolean includeDeleted)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
ParameterCheck.mandatoryString("webApp", webApp);
@@ -374,7 +381,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#listChanged(java.lang.String, java.lang.String, boolean)
*/
public List<AVMNodeDescriptor> listChanged(String sbStoreId, String relativePath, boolean includeDeleted)
public List<AssetInfo> listChanged(String sbStoreId, String relativePath, boolean includeDeleted)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
ParameterCheck.mandatoryString("relativePath", relativePath);
@@ -395,7 +402,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#listChanged(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
*/
public List<AVMNodeDescriptor> listChanged(String srcSandboxStoreId, String srcRelativePath, String dstSandboxStoreId, String dstRelativePath, boolean includeDeleted)
public List<AssetInfo> listChanged(String srcSandboxStoreId, String srcRelativePath, String dstSandboxStoreId, String dstRelativePath, boolean includeDeleted)
{
ParameterCheck.mandatoryString("srcSandboxStoreId", srcSandboxStoreId);
ParameterCheck.mandatoryString("srcRelativePath", srcRelativePath);
@@ -403,28 +410,30 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
ParameterCheck.mandatoryString("dstSandboxStoreId", dstSandboxStoreId);
ParameterCheck.mandatoryString("dstRelativePath", dstRelativePath);
String avmSrcPath = srcSandboxStoreId + AVM_STORE_SEPARATOR + srcRelativePath;
String avmDstPath = dstSandboxStoreId + AVM_STORE_SEPARATOR + dstRelativePath;
String avmSrcPath = srcSandboxStoreId + WCMUtil.AVM_STORE_SEPARATOR + srcRelativePath;
String avmDstPath = dstSandboxStoreId + WCMUtil.AVM_STORE_SEPARATOR + dstRelativePath;
return listChanged(-1, avmSrcPath, -1, avmDstPath, includeDeleted);
}
private List<AVMNodeDescriptor> listChanged(int srcVersion, String srcPath, int dstVersion, String dstPath, boolean includeDeleted)
private List<AssetInfo> listChanged(int srcVersion, String srcPath, int dstVersion, String dstPath, boolean includeDeleted)
{
long start = System.currentTimeMillis();
List<AVMDifference> diffs = avmSyncService.compare(srcVersion, srcPath, dstVersion, dstPath, nameMatcher);
List<AVMNodeDescriptor> assets = new ArrayList<AVMNodeDescriptor>(diffs.size());
List<AssetInfo> assets = new ArrayList<AssetInfo>(diffs.size());
for (AVMDifference diff : diffs)
{
// convert each diff record into an AVM node descriptor
String sourcePath = diff.getSourcePath();
AVMNodeDescriptor node = avmService.lookup(-1, sourcePath, includeDeleted);
if (node != null)
String[] parts = WCMUtil.splitPath(sourcePath);
AssetInfo asset = assetService.getAsset(parts[0], -1, parts[1], includeDeleted);
if (asset != null)
{
assets.add(node);
assets.add(asset);
}
}
@@ -467,9 +476,9 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
ParameterCheck.mandatoryString("relativePath", relativePath);
List<AVMNodeDescriptor> assets = listChanged(sbStoreId, relativePath, true);
List<AssetInfo> assets = listChanged(sbStoreId, relativePath, true);
submitListNodes(sbStoreId, assets, submitLabel, submitComment);
submitListAssets(sbStoreId, assets, submitLabel, submitComment);
}
/* (non-Javadoc)
@@ -479,35 +488,42 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
List<AVMNodeDescriptor> assets = new ArrayList<AVMNodeDescriptor>(relativePaths.size());
for (String relativePath : relativePaths)
{
// convert each path into an AVM node descriptor
AVMNodeDescriptor node = avmService.lookup(-1, sbStoreId + WCMUtil.AVM_STORE_SEPARATOR + relativePath, true);
if (node != null)
{
assets.add(node);
}
}
submitListNodes(sbStoreId, assets, null, submitLabel, submitComment);
submitList(sbStoreId, relativePaths, null, submitLabel, submitComment);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#submitListNodes(java.lang.String, java.util.List, java.lang.String, java.lang.String)
*/
public void submitListNodes(String sbStoreId, List<AVMNodeDescriptor> assets, String submitLabel, String submitComment)
public void submitList(String sbStoreId, List<String> relativePaths, Map<String, Date> expirationDates, String submitLabel, String submitComment)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
submitListNodes(sbStoreId, assets, null, submitLabel, submitComment);
List<AssetInfo> assets = new ArrayList<AssetInfo>(relativePaths.size());
for (String relativePath : relativePaths)
{
// convert each path into an asset
AssetInfo asset = assetService.getAsset(sbStoreId, -1, relativePath, true);
if (asset != null)
{
assets.add(asset);
}
}
submitListAssets(sbStoreId, assets, expirationDates, submitLabel, submitComment);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#submitListNodes(java.lang.String, java.util.List, java.util.Map, java.lang.String, java.lang.String)
* @see org.alfresco.wcm.sandbox.SandboxService#submitListAssets(java.lang.String, java.util.List, java.lang.String, java.lang.String)
*/
public void submitListNodes(String sbStoreId, List<AVMNodeDescriptor> assets, Map<String, Date> expirationDates, final String submitLabel, final String submitComment)
public void submitListAssets(String sbStoreId, List<AssetInfo> assets, String submitLabel, String submitComment)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
submitListAssets(sbStoreId, assets, null, submitLabel, submitComment);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#submitListAssets(java.lang.String, java.util.List, java.util.Map, java.lang.String, java.lang.String)
*/
public void submitListAssets(String sbStoreId, List<AssetInfo> assets, Map<String, Date> expirationDates, final String submitLabel, final String submitComment)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
@@ -525,12 +541,12 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
final List<AVMDifference> diffs = new ArrayList<AVMDifference>(assets.size());
for (AVMNodeDescriptor item : assets)
for (AssetInfo asset : assets)
{
String relativePath = WCMUtil.getStoreRelativePath(item.getPath());
String relativePath = WCMUtil.getStoreRelativePath(asset.getAvmPath());
String srcPath = sbStoreId + AVM_STORE_SEPARATOR + relativePath;
String dstPath = stagingSandboxId + AVM_STORE_SEPARATOR + relativePath;
String srcPath = sbStoreId + WCMUtil.AVM_STORE_SEPARATOR + relativePath;
String dstPath = stagingSandboxId + WCMUtil.AVM_STORE_SEPARATOR + relativePath;
AVMDifference diff = new AVMDifference(-1, srcPath, -1, dstPath, AVMDifference.NEWER);
diffs.add(diff);
@@ -607,7 +623,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
ParameterCheck.mandatoryString("relativePath", relativePath);
List<AVMNodeDescriptor> assets = listChanged(sbStoreId, relativePath, true);
List<AssetInfo> assets = listChanged(sbStoreId, relativePath, true);
revertListNodes(sbStoreId, assets);
}
@@ -619,15 +635,15 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
List<AVMNodeDescriptor> assets = new ArrayList<AVMNodeDescriptor>(relativePaths.size());
List<AssetInfo> assets = new ArrayList<AssetInfo>(relativePaths.size());
for (String relativePath : relativePaths)
{
// convert each path into an AVM node descriptor
AVMNodeDescriptor node = avmService.lookup(-1, sbStoreId + WCMUtil.AVM_STORE_SEPARATOR + relativePath, true);
if (node != null)
// convert each path into an asset
AssetInfo asset = assetService.getAsset(sbStoreId, -1, relativePath, true);
if (asset != null)
{
assets.add(node);
assets.add(asset);
}
}
@@ -637,22 +653,26 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#revertListNodes(java.lang.String, java.util.List)
*/
public void revertListNodes(String sbStoreId, List<AVMNodeDescriptor> assets)
public void revertListNodes(String sbStoreId, List<AssetInfo> assets)
{
ParameterCheck.mandatoryString("sbStoreId", sbStoreId);
List<Pair<Integer, String>> versionPaths = new ArrayList<Pair<Integer, String>>(assets.size());
List<WorkflowTask> tasks = null;
for (AVMNodeDescriptor node : assets)
for (AssetInfo asset : assets)
{
if (tasks == null)
{
tasks = WCMWorkflowUtil.getAssociatedTasksForSandbox(workflowService, WCMUtil.getSandboxStoreId(node.getPath()));
tasks = WCMWorkflowUtil.getAssociatedTasksForSandbox(workflowService, WCMUtil.getSandboxStoreId(asset.getAvmPath()));
}
// TODO ... extra lookup ... either return AVMNodeDescriptor or change getAssociatedTasksForNode ...
AVMNodeDescriptor node = avmService.lookup(-1, asset.getAvmPath());
if (WCMWorkflowUtil.getAssociatedTasksForNode(avmService, node, tasks).size() == 0)
{
String revertPath = node.getPath();
String revertPath = asset.getAvmPath();
versionPaths.add(new Pair<Integer, String>(-1, revertPath));
if (VirtServerUtils.requiresUpdateNotification(revertPath))
@@ -747,7 +767,7 @@ public class SandboxServiceImpl extends WCMUtil implements SandboxService
Map<String, Serializable> args = new HashMap<String, Serializable>(1, 1.0f);
args.put(AVMRevertStoreAction.PARAM_VERSION, version);
Action action = actionService.createAction(AVMRevertStoreAction.NAME, args);
actionService.executeAction(action, AVMNodeConverter.ToNodeRef(-1, sbStoreId + AVM_STORE_SEPARATOR + "/"));
actionService.executeAction(action, AVMNodeConverter.ToNodeRef(-1, sbStoreId + WCMUtil.AVM_STORE_SEPARATOR + "/"));
return diffs;
}
}, AuthenticationUtil.getSystemUserName());

View File

@@ -26,7 +26,6 @@ package org.alfresco.wcm.sandbox;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -36,17 +35,21 @@ import junit.framework.TestCase;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.VersionDescriptor;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap;
import org.alfresco.wcm.asset.AssetInfo;
import org.alfresco.wcm.asset.AssetService;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.wcm.webproject.WebProjectInfo;
import org.alfresco.wcm.webproject.WebProjectService;
@@ -61,8 +64,6 @@ public class SandboxServiceImplTest extends TestCase
{
private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private char AVM_STORE_SEPARATOR = ':';
//
// test data
//
@@ -100,11 +101,15 @@ public class SandboxServiceImplTest extends TestCase
private WebProjectService wpService;
private SandboxService sbService;
private AssetService assetService;
private AuthenticationService authenticationService;
private PersonService personService;
private AVMService avmLockingAwareService;
private AVMService avmNonLockingAwareService;
private AVMService avmService; // non-locking-aware
//private AVMService avmLockingAwareService;
//private AVMService avmNonLockingAwareService;
@Override
@@ -113,14 +118,18 @@ public class SandboxServiceImplTest extends TestCase
// Get the required services
wpService = (WebProjectService)ctx.getBean("WebProjectService");
sbService = (SandboxService)ctx.getBean("SandboxService");
assetService = (AssetService)ctx.getBean("AssetService");
authenticationService = (AuthenticationService)ctx.getBean("AuthenticationService");
personService = (PersonService)ctx.getBean("PersonService");
avmService = (AVMService)ctx.getBean("AVMService");
// WCM locking
avmLockingAwareService = (AVMService)ctx.getBean("AVMLockingAwareService");
//avmLockingAwareService = (AVMService)ctx.getBean("AVMLockingAwareService");
// without WCM locking
avmNonLockingAwareService = (AVMService)ctx.getBean("AVMService");
//avmNonLockingAwareService = (AVMService)ctx.getBean("AVMService");
// By default run as Admin
AuthenticationUtil.setFullyAuthenticatedUser(USER_ADMIN);
@@ -184,7 +193,7 @@ public class SandboxServiceImplTest extends TestCase
public void testSimple()
{
int storeCnt = avmLockingAwareService.getStores().size();
int storeCnt = avmService.getStores().size();
// create web project (also creates staging sandbox and admin's author sandbox)
WebProjectInfo wpInfo = wpService.createWebProject(TEST_WEBPROJ_DNS+"-simple", TEST_WEBPROJ_NAME+"-simple", TEST_WEBPROJ_TITLE, TEST_WEBPROJ_DESCRIPTION, TEST_WEBPROJ_DEFAULT_WEBAPP, TEST_WEBPROJ_DONT_USE_AS_TEMPLATE, null);
@@ -194,7 +203,7 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(2, sbService.listSandboxes(wpStoreId).size());
// list 4 extra AVM stores (2 per sandbox)
assertEquals(storeCnt+4, avmLockingAwareService.getStores().size()); // 2x stating (main,preview), 2x admin author (main, preview)
assertEquals(storeCnt+4, avmService.getStores().size()); // 2x stating (main,preview), 2x admin author (main, preview)
// get admin's sandbox
SandboxInfo sbInfo = sbService.getAuthorSandbox(wpStoreId);
@@ -222,7 +231,7 @@ public class SandboxServiceImplTest extends TestCase
// delete web project (also deletes staging sandbox)
wpService.deleteWebProject(wpStoreId);
assertEquals(storeCnt, avmLockingAwareService.getStores().size());
assertEquals(storeCnt, avmService.getStores().size());
}
public void testCreateAuthorSandbox()
@@ -508,38 +517,35 @@ public class SandboxServiceImplTest extends TestCase
String sbStoreId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(sbStoreId, true);
List<AssetInfo> assets = sbService.listChangedAll(sbStoreId, true);
assertEquals(0, assets.size());
String authorSandboxMyWebAppRelativePath = sbInfo.getSandboxRootPath() + "/" + myWebApp; // in this case, my web app is 'myWebApp'
String authorSandboxMyWebAppPath = sbStoreId + AVM_STORE_SEPARATOR + authorSandboxMyWebAppRelativePath;
String authorSandboxDefaultWebAppRelativePath = sbInfo.getSandboxRootPath() + "/" + wpInfo.getDefaultWebApp(); // in this case, default web app is 'ROOT'
String authorSandboxDefaultWebAppPath = sbStoreId + AVM_STORE_SEPARATOR + authorSandboxDefaultWebAppRelativePath;
avmLockingAwareService.createFile(authorSandboxMyWebAppPath, "myFile1");
assetService.createFile(sbStoreId, authorSandboxMyWebAppRelativePath, "myFile1", null);
assets = sbService.listChangedAll(sbStoreId, false);
assertEquals(1, assets.size());
assertEquals("myFile1", assets.get(0).getName());
avmLockingAwareService.createDirectory(authorSandboxDefaultWebAppPath, "myDir1");
avmLockingAwareService.createFile(authorSandboxDefaultWebAppPath+"/myDir1", "myFile2");
avmLockingAwareService.createDirectory(authorSandboxDefaultWebAppPath+"/myDir1", "myDir2");
avmLockingAwareService.createFile(authorSandboxDefaultWebAppPath+"/myDir1/myDir2", "myFile3");
avmLockingAwareService.createFile(authorSandboxDefaultWebAppPath+"/myDir1/myDir2", "myFile4");
avmLockingAwareService.createDirectory(authorSandboxDefaultWebAppPath+"/myDir1", "myDir3");
assetService.createFolder(sbStoreId, authorSandboxDefaultWebAppRelativePath, "myDir1", null);
assetService.createFile(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1", "myFile2", null);
assetService.createFolder(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1", "myDir2", null);
assetService.createFile(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1/myDir2", "myFile3", null);
assetService.createFile(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1/myDir2", "myFile4", null);
assetService.createFolder(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1", "myDir3", null);
assets = sbService.listChangedAll(sbStoreId, false);
assertEquals(2, assets.size()); // new dir with new dirs/files is returned as single change
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myFile1") && asset.isFile())
{
continue;
}
else if (asset.getName().equals("myDir1") && asset.isDirectory())
else if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
@@ -552,9 +558,9 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChangedWebApp(sbStoreId, wpInfo.getDefaultWebApp(), false);
assertEquals(1, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
@@ -567,9 +573,9 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChanged(sbStoreId, authorSandboxDefaultWebAppRelativePath+"/myDir1", false);
assertEquals(1, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
@@ -596,12 +602,10 @@ public class SandboxServiceImplTest extends TestCase
SandboxInfo sbInfo1 = sbService.getAuthorSandbox(wpStoreId);
String sbStoreId = sbInfo1.getSandboxId();
List<AVMNodeDescriptor> assets = sbService.listChangedAll(sbStoreId, true);
List<AssetInfo> assets = sbService.listChangedAll(sbStoreId, true);
assertEquals(0, assets.size());
String authorSandboxRootPath = sbStoreId + AVM_STORE_SEPARATOR + sbInfo1.getSandboxRootPath();
avmLockingAwareService.createFile(authorSandboxRootPath, "myFile1");
assetService.createFile(sbStoreId, sbInfo1.getSandboxRootPath(), "myFile1", null);
assets = sbService.listChangedAll(sbStoreId, false);
assertEquals(1, assets.size());
@@ -615,16 +619,14 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChangedAll(sbStoreId, true);
assertEquals(0, assets.size());
authorSandboxRootPath = sbStoreId + AVM_STORE_SEPARATOR + sbInfo2.getSandboxRootPath();
avmLockingAwareService.createFile(authorSandboxRootPath, "myFile2");
avmLockingAwareService.createFile(authorSandboxRootPath, "myFile3");
assetService.createFile(sbStoreId, sbInfo2.getSandboxRootPath(), "myFile2", null);
assetService.createFile(sbStoreId, sbInfo2.getSandboxRootPath(), "myFile3", null);
assets = sbService.listChangedAll(sbStoreId, false);
assertEquals(2, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myFile2") && asset.isFile())
{
@@ -650,10 +652,10 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(1, assets.size());
assertEquals("myFile1", assets.get(0).getName());
assets = sbService.listChanged(sbInfo2.getSandboxId(), sbInfo1.getSandboxRootPath(), sbInfo1.getSandboxId(), sbInfo2.getSandboxRootPath(), false);
assets = sbService.listChanged(sbInfo2.getSandboxId(), sbInfo2.getSandboxRootPath(), sbInfo1.getSandboxId(), sbInfo1.getSandboxRootPath(), false);
assertEquals(2, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myFile2") && asset.isFile())
{
@@ -670,6 +672,7 @@ public class SandboxServiceImplTest extends TestCase
}
}
/*
// list changed (in this test, new) assets in two different user sandboxes compared to each other - without locking
public void testListNewItems3()
{
@@ -686,7 +689,7 @@ public class SandboxServiceImplTest extends TestCase
SandboxInfo sbInfo1 = sbService.getAuthorSandbox(wpStoreId);
String sbStoreId = sbInfo1.getSandboxId();
List<AVMNodeDescriptor> assets = sbService.listChangedAll(sbStoreId, true);
List<AssetInfo> assets = sbService.listChangedAll(sbStoreId, true);
assertEquals(0, assets.size());
String authorSandboxRootPath = sbStoreId + AVM_STORE_SEPARATOR + sbInfo1.getSandboxRootPath();
@@ -715,7 +718,7 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChangedAll(sbStoreId, false);
assertEquals(3, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myFile1") && asset.isFile())
{
@@ -748,7 +751,7 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChanged(sbInfo2.getSandboxId(), sbInfo1.getSandboxRootPath(), sbInfo1.getSandboxId(), sbInfo2.getSandboxRootPath(), false);
assertEquals(3, assets.size());
for (AVMNodeDescriptor asset : assets)
for (AssetInfo asset : assets)
{
if (asset.getName().equals("myFile1") && asset.isFile())
{
@@ -768,6 +771,7 @@ public class SandboxServiceImplTest extends TestCase
}
}
}
*/
// submit new assets in user sandbox to staging sandbox
public void testSubmitNewItems1()
@@ -788,25 +792,25 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
String authorSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
avmLockingAwareService.createFile(authorSandboxWebppPath, "myFile1");
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1", "myFile2");
avmLockingAwareService.createDirectory(authorSandboxWebppPath+"/myDir1", "myDir2");
avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1/myDir2", "myFile3");
avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1/myDir2", "myFile4");
avmLockingAwareService.createDirectory(authorSandboxWebppPath+"/myDir1", "myDir3");
assetService.createFile(authorSandboxId, authorSandboxPath, "myFile1", null);
assetService.createFolder(authorSandboxId, authorSandboxPath, "myDir1", null);
assetService.createFile(authorSandboxId, authorSandboxPath+"/myDir1", "myFile2", null);
assetService.createFolder(authorSandboxId, authorSandboxPath+"/myDir1", "myDir2", null);
assetService.createFile(authorSandboxId, authorSandboxPath+"/myDir1/myDir2", "myFile3", null);
assetService.createFile(authorSandboxId, authorSandboxPath+"/myDir1/myDir2", "myFile4", null);
assetService.createFolder(authorSandboxId, authorSandboxPath+"/myDir1", "myDir3", null);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size()); // new dir with new dirs/files is returned as single change
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
@@ -815,16 +819,16 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
for (AVMNodeDescriptor asset : listing.values())
for (AssetInfo asset : listing)
{
if (asset.getName().equals("myFile1") && asset.isFile())
{
continue;
}
else if (asset.getName().equals("myDir1") && asset.isDirectory())
else if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
@@ -855,31 +859,31 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
//String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
final String MYFILE1 = "This is myFile1";
OutputStream out = avmLockingAwareService.createFile(authorSandboxWebppPath, "myFile1");
byte [] buff = MYFILE1.getBytes();
out.write(buff);
out.close();
ContentWriter writer = assetService.createFileWebApp(authorSandboxId, webApp, "/", "myFile1");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE1);
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir1");
final String MYFILE2 = "This is myFile2";
out = avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1", "myFile2");
buff = MYFILE2.getBytes();
out.write(buff);
out.close();
writer = assetService.createFileWebApp(authorSandboxId, webApp, "/myDir1", "myFile2");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE2);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size());
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + ":" + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
@@ -888,7 +892,7 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
// Switch to USER_TWO
@@ -900,34 +904,35 @@ public class SandboxServiceImplTest extends TestCase
// no changes yet
assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
final String MYFILE1_MODIFIED = "This is myFile1 ... modified by "+USER_TWO;
out = avmLockingAwareService.getFileOutputStream(authorSandboxWebppPath+"/myFile1");
buff = (MYFILE1_MODIFIED).getBytes();
out.write(buff);
out.close();
writer = assetService.getContentWriter(assetService.getAssetWebApp(authorSandboxId, webApp, "/myFile1"));
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE1_MODIFIED);
final String MYFILE2_MODIFIED = "This is myFile2 ... modified by "+USER_TWO;
out = avmLockingAwareService.getFileOutputStream(authorSandboxWebppPath+"/myDir1/myFile2");
buff = (MYFILE2_MODIFIED).getBytes();
out.write(buff);
out.close();
writer = assetService.getContentWriter(assetService.getAssetWebApp(authorSandboxId, webApp, "/myDir1/myFile2"));
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE2_MODIFIED);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size());
// check staging before
stagingSandboxWebppPath = stagingSandboxId + ":" + sbInfo.getSandboxRootPath() + "/" + webApp;
stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
InputStream in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myFile1");
buff = new byte[1024];
ContentReader reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myFile1", false));
InputStream in = reader.getContentInputStream();
byte[] buff = new byte[1024];
in.read(buff);
in.close();
assertEquals(MYFILE1, new String(buff, 0, MYFILE1.length())); // assumes 1byte=1char
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myDir1/myFile2");
reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myDir1/myFile2", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
@@ -940,13 +945,15 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myFile1");
reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myFile1", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
assertEquals(MYFILE1_MODIFIED, new String(buff, 0, MYFILE1_MODIFIED.length()));
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myDir1/myFile2");
reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myDir1/myFile2", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
@@ -973,32 +980,32 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
String authorSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
final String MYFILE1 = "This is myFile1";
OutputStream out = avmLockingAwareService.createFile(authorSandboxWebppPath, "myFile1");
byte [] buff = MYFILE1.getBytes();
out.write(buff);
out.close();
ContentWriter writer = assetService.createFile(authorSandboxId, authorSandboxPath, "myFile1", null);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE1);
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
avmLockingAwareService.createDirectory(authorSandboxWebppPath+"/myDir1", "myDir2");
assetService.createFolder(authorSandboxId, authorSandboxPath, "myDir1", null);
assetService.createFolder(authorSandboxId, authorSandboxPath+"/myDir1", "myDir2", null);
final String MYFILE2 = "This is myFile2";
out = avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1", "myFile2");
buff = MYFILE2.getBytes();
out.write(buff);
out.close();
writer = assetService.createFile(authorSandboxId, authorSandboxPath+"/myDir1", "myFile2", null);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE2);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size());
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
@@ -1007,7 +1014,7 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
// Switch to USER_TWO
@@ -1020,10 +1027,11 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
//authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
avmLockingAwareService.removeNode(authorSandboxWebppPath+"/myFile1");
avmLockingAwareService.removeNode(authorSandboxWebppPath+"/myDir1/myDir2");
assetService.deleteAsset(assetService.getAssetWebApp(authorSandboxId, webApp, "myFile1"));
assetService.deleteAsset(assetService.getAssetWebApp(authorSandboxId, webApp, "/myDir1/myDir2"));
// do not list deleted
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
@@ -1034,12 +1042,12 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(2, assets.size());
// check staging before
stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
//stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myFile1"));
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1"));
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1/myDir2"));
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1/myFile2"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myFile1"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1/myDir2"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1/myFile2"));
// submit (deleted assets) !
sbService.submitWebApp(authorSandboxId, webApp, null, null);
@@ -1048,11 +1056,11 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
assertNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myFile1"));
assertNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1/myDir2"));
assertNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myFile1"));
assertNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1/myDir2"));
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1"));
assertNotNull(avmLockingAwareService.lookup(-1, stagingSandboxWebppPath+"/myDir1/myFile2"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1"));
assertNotNull(assetService.getAssetWebApp(stagingSandboxId, webApp, "/myDir1/myFile2"));
}
// revert all (changed) assets in user sandbox
@@ -1079,31 +1087,31 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
String authorSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
final String MYFILE1 = "This is myFile1";
OutputStream out = avmLockingAwareService.createFile(authorSandboxWebppPath, "myFile1");
byte [] buff = MYFILE1.getBytes();
out.write(buff);
out.close();
ContentWriter writer = assetService.createFile(authorSandboxId, authorSandboxPath, "myFile1", null);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE1);
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
assetService.createFolder(authorSandboxId, authorSandboxPath, "myDir1", null);
final String MYFILE2 = "This is myFile2";
out = avmLockingAwareService.createFile(authorSandboxWebppPath+"/myDir1", "myFile2");
buff = MYFILE2.getBytes();
out.write(buff);
out.close();
writer = assetService.createFile(authorSandboxId, authorSandboxPath+"/myDir1", "myFile2", null);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE2);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size());
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
@@ -1112,7 +1120,7 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
// Switch to USER_TWO
@@ -1125,33 +1133,35 @@ public class SandboxServiceImplTest extends TestCase
assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
//authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
final String MYFILE1_MODIFIED = "This is myFile1 ... modified by "+USER_TWO;
out = avmLockingAwareService.getFileOutputStream(authorSandboxWebppPath+"/myFile1");
buff = (MYFILE1_MODIFIED).getBytes();
out.write(buff);
out.close();
writer = assetService.getContentWriter(assetService.getAssetWebApp(authorSandboxId, webApp, "/myFile1"));
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE1_MODIFIED);
final String MYFILE2_MODIFIED = "This is myFile2 ... modified by "+USER_TWO;
out = avmLockingAwareService.getFileOutputStream(authorSandboxWebppPath+"/myDir1/myFile2");
buff = (MYFILE2_MODIFIED).getBytes();
out.write(buff);
out.close();
writer = assetService.getContentWriter(assetService.getAssetWebApp(authorSandboxId, webApp, "/myDir1/myFile2"));
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(MYFILE2_MODIFIED);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(2, assets.size());
// check staging before
stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
InputStream in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myFile1");
buff = new byte[1024];
ContentReader reader = assetService.getContentReader(assetService. getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myFile1", false));
InputStream in = reader.getContentInputStream();
byte[] buff = new byte[1024];
in.read(buff);
in.close();
assertEquals(MYFILE1, new String(buff, 0, MYFILE1.length())); // assumes 1byte = 1char
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myDir1/myFile2");
reader = assetService.getContentReader(assetService. getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myDir1/myFile2", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
@@ -1164,13 +1174,15 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myFile1");
reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myFile1", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
assertEquals(MYFILE1, new String(buff, 0, MYFILE1.length()));
in = avmLockingAwareService.getFileInputStream(-1, stagingSandboxWebppPath+"/myDir1/myFile2");
reader = assetService.getContentReader(assetService.getAsset(stagingSandboxId, -1, stagingSandboxPath+"/myDir1/myFile2", false));
in = reader.getContentInputStream();
buff = new byte[1024];
in.read(buff);
in.close();
@@ -1197,21 +1209,19 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir2");
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir3");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir1");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir2");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir3");
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(3, assets.size());
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
List<VersionDescriptor> sbVersions = sbService.listSnapshots(stagingSandboxId, fromDate, new Date(), false);
assertEquals(0, sbVersions.size());
@@ -1223,20 +1233,20 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(3, listing.size());
sbVersions = sbService.listSnapshots(stagingSandboxId, fromDate, new Date(), false);
assertEquals(1, sbVersions.size());
// more changes ...
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir4");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir4");
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
// check staging after
listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(4, listing.size());
sbVersions = sbService.listSnapshots(stagingSandboxId, fromDate, new Date(), false);
@@ -1267,19 +1277,19 @@ public class SandboxServiceImplTest extends TestCase
String authorSandboxId = sbInfo.getSandboxId();
// no changes yet
List<AVMNodeDescriptor> assets = sbService.listChangedAll(authorSandboxId, true);
List<AssetInfo> assets = sbService.listChangedAll(authorSandboxId, true);
assertEquals(0, assets.size());
String authorSandboxWebppPath = authorSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
String authorSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir1");
assetService.createFolder(authorSandboxId, authorSandboxPath, "myDir1", null);
assets = sbService.listChangedWebApp(authorSandboxId, webApp, false);
assertEquals(1, assets.size());
// check staging before
String stagingSandboxWebppPath = stagingSandboxId + AVM_STORE_SEPARATOR + sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false).size());
String stagingSandboxPath = sbInfo.getSandboxRootPath() + "/" + webApp;
assertEquals(0, assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false).size());
List<VersionDescriptor> sbVersions = sbService.listSnapshots(stagingSandboxId, fromDate, new Date(), false);
assertEquals(0, sbVersions.size());
@@ -1291,11 +1301,11 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(0, assets.size());
// check staging after
Map<String, AVMNodeDescriptor> listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
List<AssetInfo> listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(1, listing.size());
for (AVMNodeDescriptor asset : listing.values())
for (AssetInfo asset : listing)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
@@ -1309,21 +1319,21 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(1, sbVersions.size());
// more changes ...
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir2");
assetService.createFolder(authorSandboxId, authorSandboxPath, "myDir2", null);
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
// check staging after
listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
for (AVMNodeDescriptor asset : listing.values())
for (AssetInfo asset : listing)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
else if (asset.getName().equals("myDir2") && asset.isDirectory())
else if (asset.getName().equals("myDir2") && asset.isFolder())
{
continue;
}
@@ -1337,25 +1347,25 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(2, sbVersions.size());
// more changes ...
avmLockingAwareService.createDirectory(authorSandboxWebppPath, "myDir3");
assetService.createFolderWebApp(authorSandboxId, webApp, "/", "myDir3");
// submit (new assets) !
sbService.submitWebApp(authorSandboxId, webApp, "a submit label", "a submit comment");
// check staging after
listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(3, listing.size());
for (AVMNodeDescriptor asset : listing.values())
for (AssetInfo asset : listing)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
else if (asset.getName().equals("myDir2") && asset.isDirectory())
else if (asset.getName().equals("myDir2") && asset.isFolder())
{
continue;
}
else if (asset.getName().equals("myDir3") && asset.isDirectory())
else if (asset.getName().equals("myDir3") && asset.isFolder())
{
continue;
}
@@ -1379,15 +1389,15 @@ public class SandboxServiceImplTest extends TestCase
assertEquals(4, sbVersions.size());
// check staging after
listing = avmLockingAwareService.getDirectoryListing(-1, stagingSandboxWebppPath, false);
listing = assetService.listAssets(stagingSandboxId, -1, stagingSandboxPath, false);
assertEquals(2, listing.size());
for (AVMNodeDescriptor asset : listing.values())
for (AssetInfo asset : listing)
{
if (asset.getName().equals("myDir1") && asset.isDirectory())
if (asset.getName().equals("myDir1") && asset.isFolder())
{
continue;
}
else if (asset.getName().equals("myDir2") && asset.isDirectory())
else if (asset.getName().equals("myDir2") && asset.isFolder())
{
continue;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -28,8 +28,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.util.ISO8601DateFormat;
import org.alfresco.wcm.asset.AssetInfo;
import org.alfresco.wcm.sandbox.SandboxService;
/**
@@ -39,13 +39,13 @@ import org.alfresco.wcm.sandbox.SandboxService;
*/
public class Asset
{
private AVMNodeDescriptor desc;
private AssetInfo asset;
private Sandbox sandbox;
public Asset(Sandbox sandbox, AVMNodeDescriptor desc)
public Asset(Sandbox sandbox, AssetInfo asset)
{
this.sandbox = sandbox;
this.desc = desc;
this.asset = asset;
}
/**
@@ -54,12 +54,12 @@ public class Asset
*/
public String getCreator()
{
return desc.getCreator();
return asset.getCreator();
}
public Date getCreatedDate()
{
return new Date(desc.getCreateDate());
return asset.getCreatedDate();
}
public String getCreatedDateAsISO8601()
@@ -69,12 +69,12 @@ public class Asset
public String getModifier()
{
return desc.getLastModifier();
return asset.getModifier();
}
public Date getModifiedDate()
{
return new Date(desc.getModDate());
return asset.getModifiedDate();
}
public String getModifiedDateAsISO8601()
@@ -82,14 +82,16 @@ public class Asset
return ISO8601DateFormat.format(getModifiedDate());
}
/*
public String getAssetRef()
{
return desc.getGuid();
return asset.getGuid();
}
*/
public String getName()
{
return desc.getName();
return asset.getName();
}
/**
@@ -98,39 +100,35 @@ public class Asset
*/
public String getPath()
{
String path = desc.getPath();
if (path != null)
{
String[] splits = path.split(":");
return splits[1];
}
else
{
return path;
}
return asset.getPath();
}
public boolean isFile()
{
return desc.isFile();
return asset.isFile();
}
public boolean isDirectory()
{
return desc.isDirectory();
return asset.isFolder();
}
public boolean isDeleted()
{
return desc.isDeleted();
return asset.isDeleted();
}
public boolean isLocked()
{
return asset.isLocked();
}
/* TODO review
public int getVersion()
{
return desc.getVersionID();
return asset.getVersion();
}
*/
/**
* Submit this asset to staging

View File

@@ -31,6 +31,8 @@ import java.util.List;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.util.ISO8601DateFormat;
import org.alfresco.wcm.asset.AssetInfo;
import org.alfresco.wcm.asset.AssetService;
import org.alfresco.wcm.sandbox.SandboxInfo;
import org.alfresco.wcm.sandbox.SandboxConstants;
import org.alfresco.wcm.sandbox.SandboxService;
@@ -138,6 +140,7 @@ public class Sandbox implements Serializable
getSandboxService().submitList(getSandboxRef(), items, submitLabel, submitComment);
}
/**
* Submit the specified files and directories modified contents of this sandbox
*/
@@ -260,28 +263,55 @@ public class Sandbox implements Serializable
*/
public Asset[] getModifiedAssets()
{
List<AVMNodeDescriptor> items = getSandboxService().listChangedAll(getSandboxRef(), true);
List<AssetInfo> items = getSandboxService().listChangedAll(getSandboxRef(), true);
Asset[] ret = new Asset[items.size()];
int i = 0;
for(AVMNodeDescriptor item : items)
for(AssetInfo item : items)
{
ret[i++] = new Asset(this, item);
}
return ret;
}
/**
* Get the specified asset (Either folder or file)
* @param path the full path e.g. /www/web_apps/ROOT/index.html
* @return the asset
*/
public Asset getAsset(String path)
{
AssetService as = getAssetService();
AssetInfo item = as.getAsset(getSandboxRef(), path);
Asset newAsset = new Asset(this, item);
return newAsset;
}
/**
* Get the specified asset with a path relative to the specified web app.
* @param path e.g. index.html
* @param webApp e.g. ROOT
* @return the asset
*/
public Asset getAssetWebApp(String webApp, String path)
{
AssetService as = getAssetService();
AssetInfo item = as.getAssetWebApp(getSandboxRef(), webApp, path);
Asset newAsset = new Asset(this, item);
return newAsset;
}
/**
* Get the modified assets within this sandbox
* @return the list of changed assets
*/
public Asset[] getModifiedAssetsWebApp(String webApp)
{
List<AVMNodeDescriptor> items = getSandboxService().listChangedWebApp(getSandboxRef(), webApp, true);
List<AssetInfo> items = getSandboxService().listChangedWebApp(getSandboxRef(), webApp, true);
Asset[] ret = new Asset[items.size()];
int i = 0;
for(AVMNodeDescriptor item : items)
for(AssetInfo item : items)
{
ret[i++] = new Asset(this, item);
}
@@ -305,4 +335,13 @@ public class Sandbox implements Serializable
{
return webproject.getWebProjects().getSandboxService();
}
/**
* Get the asset service
* @return the asset service
*/
private AssetService getAssetService()
{
return webproject.getWebProjects().getAssetService();
}
}