05-15-2019 06:05 AM
Hi i'm using a simple smatrt folder with the standard json "smartFoldersExample.json", now i need from the java code server to retrieve from the virtual noderef of a SmartFolder the WorkSpace reference to the json i using.
Noderef destinationRef = "workspace://SpacesStore/vH1-6-1-1-11c6wqns739n0vhwarudfo9wfsm-2LzEwMC8xMDg=-1-1148bugjuze5e6wo2ogsblfgfce";
...........
if(nodeService.hasAspect(destinationRef, VirtualContentModel.ASPECT_VIRTUAL)){ 
    NodeRef jsonTemplate = null;
    NodeRef parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"), nodeService);    
    if(parentSmartFolder!=null){
        List<ChildAssociationRef> assocJsonTemplate = nodeService.getChildAssocs(parentSmartFolder, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}smf:custom-template-association"),RegexQNamePattern.MATCH_ALL);
        //MUST BE UNIQUE
        jsonTemplate = assocJsonTemplate.get(0).getChildRef();                    
    }else{
        parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}systemConfigSmartFolder"), nodeService);
        if(parentSmartFolder==null){
            throw new AlfrescoRuntimeException("The obj 'destination' for the SmartFolder is NULL for " + destination);
        }else{
            String jsonTemplatePath = (String) nodeService.getProperty(parentSmartFolder, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}system-template-location"));
            jsonTemplate = getNodeRefByPath(jsonTemplatePath, fileFolderService, repositoryHelper);
        }
    
    }
    if(jsonTemplate==null){
        throw new AlfrescoRuntimeException("The obj 'jsonTemplate' for the SmartFolder is NULL for " + destination);
    }else{
        //READ JSON AND EGT THE FIRST ID WITH THE UID     
        ContentReader contentReader = getReader(nodeService, contentService, dictionaryService, jsonTemplate.toString());
        JSONObject jsonObject = (JSONObject)new JSONParser().parse(new InputStreamReader(contentReader.getContentInputStream(), StandardCharsets.UTF_8));
        String path = (String) jsonObject.get("path");        
        
        destinationRef = getNodeRefByPath(path, fileFolderService, repositoryHelper);
    }                
}        
.................
//OTHER FUNCTION
public static NodeRef getParentFolderWithAspect(NodeRef nodeRef, QName aspect,NodeService nodeService) {          
  if (nodeRef == null || !nodeService.exists(nodeRef)) {
      return null;
  }
  if (nodeService.hasAspect(nodeRef, aspect)) {
      return nodeRef;
  }
  ChildAssociationRef parentFolderRef = nodeService.getPrimaryParent(nodeRef);
  if (parentFolderRef == null) {
      return null;
  }
  return getParentFolderWithAspect(parentFolderRef.getParentRef(), aspect, nodeService);
}
public static NodeRef getNodeRefByPath(String path, FileFolderService fileFolderService,Repository repositoryHelper) throws FileNotFoundException{
  NodeRef companyHomeRef = repositoryHelper.getCompanyHome();
  List<String> pathElements = Arrays.asList(StringUtils.split(path, '/'));
  NodeRef templateRef = fileFolderService.resolveNamePath(companyHomeRef, pathElements).getNodeRef();
  return templateRef;
}
The error is the code
NodeRef parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"), nodeService);
and
if (nodeService.hasAspect(nodeRef, aspect)) {
it's seem the condition
nodeService.hasAspect(nodeRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"))
is valid for every noderef virtual of a SmartFolder, why ??????????????????
So my final goal is to retrieve the nodeRef of the Json template from the associaton:
{http://www.alfresco.org/model/content/smartfolder/1.0}smf:custom-template-association
but at this point the major problem is rerieve the workspace noderef where i applied the aspect
{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder
Anyone can help me?
Explore our Alfresco products with the links below. Use labels to filter content by product module.