Merge DEV\WCM_SERVICES2 to HEAD

12513 Implementation of Asset.getProperties
    12469 Implement paths relative to web app.  And unit tests.   Asset Test is now clean of TODOs.
    12413  Implementation of WCM Asset.    Still work remaining but this is 80% of the implementation.
    12404 WCM Services
        - asset service - fix rename/move folder issue (folders are not locked)
        - sandbox service - fix delete sandbox test
    12374 WCM Services - optimise get/is web project
    12347  WCM Services - "asset service" - add/remove/has aspect, get aspects
    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@12547 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2008-12-23 22:54:46 +00:00
parent eb906a0d52
commit d09673969d
14 changed files with 507 additions and 192 deletions

View File

@@ -341,7 +341,7 @@ public class SandboxServiceImpl implements SandboxService
if (sbStoreId.equals(wpStoreId))
{
throw new AlfrescoRuntimeException("Cannot delete staging sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
throw new AccessDeniedException("Cannot delete staging sandbox '"+sbStoreId+"' (web project id: "+wpStoreId+")");
}
// content manager may delete sandboxes, except staging sandbox

View File

@@ -33,12 +33,10 @@ import java.util.Map;
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.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.VersionDescriptor;
import org.alfresco.service.cmr.repository.ContentReader;
@@ -419,7 +417,7 @@ public class SandboxServiceImplTest extends TestCase
sbService.deleteSandbox(sbInfo.getSandboxId());
fail("Shouldn't be able to delete staging sandbox");
}
catch (AlfrescoRuntimeException exception)
catch (AccessDeniedException exception)
{
// Expected
}
@@ -430,7 +428,7 @@ public class SandboxServiceImplTest extends TestCase
sbService.deleteSandbox("some-random-staging-sandbox");
fail("Shouldn't be able to delete non-existant sandbox");
}
catch (AVMNotFoundException exception)
catch (AccessDeniedException exception)
{
// Expected
}

View File

@@ -24,12 +24,20 @@
*/
package org.alfresco.wcm.sandbox.script;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO8601DateFormat;
import org.alfresco.wcm.asset.AssetInfo;
import org.alfresco.wcm.asset.AssetService;
import org.alfresco.wcm.sandbox.SandboxService;
/**
@@ -37,10 +45,15 @@ import org.alfresco.wcm.sandbox.SandboxService;
* @author mrogers
*
*/
public class Asset
public class Asset implements Serializable
{
/**
*
*/
private static final long serialVersionUID = -5759260478423750966L;
private AssetInfo asset;
private Sandbox sandbox;
private Map<String, String> props;
public Asset(Sandbox sandbox, AssetInfo asset)
{
@@ -62,6 +75,11 @@ public class Asset
return asset.getCreatedDate();
}
public long getFileSize()
{
return asset.getFileSize();
}
public String getCreatedDateAsISO8601()
{
return ISO8601DateFormat.format(getCreatedDate());
@@ -82,12 +100,33 @@ public class Asset
return ISO8601DateFormat.format(getModifiedDate());
}
/*
public String getAssetRef()
{
return asset.getGuid();
}
*/
/**
* rename this asset
* @param newName
*/
public Asset rename(String newName)
{
if(!newName.equals(asset.getName()))
{
AssetInfo newAsset = getAssetService().renameAsset(asset, newName);
this.asset = newAsset;
}
return this;
}
/**
* move this asset
* @param newPath
*/
public Asset move(String newPath)
{
if(!newPath.equals(asset.getPath()))
{
AssetInfo newAsset = getAssetService().moveAsset(asset, newPath);
this.asset = newAsset;
}
return this;
}
public String getName()
{
@@ -108,7 +147,7 @@ public class Asset
return asset.isFile();
}
public boolean isDirectory()
public boolean isFolder()
{
return asset.isFolder();
}
@@ -123,14 +162,82 @@ public class Asset
return asset.isLocked();
}
/* TODO review
public String lockOwner()
{
return asset.getLockOwner();
}
public int getVersion()
{
return asset.getVersion();
return asset.getSandboxVersion();
}
*/
/**
* Get the properties as a key value pair. The key will be either a local qname e.g. "cm:content" or
* a global qname e.g. "{http://www.alfresco.com/content/1.0}content".
*
* Some properties will be updatable, protected properties are not.
*
* @return the properties in a key, value pair
*/
public Map<String, String> getProperties()
{
if(props == null) {
// Note there is something very strange going on with scope which is why there's this guff with propsX
Map<String, String> propsX = new HashMap<String, String>();
props = propsX;
NamespaceService ns = getNamespaceService();
if(!asset.isDeleted())
{
Map <QName, Serializable> intprops = getAssetService().getAssetProperties(asset);
for (QName qname : intprops.keySet())
{
QName prefixQname = qname.getPrefixedQName(ns);
Serializable propValue = intprops.get(qname);
try
{
propsX.put(prefixQname.toPrefixString(), propValue.toString());
}
catch (NamespaceException ne)
{ // No local name, only thing I can do is use the full namke
propsX.put(qname.toString(), propValue.toString());
}
}
}
}
return props;
}
// /**
// * Save the properties please note some system properties are protected and cannot be updated. If you attempt to
// * update a protected property your request will be ignored.
// * @param properties
// */
// public void save()
// {
// if(props != null)
// {
// /**
// * Need to map the <String, String> to a <Qname, Serializable>
// */
// NamespaceService ns = getNamespaceService();
// Map<QName, Serializable> newProps = new HashMap<QName, Serializable>(props.size());
// for (String key : props.keySet())
// {
// String value = props.get(key);
// QName q = QName.resolveToQName(ns, key);
// newProps.put(q, value);
// }
// getAssetService().setAssetProperties(asset, newProps);
// }
// }
/**
* Submit this asset to staging
* @param submitLabel
* @param submitComment
@@ -143,6 +250,14 @@ public class Asset
}
/**
* Delete this asset, after it has been deleted do not use this asset.
*/
public void deleteAsset()
{
getAssetService().deleteAsset(this.asset);
}
/**
* revert this asset
*/
public void revert()
@@ -153,6 +268,49 @@ public class Asset
}
/**
* Get children of this asset, returns an empty array if there are no children.
* Only folders have children.
*/
public Asset[] getChildren()
{
Asset[] ret = new Asset[0];
if(asset.isFolder())
{
int i = 0;
List<AssetInfo> assets = getAssetService().listAssets(getSandbox().getSandboxRef(), asset.getPath(), true);
ret = new Asset[assets.size()];
for(AssetInfo asset : assets)
{
ret[i++]=new Asset(sandbox, asset);
}
}
return ret;
}
/**
* create a new file with the specified properties and content.
* @param name the name of the file
* @param stringContent the content of the file. Can be null.
*/
public void createFile(String name, String stringContent)
{
ContentWriter writer = getAssetService().createFile(getSandbox().getSandboxRef(), asset.getPath(), name, null);
if(stringContent != null)
{
writer.putContent(stringContent);
}
}
/**
* create a new folder
* @param name the name of the new folder
*/
public void createFolder(String name)
{
getAssetService().createFolder(getSandbox().getSandboxRef(), asset.getPath(), name, null);
}
/**
* Get the parent sandbox which contains this asset
* @return the parent sandbox which contains this asset
*/
@@ -161,8 +319,29 @@ public class Asset
return this.sandbox;
}
/**
* @return
*/
private SandboxService getSandboxService()
{
return getSandbox().getWebproject().getWebProjects().getSandboxService();
}
/**
* Get the asset service
* @return the asset service
*/
private AssetService getAssetService()
{
return getSandbox().getWebproject().getWebProjects().getAssetService();
}
/**
* Get the asset service
* @return the asset service
*/
private NamespaceService getNamespaceService()
{
return getSandbox().getWebproject().getWebProjects().getNamespaceService();
}
}

View File

@@ -29,7 +29,6 @@ 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.asset.AssetService;
@@ -277,28 +276,37 @@ public class Sandbox implements Serializable
/**
* Get the specified asset (Either folder or file)
* @param path the full path e.g. /www/web_apps/ROOT/index.html
* @return the asset
* @return the asset or null if it does not exist
*/
public Asset getAsset(String path)
{
AssetService as = getAssetService();
AssetInfo item = as.getAsset(getSandboxRef(), path);
Asset newAsset = new Asset(this, item);
return newAsset;
if (item != null)
{
Asset newAsset = new Asset(this, item);
return newAsset;
}
return null;
}
/**
* 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
* @return the asset or null if it does not exist
*/
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;
if (item != null)
{
Asset newAsset = new Asset(this, item);
return newAsset;
}
return null;
}
/**