04-13-2015 05:27 AM
//I have registered my Java class in the bean as shown below,
<bean id="${project.artifactId}_updateProduct" parent="baseJavaScriptExtension" class="mypackage.UpdateProduct" lazy-init="default" autowire="default" dependency-check="default">
<property name="extensionName">
<value>updateProduct</value>
</property>
<property name="serviceRegistry" ref="ServiceRegistry"/>
</bean>
//My JS file is as shown below,
function delete_folders_main(){
logger.log("Execution Started!");
//Getting the nodeRef of a document that is getting deleted.
var deletedNodeRef = document.getNodeRef();
//Setting the noderef in the Java class.
updateProduct.setDeletedNodeRef(deletedNodeRef);
logger.log("Execution Completed!");
}
deletefolders_main();
public class UpdateProduct extends BaseProcessorExtension {
protected static Logger logger = Logger.getLogger(UpdateProduct.class);
private static ServiceRegistry serviceRegistry;
private static NodeRef deletedNodeRef;
//Getters and setters for these.
private void doDelete() {
if(nodeService != null && nodeService.exists(deletedNodeRef)){
//Extracting the name of the deleted folder.
deletedFolderName = serviceRegistry.getFileFolderService().getFileInfo(deletedNodeRef).getName();
}
else{
throw new AlfrescoRuntimeException("Unable to Extract the Folder Name from the passed NodeRef :"+deletedNodeRef);
}
NodeRef stagingProductNodeRef = new NodeRef(HCNodeReferences.NODEREF_MY_COPY_FOLDER);
if (nodeService != null && nodeService.exists(stagingProductNodeRef)) {
List<ChildAssociationRef> childAssoc = nodeService.getChildAssocs(stagingProductNodeRef);
for(ChildAssociationRef child : childAssoc){
NodeRef childNodeRef = child.getChildRef();
stagingFolderToUpdate = serviceRegistry.getFileFolderService().getFileInfo(childNodeRef).getName();
//Finding the ChildFolder in Staging to delete.
if(deletedFolderName != null && stagingFolderToUpdate != null && deletedFolderName.equals(stagingFolderToUpdate)){//this check properly takes me to the exact folder which I want to delete
try {
serviceRegistry.getNodeService().deleteNode(childNodeRef);//No exception thrown in this step, but still my folder in not deleted.
break;
}
catch(Exception e){
logger.error(e.getMessage());
}
}
}
}
}
public static void setDeletedNodeRef(NodeRef deletedNodeRef) {
nodeService = serviceRegistry.getNodeService();
if (nodeService != null && nodeService.exists(deletedNodeRef)){
UpdateProduct.deletedNodeRef = deletedNodeRef;
new UpdateProduct().doDelete();
logger.warn("Delete action Completed successfully for the Folder :"+serviceRegistry.getFileFolderService().getFileInfo(deletedNodeRef).getName());
deletedNodeRef = null;
UpdateProduct.clearFields();
}
else{
logger.error("There was an error while updating the Staging Folder");
}
}
}
04-29-2015 02:32 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.