<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How retrieve the json template workspace noderef from a SmartFolder virtual noderef with java in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-retrieve-the-json-template-workspace-noderef-from-a/m-p/96705#M28361</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi i'm using a simple smatrt folder with the standard json "&lt;EM&gt;smartFoldersExample.json&lt;/EM&gt;", 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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Noderef &lt;EM&gt;destinationRef = "workspace://SpacesStore/vH1-6-1-1-11c6wqns739n0vhwarudfo9wfsm-2LzEwMC8xMDg=-1-1148bugjuze5e6wo2ogsblfgfce";&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;...........&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if(nodeService.hasAspect(destinationRef, VirtualContentModel.ASPECT_VIRTUAL)){ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;NodeRef jsonTemplate = null;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;NodeRef parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"), nodeService);&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(parentSmartFolder!=null){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;List&amp;lt;ChildAssociationRef&amp;gt; assocJsonTemplate = nodeService.getChildAssocs(parentSmartFolder, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}smf:custom-template-association"),RegexQNamePattern.MATCH_ALL);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//MUST BE UNIQUE&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;jsonTemplate = assocJsonTemplate.get(0).getChildRef();&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}else{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}systemConfigSmartFolder"), nodeService);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(parentSmartFolder==null){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;throw new AlfrescoRuntimeException("The obj 'destination' for the SmartFolder is NULL for " + destination);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}else{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;String jsonTemplatePath = (String) nodeService.getProperty(parentSmartFolder, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}system-template-location"));&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;jsonTemplate = getNodeRefByPath(jsonTemplatePath, fileFolderService, repositoryHelper);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(jsonTemplate==null){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;throw new AlfrescoRuntimeException("The obj 'jsonTemplate' for the SmartFolder is NULL for " + destination);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}else{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//READ JSON AND EGT THE FIRST ID WITH THE UID &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ContentReader contentReader = getReader(nodeService, contentService, dictionaryService, jsonTemplate.toString());&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;JSONObject jsonObject = (JSONObject)new JSONParser().parse(new InputStreamReader(contentReader.getContentInputStream(), StandardCharsets.UTF_8));&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;String path = (String) jsonObject.get("path");&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;destinationRef = getNodeRefByPath(path, fileFolderService, repositoryHelper);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;.................&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//OTHER FUNCTION&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;public static NodeRef getParentFolderWithAspect(NodeRef nodeRef, QName aspect,NodeService nodeService) {&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; if (nodeRef == null || !nodeService.exists(nodeRef)) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; return null;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; }&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; &lt;STRONG&gt;if (nodeService.hasAspect(nodeRef, aspect)) {&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; return nodeRef;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; }&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; ChildAssociationRef parentFolderRef = nodeService.getPrimaryParent(nodeRef);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; if (parentFolderRef == null) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; return null;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; }&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; return getParentFolderWithAspect(parentFolderRef.getParentRef(), aspect, nodeService);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;public static NodeRef getNodeRefByPath(String path, FileFolderService fileFolderService,Repository repositoryHelper) throws FileNotFoundException{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; NodeRef companyHomeRef = repositoryHelper.getCompanyHome();&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; List&amp;lt;String&amp;gt; pathElements = Arrays.asList(StringUtils.split(path, '/'));&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; NodeRef templateRef = fileFolderService.resolveNamePath(companyHomeRef, pathElements).getNodeRef();&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; return templateRef;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error is the code&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;NodeRef parentSmartFolder = getParentFolderWithAspect(destinationRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"), nodeService);&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &lt;STRONG&gt;if (nodeService.hasAspect(nodeRef, aspect)) {&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it's seem the condition&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;nodeService.hasAspect(nodeRef, QName.createQName("{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder"))&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is valid for every noderef virtual of a SmartFolder, why ??????????????????&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So my&amp;nbsp; final goal is to retrieve the nodeRef of the Json template from the associaton:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;{http://www.alfresco.org/model/content/smartfolder/1.0}smf:custom-template-association&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but at this point the major problem is rerieve the workspace noderef where i applied the aspect&lt;/P&gt;&lt;P&gt;&lt;EM&gt;{http://www.alfresco.org/model/content/smartfolder/1.0}customConfigSmartFolder&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone can help me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 May 2019 10:05:23 GMT</pubDate>
    <dc:creator>AlfrescoZZZ</dc:creator>
    <dc:date>2019-05-15T10:05:23Z</dc:date>
    <item>
      <title>How retrieve the json template workspace noderef from a SmartFolder virtual noderef with java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-retrieve-the-json-template-workspace-noderef-from-a/m-p/96705#M28361</link>
      <description>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-11c6wqns739n0vhwar</description>
      <pubDate>Wed, 15 May 2019 10:05:23 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-retrieve-the-json-template-workspace-noderef-from-a/m-p/96705#M28361</guid>
      <dc:creator>AlfrescoZZZ</dc:creator>
      <dc:date>2019-05-15T10:05:23Z</dc:date>
    </item>
  </channel>
</rss>

