Package com.haulmont.yarg.loaders.impl

Examples of com.haulmont.yarg.loaders.impl.JsonDataLoader


        reporting.setFormatterFactory(formatterFactory);
        reporting.setLoaderFactory(
                new DefaultLoaderFactory()
                        .setSqlDataLoader(new PropertiesSqlLoaderFactory(propertiesLoader).create())
                        .setGroovyDataLoader(new GroovyDataLoader(new DefaultScriptingImpl()))
                        .setJsonDataLoader(new JsonDataLoader()));
        return reporting;
    }
View Full Code Here


    }

    @Test
    public void testJson() throws Exception {
        JsonDataLoader jsonDataLoader = new JsonDataLoader();
        BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
        rootBand.setData(Collections.<String, Object>emptyMap());
        ReportQueryImpl reportQuery = new ReportQueryImpl("", "parameter=param1 $.store.book[*]", "json", null, null);

        String json = "{ \"store\": {\n" +
                "    \"book\": [ \n" +
                "      { \"category\": \"reference\",\n" +
                "        \"author\": \"Nigel Rees\",\n" +
                "        \"title\": \"Sayings of the Century\",\n" +
                "        \"price\": 8.95\n" +
                "      },\n" +
                "      { \"category\": \"fiction\",\n" +
                "        \"author\": \"Evelyn Waugh\",\n" +
                "        \"title\": \"Sword of Honour\",\n" +
                "        \"price\": 12.99,\n" +
                "        \"isbn\": \"0-553-21311-3\"\n" +
                "      }\n" +
                "    ],\n" +
                "    \"bicycle\": {\n" +
                "      \"color\": \"red\",\n" +
                "      \"price\": 19.95\n" +
                "    }\n" +
                "  }\n" +
                "}";

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("param1", json);

        List<Map<String, Object>> maps = jsonDataLoader.loadData(reportQuery, rootBand, params);
        Assert.assertEquals(2, maps.size());

        Map<String, Object> book1 = maps.get(0);
        Assert.assertEquals("Sayings of the Century", book1.get("title"));

        reportQuery = new ReportQueryImpl("", "parameter=param1 $", "json", null, null);
        maps = jsonDataLoader.loadData(reportQuery, rootBand, params);

        Map<String, Object> map = maps.get(0);

        Assert.assertEquals("red", map.get("store.bicycle.color"));

        reportQuery = new ReportQueryImpl("", "parameter=param1 $some.not.existing", "json", null, null);
        maps = jsonDataLoader.loadData(reportQuery, rootBand, params);
        Assert.assertEquals(0, maps.size());

    }
View Full Code Here

TOP

Related Classes of com.haulmont.yarg.loaders.impl.JsonDataLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.