mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
CMIS Relationship support in AtomPub binding
- getRelationships - getRelationship - createRelationship - unit tests for above TODO: delete relationship, includeRelationships flag git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14461 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.Serializable;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
@@ -85,6 +86,11 @@ public class Association implements Scopeable, Serializable
|
||||
return assocRef.getTypeQName().toString();
|
||||
}
|
||||
|
||||
public QName getTypeQName()
|
||||
{
|
||||
return assocRef.getTypeQName();
|
||||
}
|
||||
|
||||
public ScriptNode getSource()
|
||||
{
|
||||
return (ScriptNode)new ValueConverter().convertValueForScript(this.services, this.scope, null, assocRef.getSourceRef());
|
||||
|
@@ -1361,13 +1361,14 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
* @param target Destination node for the association
|
||||
* @param assocType Association type qname (short form or fully qualified)
|
||||
*/
|
||||
public void createAssociation(ScriptNode target, String assocType)
|
||||
public Association createAssociation(ScriptNode target, String assocType)
|
||||
{
|
||||
ParameterCheck.mandatory("Target", target);
|
||||
ParameterCheck.mandatoryString("Association Type Name", assocType);
|
||||
|
||||
this.nodeService.createAssociation(this.nodeRef, target.nodeRef, createQName(assocType));
|
||||
AssociationRef assocRef = this.nodeService.createAssociation(this.nodeRef, target.nodeRef, createQName(assocType));
|
||||
reset();
|
||||
return new Association(this.services, assocRef);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -204,11 +204,11 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
{
|
||||
tenantAdminService.register(this);
|
||||
|
||||
if (companyHomeRefs == null)
|
||||
{
|
||||
companyHomeRefs = new ConcurrentHashMap<String, NodeRef>(4);
|
||||
}
|
||||
|
||||
if (companyHomeRefs == null)
|
||||
{
|
||||
companyHomeRefs = new ConcurrentHashMap<String, NodeRef>(4);
|
||||
}
|
||||
|
||||
getCompanyHome();
|
||||
}
|
||||
|
||||
@@ -237,26 +237,26 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
String tenantDomain = tenantAdminService.getCurrentUserDomain();
|
||||
NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain);
|
||||
if (companyHomeRef == null)
|
||||
{
|
||||
{
|
||||
companyHomeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||
{
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
public NodeRef execute() throws Exception
|
||||
{
|
||||
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
public NodeRef execute() throws Exception
|
||||
{
|
||||
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
companyHomeRefs.put(tenantDomain, companyHomeRef);
|
||||
}
|
||||
return companyHomeRef;
|
||||
@@ -336,51 +336,51 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
}
|
||||
else
|
||||
{
|
||||
// construct store reference
|
||||
if (reference.length < 3)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Reference " + Arrays.toString(reference) + " is not properly formed");
|
||||
}
|
||||
StoreRef storeRef = new StoreRef(reference[0], reference[1]);
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
if (referenceType.equals("node"))
|
||||
{
|
||||
// find the node the rest of the path is relative to
|
||||
NodeRef relRef = new NodeRef(storeRef, reference[2]);
|
||||
if (nodeService.exists(relRef))
|
||||
{
|
||||
// are there any relative path elements to process?
|
||||
if (reference.length == 3 || reference.length == 4)
|
||||
{
|
||||
// just the NodeRef can be specified
|
||||
nodeRef = relRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
// process optional path elements
|
||||
List<String> paths = new ArrayList<String>(reference.length - 3);
|
||||
for (int i=3; i<reference.length; i++)
|
||||
{
|
||||
paths.add(reference[i]);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef parentRef = nodeService.getPrimaryParent(relRef).getParentRef();
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(parentRef, paths);
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// construct store reference
|
||||
if (reference.length < 3)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Reference " + Arrays.toString(reference) + " is not properly formed");
|
||||
}
|
||||
StoreRef storeRef = new StoreRef(reference[0], reference[1]);
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
if (referenceType.equals("node"))
|
||||
{
|
||||
// find the node the rest of the path is relative to
|
||||
NodeRef relRef = new NodeRef(storeRef, reference[2]);
|
||||
if (nodeService.exists(relRef))
|
||||
{
|
||||
// are there any relative path elements to process?
|
||||
if (reference.length == 3 || reference.length == 4)
|
||||
{
|
||||
// just the NodeRef can be specified
|
||||
nodeRef = relRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
// process optional path elements
|
||||
List<String> paths = new ArrayList<String>(reference.length - 3);
|
||||
for (int i=3; i<reference.length; i++)
|
||||
{
|
||||
paths.add(reference[i]);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef parentRef = nodeService.getPrimaryParent(relRef).getParentRef();
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(parentRef, paths);
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (referenceType.equals("path"))
|
||||
{
|
||||
else if (referenceType.equals("path"))
|
||||
{
|
||||
// NOTE: special case for avm based path
|
||||
if (reference[0].equals(StoreRef.PROTOCOL_AVM))
|
||||
{
|
||||
@@ -398,37 +398,37 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Allow a root path to be specified - for now, hard-code to Company Home
|
||||
//NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
NodeRef rootNodeRef = getCompanyHome();
|
||||
if (reference.length == 3)
|
||||
{
|
||||
nodeRef = rootNodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] path = new String[reference.length - /*2*/3];
|
||||
System.arraycopy(reference, /*2*/3, path, 0, path.length);
|
||||
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path));
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
// TODO: Allow a root path to be specified - for now, hard-code to Company Home
|
||||
//NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
NodeRef rootNodeRef = getCompanyHome();
|
||||
if (reference.length == 3)
|
||||
{
|
||||
nodeRef = rootNodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] path = new String[reference.length - /*2*/3];
|
||||
System.arraycopy(reference, /*2*/3, path, 0, path.length);
|
||||
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path));
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// TODO: Implement 'qname' style
|
||||
throw new AlfrescoRuntimeException("Web Script Node URL specified an invalid reference style of '" + referenceType + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// TODO: Implement 'qname' style
|
||||
throw new AlfrescoRuntimeException("Web Script Node URL specified an invalid reference style of '" + referenceType + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodeRef;
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package org.alfresco.repo.template;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -34,6 +33,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.processor.ProcessorExtension;
|
||||
import org.alfresco.repo.processor.BaseProcessor;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
@@ -331,7 +331,12 @@ public class FreeMarkerProcessor extends BaseProcessor implements TemplateProces
|
||||
{
|
||||
return new TemplateNode((NodeRef)value, this.services, imageResolver);
|
||||
}
|
||||
|
||||
|
||||
else if (value instanceof AssociationRef)
|
||||
{
|
||||
return new TemplateAssociation((AssociationRef)value, this.services, imageResolver);
|
||||
}
|
||||
|
||||
else if (value instanceof Map)
|
||||
{
|
||||
Map<Object, Object> map = (Map<Object, Object>)value;
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.template;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Object representing an association
|
||||
*/
|
||||
public class TemplateAssociation implements Serializable
|
||||
{
|
||||
/** Serial version UUID*/
|
||||
private static final long serialVersionUID = -2903588739741433082L;
|
||||
|
||||
/** Service registry **/
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** Association reference **/
|
||||
private AssociationRef assocRef;
|
||||
|
||||
/** Image Resolver **/
|
||||
private TemplateImageResolver resolver;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param services
|
||||
* @param assocRef
|
||||
*/
|
||||
public TemplateAssociation(AssociationRef assocRef, ServiceRegistry services, TemplateImageResolver resolver)
|
||||
{
|
||||
this.assocRef = assocRef;
|
||||
this.services = services;
|
||||
this.resolver = resolver;
|
||||
}
|
||||
|
||||
public AssociationRef getAssociationRef()
|
||||
{
|
||||
return this.assocRef;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return assocRef.getTypeQName().toString();
|
||||
}
|
||||
|
||||
public QName getTypeQName()
|
||||
{
|
||||
return assocRef.getTypeQName();
|
||||
}
|
||||
|
||||
public TemplateNode getSource()
|
||||
{
|
||||
return new TemplateNode(assocRef.getSourceRef(), services, resolver);
|
||||
}
|
||||
|
||||
public TemplateNode getTarget()
|
||||
{
|
||||
return new TemplateNode(assocRef.getTargetRef(), services, resolver);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user