cancel
Showing results for 
Search instead for 
Did you mean: 

Copy a document in a specific space

soeursourire
Champ in-the-making
Champ in-the-making
Hi!

I would like to copy a file in the same folder where was the file programmatically. I was thinking to use the Clipboard but I do not see really how I can paste the file in the specific space:

addClipboardNode(id, ClipboardStatus.COPY);

I have a file stored in admin/procedures/record.xml and I would like to have a copy in admin/procesures/record1.xml

How can I paste the copy then in the same folder?

Thanks in advance for your help
11 REPLIES 11

kevinr
Star Contributor
Star Contributor
If you are doing this programmatically, then I would use the "CopyService" - this is what the clipboard (which is just for web-client UI) uses internally. Take a look at ClipboardBean.performClipboardOperation() for a code example.

Thanks,

Kevin

soeursourire
Champ in-the-making
Champ in-the-making
Thanks a lot for your answer. Actually I chose another solution before seeing your answer. I used the function createNode and copy the properties and content of the original file inside… However I get into troubles because I am not allowed to create the node.

Please would you mind telling me what is the easiest and fastest way to give rights to everybody to create nodes and thus to be able to use this function from any session:

return this.nodeService.createNode(sysCont, ContentModel.ASSOC_CHILDREN, EthicFlow_ContentModel.TYPE_PS,
                EthicFlow_ContentModel.TYPE_PS, properties).getChildRef();


Thanks!

kevinr
Star Contributor
Star Contributor
It is best to use the copy service - as performing the copy "by hand" as you are will not correctly copy any aspects and associations on the node that may be important i.e. it will not be a proper copy.

The PermissionService can be used to set permissions on nodes, you can use the inheritance features to cascade permissions down hiearchies.

Cheers,

Kevin

soeursourire
Champ in-the-making
Champ in-the-making
Thanks I am following your advises. I am using the copyService but I still have permissions problems.. Is it wrong to do that:

permissionService.setPermission(ref,PermissionService.ALL_AUTHORITIES,PermissionService.ALL_PERMISSIONS,true);

?
I am trying to give all rights to my node (ref) that is a node stored in system/system_processus in mysql. Does this permissionService works only with content nodes not with nodes such as person in the database?

harshad
Champ in-the-making
Champ in-the-making
I was going to post this right now, but saw this thread and decided to put it here.

I have certain fixed folders /companyhome/pending
                                       /companyhome/review

For each users there is a home folder /companyhome/users/user1 ..etc.

The users create documents in their home folders. I need to provide an action in inline action area of content space, which when clicked, copies the document to /companyhome.pending folder

Is there any sample code?
I was thinking of using the move action executer, but how do I provide the destination node to it?
How do I convert the fixed folder structure /companyhome/pending to a node?

Thanks,

soeursourire
Champ in-the-making
Champ in-the-making
Hi!

If I well understood I think you can copy your document if you have the id of the document and the id of the node where you want to copy your document

//Here I get the nodeRef where I want to copy the document
//In my case I store the copy in the same folder where I have my node with id psId
NodeRef parentRef = new NodeRef(Repository.getStoreRef(), psId);

ChildAssociationRef assocRef = this.nodeService.getPrimaryParent(ref);
   
//Then you use the CopyService to copy your document (in my case my document is contained in the node "ref") and you choose false if you copy a document and true if you want to copy a folder and all its content. Maybe there is a similar service for moving your document..
NodeRef copyRef = this.copyService.copy( ref,         //source
              parentRef,         //destination
             ContentModel.ASSOC_CONTAINS,
             assocRef.getQName(),
             false);              //copy children

But for permission I do not know if you will have the same problem than me: I am trying to copy a node stored in my database in the same space but I do not have permissions to do it and while doing this, that fails (maybe I cannot set permission on nodes from the database maybe I should set permission on the method copy but I do not see how?):

permissionService.setPermission(ref,PermissionService.ALL_AUTHORITIES,PermissionService.ALL_PERMISSIONS,true);

And If I do not have permission set I have this error:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

And I get the same error while launching my operation as admin…

soeursourire
Champ in-the-making
Champ in-the-making
Even while changing nodeService_security as follow I get exactly the same error:

org.alfresco.service.cmr.repository.NodeService.getStores=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.createStore=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.exists=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getNodeStatus=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getRootNode=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.createNode=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.moveNode=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.setChildAssociationIndex=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getType=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.setType=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.addAspect=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.removeAspect=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.hasAspect=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getAspects=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.deleteNode=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.addChild=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.removeChild=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getProperties=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getProperty=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.setProperties=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.setProperty=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getParentAssocs=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getChildAssocs=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getPrimaryParent=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.createAssociation=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.removeAssociation=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getTargetAssocs=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getSourceAssocs=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getPath=ROLE_AUTHENTICATED
               org.alfresco.service.cmr.repository.NodeService.getPaths=ROLE_AUTHENTICATED

ROLE_AUTHENTICATED means that no permission is required right?

soeursourire
Champ in-the-making
Champ in-the-making
It seems that I was needing to replace:

tx = Repository.getUserTransaction(context, true);

by

tx = Repository.getUserTransaction(context);

With true it is is readonly modeSmiley Happy

kevinr
Star Contributor
Star Contributor
It seems that I was needing to replace:

tx = Repository.getUserTransaction(context, true);

by

tx = Repository.getUserTransaction(context);

With true it is is readonly modeSmiley Happy

Yes that will do it Smiley Happy

Cheers,

Kev