Merged HEAD (5.2) to 5.2.N (5.2.1)

127579 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)
      126567 jvonka: Node Associations - further updates
      - for child assocs, do not expose assoc child qname (nominally like file/folder for primary child assoc)
      - additional api tests (+ve & -ve) for peer assocs & secondary child assocs
      - RA-745, RA-920, RA-921, RA-930, RA-742, RA-918, RA-919


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127672 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-06-03 14:14:43 +00:00
parent c49322624a
commit 50af2e5cc1
9 changed files with 257 additions and 176 deletions

View File

@@ -24,6 +24,8 @@ import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
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;
@@ -108,17 +110,25 @@ public class NodeTargetsRelation extends AbstractNodeRelation implements
for (AssocTarget assoc : entity)
{
QName assocTypeQName = getAssocType(assoc.getAssocType(), true);
String assocTypeStr = assoc.getAssocType();
QName assocTypeQName = getAssocType(assocTypeStr);
String targetNodeId = assoc.getTargetId();
try
{
NodeRef tgtNodeRef = nodes.validateNode(assoc.getTargetId());
NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);
nodeService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
}
catch (AssociationExistsException aee)
{
throw new ConstraintViolatedException(aee.getMessage());
}
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);
}
@@ -133,21 +143,31 @@ public class NodeTargetsRelation extends AbstractNodeRelation implements
NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);
String assocTypeStr = parameters.getParameter(PARAM_ASSOC_TYPE);
if ((assocTypeStr != null) && (! assocTypeStr.isEmpty()))
QNamePattern assocTypeQName = getAssocType(assocTypeStr, false, true);
if (assocTypeQName == null)
{
QName assocTypeQName = QName.createQName(assocTypeStr, namespaceService);
nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
assocTypeQName = RegexQNamePattern.MATCH_ALL;
}
else
// note: even if assocType is provided, we currently don't use nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
// since silent it returns void even if nothing deleted, where as we return 404
boolean found = false;
List<AssociationRef> assocRefs = nodeService.getTargetAssocs(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sourceNodeId), assocTypeQName);
for (AssociationRef assocRef : assocRefs)
{
List<AssociationRef> assocRefs = nodeService.getTargetAssocs(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sourceNodeId), RegexQNamePattern.MATCH_ALL);
for (AssociationRef assocRef : assocRefs)
if (assocRef.getTargetRef().equals(tgtNodeRef))
{
if (assocRef.getTargetRef().equals(tgtNodeRef))
{
nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocRef.getTypeQName());
}
nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocRef.getTypeQName());
found = true;
}
}
if (! found)
{
throw new EntityNotFoundException(sourceNodeId+","+assocTypeStr+","+targetNodeId);
}
}
}