mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
127604 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2) 127414 jvonka: Node Associations - create node with assocs (peer &/or secondary child) - can be optionally used to create (eg. mandatory) assoc(s) to other existing node(s) RA-925 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127711 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -480,6 +480,7 @@
|
||||
<property name="ignoreTypes" ref="nodes.ignoreTypes"/>
|
||||
<property name="nonAttachContentTypes" ref="nodes.nonAttachContentTypes"/>
|
||||
<property name="poster" ref="activitiesPoster" />
|
||||
<property name="nodeAssocService" ref="NodeAssocService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="Nodes" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
|
@@ -30,6 +30,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -223,6 +225,26 @@ public interface Nodes
|
||||
*/
|
||||
QName createQName(String qnameStr);
|
||||
|
||||
QName getAssocType(String assocTypeQNameStr);
|
||||
|
||||
QName getAssocType(String assocTypeQNameStr, boolean mandatory);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parentNodeId
|
||||
* @param entities
|
||||
* @return
|
||||
*/
|
||||
List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sourceNodeId
|
||||
* @param entities
|
||||
* @return
|
||||
*/
|
||||
List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities);
|
||||
|
||||
/**
|
||||
* API Constants - query parameters, etc
|
||||
*/
|
||||
|
@@ -56,6 +56,7 @@ import org.alfresco.rest.api.Activities;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.QuickShareLinks;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.ContentInfo;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
@@ -64,6 +65,7 @@ import org.alfresco.rest.api.model.PathInfo;
|
||||
import org.alfresco.rest.api.model.PathInfo.ElementInfo;
|
||||
import org.alfresco.rest.api.model.QuickShareLink;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.api.nodes.NodeAssocService;
|
||||
import org.alfresco.rest.framework.core.exceptions.ApiException;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
||||
@@ -100,6 +102,7 @@ import org.alfresco.service.cmr.model.FileExistsException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.AssociationExistsException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
@@ -198,6 +201,7 @@ public class NodesImpl implements Nodes
|
||||
private SiteService siteService;
|
||||
private ActivityPoster poster;
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private NodeAssocService nodeAssocService;
|
||||
|
||||
private enum Activity_Type
|
||||
{
|
||||
@@ -289,6 +293,13 @@ public class NodesImpl implements Nodes
|
||||
this.poster = poster;
|
||||
}
|
||||
|
||||
// Introduces permissions for Node Assoc (see public-rest-context.xml)
|
||||
public void setNodeAssocService(NodeAssocService nodeAssocService)
|
||||
{
|
||||
this.nodeAssocService = nodeAssocService;
|
||||
}
|
||||
|
||||
|
||||
// excluded namespaces (aspects, properties, assoc types)
|
||||
private static final List<String> EXCLUDED_NS = Arrays.asList(NamespaceService.SYSTEM_MODEL_1_0_URI);
|
||||
|
||||
@@ -1586,6 +1597,18 @@ public class NodesImpl implements Nodes
|
||||
writer.putContent("");
|
||||
}
|
||||
|
||||
// eg. to create mandatory assoc(s)
|
||||
|
||||
if (nodeInfo.getTargets() != null)
|
||||
{
|
||||
addTargets(nodeRef.getId(), nodeInfo.getTargets());
|
||||
}
|
||||
|
||||
if (nodeInfo.getSecondaryChildren() != null)
|
||||
{
|
||||
addChildren(nodeRef.getId(), nodeInfo.getSecondaryChildren());
|
||||
}
|
||||
|
||||
Node newNode = getFolderOrDocument(nodeRef.getId(), parameters);
|
||||
|
||||
/* RA-834: commented-out since not currently applicable for empty file
|
||||
@@ -1612,6 +1635,105 @@ public class NodesImpl implements Nodes
|
||||
return parentNodeRef;
|
||||
}
|
||||
|
||||
public List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities)
|
||||
{
|
||||
NodeRef parentNodeRef = validateNode(parentNodeId);
|
||||
|
||||
List<AssocChild> result = new ArrayList<>(entities.size());
|
||||
|
||||
for (AssocChild assoc : entities)
|
||||
{
|
||||
QName assocTypeQName = getAssocType(assoc.getAssocType());
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef childNodeRef = validateNode(assoc.getChildId());
|
||||
|
||||
String nodeName = (String)nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
|
||||
QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
|
||||
|
||||
nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
|
||||
}
|
||||
catch (AssociationExistsException aee)
|
||||
{
|
||||
throw new ConstraintViolatedException(aee.getMessage());
|
||||
}
|
||||
catch (DuplicateChildNodeNameException dcne)
|
||||
{
|
||||
throw new ConstraintViolatedException(dcne.getMessage());
|
||||
}
|
||||
|
||||
result.add(assoc);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities)
|
||||
{
|
||||
List<AssocTarget> result = new ArrayList<>(entities.size());
|
||||
|
||||
NodeRef srcNodeRef = validateNode(sourceNodeId);
|
||||
|
||||
for (AssocTarget assoc : entities)
|
||||
{
|
||||
String assocTypeStr = assoc.getAssocType();
|
||||
QName assocTypeQName = getAssocType(assocTypeStr);
|
||||
|
||||
String targetNodeId = assoc.getTargetId();
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef tgtNodeRef = validateNode(targetNodeId);
|
||||
nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
|
||||
}
|
||||
catch (AssociationExistsException aee)
|
||||
{
|
||||
throw new ConstraintViolatedException("Node association '"+assocTypeStr+"' already exists from "+sourceNodeId+" to "+targetNodeId);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
// note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
|
||||
throw new InvalidArgumentException(sourceNodeId+","+assocTypeStr+","+targetNodeId);
|
||||
}
|
||||
|
||||
result.add(assoc);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public QName getAssocType(String assocTypeQNameStr)
|
||||
{
|
||||
return getAssocType(assocTypeQNameStr, true);
|
||||
}
|
||||
|
||||
public QName getAssocType(String assocTypeQNameStr, boolean mandatory)
|
||||
{
|
||||
QName assocType = null;
|
||||
|
||||
if ((assocTypeQNameStr != null) && (! assocTypeQNameStr.isEmpty()))
|
||||
{
|
||||
assocType = createQName(assocTypeQNameStr);
|
||||
if (dictionaryService.getAssociation(assocType) == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unknown assocType: " + assocTypeQNameStr);
|
||||
}
|
||||
|
||||
if (EXCLUDED_NS.contains(assocType.getNamespaceURI()))
|
||||
{
|
||||
throw new InvalidArgumentException("Invalid assocType: " + assocTypeQNameStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (mandatory && (assocType == null))
|
||||
{
|
||||
throw new InvalidArgumentException("Missing assocType");
|
||||
}
|
||||
|
||||
return assocType;
|
||||
}
|
||||
|
||||
|
||||
private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props)
|
||||
{
|
||||
NodeRef newNode = null;
|
||||
|
@@ -75,8 +75,11 @@ public class Node implements Comparable<Node>
|
||||
protected PathInfo pathInfo;
|
||||
protected String prefixTypeQName;
|
||||
|
||||
// note: currently only used for create request
|
||||
// please note: these are currently only used (optionally) for node create request
|
||||
protected String relativePath;
|
||||
protected List<AssocChild> secondaryChildren;
|
||||
protected List<AssocTarget> targets;
|
||||
|
||||
|
||||
protected List<String> aspectNames;
|
||||
protected Map<String, Object> properties;
|
||||
@@ -304,14 +307,14 @@ public class Node implements Comparable<Node>
|
||||
this.allowableOperations = allowableOperations;
|
||||
}
|
||||
|
||||
public String getRelativePath()
|
||||
public List<AssocTarget> getTargets()
|
||||
{
|
||||
return relativePath;
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void setRelativePath(String relativePath)
|
||||
public void setTargets(List<AssocTarget> targets)
|
||||
{
|
||||
this.relativePath = relativePath;
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
public Date getArchivedAt()
|
||||
@@ -350,6 +353,26 @@ public class Node implements Comparable<Node>
|
||||
return EqualsHelper.nullSafeEquals(getNodeRef(), node.getNodeRef());
|
||||
}
|
||||
|
||||
public String getRelativePath()
|
||||
{
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
public void setRelativePath(String relativePath)
|
||||
{
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
|
||||
public List<AssocChild> getSecondaryChildren()
|
||||
{
|
||||
return secondaryChildren;
|
||||
}
|
||||
|
||||
public void setSecondaryChildren(List<AssocChild> secondaryChildren)
|
||||
{
|
||||
this.secondaryChildren = secondaryChildren;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Node node)
|
||||
{
|
||||
|
@@ -24,7 +24,6 @@ import org.alfresco.rest.api.model.Assoc;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
@@ -101,37 +100,6 @@ public class AbstractNodeRelation implements InitializingBean
|
||||
this.dictionaryService = sr.getDictionaryService();
|
||||
}
|
||||
|
||||
protected QName getAssocType(String assocTypeQNameStr)
|
||||
{
|
||||
return getAssocType(assocTypeQNameStr, true);
|
||||
}
|
||||
|
||||
protected QName getAssocType(String assocTypeQNameStr, boolean mandatory)
|
||||
{
|
||||
QName assocType = null;
|
||||
|
||||
if ((assocTypeQNameStr != null) && (! assocTypeQNameStr.isEmpty()))
|
||||
{
|
||||
assocType = nodes.createQName(assocTypeQNameStr);
|
||||
if (dictionaryService.getAssociation(assocType) == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unknown assocType: " + assocTypeQNameStr);
|
||||
}
|
||||
|
||||
if (EXCLUDED_NS.contains(assocType.getNamespaceURI()))
|
||||
{
|
||||
throw new InvalidArgumentException("Invalid assocType: " + assocTypeQNameStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (mandatory && (assocType == null))
|
||||
{
|
||||
throw new InvalidArgumentException("Missing "+PARAM_ASSOC_TYPE);
|
||||
}
|
||||
|
||||
return assocType;
|
||||
}
|
||||
|
||||
protected QNamePattern getAssocTypeFromWhereElseAll(Parameters parameters)
|
||||
{
|
||||
QNamePattern assocTypeQNamePattern = RegexQNamePattern.MATCH_ALL;
|
||||
@@ -145,7 +113,7 @@ public class AbstractNodeRelation implements InitializingBean
|
||||
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
||||
if (assocTypeQNameStr != null)
|
||||
{
|
||||
assocTypeQNamePattern = getAssocType(assocTypeQNameStr);
|
||||
assocTypeQNamePattern = nodes.getAssocType(assocTypeQNameStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -53,8 +53,10 @@ import org.springframework.extensions.webscripts.servlet.FormData;
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@RelationshipResource(name = "children", entityResource = NodesEntityResource.class, title = "Folder children")
|
||||
public class NodeChildrenRelation implements RelationshipResourceAction.Read<Node>, RelationshipResourceAction.Create<Node>,
|
||||
MultiPartRelationshipResourceAction.Create<Node>, InitializingBean
|
||||
public class NodeChildrenRelation implements
|
||||
RelationshipResourceAction.Read<Node>,
|
||||
RelationshipResourceAction.Create<Node>,
|
||||
MultiPartRelationshipResourceAction.Create<Node>, InitializingBean
|
||||
{
|
||||
private Nodes nodes;
|
||||
|
||||
@@ -108,7 +110,6 @@ public class NodeChildrenRelation implements RelationshipResourceAction.Read<Nod
|
||||
{
|
||||
List<Node> result = new ArrayList<>(nodeInfos.size());
|
||||
|
||||
// TODO should we prevent batch create when we introduce new batch/bulk operation API ?
|
||||
for (Node nodeInfo : nodeInfos)
|
||||
{
|
||||
result.add(nodes.createNode(parentFolderNodeId, nodeInfo, parameters));
|
||||
|
@@ -79,7 +79,7 @@ public class NodeParentsRelation extends AbstractNodeRelation implements Relatio
|
||||
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
||||
if (assocTypeQNameStr != null)
|
||||
{
|
||||
assocTypeQNameParam = getAssocType(assocTypeQNameStr);
|
||||
assocTypeQNameParam = nodes.getAssocType(assocTypeQNameStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,27 +18,21 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.service.cmr.repository.AssociationExistsException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -88,37 +82,9 @@ public class NodeSecondaryChildrenRelation extends AbstractNodeRelation implemen
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Add secondary child assoc")
|
||||
public List<AssocChild> create(String parentNodeId, List<AssocChild> entity, Parameters parameters)
|
||||
public List<AssocChild> create(String parentNodeId, List<AssocChild> entities, Parameters parameters)
|
||||
{
|
||||
List<AssocChild> result = new ArrayList<>(entity.size());
|
||||
|
||||
NodeRef parentNodeRef = nodes.validateNode(parentNodeId);
|
||||
|
||||
for (AssocChild assoc : entity)
|
||||
{
|
||||
QName assocTypeQName = getAssocType(assoc.getAssocType());
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef childNodeRef = nodes.validateNode(assoc.getChildId());
|
||||
|
||||
String nodeName = (String)nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
|
||||
QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
|
||||
|
||||
nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
|
||||
}
|
||||
catch (AssociationExistsException aee)
|
||||
{
|
||||
throw new ConstraintViolatedException(aee.getMessage());
|
||||
}
|
||||
catch (DuplicateChildNodeNameException dcne)
|
||||
{
|
||||
throw new ConstraintViolatedException(dcne.getMessage());
|
||||
}
|
||||
|
||||
result.add(assoc);
|
||||
}
|
||||
return result;
|
||||
return nodes.addChildren(parentNodeId, entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +95,7 @@ public class NodeSecondaryChildrenRelation extends AbstractNodeRelation implemen
|
||||
NodeRef childNodeRef = nodes.validateNode(childNodeId);
|
||||
|
||||
String assocTypeStr = parameters.getParameter(PARAM_ASSOC_TYPE);
|
||||
QName assocTypeQName = getAssocType(assocTypeStr, false);
|
||||
QName assocTypeQName = nodes.getAssocType(assocTypeStr, false);
|
||||
|
||||
List<ChildAssociationRef> assocRefs = nodeService.getChildAssocs(parentNodeRef);
|
||||
|
||||
|
@@ -21,22 +21,17 @@ package org.alfresco.rest.api.nodes;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.service.cmr.repository.AssociationExistsException;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -72,37 +67,9 @@ public class NodeTargetsRelation extends AbstractNodeRelation implements
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Add node assoc")
|
||||
public List<AssocTarget> create(String sourceNodeId, List<AssocTarget> entity, Parameters parameters)
|
||||
public List<AssocTarget> create(String sourceNodeId, List<AssocTarget> entities, Parameters parameters)
|
||||
{
|
||||
List<AssocTarget> result = new ArrayList<>(entity.size());
|
||||
|
||||
NodeRef srcNodeRef = nodes.validateNode(sourceNodeId);
|
||||
|
||||
for (AssocTarget assoc : entity)
|
||||
{
|
||||
String assocTypeStr = assoc.getAssocType();
|
||||
QName assocTypeQName = getAssocType(assocTypeStr);
|
||||
|
||||
String targetNodeId = assoc.getTargetId();
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);
|
||||
nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
|
||||
}
|
||||
catch (AssociationExistsException aee)
|
||||
{
|
||||
throw new ConstraintViolatedException("Node association '"+assocTypeStr+"' already exists from "+sourceNodeId+" to "+targetNodeId);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
// note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
|
||||
throw new InvalidArgumentException(sourceNodeId+","+assocTypeStr+","+targetNodeId);
|
||||
}
|
||||
|
||||
result.add(assoc);
|
||||
}
|
||||
return result;
|
||||
return nodes.addTargets(sourceNodeId, entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +80,7 @@ public class NodeTargetsRelation extends AbstractNodeRelation implements
|
||||
NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);
|
||||
|
||||
String assocTypeStr = parameters.getParameter(PARAM_ASSOC_TYPE);
|
||||
QNamePattern assocTypeQName = getAssocType(assocTypeStr, false);
|
||||
QNamePattern assocTypeQName = nodes.getAssocType(assocTypeStr, false);
|
||||
|
||||
if (assocTypeQName == null)
|
||||
{
|
||||
|
@@ -1198,6 +1198,77 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNodeWithAssocs() throws Exception
|
||||
{
|
||||
// as user 1
|
||||
String myFolderNodeId = getMyNodeId(user1);
|
||||
|
||||
// create node with some assocs in a single call
|
||||
|
||||
// create folder
|
||||
Node n = new Node();
|
||||
n.setName("f1");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES));
|
||||
HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201);
|
||||
String f1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
|
||||
|
||||
// create content node
|
||||
String o1Name = "o1";
|
||||
n = new Node();
|
||||
n.setName(o1Name);
|
||||
n.setNodeType(TYPE_CM_CONTENT);
|
||||
response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201);
|
||||
String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
|
||||
|
||||
String o2Name = "o2";
|
||||
n = new Node();
|
||||
n.setName(o2Name);
|
||||
n.setNodeType(TYPE_CM_CONTENT);
|
||||
response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201);
|
||||
String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
|
||||
|
||||
// create folder node with some assocs
|
||||
String f2Name = "f2";
|
||||
n = new Node();
|
||||
n.setName(f2Name);
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
|
||||
AssocChild secChild = new AssocChild(o1Id, ASSOC_TYPE_CM_CONTAINS);
|
||||
n.setSecondaryChildren(Collections.singletonList(secChild));
|
||||
|
||||
AssocTarget tgt = new AssocTarget(o2Id, ASSOC_TYPE_CM_REFERENCES);
|
||||
n.setTargets(Collections.singletonList(tgt));
|
||||
|
||||
response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201);
|
||||
String f2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
|
||||
|
||||
try
|
||||
{
|
||||
Paging paging = getPaging(0, 100);
|
||||
|
||||
response = getAll(getNodeSecondaryChildrenUrl(f2Id), user1, paging, null, 200);
|
||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(1, nodes.size());
|
||||
assertEquals(o1Id, nodes.get(0).getId());
|
||||
|
||||
response = getAll(getNodeTargetsUrl(f2Id), user1, paging, null, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(1, nodes.size());
|
||||
assertEquals(o2Id, nodes.get(0).getId());
|
||||
|
||||
// TODO test model with mandatory aspect
|
||||
}
|
||||
finally
|
||||
{
|
||||
// some cleanup
|
||||
Map<String, String> params = Collections.singletonMap(Nodes.PARAM_PERMANENT, "true");
|
||||
delete(URL_NODES, user1, f1Id, params, 204);
|
||||
delete(URL_NODES, user1, f2Id, params, 204);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
|
@@ -25,6 +25,9 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -70,7 +73,10 @@ public class Node
|
||||
|
||||
protected List<String> allowableOperations;
|
||||
|
||||
protected String relativePath; // optionally used in create node request
|
||||
// please note: these are currently only used (optionally) for node create request
|
||||
protected String relativePath;
|
||||
protected List<AssocChild> secondaryChildren;
|
||||
protected List<AssocTarget> targets;
|
||||
|
||||
public Node()
|
||||
{
|
||||
@@ -246,6 +252,7 @@ public class Node
|
||||
this.allowableOperations = allowableOperations;
|
||||
}
|
||||
|
||||
|
||||
public String getRelativePath()
|
||||
{
|
||||
return relativePath;
|
||||
@@ -256,6 +263,27 @@ public class Node
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
|
||||
public List<AssocChild> getSecondaryChildren()
|
||||
{
|
||||
return secondaryChildren;
|
||||
}
|
||||
|
||||
public void setSecondaryChildren(List<AssocChild> secondaryChildren)
|
||||
{
|
||||
this.secondaryChildren = secondaryChildren;
|
||||
}
|
||||
|
||||
public List<AssocTarget> getTargets()
|
||||
{
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void setTargets(List<AssocTarget> targets)
|
||||
{
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
|
||||
// note: can be child or peer (latter has assocType only)
|
||||
protected Association association;
|
||||
|
||||
|
Reference in New Issue
Block a user