cancel
Showing results for 
Search instead for 
Did you mean: 

Create Relationship between two files (4.2.c version)

swanands
Champ in-the-making
Champ in-the-making
Hi,

1. I have been exploring Alfresco for programmatic data retrieval to & fro from Alfresco Repository and finding it really interesting and I think I am going to decide to go with Alfresco in production as well.
2. I was able to setup Alfresco and am able to create spaces, folders, files, upload docs, versioning, etc. but stuck at one point.
3. I am not able to create relationship between two files.

My model looks like this:
<ul><li> 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 to that chapter1.html should be fetched from the Repository and sent.
</li></ul>

– 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-...

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 Smiley Sad


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, please suggest.

Any help is appreciated.

Thanks,
Swanand
6 REPLIES 6

jpotts
World-Class Innovator
World-Class Innovator
The problem with testBelarus is that you are trying to create a relationship of type "cmis:relationship" which is not an association in Alfresco. You need to use an association that is in the content model, like you've done in testCreateRelationship().

I can't tell what's wrong with your getRelationships() call because that code is not included in the snippet.

One thing to watch out for is that the source and target of your association must both be descendants of cmis:document or they won't show up in the getRelationships() call.

Jeff

swanands
Champ in-the-making
Champ in-the-making
Thanks Jeff, got the testCreateRelationhip() working. Was an issue with:
CmisObject object = session.getObject(doc1,operationContext);
List<Relationship> relationships = object.getRelationships();

by using "R:cmiscustom:assoc"

But now the final thing remaining is querying for the targetId. Something like this doesn't work(Checked on the Workbench):-


SELECT * FROM cmis.document where cmis:targetId= 'workspace://SpacesStore/dc7c5a6a-9c74-4f97-8835-322d3ec87e44'


What is the best way to fetch all the sourceIds with a given targetId (or vice versa)? If direct query is not possible then do I need to use Aspects with Joins for my use case(Fetching all the Images which are in relation with HTML page in the Alfresco Repo.)?

Regards,
Swan

gran
Champ in-the-making
Champ in-the-making
Hi Swanands,

We are encountering similar problem unable to see relationships between parent (questionnaire) and child (question) documents. We can see peer relationships but not parent-child, verified through opencmis api getRelationships() method, through opencmis workbench and via cmis atom browser. We have set our operational context to include BOTH relationships. Note after creating model, we used alfresco explorer to create documents and associate them via web-client-config.xml customization. What could be the issue?

Our model is defined below,


<type name="ques:questionnaire">
      <title>TU Questionnaire Content</title>
      <parent>tubase:content</parent>
      <properties>
        <property name="ques:questionnaireName">
          <title>Questionnaire Name</title>
          <type>d:text</type>
          <mandatory>true</mandatory>        
       </property>
       <property name="ques:questionnaireDescription">
          <title>Questionnaire Description</title>
          <type>d:text</type>
          <mandatory>false</mandatory>        
       </property>
       <property name="ques:questionnaireType">
          <title>Questionnaire Type</title>
          <type>d:text</type>
          <mandatory>true</mandatory>
         <default>Medical</default>
         <constraints>
          <constraint ref="ques:questionnaireTypeConstraint"/>
         </constraints>
       </property>
      </properties>   
     
      <associations>     
        <!– Questionnaire header footer peer relationship –>
          <association name="ques:hasQuestionnaireFooter">
          <title>Questionnaire Footer</title>        
         <source>
           <mandatory>false</mandatory>
           <many>false</many>
         </source>
         <target>
           <class>ques:questionnaireFooter</class>
           <mandatory>false</mandatory>
           <many>false</many>
         </target>
        </association>
       
        <!– Questionnaire contains questions child relationship –>
        <child-association name="ques:containsQuestions">
          <title>Questionnaire Questions</title>        
         <target>
           <class>ques:question</class>
           <mandatory>false</mandatory>
           <many>true</many>
         </target>       
        </child-association>
     </associations>
    
   </type>   

jpotts
World-Class Innovator
World-Class Innovator
Parent-child relationships are not supported by the CMIS specification except in the case of a Folder containing a Folder or Document.

Jeff

jpotts
World-Class Innovator
World-Class Innovator
@swanands,

You cannot query relationships in this way.

One workaround is to store object IDs on the objects they are related to and then query them. You can use a behavior to set the object IDs and to update them when/if they change.

Jeff

swanands
Champ in-the-making
Champ in-the-making
Thanks for the workaround Jeff. Got it working now though it doesn't seem an ideal way but would do for now.
Hope we have a better solution in the upcoming releases.