WCM: consolidate getWebProject & deleteSandbox (also precursor for SAIL-359)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19378 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-03-18 17:33:21 +00:00
parent b9ae66b146
commit 49856600ae
11 changed files with 459 additions and 439 deletions

View File

@@ -378,26 +378,34 @@ public class SandboxServiceImpl implements SandboxService
String wpStoreId = WCMUtil.getWebProjectStoreId(sbStoreId);
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
if (sbStoreId.equals(WCMUtil.buildUserMainStoreName(wpStoreId, currentUserName)))
if (AuthenticationUtil.isRunAsUserTheSystemUser())
{
// author may delete their own sandbox
// system may delete (eg. workflow) sandbox
sandboxFactory.deleteSandbox(sbStoreId);
}
else
{
if (! wpService.isContentManager(wpStoreId))
{
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
if (sbStoreId.equals(WCMUtil.buildUserMainStoreName(wpStoreId, currentUserName)))
{
throw new AccessDeniedException("Only content managers may delete sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
// author may delete their own sandbox
sandboxFactory.deleteSandbox(sbStoreId);
}
if (sbStoreId.equals(wpStoreId))
else
{
throw new AccessDeniedException("Cannot delete staging sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
if (! wpService.isContentManager(wpStoreId, currentUserName))
{
throw new AccessDeniedException("Only content managers may delete sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
}
if (sbStoreId.equals(wpStoreId))
{
throw new AccessDeniedException("Cannot delete staging sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
}
// content manager may delete sandboxes, except staging sandbox
sandboxFactory.deleteSandbox(sbStoreId);
}
// content manager may delete sandboxes, except staging sandbox
sandboxFactory.deleteSandbox(sbStoreId);
}
if (logger.isInfoEnabled())
@@ -834,7 +842,7 @@ public class SandboxServiceImpl implements SandboxService
/**
* Cleans up the workflow sandbox created by the first transaction. This
* action is itself preformed in a separate transaction.
* action is itself performed in a separate transaction.
*/
private void cleanupWorkflowSandbox(final SandboxInfo sandboxInfo)
{
@@ -844,12 +852,12 @@ public class SandboxServiceImpl implements SandboxService
{
public String execute() throws Throwable
{
// call the actual implementation
cleanupWorkflowSandboxImpl(sandboxInfo);
// delete AVM stores in the workflow sandbox
sandboxFactory.deleteSandbox(sandboxInfo);
return null;
}
};
try
{
// Execute the cleanup handler
@@ -861,27 +869,6 @@ public class SandboxServiceImpl implements SandboxService
logger.error("Failed to cleanup workflow sandbox after workflow failure", e);
}
}
/**
* Performs the actual deletion of stores in the workflow sandbox.
*/
private void cleanupWorkflowSandboxImpl(SandboxInfo sandboxInfo)
{
if (sandboxInfo != null)
{
String mainWorkflowStore = sandboxInfo.getMainStoreName();
Map<QName, PropertyValue> matches = avmService.queryStorePropertyKey(mainWorkflowStore,
QName.createQName(null, ".sandbox-id%"));
QName sandboxID = matches.keySet().iterator().next();
// Get all the stores in the sandbox.
Map<String, Map<QName, PropertyValue>> stores = avmService.queryStoresPropertyKeys(sandboxID);
for (String storeName : stores.keySet())
{
avmService.purgeStore(storeName);
}
}
}
/* (non-Javadoc)
* @see org.alfresco.wcm.sandbox.SandboxService#revertAll(java.lang.String)