cancel
Showing results for 
Search instead for 
Did you mean: 

Add an attachment via CMIS to datalist

chocox
Champ in-the-making
Champ in-the-making
Hello,

how can i add an attachment (file) to a field in a datalist??

This is my Model:

<aspects>
      <aspect name="gc:Attachments2">
         <title>Anhänge</title>
         <associations>
            <association name="gc:gcAttachments">
               <title>Attachements</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:content</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </aspect>
   </aspects>


And this is my Java Code:


//Add Document to Space

   Document doc = folder.createDocument(
                      properties,
                      contentStream,VersioningState.MAJOR);

//Add Datalist Item
Map<String, Object> properties2 = new HashMap<String, Object>();
               properties2.put(PropertyIds.OBJECT_TYPE_ID,  "D:gc:generalRechnung");
               properties2.put(PropertyIds.NAME, filename);
               properties2.put("gc:gcBeschreibung", filename);
               ObjectId newItemId = session.createDocument(properties2, dataList,contentStream,null);

//Add Relationship

               Map<String,Object> relProps = new HashMap<String, Object>();
               relProps.put("cmis:sourceId", newItemId.getId());
               relProps.put("cmis:targetId", doc.getId());
               relProps.put("cmis:objectTypeId", "R:gc:gcAttachments");
               session.createRelationship(relProps, null, null, null);


But the Code doesnt work. I have a new Item in the datalist but no attachment.

Thanks for answering,

1 REPLY 1

chocox
Champ in-the-making
Champ in-the-making
Ok…now it works…

Model:

      <associations>
           <association name="gc:attachments">
               <title>Attachments Neu</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>


Java Code


      
                                        Map<String, Object> properties2 = new HashMap<String, Object>();
               properties2.put(PropertyIds.OBJECT_TYPE_ID,  "D:gc:generalRechnung");
               properties2.put(PropertyIds.NAME, filename);
               properties2.put("gc:gcBeschreibung", filename);
               properties2.put("gc:gcStatus","offen");
               ObjectId newItemId = session.createDocument(properties2, dataList,null,null);

               Map<String,Object> relProps = new HashMap<String, Object>();
               //relProps.put("cmis:objectTypeId","R:gc:Attachmets2");
               relProps.put(PropertyIds.OBJECT_TYPE_ID, "R:gc:attachments");
               relProps.put(PropertyIds.SOURCE_ID,newItemId.getId());
               relProps.put(PropertyIds.TARGET_ID,doc.getId());
            
                    session.createRelationship(relProps);