How to Delete Document Using CMIS

我的梦境 提交于 2019-12-05 08:08:27

问题


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.



来源:https://stackoverflow.com/questions/39462789/how-to-delete-document-using-cmis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!