Search in sources :

Example 76 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class FhirImportTest method createSyncConfig.

@Request
public static SynchronizationConfig createSyncConfig(ExternalSystem system) {
    // Define reusable objects
    final ServerHierarchyType ht = USATestData.HIER_ADMIN.getServerObject();
    final Organization org = USATestData.ORG_NPS.getServerObject();
    // Create DHIS2 Sync Config
    FhirSyncImportConfig sourceConfig = new FhirSyncImportConfig();
    sourceConfig.setLabel(new LocalizedValue("FHIR Import Test Data"));
    sourceConfig.setOrganization(org);
    sourceConfig.setImplementation(BasicFhirResourceProcessor.class.getName());
    // Serialize the FHIR Config
    GsonBuilder builder = new GsonBuilder();
    String fhirExportJsonConfig = builder.create().toJson(sourceConfig);
    // Create a SynchronizationConfig
    SynchronizationConfig config = new SynchronizationConfig();
    config.setConfiguration(fhirExportJsonConfig);
    config.setOrganization(org);
    config.setHierarchy(ht.getMdTermRelationship());
    config.setSystem(system.getOid());
    config.getLabel().setValue("FHIR Import Test");
    config.setIsImport(true);
    config.apply();
    return config;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) GsonBuilder(com.google.gson.GsonBuilder) BasicFhirResourceProcessor(net.geoprism.registry.etl.fhir.BasicFhirResourceProcessor) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Example 77 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType 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 78 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ShapefileServiceTest method testImportShapefileInteger.

@Test
@Request
public void testImportShapefileInteger() throws Throwable {
    InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
    Assert.assertNotNull(istream);
    ShapefileService service = new ShapefileService();
    GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
    config.setFunction(testInteger.getName(), new BasicColumnFunction("ALAND"));
    config.setHierarchy(hierarchyType);
    ImportHistory hist = mockImport(config);
    Assert.assertTrue(hist.getStatus().get(0).equals(AllJobStatus.SUCCESS));
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(56), hist.getWorkTotal());
    Assert.assertEquals(new Long(56), hist.getWorkProgress());
    Assert.assertEquals(new Long(56), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
    GeoObject object = ServiceFactory.getRegistryService().getGeoObjectByCode(testData.clientRequest.getSessionId(), "01", USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertNotNull(object);
    Assert.assertNotNull(object.getGeometry());
    Assert.assertEquals("Alabama", object.getLocalizedDisplayLabel());
    Assert.assertEquals(131174431216L, object.getValue(testInteger.getName()));
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ShapefileService(net.geoprism.registry.service.ShapefileService) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 79 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ShapefileServiceTest method testBadParentSynonymAndResume.

@Test
@Request
public void testBadParentSynonymAndResume() throws Throwable {
    InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
    Assert.assertNotNull(istream);
    ShapefileService service = new ShapefileService();
    GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
    config.setHierarchy(hierarchyType);
    config.addParent(new Location(USATestData.COUNTRY.getServerObject(), hierarchyType, new BasicColumnFunction("LSAD"), ParentMatchStrategy.ALL));
    // ImportHistory hist = mockImport(config);
    // Assert.assertTrue(hist.getStatus().get(0).equals(AllJobStatus.FEEDBACK));
    ImportHistory hist = importShapefile(testData.clientRequest.getSessionId(), config.toJSON().toString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.FEEDBACK);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(56), hist.getWorkTotal());
    Assert.assertEquals(new Long(56), hist.getWorkProgress());
    Assert.assertEquals(new Long(0), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.VALIDATION_RESOLVE, hist.getStage().get(0));
    JSONObject page = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    JSONArray results = page.getJSONArray("resultSet");
    Assert.assertEquals(1, results.length());
    // Ensure the geo objects were not created
    ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(USATestData.STATE.getServerObject(), config.getStartDate());
    query.setRestriction(new ServerCodeRestriction("01"));
    Assert.assertNull(query.getSingleResult());
    // Resolve the import problem with a synonym
    GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(testData.clientRequest.getSessionId(), USATestData.COUNTRY.getCode());
    geoObj.setCode("99");
    geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label99");
    geoObj.setUid(ServiceFactory.getIdService().getUids(1)[0]);
    ServerGeoObjectIF serverGo = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService()).apply(geoObj, TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE, true, false);
    JSONObject valRes = new JSONObject();
    valRes.put("validationProblemId", results.getJSONObject(0).getString("id"));
    valRes.put("resolution", ValidationResolution.SYNONYM);
    valRes.put("code", serverGo.getCode());
    valRes.put("typeCode", serverGo.getType().getCode());
    valRes.put("label", "00");
    new ETLService().submitValidationProblemResolution(testData.clientRequest.getSessionId(), valRes.toString());
    ValidationProblem vp = ValidationProblem.get(results.getJSONObject(0).getString("id"));
    Assert.assertEquals(ValidationResolution.SYNONYM.name(), vp.getResolution());
    Assert.assertEquals(ParentReferenceProblem.DEFAULT_SEVERITY, vp.getSeverity());
    ImportHistory hist2 = importShapefile(testData.clientRequest.getSessionId(), hist.getConfigJson());
    Assert.assertEquals(hist.getOid(), hist2.getOid());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
    Assert.assertEquals(new Long(56), hist.getWorkTotal());
    Assert.assertEquals(new Long(56), hist.getWorkProgress());
    Assert.assertEquals(new Long(56), hist.getImportedRecords());
    String sessionId = testData.clientRequest.getSessionId();
    GeoObject go = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, "01", USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertEquals("01", go.getCode());
    ParentTreeNode nodes = ServiceFactory.getRegistryService().getParentGeoObjects(sessionId, go.getCode(), config.getType().getCode(), new String[] { USATestData.COUNTRY.getCode() }, false, TestDataSet.DEFAULT_OVER_TIME_DATE);
    List<ParentTreeNode> parents = nodes.getParents();
    Assert.assertEquals(1, parents.size());
    JSONObject page2 = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    JSONArray results2 = page2.getJSONArray("resultSet");
    Assert.assertEquals(0, results2.length());
    Assert.assertEquals(0, page2.getInt("count"));
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) JSONArray(org.json.JSONArray) ShapefileService(net.geoprism.registry.service.ShapefileService) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) JSONObject(org.json.JSONObject) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) Location(net.geoprism.registry.io.Location) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 80 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class GeoObjectTypeRelationshipServiceTest method testAddChildAbstractType.

@Test
@Request
public void testAddChildAbstractType() {
    TEST_CHILD.apply();
    TestGeoObjectTypeInfo childGot = new TestGeoObjectTypeInfo("HMST_Abstract", FastTestDataset.ORG_CGOV);
    childGot.setAbstract(true);
    try {
        childGot.apply();
        ServerHierarchyType type = FastTestDataset.HIER_ADMIN.getServerObject();
        ServerGeoObjectType parentType = TEST_CHILD.getServerObject();
        ServerGeoObjectType childType = childGot.getServerObject();
        try {
            type.addToHierarchy(RootGeoObjectType.INSTANCE, parentType);
            type.addToHierarchy(parentType, childType);
            List<ServerGeoObjectType> children = parentType.getChildren(type);
            Assert.assertEquals(1, children.size());
            Assert.assertEquals(childType.getCode(), children.get(0).getCode());
        } finally {
            type.removeChild(RootGeoObjectType.INSTANCE, parentType, false);
            type.removeChild(parentType, childType, false);
        }
    } finally {
        childGot.delete();
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) TestGeoObjectTypeInfo(net.geoprism.registry.test.TestGeoObjectTypeInfo) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)86 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)55 Request (com.runwaysdk.session.Request)38 JsonObject (com.google.gson.JsonObject)20 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)17 JsonArray (com.google.gson.JsonArray)16 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)12 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 Locale (java.util.Locale)10 Point (com.vividsolutions.jts.geom.Point)9 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)8 Organization (net.geoprism.registry.Organization)8