mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
package org.alfresco.wcm.sandbox.script;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -44,14 +44,14 @@ import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.wcm.asset.AssetInfo;
|
||||
import org.alfresco.wcm.asset.AssetService;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.wcm.asset.AssetInfo;
|
||||
import org.alfresco.wcm.asset.AssetService;
|
||||
import org.alfresco.wcm.sandbox.SandboxService;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -63,22 +63,22 @@ import org.springframework.extensions.surf.util.ISO8601DateFormat;
|
||||
* @author mrogers
|
||||
*
|
||||
*/
|
||||
public class Asset implements Serializable
|
||||
public class Asset implements Serializable
|
||||
{
|
||||
private static final QName NAMESPACE_SERVICE = QName.createQName("", "namespaceService");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5759260478423750966L;
|
||||
private AssetInfo asset;
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5759260478423750966L;
|
||||
private AssetInfo asset;
|
||||
private Sandbox sandbox;
|
||||
private Map<String, String> props;
|
||||
private Map<String, String> props;
|
||||
private Set<QName> updatedProperties = new HashSet<QName>();
|
||||
|
||||
public Asset(Sandbox sandbox, AssetInfo asset)
|
||||
public Asset(Sandbox sandbox, AssetInfo asset)
|
||||
{
|
||||
this.sandbox = sandbox;
|
||||
this.asset = asset;
|
||||
this.asset = asset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,19 +87,19 @@ public class Asset implements Serializable
|
||||
*/
|
||||
public String getCreator()
|
||||
{
|
||||
return asset.getCreator();
|
||||
return asset.getCreator();
|
||||
}
|
||||
|
||||
public Date getCreatedDate()
|
||||
{
|
||||
return asset.getCreatedDate();
|
||||
return asset.getCreatedDate();
|
||||
}
|
||||
|
||||
public long getFileSize()
|
||||
{
|
||||
return asset.getFileSize();
|
||||
}
|
||||
|
||||
public long getFileSize()
|
||||
{
|
||||
return asset.getFileSize();
|
||||
}
|
||||
|
||||
public String getCreatedDateAsISO8601()
|
||||
{
|
||||
return ISO8601DateFormat.format(getCreatedDate());
|
||||
@@ -107,12 +107,12 @@ public class Asset implements Serializable
|
||||
|
||||
public String getModifier()
|
||||
{
|
||||
return asset.getModifier();
|
||||
return asset.getModifier();
|
||||
}
|
||||
|
||||
public Date getModifiedDate()
|
||||
{
|
||||
return asset.getModifiedDate();
|
||||
return asset.getModifiedDate();
|
||||
}
|
||||
|
||||
public String getModifiedDateAsISO8601()
|
||||
@@ -120,37 +120,37 @@ public class Asset implements Serializable
|
||||
return ISO8601DateFormat.format(getModifiedDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return asset.getName();
|
||||
return asset.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,79 +159,79 @@ public class Asset implements Serializable
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return asset.getPath();
|
||||
return asset.getPath();
|
||||
}
|
||||
|
||||
public boolean isFile()
|
||||
{
|
||||
return asset.isFile();
|
||||
return asset.isFile();
|
||||
}
|
||||
|
||||
public boolean isFolder()
|
||||
public boolean isFolder()
|
||||
{
|
||||
return asset.isFolder();
|
||||
return asset.isFolder();
|
||||
}
|
||||
|
||||
public boolean isDeleted()
|
||||
{
|
||||
return asset.isDeleted();
|
||||
return asset.isDeleted();
|
||||
}
|
||||
|
||||
public boolean isLocked()
|
||||
{
|
||||
return asset.isLocked();
|
||||
}
|
||||
|
||||
public String lockOwner()
|
||||
{
|
||||
return asset.getLockOwner();
|
||||
}
|
||||
|
||||
public boolean isLocked()
|
||||
{
|
||||
return asset.isLocked();
|
||||
}
|
||||
|
||||
public String lockOwner()
|
||||
{
|
||||
return asset.getLockOwner();
|
||||
}
|
||||
|
||||
public int getVersion()
|
||||
{
|
||||
return asset.getSandboxVersion();
|
||||
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
|
||||
{
|
||||
* 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(), (null == propValue) ? (null):(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;
|
||||
}
|
||||
}
|
||||
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.
|
||||
@@ -400,7 +400,7 @@ public class Asset implements Serializable
|
||||
{
|
||||
public QName doWork() throws Exception
|
||||
{
|
||||
RetryingTransactionHelper helper = getSandbox().getWebproject().getWebProjects().getServiceRegistry().getRetryingTransactionHelper();
|
||||
RetryingTransactionHelper helper = getSandbox().getWebproject().getWebProjects().getServiceRegistry().getTransactionService().getRetryingTransactionHelper();
|
||||
return helper.doInTransaction(new RetryingTransactionCallback<QName>()
|
||||
{
|
||||
public QName execute() throws Throwable
|
||||
@@ -469,7 +469,7 @@ public class Asset implements Serializable
|
||||
return (null != reader) ? (reader.getContentString()) : (null);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Submit this asset to staging
|
||||
* @param submitLabel
|
||||
* @param submitComment
|
||||
@@ -482,14 +482,14 @@ public class Asset implements Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this asset, after it has been deleted do not use this asset.
|
||||
*/
|
||||
public void deleteAsset()
|
||||
{
|
||||
getAssetService().deleteAsset(this.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()
|
||||
@@ -500,49 +500,49 @@ public class Asset implements Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*/
|
||||
@@ -551,31 +551,31 @@ public class Asset implements Serializable
|
||||
return this.sandbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
private NodeService getNodeService()
|
||||
{
|
||||
|
Reference in New Issue
Block a user