Search in sources :

Example 36 with HierarchyType

use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.

the class HierarchyServiceTest method testDeleteHierarchyTypeAsBadRole.

@Test
public void testDeleteHierarchyTypeAsBadRole() {
    String organizationCode = FastTestDataset.ORG_CGOV.getCode();
    HierarchyType reportingDivision = MetadataFactory.newHierarchyType(TEST_HT.getCode(), new LocalizedValue("Reporting Division"), new LocalizedValue("The rporting division hieracy..."), organizationCode, testData.adapter);
    String gtJSON = reportingDivision.toJSON().toString();
    ServiceFactory.getHierarchyService().createHierarchyType(testData.clientSession.getSessionId(), gtJSON);
    TestUserInfo[] users = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : users) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                ServiceFactory.getHierarchyService().deleteHierarchyType(request.getSessionId(), TEST_HT.getCode());
            });
            Assert.fail("Able to update a geo object type as a user with bad roles");
        } catch (SmartExceptionDTO e) {
        // This is expected
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 37 with HierarchyType

use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.

the class HierarchyServiceTest method testCreateHierarchyType.

@Test
public void testCreateHierarchyType() {
    String organizationCode = FastTestDataset.ORG_CGOV.getCode();
    HierarchyType reportingDivision = MetadataFactory.newHierarchyType(TEST_HT.getCode(), new LocalizedValue("Reporting Division"), new LocalizedValue("The rporting division hieracy..."), organizationCode, testData.adapter);
    reportingDivision.setAbstractDescription("Test Abstract");
    reportingDivision.setAcknowledgement("Test Acknowledgement");
    reportingDivision.setDisclaimer("Test disclaimer");
    reportingDivision.setContact("Test Contact");
    reportingDivision.setPhoneNumber("Test phone number");
    reportingDivision.setEmail("Test email");
    reportingDivision.setProgress("Test Progress");
    reportingDivision.setAccessConstraints("Access Constraints");
    reportingDivision.setUseConstraints("Test Use Constraints");
    String gtJSON = reportingDivision.toJSON().toString();
    ServiceFactory.getHierarchyService().createHierarchyType(testData.clientSession.getSessionId(), gtJSON);
    HierarchyType[] hierarchies = ServiceFactory.getHierarchyService().getHierarchyTypes(testData.clientSession.getSessionId(), new String[] { TEST_HT.getCode() }, PermissionContext.READ);
    Assert.assertNotNull("The created hierarchy was not returned", hierarchies);
    Assert.assertEquals("The wrong number of hierarchies were returned.", 1, hierarchies.length);
    HierarchyType hierarchy = hierarchies[0];
    Assert.assertEquals("Reporting Division", hierarchy.getLabel().getValue());
    Assert.assertEquals("Test Abstract", hierarchy.getAbstractDescription());
    Assert.assertEquals("Test Acknowledgement", hierarchy.getAcknowledgement());
    Assert.assertEquals("Test disclaimer", hierarchy.getDisclaimer());
    Assert.assertEquals("Test Contact", hierarchy.getContact());
    Assert.assertEquals("Test phone number", hierarchy.getPhoneNumber());
    Assert.assertEquals("Test email", hierarchy.getEmail());
    Assert.assertEquals("Test Progress", hierarchy.getProgress());
    Assert.assertEquals("Access Constraints", hierarchy.getAccessConstraints());
    Assert.assertEquals("Test Use Constraints", hierarchy.getUseConstraints());
    // test the types that were created
    String mdTermRelUniversal = ServerHierarchyType.buildMdTermRelUniversalKey(reportingDivision.getCode());
    String expectedMdTermRelUniversal = GISConstants.GEO_PACKAGE + "." + reportingDivision.getCode() + RegistryConstants.UNIVERSAL_RELATIONSHIP_POST;
    Assert.assertEquals("The type name of the MdTermRelationshp defining the universals was not correctly defined for the given code.", expectedMdTermRelUniversal, mdTermRelUniversal);
    String mdTermRelGeoEntity = ServerHierarchyType.buildMdTermRelGeoEntityKey(reportingDivision.getCode());
    String expectedMdTermRelGeoEntity = GISConstants.GEO_PACKAGE + "." + reportingDivision.getCode();
    Assert.assertEquals("The type name of the MdTermRelationshp defining the geoentities was not correctly defined for the given code.", expectedMdTermRelGeoEntity, mdTermRelGeoEntity);
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Test(org.junit.Test)

Example 38 with HierarchyType

use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.

the class HierarchyServiceTest method testUpdateHierarchyType.

@Test
public void testUpdateHierarchyType() {
    HierarchyType reportingDivision = FastTestDataset.HIER_ADMIN.toDTO();
    String gtJSON = reportingDivision.toJSON().toString();
    reportingDivision.setLabel(new LocalizedValue("Reporting Division 2"));
    reportingDivision.setDescription(new LocalizedValue("The rporting division hieracy 2"));
    gtJSON = reportingDivision.toJSON().toString();
    reportingDivision = ServiceFactory.getHierarchyService().updateHierarchyType(testData.clientSession.getSessionId(), gtJSON);
    try {
        Assert.assertNotNull("The created hierarchy was not returned", reportingDivision);
        Assert.assertEquals("Reporting Division 2", reportingDivision.getLabel().getValue());
        Assert.assertEquals("The rporting division hieracy 2", reportingDivision.getDescription().getValue());
    } finally {
        reportingDivision.setLabel(new LocalizedValue(FastTestDataset.HIER_ADMIN.getDisplayLabel()));
        reportingDivision.setDescription(new LocalizedValue(FastTestDataset.HIER_ADMIN.getDisplayLabel()));
        gtJSON = reportingDivision.toJSON().toString();
        reportingDivision = ServiceFactory.getHierarchyService().updateHierarchyType(testData.clientSession.getSessionId(), gtJSON);
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Test(org.junit.Test)

Example 39 with HierarchyType

use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method testGetHierarchyTypes.

@Test
public void testGetHierarchyTypes() {
    final String[] types = new String[] { FastTestDataset.HIER_ADMIN.getCode() };
    HierarchyType[] hts = testData.adapter.getHierarchyTypes(types);
    Assert.assertEquals(types.length, hts.length);
    HierarchyType locatedIn = hts[0];
    Assert.assertEquals(locatedIn.toJSON().toString(), HierarchyType.fromJSON(locatedIn.toJSON().toString(), testData.adapter).toJSON().toString());
    // Test to make sure we can provide no types and get everything back
    HierarchyType[] hts2 = testData.adapter.getHierarchyTypes(new String[] {});
    checkHierarchyTypeResponse(hts2, true);
    HierarchyType[] hts3 = testData.adapter.getHierarchyTypes(null);
    checkHierarchyTypeResponse(hts3, true);
}
Also used : HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) Test(org.junit.Test)

Example 40 with HierarchyType

use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method checkHierarchyTypeResponse.

private void checkHierarchyTypeResponse(HierarchyType[] hts, boolean hasPrivate) {
    hts = Arrays.stream(hts).filter(ht -> ArrayUtils.contains(new String[] { FastTestDataset.HIER_ADMIN.getCode(), FastTestDataset.HIER_HEALTH_ADMIN.getCode() }, ht.getCode())).toArray(HierarchyType[]::new);
    Assert.assertEquals(2, hts.length);
    for (HierarchyType ht : hts) {
        List<HierarchyNode> rootTypes = ht.getRootGeoObjectTypes();
        Assert.assertEquals(1, rootTypes.size());
        HierarchyNode hnRoot = rootTypes.get(0);
        Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), hnRoot.getGeoObjectType().getCode());
        List<HierarchyNode> provinces = hnRoot.getChildren();
        HierarchyNode hnProvince = null;
        if (ht.getCode().equals(FastTestDataset.HIER_ADMIN.getCode()) && hasPrivate) {
            Assert.assertEquals(2, provinces.size());
            for (HierarchyNode province : provinces) {
                if (province.getGeoObjectType().getCode().equals(FastTestDataset.PROVINCE.getCode())) {
                    hnProvince = province;
                } else {
                    Assert.assertEquals(FastTestDataset.PROVINCE_PRIVATE.getCode(), province.getGeoObjectType().getCode());
                }
            }
            Assert.assertNotNull(hnProvince);
        } else {
            Assert.assertEquals(1, provinces.size());
            hnProvince = provinces.get(0);
        }
        Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), hnProvince.getGeoObjectType().getCode());
        if (ht.getCode().equals(FastTestDataset.HIER_ADMIN.getCode())) {
            Assert.assertEquals(1, hnProvince.getChildren().size());
        } else if (ht.getCode().equals(FastTestDataset.HIER_HEALTH_ADMIN.getCode())) {
            List<HierarchyNode> provChildren = hnProvince.getChildren();
            Assert.assertEquals(2, provChildren.size());
        // HierarchyNode hnHospital = provChildren.get(0);
        // 
        // Assert.assertEquals(FastTestDataset.HOSPITAL.getCode(),
        // hnHospital.getGeoObjectType().getCode());
        } else {
            Assert.fail("Unexpected Hierarchy [" + ht.getCode() + "]");
        }
    }
}
Also used : HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ArrayList(java.util.ArrayList) List(java.util.List) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Aggregations

HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)40 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)21 CustomSerializer (org.commongeoregistry.adapter.metadata.CustomSerializer)12 Endpoint (com.runwaysdk.mvc.Endpoint)11 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)11 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)10 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 Test (org.junit.Test)9 JsonArray (com.google.gson.JsonArray)6 Request (com.runwaysdk.session.Request)6 JsonObject (com.google.gson.JsonObject)5 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)5 HierarchyNode (org.commongeoregistry.adapter.metadata.HierarchyNode)4 List (java.util.List)3 ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)3 GeoObjectRelationshipPermissionServiceIF (net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF)3 TestUserInfo (net.geoprism.registry.test.TestUserInfo)3 SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)2 MdAttributeCharacterDAO (com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO)2 MdAttributeUUIDDAO (com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO)2