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:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user