<?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 Efficient CMIS query for nodes with optional aspects in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304424#M257554</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, folks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to create a small groovy app with OpenCMIS and Alfresco Community 5.0.a as the backend (so CMIS 1.1 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I experienced quick progress during the first weeks with Alfresco (Content Modelling, customizations) and OpenCMIS APIs. Having arrived on the fine-tuning level some questions arise where I am not sure how to proceed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scenario: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. I want to provide a tabular view of all cmis:document objects of a folder (like detail view in Windows explorer for example)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Some columns refer to properties of aspects (e.g. number of pages inside PDF file)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Not all documents necessarily have all aspects (e.g. jpeg's don't have "number of pages" aspect, would not make any sense)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have done so far: I Started with Session.query method for creating the query. The tabular view renders the List of QueryResult-items. That means: Fast access to the repo, only one AtomPub-Request per query (verified with tcp sniffer) - quite snappy (OperationsContext is tuned appropriately). I can display basic data, like name, contentstream size, content type, thumbnail etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example for OpenCMIS workbench (simplified):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;def folder = session.getObjectByPath('&amp;lt;some folder&amp;gt;');&lt;BR /&gt;// hint: select * just for simplicity of example, don't do this in production, if performance matters&lt;BR /&gt;def result = session.query("select * from cmis:document where IN_FOLDER('${folder.id}')", false)&lt;BR /&gt;&lt;BR /&gt;result.each {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println it.getPropertyValueById('cmis:name')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println it.getPropertyValueById('pdfp:numberOfPages')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println '—————'&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem: The &lt;/SPAN&gt;&lt;STRONG&gt;optional&lt;/STRONG&gt;&lt;SPAN&gt; Aspects. In order to fetch the "numberOfPages" for example, I would have to do an outer join, which is not yet supported by alfresco. This is how it should look like (note the "LEFT"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;def folder = session.getObjectByPath('&amp;lt;some folder&amp;gt;');&lt;BR /&gt;def result = session.query("select * from cmis:document d LEFT join pdfp:pages p on d.cmis:objectId=p.cmis:objectId where IN_FOLDER(d,'${folder.id}')", false)&lt;BR /&gt;&lt;BR /&gt;result.each {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println it.getPropertyValueById('cmis:name')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println it.getPropertyValueById('pdfp:numberOfPages')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; println '—————'&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I omit the "LEFT" I am exactly getting what I want, but of course only for documents which have the aspect - too bad.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I started to investigate workarounds. Some came to my mind:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. After the main query, do a subsequent query for each optional aspect with "cmis&lt;img id="smileysurprised" class="emoticon emoticon-smileysurprised" src="https://connect.hyland.com/i/smilies/16x16_smiley-surprised.png" alt="Smiley Surprised" title="Smiley Surprised" /&gt;bjectId in (&amp;lt;firstquery&amp;gt;.ids), then join in java&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Load full-blown CmisObject after the query to get the info (n+1 problem, very bad idea)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Use Session.queryObjects to get full-blown CmisObjects right away (I tried this, but it turned out that aspect's properties are not selected, you need to call object.refresh() to get them, so again n+1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. #2 but with ehcache in front, so the repo call happens only on rare occasion&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Do not add the data to the tabular view but only in the detail view&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the moment I am thinking about #4 or #5 because I wanted to keep my query code as simple as possible and rather wait for outer join to be implemented.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So: How are you guys coping with this? I can't imagine I am the only one who fell over this limitation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Btw: Hope to see aggregation implemented in the future as well (Select distinct, count(), group by, all these would be very welcome)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Sep 2014 09:21:47 GMT</pubDate>
    <dc:creator>pco</dc:creator>
    <dc:date>2014-09-29T09:21:47Z</dc:date>
    <item>
      <title>Efficient CMIS query for nodes with optional aspects</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304424#M257554</link>
      <description>Hi, folks,I am trying to create a small groovy app with OpenCMIS and Alfresco Community 5.0.a as the backend (so CMIS 1.1 :-)I experienced quick progress during the first weeks with Alfresco (Content Modelling, customizations) and OpenCMIS APIs. Having arrived on the fine-tuning level some questions</description>
      <pubDate>Mon, 29 Sep 2014 09:21:47 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304424#M257554</guid>
      <dc:creator>pco</dc:creator>
      <dc:date>2014-09-29T09:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient CMIS query for nodes with optional aspects</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304425#M257555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi pco,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i've also encountered this case and for now i'm using the second solution (load the hole CmisObject) since the search results in my case don't exceed 10 items. I hope that the next versions will implement the outer joins&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Sep 2014 10:02:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304425#M257555</guid>
      <dc:creator>iv0id</dc:creator>
      <dc:date>2014-09-30T10:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient CMIS query for nodes with optional aspects</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304426#M257556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, iv0id,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your reply, then it seems to be the right way to do it at the moment. Let's hope for outer JOIN. Probably I'll try to explore the cmis server code once I have some spare time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In fact, I also had a little "weird" Idea yesterday: Create one aspect that contains all Fields of all my optional aspects as non-mandatory and protected (AspectsCarbonCopyAspect) and then basically write a custom Behaviour that updates the CC aspect's fields upon property changes on the original aspects. The query then is an inner join of cmis:document and the CC aspect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This would resolve the problem but I do not feel very comfortable polluting the entire repository with redundant information just because of a "lack of flexibility". So I'll also stick with #2 (or #4 to be precise, ehcache does not hurt).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have a great day&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 07:49:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/efficient-cmis-query-for-nodes-with-optional-aspects/m-p/304426#M257556</guid>
      <dc:creator>pco</dc:creator>
      <dc:date>2014-10-02T07:49:03Z</dc:date>
    </item>
  </channel>
</rss>

