use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class HierarchyServiceTest method testCreateHierarchyTypeWithOrganization.
@Test
public void testCreateHierarchyTypeWithOrganization() {
HierarchyType reportingDivision = null;
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
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);
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(organizationCode, hierarchy.getOrganizationCode());
// 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);
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class HierarchyServiceTest method testCreateHierarchyTypeAsBadRole.
@Test(expected = SmartExceptionDTO.class)
public void testCreateHierarchyTypeAsBadRole() {
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();
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().createHierarchyType(request.getSessionId(), gtJSON);
});
Assert.fail("Able to update a geo object type as a user with bad roles");
} catch (RunwayExceptionDTO e) {
// This is expected
}
}
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class InheritedHierarchyAnnotationTest method testSetInheritedHierarchy.
@Test
public void testSetInheritedHierarchy() {
FastTestDataset.runAsUser(FastTestDataset.USER_CGOV_RA, (request, adapter) -> {
HierarchyService service = new HierarchyService();
try {
HierarchyType ht = service.setInheritedHierarchy(request.getSessionId(), TEST_HT.getCode(), FastTestDataset.HIER_ADMIN.getCode(), FastTestDataset.PROVINCE.getCode());
List<HierarchyNode> nodes = ht.getRootGeoObjectTypes();
HierarchyNode node = nodes.get(0);
GeoObjectType root = node.getGeoObjectType();
Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), root.getCode());
Assert.assertEquals(FastTestDataset.HIER_ADMIN.getCode(), node.getInheritedHierarchyCode());
} finally {
HierarchyType ht = service.removeInheritedHierarchy(request.getSessionId(), TEST_HT.getCode(), FastTestDataset.PROVINCE.getCode());
List<HierarchyNode> nodes = ht.getRootGeoObjectTypes();
HierarchyNode node = nodes.get(0);
GeoObjectType root = node.getGeoObjectType();
Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), root.getCode());
Assert.assertNull(node.getInheritedHierarchyCode());
}
});
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class GeoObjectRelationshipServiceTest method testGetPrivateHierarchyTypes.
@Test
public void testGetPrivateHierarchyTypes() {
TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_RM_PRIVATE, FastTestDataset.USER_CGOV_RC_PRIVATE, FastTestDataset.USER_CGOV_AC_PRIVATE };
for (TestUserInfo user : allowedUsers) {
TestDataSet.runAsUser(user, (request, adapter) -> {
HierarchyType[] hts = adapter.getHierarchyTypes(null);
checkHierarchyTypeResponse(hts, true);
});
}
TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC };
for (TestUserInfo user : disallowedUsers) {
TestDataSet.runAsUser(user, (request, adapter) -> {
HierarchyType[] hts = adapter.getHierarchyTypes(null);
checkHierarchyTypeResponse(hts, false);
});
}
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class MasterListVersion method createTable.
private TableMetadata createTable() {
MasterList masterlist = this.getMasterlist();
TableMetadata metadata = new TableMetadata();
Locale currentLocale = Session.getCurrentLocale();
String viewName = this.getTableName();
// Create the MdTable
MdBusinessDAO mdTableDAO = MdBusinessDAO.newInstance();
mdTableDAO.setValue(MdTableInfo.NAME, viewName);
mdTableDAO.setValue(MdTableInfo.PACKAGE, RegistryConstants.TABLE_PACKAGE);
mdTableDAO.setStructValue(MdTableInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, masterlist.getDisplayLabel().getValue());
mdTableDAO.setValue(MdTableInfo.TABLE_NAME, viewName);
mdTableDAO.setValue(MdTableInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
mdTableDAO.apply();
MdBusiness mdBusiness = (MdBusiness) BusinessFacade.get(mdTableDAO);
MdAttributeUUIDDAO mdAttributeOriginalId = MdAttributeUUIDDAO.newInstance();
mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.NAME, ORIGINAL_OID);
mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeOriginalId.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Original oid");
mdAttributeOriginalId.apply();
metadata.setMdBusiness(mdBusiness);
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
ServerGeoObjectType type = masterlist.getGeoObjectType();
this.createMdAttributeFromAttributeType(mdBusiness, type.getGeometryType());
Collection<AttributeType> attributeTypes = type.getAttributeMap().values();
for (AttributeType attributeType : attributeTypes) {
if (this.isValid(attributeType)) {
createMdAttributeFromAttributeType(metadata, attributeType, type, locales);
}
}
JsonArray hierarchies = masterlist.getHierarchiesAsJson();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
List<String> pCodes = masterlist.getParentCodes(hierarchy);
if (pCodes.size() > 0) {
String hCode = hierarchy.get("code").getAsString();
ServerHierarchyType hierarchyType = ServiceFactory.getMetadataCache().getHierachyType(hCode).get();
String hierarchyLabel = hierarchyType.getDisplayLabel().getValue(currentLocale);
for (String pCode : pCodes) {
ServerGeoObjectType got = ServerGeoObjectType.get(pCode);
String typeLabel = got.getLabel().getValue(currentLocale);
String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
String label = typeLabel + " (" + hierarchyLabel + ")";
String codeDescription = LocalizationFacade.localize("masterlist.code.description");
codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", typeLabel);
codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
String labelDescription = LocalizationFacade.localize("masterlist.label.description");
labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", typeLabel);
labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label);
mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
mdAttributeCode.apply();
MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (defaultLocale)");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (" + locale + ")");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
mdAttributeLocale.apply();
}
}
}
}
JsonArray subtypeHierarchies = masterlist.getSubtypeHierarchiesAsJson();
for (int i = 0; i < subtypeHierarchies.size(); i++) {
JsonObject hierarchy = subtypeHierarchies.get(i).getAsJsonObject();
if (hierarchy.has("selected") && hierarchy.get("selected").getAsBoolean()) {
String hCode = hierarchy.get("code").getAsString();
HierarchyType hierarchyType = ServiceFactory.getAdapter().getMetadataCache().getHierachyType(hCode).get();
String hierarchyLabel = hierarchyType.getLabel().getValue(currentLocale);
String attributeName = hCode.toLowerCase();
String codeDescription = LocalizationFacade.localize("masterlist.code.description");
codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", "");
codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
String labelDescription = LocalizationFacade.localize("masterlist.label.description");
labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", "");
labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel);
mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
mdAttributeCode.apply();
MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (defaultLocale)");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (" + locale + ")");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
mdAttributeLocale.apply();
}
}
}
return metadata;
}
Aggregations