Search code examples
alfrescoalfresco-sharealfresco-webscriptsalfresco-enterprise

Assigning content store using JAVA API


I had posting in alfresco hub , couldnt get solution yet.

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();
  }

}

Below is Java API Code - But this code is not moving files to 'storeB'. Is there anything i am missing ?

Is there any similiar method available in java APIs.

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);                

            }
        }

I can see a save method is java script API. based on response recieved Alfresco forum , there is no save method in javascript API. Java API run in transactions , so will commit eventually . But i can see from DB using the below SQL -

SELECT count(*)
FROM alf_content_url
WHERE orphan_time IS NOT NULL;

the above SQL returns same count after executing the code , so no DB updates happening. Anything wrong ?

Any help , appreciated

Regards Brijesh


Solution

  • I don't see why that would not work, are you positive you're even entering that method? Try adding the content store selector aspect with no properties map, then add the content store name property with setProperty method separately.