Search in sources :

Example 21 with GeoObjectOverTime

use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.

the class RegistryService method newGeoObjectInstanceOverTime.

@Request(RequestType.SESSION)
public String newGeoObjectInstanceOverTime(String sessionId, String typeCode) {
    final ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
    ServerGeoObjectIF go = service.newInstance(type);
    go.setInvalid(false);
    final GeoObjectOverTime goot = go.toGeoObjectOverTime();
    ServerParentTreeNodeOverTime pot = go.getParentsOverTime(null, true);
    HierarchyService.filterHierarchiesFromPermissions(type, pot);
    /**
     * Serialize the GeoObject and add it to the response
     */
    JsonObject response = new JsonObject();
    response.add("geoObject", goot.toJSON());
    response.add("hierarchies", pot.toJSON());
    return response.toString();
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 22 with GeoObjectOverTime

use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.

the class RegistryService method updateGeoObjectOverTime.

@Request(RequestType.SESSION)
public GeoObjectOverTime updateGeoObjectOverTime(String sessionId, String jGeoObj) {
    GeoObjectOverTime goTime = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), jGeoObj);
    ServerGeoObjectType type = ServerGeoObjectType.get(goTime.getType().getCode());
    ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(goTime.getType().getOrganizationCode(), type);
    ServerGeoObjectIF object = service.apply(goTime, false, false);
    return object.toGeoObjectOverTime();
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 23 with GeoObjectOverTime

use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.

the class RegistryService method createGeoObjectOverTime.

@Request(RequestType.SESSION)
public GeoObjectOverTime createGeoObjectOverTime(String sessionId, String jGeoObj) {
    GeoObjectOverTime goTime = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), jGeoObj);
    ServerGeoObjectType type = ServerGeoObjectType.get(goTime.getType().getCode());
    ServiceFactory.getGeoObjectPermissionService().enforceCanCreate(goTime.getType().getOrganizationCode(), type);
    ServerGeoObjectIF object = service.apply(goTime, true, false);
    return object.toGeoObjectOverTime();
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 24 with GeoObjectOverTime

use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.

the class GeoObjectImporterTest method testNewAndUpdate.

/*
   * I simply could not get this test to work on the build machine :(. It works locally for me but not on the build machine and I don't know why.
   */
// @Test
// public void testSessionExpire() throws InterruptedException
// {
// CommonsConfigurationResolver.getInMemoryConfigurator().setProperty("import.refreshSessionRecordCount", "1");
// Assert.assertEquals(1, GeoregistryProperties.getRefreshSessionRecordCount());
// 
// Date benchmarkStartTime = new Date();
// testUpdateOnly();
// Date benchmarkEndTime = new Date();
// long benchmarkRuntime = benchmarkEndTime.getTime() - benchmarkStartTime.getTime();
// System.out.println("Benchmark time is " + benchmarkRuntime); // Find out how long it takes on this computer to import one record
// 
// GeoObjectImportConfiguration config = testSessionSetup();
// 
// Date startTime = new Date();
// 
// long oldSessionTime = Session.getSessionTime();
// 
// // This value must be very finely tuned. It has to be short enough such that it is less than the time a fast computer
// // will take to import the entire spreadsheet, but small enough so that a slow computer can import a single record
// // before the session expires.
// final long sessionTimeMs = benchmarkRuntime + 1500;
// Session.setSessionTime(sessionTimeMs / (1000));
// 
// ImportHistory hist;
// try
// {
// hist = testSessionExpireInReq(config);
// }
// finally
// {
// Session.setSessionTime(oldSessionTime);
// }
// 
// sessionTestValidateInRequest(hist, startTime, sessionTimeMs);
// }
// 
// @Request
// private void sessionTestValidateInRequest(ImportHistory hist, Date startTime, long sessionTimeMs) throws InterruptedException
// {
// SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
// 
// Date endTime = new Date();
// 
// System.out.println("Session expiration test took " + (endTime.getTime() - startTime.getTime()) + " miliseconds to complete.");
// 
// if ((endTime.getTime() - startTime.getTime()) < sessionTimeMs)
// {
// Assert.fail("The test completed before the session had a chance to expire. Try setting the 'sessionTimeMs' lower.");
// }
// }
// 
// @Request
// private GeoObjectImportConfiguration testSessionSetup()
// {
// InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet-500records.xlsx");
// 
// Assert.assertNotNull(istream);
// 
// ExcelService service = new ExcelService();
// ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
// 
// GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
// config.setHierarchy(hierarchyType);
// return config;
// }
// 
// @Request
// public ImportHistory testSessionExpireInReq(GeoObjectImportConfiguration config) throws InterruptedException
// {
// ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
// 
// // We have to wait until the job is running so that it will run with the session time.
// SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.RUNNING);
// 
// return hist;
// }
@Test
@Request
public void testNewAndUpdate() throws InterruptedException {
    InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet2.xlsx");
    Assert.assertNotNull(istream);
    ExcelService service = new ExcelService();
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
    GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
    config.setHierarchy(hierarchyType);
    ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(ROW_COUNT), hist.getWorkTotal());
    Assert.assertEquals(new Long(ROW_COUNT), hist.getWorkProgress());
    Assert.assertEquals(new Long(3), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
    GeoObject object = ServiceFactory.getRegistryService().getGeoObjectByCode(testData.clientRequest.getSessionId(), "0001", USATestData.DISTRICT.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertNotNull(object);
    Assert.assertEquals("Test", object.getLocalizedDisplayLabel());
    Geometry geometry = object.getGeometry();
    Assert.assertNotNull(geometry);
    Double lat = new Double(2.232343);
    Double lon = new Double(1.134232);
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    Point expected = new Point(new CoordinateSequence2D(lon, lat), factory);
    Assert.assertEquals(expected, geometry);
    GeoObjectOverTime coloradoDistOne = ServiceFactory.getRegistryService().getGeoObjectOverTimeByCode(testData.clientRequest.getSessionId(), USATestData.CO_D_ONE.getCode(), USATestData.DISTRICT.getCode());
    Double cd1_lat = new Double(4.3333);
    Double cd1_lon = new Double(1.222);
    GeometryFactory cd1_factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    Point cd1_expected = new Point(new CoordinateSequence2D(cd1_lon, cd1_lat), cd1_factory);
    Geometry cd1_geometry = coloradoDistOne.getGeometry(TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertEquals(cd1_expected, cd1_geometry);
    JSONObject json = new JSONObject(new ETLService().getImportErrors(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    Assert.assertEquals(0, json.getJSONArray("resultSet").length());
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) CoordinateSequence2D(org.jaitools.jts.CoordinateSequence2D) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) InputStream(java.io.InputStream) ExcelService(net.geoprism.registry.service.ExcelService) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) JSONObject(org.json.JSONObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 25 with GeoObjectOverTime

use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.

the class AttributeClassificationTest method testCreateGeoObjectOverTime.

@Test
public void testCreateGeoObjectOverTime() {
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA };
    for (TestUserInfo user : allowedUsers) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            TestDataSet.populateAdapterIds(user, adapter);
            GeoObjectOverTime object = TEST_GO.newGeoObjectOverTime(adapter);
            object.setValue(testClassification.getName(), CODE, TEST_GO.getDate(), ValueOverTime.INFINITY_END_DATE);
            GeoObjectOverTime returned = adapter.createGeoObjectOverTime(object.toJSON().toString());
            Assert.assertEquals(CODE, returned.getValue(testClassification.getName(), TEST_GO.getDate()));
            TEST_GO.assertApplied();
            TEST_GO.delete();
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest)

Aggregations

GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)30 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 Test (org.junit.Test)9 Geometry (com.vividsolutions.jts.geom.Geometry)5 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 Endpoint (com.runwaysdk.mvc.Endpoint)4 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)4 Request (com.runwaysdk.session.Request)4 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)4 ServerParentTreeNodeOverTime (net.geoprism.registry.view.ServerParentTreeNodeOverTime)4 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 ValueOverTimeCollectionDTO (org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO)4 JsonObject (com.google.gson.JsonObject)3 VertexObject (com.runwaysdk.business.graph.VertexObject)3 SimpleDateFormat (java.text.SimpleDateFormat)3 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)3 TestUserInfo (net.geoprism.registry.test.TestUserInfo)3 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)3