-->

How to Delete Document Using CMIS

2019-04-02 21:13发布

问题:

I have Created a External web application using Servlets which is connected to alfresco repository.

I am also able to upload document in to the repository, download document from repository.

now my requirement is, i have to delete document based on user role. means i want to give delete document access to only site manager.

Please provide sample code if you have.

Thanks in Advance

回答1:

In order to delete a document you first need to see if the user have the role to delete this is why the answer will be split in two part

Part 1 : search for authority

in this part you will see if the user have the authority to delete

Session session = getSession(serverUrl, username, password); // Get the session 

object = session.getObjectByPath(idObject); // get the object 

if (object.getAllowableActions().getAllowableActions().contains(Action.CAN_DELETE_OBJECT)) { //// You can delete 

   } else {  //// You can't delete 
       System.out.println("I can't ");            
   }

Part 2 : delete method

for a document it is simple to delete it

Session session = getSession(serverUrl, username, password);
CmisObject object = session.getObject(path);
Document suppDoc = (Document) object;
suppDoc.delete(true);

Note that it's different for a folder , but only the part 2 will be changed ( because when you delete a folder you need to delete his child's)

to complete this answer you only need to combine part 1 with part 2.