diff --git a/source/java/org/alfresco/wcm/sandbox/script/Asset.java b/source/java/org/alfresco/wcm/sandbox/script/Asset.java index 5fb9b243df..dbb3c6e36f 100644 --- a/source/java/org/alfresco/wcm/sandbox/script/Asset.java +++ b/source/java/org/alfresco/wcm/sandbox/script/Asset.java @@ -24,13 +24,16 @@ */ package org.alfresco.wcm.sandbox.script; +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.sandbox.SandboxService; /** - * Asset in a sandbox exposed over Java Script API. + * WCM Asset in a sandbox exposed over Java Script API. * @author mrogers * */ @@ -45,6 +48,10 @@ public class Asset this.desc = desc; } + /** + * The creator of this asset + * @return the creator + */ public String getCreator() { return desc.getCreator(); @@ -85,9 +92,23 @@ public class Asset return desc.getName(); } + /** + * Get the full path of this asset eg. /www/avm_webapps/ROOT/myFile.jpg + * @return the path of this asset. + */ public String getPath() { - return desc.getPath(); + String path = desc.getPath(); + + if (path != null) + { + String[] splits = path.split(":"); + return splits[1]; + } + else + { + return path; + } } public boolean isFile() @@ -105,6 +126,32 @@ public class Asset return desc.isDeleted(); } + + public int getVersion() + { + return desc.getVersionID(); + } + + /** + * Submit this asset to staging + * @param submitLabel + * @param submitComment + */ + public void submit(String submitLabel, String submitComment) + { + List items = new ArrayList(1); + items.add(this.getPath()); + getSandboxService().submitList(getSandbox().getSandboxRef(), items, submitLabel, submitComment); + } + + /** + * revert this asset + */ + public void revert() + { + //getSandboxService().revertList(getSandbox().getSandboxRef(), items); + } + /** * Get the parent sandbox which contains this asset * @return the parent sandbox which contains this asset @@ -113,4 +160,9 @@ public class Asset { return this.sandbox; } + + private SandboxService getSandboxService() + { + return getSandbox().getWebproject().getWebProjects().getSandboxService(); + } } diff --git a/source/java/org/alfresco/wcm/sandbox/script/Sandbox.java b/source/java/org/alfresco/wcm/sandbox/script/Sandbox.java index 5b922a99dc..bc1521dc46 100644 --- a/source/java/org/alfresco/wcm/sandbox/script/Sandbox.java +++ b/source/java/org/alfresco/wcm/sandbox/script/Sandbox.java @@ -32,6 +32,7 @@ import java.util.List; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.util.ISO8601DateFormat; import org.alfresco.wcm.sandbox.SandboxInfo; +import org.alfresco.wcm.sandbox.SandboxConstants; import org.alfresco.wcm.sandbox.SandboxService; import org.alfresco.wcm.webproject.script.WebProject; @@ -81,7 +82,7 @@ public class Sandbox implements Serializable { // read only } - + /** * Submit the modified contents of this sandbox */ @@ -90,6 +91,35 @@ public class Sandbox implements Serializable getSandboxService().submitAll(getSandboxRef(), submitLabel, submitComment); } + /** + * Submit the specified assets (files and directories) modified contents of this sandbox + */ + public void submitAssets(Asset[] files, String submitLabel, String submitComment) + { + List items = new ArrayList(files.length); + + for(int i = 0; i < files.length; i++) + { + items.add(i, files[i].getPath()); + } + + getSandboxService().submitList(getSandboxRef(), items, submitLabel, submitComment); + } + /** + * Submit the specified files and directories modified contents of this sandbox + */ + public void submit(String[] files, String submitLabel, String submitComment) + { + List items = new ArrayList(files.length); + + for(int i = 0; i < files.length; i++) + { + items.add(i, files[i]); + } + + getSandboxService().submitList(getSandboxRef(), items, submitLabel, submitComment); + } + /** * Submit the modified contents of the webapp within this sandbox */ @@ -171,19 +201,38 @@ public class Sandbox implements Serializable return si.getStoreNames(); } + /** + * Is this an author sandbox ? + * @return is this an author sandbox + */ + public boolean isAuthorSandbox() + { + return si.getSandboxType().equals(SandboxConstants.PROP_SANDBOX_AUTHOR_MAIN); + } + + /** + * Is this a staging sandbox ? + * @return is this an author sandbox + */ + public boolean isStagingSandbox() + { + return si.getSandboxType().equals(SandboxConstants.PROP_SANDBOX_STAGING_MAIN); + } + + /** * Get the modified assets within this sandbox * @return the list of changed assets */ - public List getModifiedAssets() + public Asset[] getModifiedAssets() { List items = getSandboxService().listChangedAll(getSandboxRef(), true); - ArrayList ret = new ArrayList(items.size()); + Asset[] ret = new Asset[items.size()]; + int i = 0; for(AVMNodeDescriptor item : items) { - Asset a = new Asset(this, item); - ret.add(a); + ret[i++] = new Asset(this, item); } return ret; } @@ -192,38 +241,32 @@ public class Sandbox implements Serializable * Get the modified assets within this sandbox * @return the list of changed assets */ - public List getModifiedAssetsWebApp(String webApp) + public Asset[] getModifiedAssetsWebApp(String webApp) { List items = getSandboxService().listChangedWebApp(getSandboxRef(), webApp, true); - ArrayList ret = new ArrayList(items.size()); - + Asset[] ret = new Asset[items.size()]; + + int i = 0; for(AVMNodeDescriptor item : items) { - Asset a = new Asset(this, item); - ret.add(a); + ret[i++] = new Asset(this, item); } return ret; } /** - * Submit a list of files + * Get the web project that owns this sandbox + * @return the web project */ - public void submitList(List toSubmit, String submitLabel, String submitComment) - { - // TODO - Interface will add string list - //ss.submitList(sbStoreId, items, submitLabel, submitComment) - } - - public List getAssets(String path) - { - return null; - } - public WebProject getWebproject() { return this.webproject; } + /** + * Get the sandbox service + * @return the sandbox service + */ private SandboxService getSandboxService() { return webproject.getWebProjects().getSandboxService();