cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple version creations while creating/updating

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().

One option is to use "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
4 REPLIES 4

satishvarmadand
Champ in-the-making
Champ in-the-making
Hi,
I found the solution and posting here. This moght be helpful if anyone is searching for this

Here is the way .
1) Search for "contentModel.xml" file . This will be under tomcat/webapps/alfresco/WEB-INF/classes/alfresco/model/contentModel.xml
2) Look for "<aspect name="cm:versionable">" inside that and make "<property name="cm:initialVersion">" & "<property name="cm:autoVersion">"  as false.

By updating this, it wont add a version by default. Now you will get more control on when to add a version and you can do that by
VersionResult res = authoringService.createVersion(predicateVersion, ….versioncomments,  false);

We can get the versionLabel & other version properties from this returned object.

-Satish

cviaud
Champ in-the-making
Champ in-the-making
Thanks for this information. Anyway, I have one relating problem.

When I set <property name="cm:initialVersion">" & "<property name="cm:autoVersion">" as false, I've got an error on the first "check-in" I make.

Didin't you get this problem ?

ra74
Champ in-the-making
Champ in-the-making
Hi,
I found the solution and posting here. This moght be helpful if anyone is searching for this

Here is the way .
1) Search for "contentModel.xml" file . This will be under tomcat/webapps/alfresco/WEB-INF/classes/alfresco/model/contentModel.xml
2) Look for "<aspect name="cm:versionable">" inside that and make "<property name="cm:initialVersion">" & "<property name="cm:autoVersion">"  as false.

By updating this, it wont add a version by default. Now you will get more control on when to add a version and you can do that by
VersionResult res = authoringService.createVersion(predicateVersion, ….versioncomments,  false);

We can get the versionLabel & other version properties from this returned object.

-Satish

But I think there's a risk that it can change alfresco's default behavior for example type cm:mlContainer is versionable. And you have to remember to change the war during upgrade - that sort of customization should be done not in the war
I'm setting properties initialVersion and autoVersion directly in my code just before update

jneeve
Champ in-the-making
Champ in-the-making
In case anyone finds this helpfull, this is what I did..

Assuming you have created a file already, use the authoring service to checkout the file. Then use the content service to update that working copy, and check it back in forcing a major version.

You''ll need to get a reference to the file you want to work with…In this example Im dealing with the bytes of a file Im reading in.



// Add the versionable aspect to the document.  This will allows the content to be versioned
makeVersionable(repositoryService, contentReference);

// Use authoring service to checkout file, update content, then check back in with major revision
AuthoringServiceSoapBindingStub authoringService = WebServiceFactory.getAuthoringService();

// Checkout the document to update, placing the working document in the same folder
Predicate itemsToCheckOut = new Predicate(new Reference[]{contentReference}, null, null);
CheckoutResult checkOutResult = authoringService.checkout(itemsToCheckOut, null);

// Get a reference to the working copy
Reference workingCopyReference = checkOutResult.getWorkingCopies()[0];

// Update the content of the working copy
ContentFormat contentFormat = new ContentFormat(MIME_TYPE, "UTF-8");
contentService.write(workingCopyReference, Constants.PROP_CONTENT, bytearray, contentFormat);

// Now check the working copy in with a description of the change made that will be recorded in the version history
Predicate predicate = new Predicate(new Reference[]{workingCopyReference}, null, null);

NamedValue[] revisionType = new NamedValue[]{Utils.createNamedValue("versionType", "MAJOR")};
authoringService.checkin(predicate, revisionType, false);