2

My model looks like this:

I have two folders(HTMLs) & (Images). Tons of files are inserted inside images folder and small part of business use case I am trying to implement is that when client asks for say chapter1.html then all the associated images for that chapter1.html should be fetched from the Alfresco Repository and sent.

I am using CMIS and able to do most of the stuff that it provides. I have gone through most of the tutorials and code snippets and could create the relationship in this way:

https://anonsvn.springframework.org/svn/se-surf/branches/DEV_CMIS_2/sandbox/spring-cmis/spring-cmis-test/src/main/java/org/springframework/extensions/cmis/test/CmisCreateTest.java

  1. testCreateRelationship(): works fine but again returns empty when getRelationships() called with setIncludeRelationships set on Context.

  2. testBelarus(): it doesnt work and throws following exception (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Bad Request).

I used the code snippet given here in 'Relationships' section http://chemistry.apache.org/java/developing/guide.html and was successful in creating it but again finding it difficult to fetch the referred Images for that particular HTML

Please suggest some solution as this is the only thing stopping me from going to Alfresco in prod.

If I am doing it in wrong way (creating relationships) and if there is a better solution for my requirements(Using custom model/alfcmis:nodeRef/cmiscustom:docprop_string, etc), please suggest.

Any help is appreciated.

Thanks

Swan
  • 21
  • 1
  • 3

1 Answers1

3

Pasting the code from testCreateRelationship() with some added code at the end demonstrating how to get the relationships and printing them to console (sounds like you tried this way with no luck? The code below works on my repo anyhow):

public void testCreateRelationship()
{
    Session session = createSession();
    Folder root = session.getRootFolder();

    Map<String,String> newFolderProps = new HashMap<String, String>();
    newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    String name = "testCreateRelationship " + System.currentTimeMillis();
    newFolderProps.put(PropertyIds.NAME, name);
    Folder folder = root.createFolder(newFolderProps, null, null, null, session.getDefaultContext());
    System.out.println(folder.getName());

    Map<String,String> newDocProps1 = new HashMap<String, String>();
    newDocProps1.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
    newDocProps1.put(PropertyIds.NAME, "Test Doc 1");
    ContentStream contentStream1 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes()));
    Document doc1 = folder.createDocument(newDocProps1, contentStream1, VersioningState.MAJOR, null, null, null, session.getDefaultContext());

    Map<String,String> newDocProps2 = new HashMap<String, String>();
    newDocProps2.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
    newDocProps2.put(PropertyIds.NAME, "Test Doc 2");
    ContentStream contentStream2 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes()));
    Document doc2 = folder.createDocument(newDocProps2, contentStream2, VersioningState.MAJOR, null, null, null, session.getDefaultContext());

    Map<String, Serializable> relProps = new HashMap<String, Serializable>(); 
    relProps.put("cmis:sourceId", doc1.getId()); 
    relProps.put("cmis:targetId", doc2.getId()); 
    relProps.put("cmis:objectTypeId", "R:cmiscustom:assoc");
    session.createRelationship(relProps, null, null, null);

    // create a OperationContext that fetches relationships on both ends...
    OperationContext operationContext = new OperationContextImpl();
    operationContext.setIncludeRelationships(IncludeRelationships.BOTH);


    CmisObject object = session.getObject(doc1,operationContext);


    List<Relationship> relationships = object.getRelationships();
    for (Relationship rel : relationships){
        System.out.println("relation: "+ rel.getName());
    }
}
billerby
  • 1,977
  • 12
  • 22
  • Thanks a lot for the reply. I was making one mistake in my code: Instead of List relList = session.getObject(sourceDoc,oc).getRelationships(); I had - List relList = sourceDoc.getRelationships(); Now I need to query to get these TargetIds. Something like this doesn't work: SELECT * FROM cmis.document where cmis:targetId= 'workspace://SpacesStore/dc7c5a6a-9c74-4f97-8835-322d3ec87e44' Can you please help me with this? – Swan Jan 29 '13 at 05:26