Hi there ,
I was trying to convert javascript API code to java API which move files to different content store(' storeB'). We have storeB defined in - 'content-store-selector-context.xml'. We are using Enterrprises version of Alfresco 5.2.
java script code as follows , - Works perfectly fine . its working code.
for each (var n in node.children) { if (n.isDocument) { //Apply script for moving files to DMS Store 01 n.removeAspect("cm:versionable"); n.addAspect("cm:storeSelector"); n.properties['cm:storeName'] = "storeB"; n.save(); } }
Java API Code - But this code is not moving files to 'storeB'. Is there anything i am missing ? I can see a save method is java script API. Is there any similiar method available in java APIs. is there anything missing in the code ?
List<ChildAssociationRef> children = nodeService.getChildAssocs(dayFolderRef); Map<QName, Serializable> aspectsProps = new HashMap<QName, Serializable>(1); aspectsProps.put(ContentModel.PROP_STORE_NAME, "storeB"); LOG.info("Folder::" + dayFolderRef.getId()); LOG.info("Number of Subfolder to be moved is ::" + children.size()); for (ChildAssociationRef childAssoc : children) { NodeRef childNodeRef = childAssoc.getChildRef(); if (ContentModel.TYPE_CONTENT.equals(nodeService.getType(childNodeRef))) { LOG.info("Moving the file to secondary storae "+childNodeRef.getId()); nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE); nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR, aspectsProps); } }
Thanks ,
Brijesh
Solved! Go to Solution.
the following trick worked ,
setting content store name , using setProperty . See code below
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR , null); nodeService.setProperty(childNodeRef, ContentModel.PROP_STORE_NAME, "storeB");
Still no idea why earlier code failed .
Where are you using that Java code? Inside a behaviour?
There is no need to save in Java API, as it's included on a DB Transaction that will be commited eventually.
thanks for the reponse. This is an action class triggered by scheduler . As soon as after executing this i was checking in DB using following query
SELECT * FROM alf_content_url WHERE orphan_time IS NOT NULL;
Before and after quey result is same.
After execution of above mentioned code, I was exepecting query to return higher number , as number of nodes become orhan.
@angelborroy , you mentioned above 'Transaction that will be commited eventually' . Is there time lag to commit transaction ? is it not immiedately after execting the code or wait for some other process to complete ? code is executed inside an action method , inititated by scheduler.
The transaction will be commited once the executeJob method is finished.
https://docs.alfresco.com/community/references/dev-extension-points-scheduled-jobs.html
the following trick worked ,
setting content store name , using setProperty . See code below
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR , null); nodeService.setProperty(childNodeRef, ContentModel.PROP_STORE_NAME, "storeB");
Still no idea why earlier code failed .
You were adding it also in your JavaScript code, so I guess that it's a required property.
Agree its mandatory and I was adding in java script code , But I was adding content store property in earlier java code- the one which was not working - please see below code:
Map<QName, Serializable> aspectsProps = new HashMap<QName, Serializable>(1);
aspectsProps.put(ContentModel.PROP_STORE_NAME, "storeB"); nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE); nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR, aspectsProps);
But the , following code works . its pretty much same code but the way i set the property is different . I used here setPreperty for setting conent store -
nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE);
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR , null); nodeService.setProperty(childNodeRef, ContentModel.PROP_STORE_NAME, "storeB");
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.