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

@@ -28,6 +28,7 @@ import java.io.File;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -175,6 +176,40 @@ public interface AssetService
*/
public void updateAssetProperties(AssetInfo asset, Map<QName, Serializable> properties);
/**
* Apply aspect to asset, with given properties (can be null)
*
* @param asset
* @param aspectName
* @param properties
*/
public void addAspect(AssetInfo asset, QName aspectName, Map<QName, Serializable> properties);
/**
* Remove aspect from asset, and any related properties
*
* @param asset
* @param aspectName
*/
public void removeAspect(AssetInfo asset, QName aspectName);
/**
* Get set of aspects applied to asset
*
* @param asset
* @return list of aspects
*/
public Set<QName> getAspects(AssetInfo asset);
/**
* True, if asset has given aspect applied
*
* @param asset
* @param aspectName
* @return
*/
public boolean hasAspect(AssetInfo asset, QName aspectName);
/**
* List assets within given sandbox and webApp and path (within webApp), optionally include deleted
*
@@ -182,7 +217,7 @@ public interface AssetService
* @param webApp
* @param parentFolderPathRelativeToWebApp
* @param includeDeleted
* @return
* @return list of assets
*/
public List<AssetInfo> listAssetsWebApp(String sbStoreId, String webApp, String parentFolderPathRelativeToWebApp, boolean includeDeleted);
@@ -192,7 +227,7 @@ public interface AssetService
* @param sbStoreId
* @param parentFolderPath
* @param includeDeleted
* @return
* @return list of assets
*/
public List<AssetInfo> listAssets(String sbStoreId, String parentFolderPath, boolean includeDeleted);
@@ -203,7 +238,7 @@ public interface AssetService
* @param version
* @param parentFolderPath
* @param includeDeleted
* @return
* @return list of assets
*/
public List<AssetInfo> listAssets(String sbStoreId, int version, String parentFolderPath, boolean includeDeleted);

View File

@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.mbeans.VirtServerRegistry;
@@ -443,13 +444,54 @@ public class AssetServiceImpl implements AssetService
private void setProperties(String avmPath, Map<QName, Serializable> properties)
{
NodeRef avmNodeRef = AVMNodeConverter.ToNodeRef(-1, avmPath);
avmNodeService.setProperties(avmNodeRef, properties); // note: assumes lock, if applicable, is taken by caller
avmNodeService.setProperties(avmNodeRef, properties);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.asset.AssetService#addAspect(org.alfresco.wcm.asset.AssetInfo, org.alfresco.service.namespace.QName, java.util.Map)
*/
public void addAspect(AssetInfo asset, QName aspectName, Map<QName, Serializable> properties)
{
addAspect(asset.getAvmPath(), aspectName, properties);
}
private void addAspect(String avmPath, QName aspect, Map<QName, Serializable> properties)
{
NodeRef avmNodeRef = AVMNodeConverter.ToNodeRef(-1, avmPath);
avmNodeService.addAspect(avmNodeRef, aspect, properties); // note: assumes lock, if applicable, is taken by caller
avmNodeService.addAspect(avmNodeRef, aspect, properties);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.asset.AssetService#removeAspect(org.alfresco.wcm.asset.AssetInfo, org.alfresco.service.namespace.QName)
*/
public void removeAspect(AssetInfo asset, QName aspectName)
{
ParameterCheck.mandatory("asset", asset);
NodeRef avmNodeRef = AVMNodeConverter.ToNodeRef(-1, asset.getAvmPath());
avmNodeService.removeAspect(avmNodeRef, aspectName);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.asset.AssetService#getAspects(org.alfresco.wcm.asset.AssetInfo)
*/
public Set<QName> getAspects(AssetInfo asset)
{
ParameterCheck.mandatory("asset", asset);
NodeRef avmNodeRef = AVMNodeConverter.ToNodeRef(asset.getSandboxVersion(), asset.getAvmPath());
return avmNodeService.getAspects(avmNodeRef);
}
/* (non-Javadoc)
* @see org.alfresco.wcm.asset.AssetService#hasAspect(org.alfresco.wcm.asset.AssetInfo, org.alfresco.service.namespace.QName)
*/
public boolean hasAspect(AssetInfo asset, QName aspectName)
{
ParameterCheck.mandatory("asset", asset);
NodeRef avmNodeRef = AVMNodeConverter.ToNodeRef(asset.getSandboxVersion(), asset.getAvmPath());
return avmNodeService.hasAspect(avmNodeRef, aspectName);
}
/* (non-Javadoc)

View File

@@ -199,7 +199,7 @@ public class AssetServiceImplTest extends TestCase
assetService.createFolder(sbStoreId, path, "myFolder1", null);
// create (empty) file
assetService.createFile(sbStoreId, path+"/myFolder1", "myFile1", null);
assetService.createFile(sbStoreId, path+"/myFolder1", "myFile1", null); // ignore return
// get assets
@@ -502,12 +502,6 @@ public class AssetServiceImplTest extends TestCase
checkAssetInfo(myFile1Asset, "myFile1Renamed", path+"/myFolder1/myFolder2/myFile1Renamed", USER_ONE, true, false, false, true, USER_ONE);
}
/*
// TODO lock issue ...
// org.alfresco.service.cmr.avm.AVMNotFoundException: Lock not found for testAsset-1228476617644-rename:/www/avm_webapps/ROOT/myFolder1
// at org.alfresco.repo.avm.locking.AVMLockingServiceImpl.modifyLock(AVMLockingServiceImpl.java:490)
// at org.alfresco.repo.avm.AVMLockingAwareService.rename(AVMLockingAwareService.java:712)
public void testRenameFolder()
{
// create web project (also creates staging sandbox and admin's author sandbox)
@@ -536,20 +530,18 @@ public class AssetServiceImplTest extends TestCase
AssetInfo myFolder2Asset = assetService.getAsset(sbStoreId, path+"/myFolder1/myFolder2");
checkAssetInfo(myFolder2Asset, "myFolder2", path+"/myFolder1/myFolder2", USER_ONE, false, true, false, false, null);
// TODO lock issue ...
// org.alfresco.service.cmr.avm.AVMNotFoundException: Lock not found for testAsset-1228476617644-rename:/www/avm_webapps/ROOT/myFolder1
// at org.alfresco.repo.avm.locking.AVMLockingServiceImpl.modifyLock(AVMLockingServiceImpl.java:490)
//at org.alfresco.repo.avm.AVMLockingAwareService.rename(AVMLockingAwareService.java:712)
// rename folder
// rename folder 1
myFolder1Asset = assetService.renameAsset(myFolder1Asset, "myFolder1Renamed");
checkAssetInfo(myFolder1Asset, "myFolder1Renamed", path+"/myFolder1Renamed", USER_ONE, false, true, false, false, null);
// rename folder
// rename folder 2
myFolder2Asset = assetService.getAsset(sbStoreId, path+"/myFolder1Renamed/myFolder2");
checkAssetInfo(myFolder2Asset, "myFolder2", path+"/myFolder1Renamed/myFolder2", USER_ONE, false, true, false, false, null);
myFolder2Asset = assetService.renameAsset(myFolder2Asset, "myFolder2Renamed");
checkAssetInfo(myFolder2Asset, "myFolder2Renamed", path+"/myFolder1/myFolder2Renamed", USER_ONE, false, true, false, false, null);
checkAssetInfo(myFolder2Asset, "myFolder2Renamed", path+"/myFolder1Renamed/myFolder2Renamed", USER_ONE, false, true, false, false, null);
}
*/
public void testCopyFile()
{
@@ -573,7 +565,7 @@ public class AssetServiceImplTest extends TestCase
assetService.createFolder(sbStoreId, path, "myFolder1", null);
assetService.createFolder(sbStoreId, path+"/myFolder1", "myFolder2", null);
// create (nn-empty) file
// create (non-empty) file
final String MYFILE1 = "This is myFile1";
ContentWriter writer = assetService.createFile(sbStoreId, path+"/myFolder1/myFolder2", "myFile1", null);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
@@ -584,9 +576,8 @@ public class AssetServiceImplTest extends TestCase
AssetInfo myFile1Asset = assetService.getAsset(sbStoreId, path+"/myFolder1/myFolder2/myFile1");
checkAssetInfo(myFile1Asset, "myFile1", path+"/myFolder1/myFolder2/myFile1", USER_ONE, true, false, false, true, USER_ONE);
myFile1Asset = assetService.copyAsset(myFile1Asset, path+"/myFolder1");
// TODO review - copied files are not locked ?
myFile1Asset = assetService.copyAsset(myFile1Asset, path+"/myFolder1");
//checkAssetInfo(myFile1Asset, "myFile1", path+"/myFolder1/myFile1", USER_ONE, true, false, false, true, USER_ONE);
checkAssetInfo(myFile1Asset, "myFile1", path+"/myFolder1/myFile1", USER_ONE, true, false, false, false, null);
}
@@ -664,7 +655,7 @@ public class AssetServiceImplTest extends TestCase
assetService.createFolder(sbStoreId, path+"/myFolder1", "myFolder2", null);
// create (empty) file
assetService.createFile(sbStoreId, path+"/myFolder1/myFolder2", "myFile1", null);
assetService.createFile(sbStoreId, path+"/myFolder1/myFolder2", "myFile1", null); // ignore return
// move file
AssetInfo myFile1Asset = assetService.getAsset(sbStoreId, path+"/myFolder1/myFolder2/myFile1");
@@ -682,7 +673,7 @@ public class AssetServiceImplTest extends TestCase
// org.alfresco.service.cmr.avm.AVMNotFoundException: Lock not found for testAsset-1228830920248-movefolder:/www/avm_webapps/ROOT/myFolder1/myFolder2
// at org.alfresco.repo.avm.locking.AVMLockingServiceImpl.modifyLock(AVMLockingServiceImpl.java:490)
// at org.alfresco.repo.avm.AVMLockingAwareService.rename(AVMLockingAwareService.java:712)
*/
public void testMoveFolder()
{
// create web project (also creates staging sandbox and admin's author sandbox)
@@ -705,12 +696,8 @@ public class AssetServiceImplTest extends TestCase
assetService.createFolder(sbStoreId, path, "myFolder1", null);
assetService.createFolder(sbStoreId, path+"/myFolder1", "myFolder2", null);
// create (non-empty) file
//final String MYFILE1 = "This is myFile1";
ContentWriter writer = assetService.createFile(sbStoreId, path+"/myFolder1/myFolder2", "myFile1", null);
//writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
//writer.setEncoding("UTF-8");
//writer.putContent(MYFILE1);
// create (empty) file
assetService.createFile(sbStoreId, path+"/myFolder1/myFolder2", "myFile1", null); // ignore return
AssetInfo myFile1Asset = assetService.getAsset(sbStoreId, path+"/myFolder1/myFolder2/myFile1");
checkAssetInfo(myFile1Asset, "myFile1", path+"/myFolder1/myFolder2/myFile1", USER_ONE, true, false, false, true, USER_ONE);
@@ -729,10 +716,9 @@ public class AssetServiceImplTest extends TestCase
AssetInfo myMovedFile1Asset = assetService.getAsset(sbStoreId, path+"/myFolder2/myFile1");
// TODO review - moved files are not locked ?
checkAssetInfo(myMovedFile1Asset, "myFile1", path+"/myFolder2/myFile1", USER_ONE, true, false, false, true, USER_ONE);
//checkAssetInfo(myMovedFile1Asset, "myFile1", path+"/myFolder2/myFile1", USER_ONE, true, false, false, false, null);
//checkAssetInfo(myMovedFile1Asset, "myFile1", path+"/myFolder2/myFile1", USER_ONE, true, false, false, true, USER_ONE);
checkAssetInfo(myMovedFile1Asset, "myFile1", path+"/myFolder2/myFile1", USER_ONE, true, false, false, false, null);
}
*/
public void testProperties()
{
@@ -817,6 +803,76 @@ public class AssetServiceImplTest extends TestCase
assertEquals(USER_ONE, assetService.getLockOwner(myFile1Asset));
}
public void testAspects()
{
// create web project (also creates staging sandbox and admin's author sandbox)
WebProjectInfo wpInfo = wpService.createWebProject(TEST_WEBPROJ_DNS+"-aspects", TEST_WEBPROJ_NAME+"-aspects", TEST_WEBPROJ_TITLE, TEST_WEBPROJ_DESCRIPTION, TEST_WEBPROJ_DEFAULT_WEBAPP, TEST_WEBPROJ_DONT_USE_AS_TEMPLATE, null);
String defaultWebApp = wpInfo.getDefaultWebApp();
// invite web user and auto-create their (author) sandbox
wpService.inviteWebUser(wpInfo.getStoreId(), USER_ONE, WCMUtil.ROLE_CONTENT_CONTRIBUTOR, true);
// switch to user
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
// get user's author sandbox
SandboxInfo sbInfo = sbService.getAuthorSandbox(wpInfo.getStoreId());
String sbStoreId = sbInfo.getSandboxId();
String path = sbInfo.getSandboxRootPath() + "/" + defaultWebApp;
// create folder
assetService.createFolderWebApp(sbStoreId, defaultWebApp, "/", "myFolder1");
AssetInfo myFolder1Asset = assetService.getAssetWebApp(sbStoreId, defaultWebApp, "/myFolder1");
checkAssetInfo(myFolder1Asset, "myFolder1", path+"/myFolder1", USER_ONE, false, true, false, false, null);
int folderAspectCnt = assetService.getAspects(myFolder1Asset).size();
// create file
assetService.createFileWebApp(sbStoreId, defaultWebApp, "/myFolder1", "myFile1");
AssetInfo myFile1Asset = assetService.getAssetWebApp(sbStoreId, defaultWebApp, "/myFolder1/myFile1");
checkAssetInfo(myFile1Asset, "myFile1", path+"/myFolder1/myFile1", USER_ONE, true, false, false, true, USER_ONE);
int fileAspectCnt = assetService.getAspects(myFile1Asset).size();
// add/remove aspect to/from folder
assertFalse(assetService.hasAspect(myFolder1Asset, ContentModel.ASPECT_TITLED));
Map<QName, Serializable> newProps = new HashMap<QName, Serializable>(2);
newProps.put(ContentModel.PROP_TITLE, "folder title");
newProps.put(ContentModel.PROP_DESCRIPTION, "folder description");
assetService.addAspect(myFolder1Asset, ContentModel.ASPECT_TITLED, newProps);
assertEquals(folderAspectCnt+1, assetService.getAspects(myFolder1Asset).size());
assertTrue(assetService.hasAspect(myFolder1Asset, ContentModel.ASPECT_TITLED));
assetService.removeAspect(myFolder1Asset, ContentModel.ASPECT_TITLED);
assertEquals(folderAspectCnt, assetService.getAspects(myFolder1Asset).size());
assertFalse(assetService.hasAspect(myFolder1Asset, ContentModel.ASPECT_TITLED));
// add/remove aspect to/from file
assertFalse(assetService.hasAspect(myFile1Asset, ContentModel.ASPECT_TITLED));
newProps = new HashMap<QName, Serializable>(2);
newProps.put(ContentModel.PROP_TITLE, "file title");
newProps.put(ContentModel.PROP_DESCRIPTION, "file description");
assetService.addAspect(myFile1Asset, ContentModel.ASPECT_TITLED, newProps);
assertEquals(fileAspectCnt+1, assetService.getAspects(myFile1Asset).size());
assertTrue(assetService.hasAspect(myFile1Asset, ContentModel.ASPECT_TITLED));
assetService.removeAspect(myFile1Asset, ContentModel.ASPECT_TITLED);
assertEquals(fileAspectCnt, assetService.getAspects(myFile1Asset).size());
assertFalse(assetService.hasAspect(myFile1Asset, ContentModel.ASPECT_TITLED));
}
public void testSimpleLockFile()
{
// create web project (also creates staging sandbox and admin's author sandbox)