mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merge V3.4-BUG-FIX to HEAD
29233: ALF-8301: Unable to retrieve relationships via CMIS using session.getRelationships(..) call Addition of system test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29279 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -7,7 +7,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
[#assign namespace][@nsLib.entryNS/][/#assign]
|
[#assign namespace][@nsLib.entryNS/][/#assign]
|
||||||
|
|
||||||
[#if node.isDocument]
|
[#if assoc?exists]
|
||||||
|
[@entryLib.assoc assoc=assoc propfilter=filter includeallowableactions=includeAllowableActions ns=namespace/]
|
||||||
|
[#elseif node?exists && node.isDocument]
|
||||||
[@entryLib.document node=node renditionfilter=renditionFilter propfilter=filter includeallowableactions=includeAllowableActions includerelationships=includeRelationships includeacl=includeACL ns=namespace/]
|
[@entryLib.document node=node renditionfilter=renditionFilter propfilter=filter includeallowableactions=includeAllowableActions includerelationships=includeRelationships includeacl=includeACL ns=namespace/]
|
||||||
[#else]
|
[#else]
|
||||||
[@entryLib.folder node=node renditionfilter=renditionFilter propfilter=filter includeallowableactions=includeAllowableActions includerelationships=includeRelationships includeacl=includeACL ns=namespace/]
|
[@entryLib.folder node=node renditionfilter=renditionFilter propfilter=filter includeallowableactions=includeAllowableActions includerelationships=includeRelationships includeacl=includeACL ns=namespace/]
|
||||||
|
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
{
|
{
|
||||||
var object = getObjectFromUrl();
|
var object = getObjectOrAssocFromUrl();
|
||||||
if (object.node === null)
|
if (object.node !== null && typeof(object.node) != 'undefined')
|
||||||
{
|
{
|
||||||
break script;
|
|
||||||
}
|
|
||||||
model.node = object.node;
|
model.node = object.node;
|
||||||
|
|
||||||
// return version
|
// return version
|
||||||
@@ -16,6 +14,15 @@ script:
|
|||||||
returnVersion = "this";
|
returnVersion = "this";
|
||||||
}
|
}
|
||||||
model.node = cmisserver.getReturnVersion(model.node, returnVersion);
|
model.node = cmisserver.getReturnVersion(model.node, returnVersion);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (object.assoc === null)
|
||||||
|
{
|
||||||
|
break script;
|
||||||
|
}
|
||||||
|
model.assoc = object.assoc;
|
||||||
|
}
|
||||||
|
|
||||||
// property filter
|
// property filter
|
||||||
model.filter = args[cmisserver.ARG_FILTER];
|
model.filter = args[cmisserver.ARG_FILTER];
|
||||||
|
@@ -60,3 +60,24 @@ function getAssocFromUrl()
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//Get Node or Association from URL
|
||||||
|
//
|
||||||
|
//@return node or association (or null, if not found)
|
||||||
|
function getObjectOrAssocFromUrl()
|
||||||
|
{
|
||||||
|
var id = url.templateArgs.id;
|
||||||
|
|
||||||
|
if (id === null)
|
||||||
|
{
|
||||||
|
id = args.noderef;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != null && id.indexOf("assoc:") === 0)
|
||||||
|
{
|
||||||
|
return getAssocFromUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getObjectFromUrl();
|
||||||
|
}
|
||||||
|
@@ -56,7 +56,7 @@ public class AssociationIdRelationshipReference implements CMISRelationshipRefer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return cmisServices.getReadableObject(CMISServices.ASSOC_ID_PREFIX + this.assocId, AssociationRef.class);
|
return cmisServices.getReadableObject(this.assocId, AssociationRef.class);
|
||||||
}
|
}
|
||||||
catch (CMISServiceException e)
|
catch (CMISServiceException e)
|
||||||
{
|
{
|
||||||
|
@@ -145,6 +145,14 @@ public class ReferenceFactory
|
|||||||
public CMISRelationshipReference createRelationshipReferenceFromUrl(Map<String, String> args, Map<String, String> templateArgs)
|
public CMISRelationshipReference createRelationshipReferenceFromUrl(Map<String, String> args, Map<String, String> templateArgs)
|
||||||
{
|
{
|
||||||
String assocId = templateArgs.get("assoc_id");
|
String assocId = templateArgs.get("assoc_id");
|
||||||
|
if (assocId == null)
|
||||||
|
{
|
||||||
|
assocId = templateArgs.get("id");
|
||||||
|
}
|
||||||
|
if (assocId == null)
|
||||||
|
{
|
||||||
|
assocId = args.get("noderef");
|
||||||
|
}
|
||||||
if (assocId != null)
|
if (assocId != null)
|
||||||
{
|
{
|
||||||
return new AssociationIdRelationshipReference(cmisService, assocId);
|
return new AssociationIdRelationshipReference(cmisService, assocId);
|
||||||
|
@@ -0,0 +1,120 @@
|
|||||||
|
package org.alfresco.repo.cmis.rest.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.Document;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.Folder;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.ItemIterable;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.ObjectType;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.OperationContext;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.Relationship;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.Session;
|
||||||
|
import org.apache.chemistry.opencmis.client.api.SessionFactory;
|
||||||
|
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
|
||||||
|
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
||||||
|
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||||
|
import org.apache.chemistry.opencmis.commons.enums.BindingType;
|
||||||
|
import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.safehaus.uuid.UUIDGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CMIS Relationship integration tests.
|
||||||
|
*
|
||||||
|
* @author Alex Strachan (tidy up by Alan Davis)
|
||||||
|
*/
|
||||||
|
public class CmisRelationshipSystemTest
|
||||||
|
{
|
||||||
|
static Session session;
|
||||||
|
|
||||||
|
static Document doc1;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void classSetup() throws Exception
|
||||||
|
{
|
||||||
|
SessionFactory factory = SessionFactoryImpl.newInstance();
|
||||||
|
Map<String, String> sessionParameters = new HashMap<String, String>();
|
||||||
|
sessionParameters
|
||||||
|
.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/s/cmis");
|
||||||
|
sessionParameters.put(SessionParameter.USER, "admin");
|
||||||
|
sessionParameters.put(SessionParameter.PASSWORD, "admin");
|
||||||
|
sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
|
||||||
|
sessionParameters.put(SessionParameter.OBJECT_FACTORY_CLASS,
|
||||||
|
AlfrescoObjectFactoryImpl.class.getName());
|
||||||
|
session = factory.getRepositories(sessionParameters).get(0).createSession();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Association example from:
|
||||||
|
* http://forums.alfresco.com/en/viewtopic.php?f=45&t=27219
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> prop1 = new HashMap<String, Object>();
|
||||||
|
prop1.put(PropertyIds.NAME, GUID());
|
||||||
|
prop1.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");
|
||||||
|
|
||||||
|
HashMap<String, Object> prop2 = new HashMap<String, Object>();
|
||||||
|
prop2.put(PropertyIds.NAME, GUID());
|
||||||
|
prop2.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");
|
||||||
|
|
||||||
|
Folder folder = (Folder) session.getObjectByPath("/");
|
||||||
|
|
||||||
|
doc1 = folder.createDocument(prop1, null, null, null, null, null,
|
||||||
|
session.getDefaultContext());
|
||||||
|
Document doc2 = folder.createDocument(prop2, null, null, null, null, null,
|
||||||
|
session.getDefaultContext());
|
||||||
|
|
||||||
|
Map<String, String> relProps = new HashMap<String, String>();
|
||||||
|
relProps.put("cmis:sourceId", doc1.getId());
|
||||||
|
relProps.put("cmis:targetId", doc2.getId());
|
||||||
|
relProps.put("cmis:objectTypeId", "R:ws:relatedArticles");
|
||||||
|
session.createRelationship(relProps, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String GUID()
|
||||||
|
{
|
||||||
|
return UUIDGenerator.getInstance().generateRandomBasedUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testObjectRelationships() throws Exception
|
||||||
|
{
|
||||||
|
// Can't use object relationships retrieval due an isValidCmisRelationship issue.
|
||||||
|
// TODO Change expected value to 1 rather than 0 once bug is fixed.
|
||||||
|
assertEquals(0, doc1.getRelationships().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGetRelationshipsViaSession(RelationshipDirection direction) throws Exception
|
||||||
|
{
|
||||||
|
// Try and get relationships using the session
|
||||||
|
ObjectType typeDefinition = session.getTypeDefinition("R:ws:relatedArticles");
|
||||||
|
OperationContext operationContext = session.createOperationContext();
|
||||||
|
|
||||||
|
ItemIterable<Relationship> relationships = session.getRelationships(doc1, true, direction,
|
||||||
|
typeDefinition, operationContext);
|
||||||
|
int relationshipCount = 0;
|
||||||
|
Iterator<Relationship> iterator = relationships.iterator();
|
||||||
|
while (iterator.hasNext())
|
||||||
|
{
|
||||||
|
relationshipCount++;
|
||||||
|
iterator.next();
|
||||||
|
}
|
||||||
|
assertEquals(1, relationshipCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelationshipDirectionEither() throws Exception
|
||||||
|
{
|
||||||
|
testGetRelationshipsViaSession(RelationshipDirection.EITHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelationshipDirectionSource() throws Exception
|
||||||
|
{
|
||||||
|
testGetRelationshipsViaSession(RelationshipDirection.SOURCE);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user