use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class RegistryService method getAncestors.
@Request(RequestType.SESSION)
public List<GeoObjectType> getAncestors(String sessionId, String code, String hierarchyCode, Boolean includeInheritedTypes, Boolean includeChild) {
ServerGeoObjectType child = ServerGeoObjectType.get(code);
ServerHierarchyType hierarchyType = ServerHierarchyType.get(hierarchyCode);
List<GeoObjectType> ancestors = child.getTypeAncestors(hierarchyType, includeInheritedTypes);
if (includeChild) {
ancestors.add(child.getType());
}
return ancestors;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class XMLImporter method createServerGeoObjectType.
private ServerGeoObjectType createServerGeoObjectType(Organization organization, Element elem) {
String code = elem.getAttribute("code");
LocalizedValue label = this.getLabel(elem);
LocalizedValue description = this.getDescription(elem);
String visibility = elem.getAttribute("visibility");
GeometryType geometryType = this.getGeometryType(elem);
boolean isGeometryEditable = this.getIsGeometryEditable(elem);
boolean isAbstract = this.getIsGroup(elem) || (elem.getElementsByTagName("group-item").getLength() > 0);
GeoObjectType type = new GeoObjectType(code, geometryType, label, description, isGeometryEditable, organization.getCode(), adapter);
type.setIsPrivate(this.getIsPrivate(visibility));
type.setIsAbstract(isAbstract);
ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(organization.getCode(), type.getIsPrivate());
return new ServerGeoObjectTypeConverter().create(type);
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class AttributeTypeServiceTest method testCreateGeoObjectTypeTerm.
@Test
public void testCreateGeoObjectTypeTerm() {
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
GeoObjectType province = MetadataFactory.newGeoObjectType(TEST_GOT.getCode(), GeometryType.POLYGON, new LocalizedValue("Province"), new LocalizedValue(""), true, organizationCode, testData.adapter);
String geoObjectTypeCode = province.getCode();
AttributeTermType attributeTermType = (AttributeTermType) AttributeType.factory("testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"), AttributeTermType.TYPE, false, false, false);
Term term = new Term(TEST_GOT.getCode() + "_" + "testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"));
attributeTermType.setRootTerm(term);
province.addAttribute(attributeTermType);
String gtJSON = province.toJSON().toString();
testData.adapter.createGeoObjectType(gtJSON);
String attributeTypeJSON = attributeTermType.toJSON().toString();
attributeTermType = (AttributeTermType) testData.adapter.createAttributeType(geoObjectTypeCode, attributeTypeJSON);
MdAttributeDAOIF mdAttributeConcreteDAOIF = checkAttribute(TEST_GOT.getCode(), attributeTermType.getName());
Assert.assertNotNull("A GeoObjectType did not define the attribute: " + attributeTermType.getName(), mdAttributeConcreteDAOIF);
Assert.assertTrue("A GeoObjectType did not define the attribute of the correct type: " + mdAttributeConcreteDAOIF.getType(), mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF);
Term rootTerm = attributeTermType.getRootTerm();
Term childTerm1 = new Term("termValue1", new LocalizedValue("Term Value 1"), new LocalizedValue(""));
Term childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2"), new LocalizedValue(""));
testData.adapter.createTerm(rootTerm.getCode(), childTerm1.toJSON().toString());
testData.adapter.createTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType2 = (AttributeTermType) province.getAttribute("testTerm").get();
// Check to see if the cache was updated.
checkTermsCreate(attributeTermType2);
attributeTermType.setLabel(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Name Update");
attributeTermType.setDescription(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Description Update");
attributeTermType = (AttributeTermType) testData.adapter.updateAttributeType(geoObjectTypeCode, attributeTermType.toJSON().toString());
Assert.assertEquals(attributeTermType.getLabel().getValue(), "Test Term Name Update");
Assert.assertEquals(attributeTermType.getDescription().getValue(), "Test Term Description Update");
checkTermsCreate(attributeTermType);
// Test updating the term
childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2a"), new LocalizedValue(""));
testData.adapter.updateTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
checkTermsUpdate(attributeTermType3);
testData.adapter.deleteTerm(rootTerm.getCode(), "termValue2");
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
System.out.println(attributeTermType3.getRootTerm().toString());
checkTermsDelete(attributeTermType3);
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType 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.GeoObjectType in project geoprism-registry by terraframe.
the class InheritedHierarchyAnnotationTest method testGetTypeAncestors.
@Test
@Request
public void testGetTypeAncestors() {
ServerGeoObjectType sGOT = FastTestDataset.PROVINCE.getServerObject();
ServerHierarchyType forHierarchy = TEST_HT.getServerObject();
ServerHierarchyType inheritedHierarchy = FastTestDataset.HIER_ADMIN.getServerObject();
InheritedHierarchyAnnotation annotation = sGOT.setInheritedHierarchy(forHierarchy, inheritedHierarchy);
try {
ServerGeoObjectType childType = TEST_CHILD.getServerObject();
List<GeoObjectType> results = childType.getTypeAncestors(TEST_HT.getServerObject(), false);
Assert.assertEquals(1, results.size());
} finally {
annotation.delete();
}
}
Aggregations