cancel
Showing results for 
Search instead for 
Did you mean: 

Use the cm:attachable aspect with WS

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi all,
can anyone help me to add this aspect to a content using WebService API?

<aspect name="cm:attachable">
         <title>Attachable</title>
         <associations>
            <association name="cm:attachments">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </aspect>

THANK YOU
5 REPLIES 5

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Take a look at the update method ( http://wiki.alfresco.com/wiki/Repository_Web_Service#update ) on the Repository web service.  You should be able to construct some CML ( http://wiki.alfresco.com/wiki/CML ) to add an aspect to a node.

Alternatively you could take a look at the support for aspects in the CMIS web service API ( http://wiki.alfresco.com/wiki/CMIS#Aspect_Support )

Cheers,
Roy

chicco0386
Champ on-the-rise
Champ on-the-rise
OK, I've understand, but it's different from the sample aspect with, for example, type d:text.
If I've this piece of code:
CMLAddAspect attachableAspect = new CMLAddAspect("{http://www.alfresco.org/model/content/1.0}attachable", new NamedValue[] { Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}attachments", **********) }, null, contentId);

But I don't understand what I must to insert in the ********** piece of code.

PLEASE, CAN YOU HELP ME?

THANK YOU

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

cm:attachments is an association.  You are trying to set it as a property on the aspect in the example code you have provided.

If you are using CML you will need to use the AddAspect command and then the CreateAssociation command to achieve what you want.

Cheers,
Roy

chicco0386
Champ on-the-rise
Champ on-the-rise
Thank you for the response.
So, you say me that I use in combination the AddAspect and the CreateAssociation commands?
It's right?

Can you post a sample code?

THANK A LOT

rwetherall
Confirmed Champ
Confirmed Champ
This code snipit creates a node, adds an aspect and writes some content using CML.  This should give an idea of how to combine the addAspect and association commands.


CMLCreate create = new CMLCreate();
        create.setId("id1");
        create.setType(Constants.TYPE_CONTENT);

        ParentReference parentReference = new ParentReference();
        parentReference.setAssociationType(Constants.ASSOC_CHILDREN);
        parentReference.setChildName(Constants.ASSOC_CHILDREN);
        parentReference.setStore(BaseWebServiceSystemTest.store);
        parentReference.setUuid(BaseWebServiceSystemTest.rootReference.getUuid());

        create.setParent(parentReference);
        create.setProperty(new NamedValue[] {
                        new NamedValue(
                                Constants.PROP_NAME,
                                false,
                                "name.txt",
                                null)});
       
        // Create a folder used for later tests
        CMLCreate createFolder = new CMLCreate();
        createFolder.setId("folder1");
        createFolder.setType(Constants.TYPE_FOLDER);
        createFolder.setParent(parentReference);
        createFolder.setProperty(new NamedValue[] {
                new NamedValue(
                        Constants.PROP_NAME,
                        false,
                        "tempFolder",
                        null)});
       
        CMLAddAspect aspect = new CMLAddAspect();
        aspect.setAspect(Constants.ASPECT_VERSIONABLE);
        aspect.setWhere_id("id1");

        ContentFormat format = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8");
       
        CMLWriteContent write = new CMLWriteContent();
        write.setProperty(Constants.PROP_CONTENT);
        write.setContent("this is a test".getBytes());
        write.setFormat(format);
        write.setWhere_id("id1");
       
        CML cml = new CML();
        cml.setCreate(new CMLCreate[]{create, createFolder});
        cml.setAddAspect(new CMLAddAspect[]{aspect});
        cml.setWriteContent(new CMLWriteContent[]{write});
       
        UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);

Cheers,
Roy