Jump to content
Changes to the Jaspersoft community edition download ×

JSONQL filter a list of images


r.koelewijn
Go to solution Solved by narcism,

Recommended Posts

Hi,

I have a list element which is populated with images from a dataset which I get from a couchdb database through webserrvice query sql.

To get the attachements to display I populate my list like this:

![CDATA[((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone("_attachments.*",$P{AttachmentsSubFieldsMap})]]

Now I have the need to leave 1 image out of the subset, but I do not know how to achieve this. 

The image I need to filter out is this one ("smallmap.png"), but as you can see smallmap.png is the key name of the object which seem to be left out of the array when calling "_attachments.*" :

"_attachments": {
    "smallmap.png": {
      "content_type": "image/png",
      "revpos": 13,
      "digest": "md5-VJaOsR0z8+RUMYCSSSvf2A==",
      "length": 34131,
      "stub": true
    }

 

My band with the list:

<band height="220">
            <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            <break>
                <reportElement x="0" y="0" width="278" height="1" uuid="2b80d028-cc12-421c-82ec-cce914577b5e"/>
            </break>
            <frame>
                <reportElement mode="Transparent" x="0" y="5" width="560" height="215" isRemoveLineWhenBlank="true" forecolor="#9EC536" backcolor="#9EC536" uuid="be586fc9-f669-4c1f-a1d9-b6c0af9329fa">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <componentElement>
                    <reportElement x="0" y="0" width="560" height="215" isRemoveLineWhenBlank="true" uuid="0b13fef0-f810-449b-82a5-da6376936dfd">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
                    </reportElement>
                    <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
                        <datasetRun subDataset="Attachments" uuid="29322791-2c92-4d6a-9624-d145428ecc41">
                            <dataSourceExpression><![CDATA[((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone("_attachments.*",$P{AttachmentsSubFieldsMap})]]></dataSourceExpression>
                        </datasetRun>
                        <jr:listContents height="215" width="280">
                            <image>
                                <reportElement x="0" y="0" width="275" height="180" backcolor="#9EC536" uuid="1f86c103-8861-40df-9ac1-fe76607915c4"/>
                                <imageExpression><![CDATA[new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{data}.getBytes()))]]></imageExpression>
                            </image>
                        </jr:listContents>
                    </jr:list>
                </componentElement>
            </frame>
        </band>

Example of the attachments JSON:

"_attachments": {
    "smallmap.png": {
      "content_type": "image/png",
      "revpos": 13,
      "digest": "md5-VJaOsR0z8+RUMYCSSSvf2A==",
      "length": 34131,
      "stub": true
    },
    "88875-PLB-1.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-3n91a7Wn4Qe4nllLJjaPIw==",
      "length": 100680,
      "stub": true
    },
    "88875-PLB-2.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-dWDKjOzY36hB3iVhh32nug==",
      "length": 95684,
      "stub": true
    },
    "88875-PLF-3.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-+7S/X8nkiuNLn64B9JAiNA==",
      "length": 89771,
      "stub": true
    },
    "88875-PLF-4.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-Cu5Zb8MPPe8alDf35OhjrA==",
      "length": 87435,
      "stub": true
    },
    "88875-LB-5.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-m0T1uzwr8ws5yIj34pqV1g==",
      "length": 4577,
      "stub": true
    },
    "88875-LB-6.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-LBB0P0AP78nqGckfhZNwCg==",
      "length": 145528,
      "stub": true
    },
    "88875-LB-7.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-avGJcB6mw16hHkDDWnM1Jw==",
      "length": 207943,
      "stub": true
    },
    "88875-LF-8.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-Q/G/HC0lvJA2E5fSFbzBTg==",
      "length": 4046,
      "stub": true
    },
    "88875-LF-9.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-Ab59Vzif7+lPiKb8LYdyKA==",
      "length": 146101,
      "stub": true
    },
    "88875-LF-10.jpeg": {
      "content_type": "image/jpeg",
      "revpos": 3,
      "digest": "md5-fRBfXQE+V3dY5inezIeyVQ==",
      "length": 180909,
      "stub": true
    }
  }

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution

You cannot operate on the keys of the "_attachments" object. Had it been an array, you could have. Future versions of JasperReports may address this issue.

In this case:

  • you could filter by a fixed key like "digest". You could do that with an expression like: 
    _attachments.*(digest != "md5-VJaOsR0z8+RUMYCSSSvf2A==")[/code]

     

  • or, if you know that the key you are trying to leave out is always the first one in the list, you could skip it with this expression:
    _attachments.*[1:][/code]

     

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...