Search in sources :

Example 16 with ListTypeVersion

use of net.geoprism.registry.ListTypeVersion in project geoprism-registry by terraframe.

the class ListTypeService method removeVersion.

@Request(RequestType.SESSION)
public void removeVersion(String sessionId, String oid) {
    try {
        ListTypeVersion version = ListTypeVersion.get(oid);
        if (version.getWorking()) {
            throw new UnsupportedOperationException("Working versions cannot be deleted");
        }
        this.enforceWritePermissions(version.getEntry().getListType());
        version.delete();
        ((Session) Session.getCurrentSession()).reloadPermissions();
    } catch (DataNotFoundException e) {
    // Do nothing
    }
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Session(com.runwaysdk.session.Session) Request(com.runwaysdk.session.Request)

Example 17 with ListTypeVersion

use of net.geoprism.registry.ListTypeVersion in project geoprism-registry by terraframe.

the class ListTypeService method values.

@Request(RequestType.SESSION)
public JsonArray values(String sessionId, String oid, String value, String attributeName, String json) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    JsonObject criteria = (json != null) ? JsonParser.parseString(json).getAsJsonObject() : new JsonObject();
    return version.values(value, attributeName, criteria);
}
Also used : JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Request(com.runwaysdk.session.Request)

Example 18 with ListTypeVersion

use of net.geoprism.registry.ListTypeVersion in project geoprism-registry by terraframe.

the class ListTypeService method applyVersion.

@Request(RequestType.SESSION)
public JsonObject applyVersion(String sessionId, String oid, String metadata) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    ListType listType = version.getListType();
    if (!listType.isValid()) {
        throw new InvalidMasterListException();
    }
    this.enforceWritePermissions(listType);
    version.appLock();
    try {
        version.parse(JsonParser.parseString(metadata).getAsJsonObject());
    } finally {
        version.apply();
    }
    return version.toJSON(false);
}
Also used : ListType(net.geoprism.registry.ListType) ListTypeVersion(net.geoprism.registry.ListTypeVersion) InvalidMasterListException(net.geoprism.registry.InvalidMasterListException) Request(com.runwaysdk.session.Request)

Example 19 with ListTypeVersion

use of net.geoprism.registry.ListTypeVersion in project geoprism-registry by terraframe.

the class ListTypeInheritedHierarchyTest method testPublishVersion.

@Test
@Request
public void testPublishVersion() {
    TestDataSet.runAsUser(USATestData.USER_ADMIN, (request, adapter) -> {
        JsonObject json = ListTypeTest.getJson(USATestData.ORG_NPS.getServerObject(), USATestData.HIER_SCHOOL, USATestData.SCHOOL_ZONE, USATestData.COUNTRY, USATestData.STATE, USATestData.DISTRICT);
        ListType test = ListType.apply(json);
        try {
            ListTypeEntry entry = test.getOrCreateEntry(new Date(), null);
            ListTypeVersion version = entry.getWorking();
            try {
                MdBusinessDAOIF mdTable = MdBusinessDAO.get(version.getMdBusinessOid());
                Assert.assertNotNull(mdTable);
                version.publish();
            } finally {
                entry.delete();
            }
        } finally {
            test.delete();
        }
    });
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeEntry(net.geoprism.registry.ListTypeEntry) ListType(net.geoprism.registry.ListType) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Date(java.util.Date) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 20 with ListTypeVersion

use of net.geoprism.registry.ListTypeVersion 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

ListTypeVersion (net.geoprism.registry.ListTypeVersion)20 Request (com.runwaysdk.session.Request)15 ListType (net.geoprism.registry.ListType)11 JsonObject (com.google.gson.JsonObject)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)5 QueryFactory (com.runwaysdk.query.QueryFactory)4 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 ListTypeEntry (net.geoprism.registry.ListTypeEntry)3 SingleListType (net.geoprism.registry.SingleListType)3 JsonArray (com.google.gson.JsonArray)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2 Session (com.runwaysdk.session.Session)2 IncrementalListType (net.geoprism.registry.IncrementalListType)2 IntervalListType (net.geoprism.registry.IntervalListType)2 InvalidMasterListException (net.geoprism.registry.InvalidMasterListException)2 ListTypeVersionQuery (net.geoprism.registry.ListTypeVersionQuery)2 FhirSyncLevel (net.geoprism.registry.etl.FhirSyncLevel)2 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)2 JsonSerializable (net.geoprism.registry.view.JsonSerializable)2 GlobalNotificationMessage (net.geoprism.registry.ws.GlobalNotificationMessage)2