. JavaScript API inter-store copy support

- Transparent support for inter-store copy added to JavaScript Node and AVMNode implementations
   The existing API mechanisms for copy() now support passing of Node or AVMNode and visa-versa as the destination target
   No changes to existing copy() semantics and no new services/APIs to learn
. Improvements to handling of missing input parameters in JavaScript Node APIs
. Added Workspace->Workspace support to CrossRepositoryCopyService

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5047 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast 2007-02-06 10:36:46 +00:00
parent 92c73dd54a
commit d781cc74c1
5 changed files with 2097 additions and 1931 deletions

View File

@ -90,7 +90,7 @@
</property>
</bean>
<bean id="avmScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.AVM">
<bean id="avmScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.AVM">
<property name="scriptName">
<value>avm</value>
</property>
@ -99,4 +99,13 @@
</property>
</bean>
<bean id="crossCopyScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.CrossRepositoryCopy">
<property name="scriptName">
<value>crossRepoCopy</value>
</property>
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
</bean>
</beans>

View File

@ -20,6 +20,7 @@ import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.CrossRepositoryCopyService;
@ -117,24 +118,24 @@ public class CrossRepositoryCopyServiceImpl implements
{
StoreRef srcStoreRef = src.getStoreRef();
StoreRef dstStoreRef = dst.getStoreRef();
if (srcStoreRef.getProtocol().equals("avm"))
if (srcStoreRef.getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
if (dstStoreRef.getProtocol().equals("avm"))
if (dstStoreRef.getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
copyAVMToAVM(src, dst, name);
}
else
else if (dstStoreRef.getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
{
copyAVMToRepo(src, dst, name);
}
}
else
else if (srcStoreRef.getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
{
if (dstStoreRef.getProtocol().equals("avm"))
if (dstStoreRef.getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
copyRepoToAVM(src, dst, name);
}
else
else if (dstStoreRef.getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
{
copyRepoToRepo(src, dst, name);
}
@ -277,6 +278,8 @@ public class CrossRepositoryCopyServiceImpl implements
*/
private void copyRepoToRepo(NodeRef src, NodeRef dst, String name)
{
ChildAssociationRef assocRef = fNodeService.getPrimaryParent(src);
fCopyService.copyAndRename(src, dst, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
}
private void copyData(InputStream in, OutputStream out)

View File

@ -19,7 +19,8 @@ package org.alfresco.repo.jscript;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.mozilla.javascript.Scriptable;
/**
@ -31,6 +32,7 @@ import org.mozilla.javascript.Scriptable;
public class AVMNode extends Node
{
private String path;
private int version;
/**
* Constructor
@ -41,8 +43,7 @@ public class AVMNode extends Node
*/
public AVMNode(NodeRef nodeRef, ServiceRegistry services)
{
super(nodeRef, services);
this.path = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
this(nodeRef, services, null);
}
/**
@ -56,11 +57,13 @@ public class AVMNode extends Node
public AVMNode(NodeRef nodeRef, ServiceRegistry services, Scriptable scope)
{
super(nodeRef, services, scope);
this.path = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
this.path = versionPath.getSecond();
this.version = versionPath.getFirst();
}
/**
* Factory method
* Factory methods
*/
@Override
public Node newInstance(NodeRef nodeRef, ServiceRegistry services, Scriptable scope)
@ -68,6 +71,11 @@ public class AVMNode extends Node
return new AVMNode(nodeRef, services, scope);
}
public Node newInstance(String path, int version, ServiceRegistry services, Scriptable scope)
{
return new AVMNode(AVMNodeConverter.ToNodeRef(version, path), services, scope);
}
// TODO: changing the 'name' property (either directly using .name or with .properties.name)
// invalidates the path and the base noderef instance!
// AVMService has a specific rename method - use this and block name property changes?
@ -85,6 +93,16 @@ public class AVMNode extends Node
return getPath();
}
public int getVersion()
{
return this.version;
}
public int jsGet_version()
{
return getVersion();
}
/**
* Copy this Node into a new parent destination.
*
@ -95,14 +113,9 @@ public class AVMNode extends Node
@Override
public Node copy(Node destination)
{
Node copy = null;
ParameterCheck.mandatory("Destination Node", destination);
if (destination instanceof AVMNode)
{
copy = copy(((AVMNode)destination).getPath());
}
return copy;
return getCrossRepositoryCopyHelper().copy(this, destination, getName());
}
/**
@ -114,17 +127,12 @@ public class AVMNode extends Node
*/
public Node copy(String destination)
{
Node copy = null;
ParameterCheck.mandatoryString("Destination Path", destination);
if (destination != null && destination.length() != 0)
{
this.services.getAVMService().copy(-1, getPath(), destination, getName());
copy = newInstance(
AVMNodeConverter.ToNodeRef(-1, destination + '/' + getName()),
this.services, this.scope);
}
return copy;
this.services.getAVMService().copy(this.version, this.path, destination, getName());
return newInstance(
AVMNodeConverter.ToNodeRef(-1, AVMNodeConverter.ExtendAVMPath(destination, getName())),
this.services, this.scope);
}
/**
@ -137,6 +145,8 @@ public class AVMNode extends Node
@Override
public boolean move(Node destination)
{
ParameterCheck.mandatory("Destination Node", destination);
boolean success = false;
if (destination instanceof AVMNode)
@ -156,6 +166,8 @@ public class AVMNode extends Node
*/
public boolean move(String destination)
{
ParameterCheck.mandatoryString("Destination Path", destination);
boolean success = false;
if (destination != null && destination.length() != 0)
@ -164,7 +176,7 @@ public class AVMNode extends Node
this.services.getAVMService().rename(
parent.getPath(), getName(), destination, getName());
reset(destination + '/' + getName());
reset(AVMNodeConverter.ExtendAVMPath(destination, getName()));
success = true;
}
@ -181,6 +193,8 @@ public class AVMNode extends Node
*/
public boolean rename(String name)
{
ParameterCheck.mandatoryString("Destination name", name);
boolean success = false;
if (name != null && name.length() != 0)
@ -189,7 +203,7 @@ public class AVMNode extends Node
this.services.getAVMService().rename(
parentPath, getName(), parentPath, name);
reset(parentPath + '/' + name);
reset(AVMNodeConverter.ExtendAVMPath(parentPath, name));
success = true;
}
@ -204,14 +218,14 @@ public class AVMNode extends Node
{
super.reset();
this.path = path;
this.nodeRef = AVMNodeConverter.ToNodeRef(-1, path);
this.nodeRef = AVMNodeConverter.ToNodeRef(version, path);
this.id = nodeRef.getId();
}
@Override
public String toString()
{
if (this.services.getAVMService().lookup(-1, this.path) != null)
if (this.services.getAVMService().lookup(version, this.path) != null)
{
return "AVM Path: " + getPath() +
"\nNode Type: " + getType() +

View File

@ -0,0 +1,103 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.jscript;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.mozilla.javascript.Scriptable;
/**
* Helper bean to access Cross Repository copy services from a script context.
*
* @author Kevin Roast
*/
public final class CrossRepositoryCopy extends BaseScriptImplementation implements Scopeable
{
public final static String BEAN_NAME = "crossCopyScript";
/** Service registry */
private ServiceRegistry services;
/** Root scope for this object */
private Scriptable scope;
/**
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
*/
public void setScope(Scriptable scope)
{
this.scope = scope;
}
/**
* Set the service registry
*
* @param services the service registry
*/
public void setServiceRegistry(ServiceRegistry services)
{
this.services = services;
}
/**
* Perform a copy of a source node to the specified parent destination node. The name will
* be applied to the destination node copy.
* <p>
* Inter-store copy operations between Workspace and AVM and visa-versa are supported.
*
* @param src Source node instance
* @param dest Destination parent node instance
* @param name Name of the node copy
*
* @return node representing the copy if successful, null on unsupported store type.
*
* @throws org.alfresco.error.AlfrescoRuntimeException on copy error
*/
public Node copy(Node src, Node dest, String name)
{
ParameterCheck.mandatory("Node source", src);
ParameterCheck.mandatory("Node destination", dest);
ParameterCheck.mandatory("Node destination name", name);
Node result = null;
// perform the copy operation using the repository service
this.services.getCrossRepositoryCopyService().copy(src.getNodeRef(), dest.getNodeRef(), name);
// if we get here then copy succeeded - retrieve the new node reference
if (dest.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(dest.getNodeRef());
String destPath = AVMNodeConverter.ExtendAVMPath(versionPath.getSecond(), name);
AVMNodeDescriptor node = this.services.getAVMService().lookup(-1, destPath);
if (node != null)
{
result = ((AVMNode)dest).newInstance(destPath, -1, this.services, this.scope);
}
}
else if (dest.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
{
result = dest.childByNamePath(name);
}
return result;
}
}

File diff suppressed because it is too large Load Diff