cancel
Showing results for 
Search instead for 
Did you mean: 

WS Upload and versionable aspect

theirish81
Champ in-the-making
Champ in-the-making
Hello everyone,
here's my problem. In my application, I upload contants via web services. To accomplish that, I followed a guide that uses two steps, one for creating the content item, and one to actually write the uploaded file in it.

CMLCreate create = new CMLCreate();
create.setId("1");
create.setParent(foldref);
create.setProperty(contentProps);
create.setType(contentType);

NamedValue[] titledProps = new NamedValue[2];
titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, fileName);
titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "Content di prova GG WS");
CML cml = new CML();
cml.setCreate(new CMLCreate[] {create});

UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
System.out.println("Reference node created");

Reference content = result[0].getDestination();
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
FileInputStream is = new FileInputStream(srcName);
byte[] bytes = ContentUtils.convertToByteArray(is);
ContentFormat format = new ContentFormat(mimeType, "UTF-8");
System.out.println("Begin uploading…");
Content cnt = contentService.write(content, Constants.PROP_CONTENT, bytes, format);

Everything goes just fine… but what happens when the content is versionable? After upload, the revision i 1.1 as:
1.0: creation of the content item
1.1: filling of the content item
obviously, revision 1.0 has no content….
any help to avoid that?
thanks in advance for your precious help
2 REPLIES 2

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

In this case, why not apply the versionable aspect after you upload the content?

You could use these two function definitions in CML.java to add or remove an aspect.



public void setAddAspect(org.alfresco.webservice.types.CMLAddAspect[] addAspect)

public void setRemoveAspect(org.alfresco.webservice.types.CMLRemoveAspect[] removeAspect)


Here is the test case, which can serve as a sample, from the CMLUnitTest.java for adding and removing an aspect.


public void testAddRemoveAspect()
    {
        CMLAddAspect addAspect = new CMLAddAspect();
        addAspect.setAspect(ContentModel.ASPECT_VERSIONABLE.toString());
        addAspect.setWhere(createPredicate(this.nodeRef));
       
        CML cml = new CML();
        cml.setAddAspect(new CMLAddAspect[]{addAspect});
       
        UpdateResult[] result = this.cmlUtil.executeCML(cml);
        assertNotNull(result);
        assertEquals(1, result.length);
       
        UpdateResult updateResult = result[0];
        assertEquals("addAspect", updateResult.getStatement());
        assertNotNull(updateResult.getSource());
        assertNotNull(updateResult.getDestination());
       
        assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
       
        // TODO should test with properties set as well
       
        CMLRemoveAspect removeAspect = new CMLRemoveAspect();
        removeAspect.setAspect(ContentModel.ASPECT_VERSIONABLE.toString());
        removeAspect.setWhere(createPredicate(this.nodeRef));
       
        CML cml2 = new CML();
        cml2.setRemoveAspect(new CMLRemoveAspect[]{removeAspect});
       
        UpdateResult[] results2 = this.cmlUtil.executeCML(cml2);
        assertNotNull(results2);
        assertEquals(1, results2.length);
       
        UpdateResult result2 = results2[0];
        assertEquals("removeAspect", result2.getStatement());
        assertNotNull(result2.getDestination());
        assertNotNull(result2.getSource());
       
        assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
       
    }



Best Regards,
Shagul

satishvarmadand
Champ in-the-making
Champ in-the-making
Hi,

How it is going o solve the problem for Update.

   When i try to update a file, i am using
Content contentRef = contentService.write(node, Constants.PROP_CONTENT, dataToUpdate, contentFormat);

But by calling this, it is creating a version. I want to disable version creation when i update a document as i want to make use of authoringService.createVersion()).

The reason is simple, i can get hold to the latest version that was created and i can find out the version label etc…  using
VersionResult res = authoringService.createVersion(predicate, versionComments, false)

But if i do both for the same update option, it end up creating 2 versions; one with contentService.write() & other with authoringService.createVersion().

Shagul,
  I followed ur suggestion using "remove aspect". But when i use this , this is removing the entire version chain. This is more of a serious problem. Is there any way to just hold of version creation when i call
contentService.write

Other option i have is

cml.setAddAspect(new CMLAddAspect[] { addVersionableAspect });
       
UpdateResult[] results = respositoryService.update(cml);

this will solve the problem, but i can not get hold to what version it created ( i want version label)… i can not get the versionObject in return type.

Any help would be appreciated.

Thanks,
-Satish