cancel
Showing results for 
Search instead for 
Did you mean: 

Delete node rendition using JS API

rvarkonyi
Champ in-the-making
Champ in-the-making
Hi all,

I'm experiencing a strange behavior using the combination of Rules and JS API and it would be really great if someone could point me in the right direction.

We're uploading PDF documents into a given folder structure in Alfresco and using a Rule to create JPEG renditions from these PDF documents and copy them into a different folder - this part is working fine. The client specified a use case for deleting original assets, in which case we want to make sure to delete the renditions of a given asset too. Simply using Rules doesn't allow us to do that so we're trying to accomplish this using the JS API, with a script executed by a Rule.

I've been testing the following script in the Javascript console :


var renditions = renditionService.getRenditions(document);

for each (rendition in renditions) {
     logger.log(rendition.getOwner());
     
     try {
        document.removeNode(rendition);
     }
     
     catch (err) {
        logger.log(err);
     }     
}


This seems to work fine when run on a selected asset.

However, using Rules it seems to break with the following message from the log:


DEBUG [repo.jscript.ScriptLogger] [http-bio-8080-exec-6] JavaException: java.lang.IllegalStateException: Operation not allowed against node pending deletion.  Check the node for aspect {http://www.alfresco.org/model/system/1.0}pendingDelete


On the front-end (Share) I can see this message: "Could not delete {filename}", and I can confirm that neither the original asset nor the rendition gets deleted. The error message in the log is not too helpful (not for me at least) so it would be great to get some advice from experienced developers.

Thanks in advance,
Rob
5 REPLIES 5

mitpatoliya
Star Collaborator
Star Collaborator
When you try to delete multiple node in one transaction it applies pendingDelete aspect on all of them so that when that transaction will be committed all of them will be deleted. Now in this case may be you could try with document.save() after remove operation.

Hi,

thanks for your reply.

In this case I'm only testing with a single PDF document so it's not the case of deleting multiple nodes in one transaction. We will of course want to delete multiple nodes in the future but not at the moment, we're just trying to get it to work when deleting a single node.

Could folder permissions play any role in this situation you think?

Thanks,
Rob

mrogers
Star Contributor
Star Contributor
What is happening is that you have deleted a node and then tried to do something with it after it has been marked for deletion.     That pending delete stuff breaks the infinite loops that would otherwise occur with those sort of cyclic rules.

You should be able to delete a rendition on deletion of the parent doc.  That's the default out of the box behaviour.   You need a little more anaysis to work out what should happen and when.   

rvarkonyi
Champ in-the-making
Champ in-the-making
Thanks for your reply.

I also read that the default behaviour is that renditions are removed when the parent node is removed. In our case, though, that doesn't seem to happen. Do you have any ideas why that might be?

Thanks

rvarkonyi
Champ in-the-making
Champ in-the-making
Hello,

thanks for your replies. Eventually I've taken a different route and use JS to first check if a transformed version of the given node already exists in the specified folder and remove if it does. Then, in the same script, I transform the node and copy it to the specified folder. There might be better solutions than my current one but this definitely works for us.

Thanks for your help,
Rob