Search in sources :

Example 1 with JsonSerializable

use of net.geoprism.registry.view.JsonSerializable in project geoprism-registry by terraframe.

the class ListTypeService method getPublishJobs.

@Request(RequestType.SESSION)
public JsonObject getPublishJobs(String sessionId, String oid, int pageSize, int pageNumber, String sortAttr, boolean isAscending) {
    QueryFactory qf = new QueryFactory();
    final ListTypeJobQuery query = new ListTypeJobQuery(qf);
    query.WHERE(query.getListType().EQ(oid));
    query.ORDER_BY_DESC(query.getCreateDate());
    // query.ORDER_BY(ihq.get(sortAttr), order);
    query.restrictRows(pageSize, pageNumber);
    try (OIterator<? extends ListTypeJob> it = query.getIterator()) {
        List<JsonSerializable> results = new LinkedList<>(it.getAll());
        return new Page<JsonSerializable>(query.getCount(), query.getPageNumber(), query.getPageSize(), results).toJSON();
    }
}
Also used : ListTypeJobQuery(net.geoprism.registry.etl.ListTypeJobQuery) QueryFactory(com.runwaysdk.query.QueryFactory) JsonSerializable(net.geoprism.registry.view.JsonSerializable) LinkedList(java.util.LinkedList) Request(com.runwaysdk.session.Request)

Example 2 with JsonSerializable

use of net.geoprism.registry.view.JsonSerializable in project geoprism-registry by terraframe.

the class ListTypeService method data.

@Request(RequestType.SESSION)
public JsonObject data(String sessionId, String oid, String criteria, Boolean showInvalid, Boolean includeGeometries) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    Page<JsonSerializable> page = version.data(JsonParser.parseString(criteria).getAsJsonObject(), showInvalid, includeGeometries);
    return page.toJSON();
}
Also used : JsonSerializable(net.geoprism.registry.view.JsonSerializable) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Request(com.runwaysdk.session.Request)

Example 3 with JsonSerializable

use of net.geoprism.registry.view.JsonSerializable in project geoprism-registry by terraframe.

the class ListTypeTest method dataTest.

private void dataTest(Boolean includeGeometries) {
    GeoJSONReader reader = new GeoJSONReader();
    TestDataSet.runAsUser(USATestData.USER_ADMIN, (request, adapter) -> {
        ListTypeBuilder.Hierarchy hierarchy = new ListTypeBuilder.Hierarchy();
        hierarchy.setType(USATestData.HIER_ADMIN);
        hierarchy.setParents(USATestData.COUNTRY, USATestData.STATE, USATestData.DISTRICT);
        hierarchy.setSubtypeHierarchies(USATestData.HIER_REPORTS_TO);
        ListTypeBuilder builder = new ListTypeBuilder();
        builder.setOrg(USATestData.ORG_NPS.getServerObject());
        builder.setInfo(USATestData.HEALTH_FACILITY);
        builder.setHts(hierarchy);
        ListType test = builder.build();
        try {
            ListTypeEntry entry = test.createEntry(TestDataSet.DEFAULT_OVER_TIME_DATE);
            try {
                entry.publish(createVersionMetadata().toString());
                List<ListTypeVersion> versions = entry.getVersions();
                Assert.assertEquals(2, versions.size());
                ListTypeVersion version = versions.get(0);
                MdBusinessDAOIF mdTable = MdBusinessDAO.get(version.getMdBusinessOid());
                Assert.assertNotNull(mdTable);
                Page<JsonSerializable> data = version.data(new JsonObject(), true, includeGeometries);
                // Entries should be HP_1, HP_2, HS_1, HS_2
                Assert.assertEquals(new Long(4), data.getCount());
                List<JsonSerializable> results = data.getResults();
                for (int i = 0; i < results.size(); i++) {
                    JsonObject result = results.get(i).toJSON().getAsJsonObject();
                    String code = result.get("code").getAsString();
                    if (code.equals(USATestData.HS_ONE.getCode())) {
                        String reportsTo = result.get("usatestdatareportstocode").getAsString();
                        Assert.assertEquals(USATestData.HP_ONE.getCode(), reportsTo);
                    } else if (code.equals(USATestData.HS_TWO.getCode())) {
                        String reportsTo = result.get("usatestdatareportstocode").getAsString();
                        Assert.assertEquals(USATestData.HP_TWO.getCode(), reportsTo);
                    }
                    if (includeGeometries != null && includeGeometries.equals(Boolean.TRUE)) {
                        Assert.assertEquals(true, result.has("geometry"));
                        JsonObject geometries = result.get("geometry").getAsJsonObject();
                        Geometry jtsGeom = reader.read(geometries.toString());
                        Assert.assertTrue(jtsGeom.isValid());
                    } else {
                        Assert.assertEquals(false, result.has("geometry"));
                    }
                }
            } finally {
                entry.delete();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            throw new RuntimeException(t);
        } finally {
            test.delete();
        }
    });
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeEntry(net.geoprism.registry.ListTypeEntry) JsonSerializable(net.geoprism.registry.view.JsonSerializable) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Geometry(com.vividsolutions.jts.geom.Geometry) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) SingleListType(net.geoprism.registry.SingleListType) IntervalListType(net.geoprism.registry.IntervalListType) ListType(net.geoprism.registry.ListType) IncrementalListType(net.geoprism.registry.IncrementalListType) ListTypeBuilder(net.geoprism.registry.ListTypeBuilder)

Aggregations

JsonSerializable (net.geoprism.registry.view.JsonSerializable)3 Request (com.runwaysdk.session.Request)2 ListTypeVersion (net.geoprism.registry.ListTypeVersion)2 JsonObject (com.google.gson.JsonObject)1 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 LinkedList (java.util.LinkedList)1 IncrementalListType (net.geoprism.registry.IncrementalListType)1 IntervalListType (net.geoprism.registry.IntervalListType)1 ListType (net.geoprism.registry.ListType)1 ListTypeBuilder (net.geoprism.registry.ListTypeBuilder)1 ListTypeEntry (net.geoprism.registry.ListTypeEntry)1 SingleListType (net.geoprism.registry.SingleListType)1 ListTypeJobQuery (net.geoprism.registry.etl.ListTypeJobQuery)1 GeoJSONReader (org.wololo.jts2geojson.GeoJSONReader)1