use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.
the class ServerGeoObjectType method setInheritedHierarchy.
@Transaction
public InheritedHierarchyAnnotation setInheritedHierarchy(ServerHierarchyType forHierarchy, ServerHierarchyType inheritedHierarchy) {
// Hierarchy"
if (!this.isRoot(forHierarchy) || this.getIsAbstract()) {
throw new HierarchyRootException();
}
HierarchicalRelationshipType fhrt = forHierarchy.getHierarchicalRelationshipType();
HierarchicalRelationshipType ihrt = inheritedHierarchy.getHierarchicalRelationshipType();
if (InheritedHierarchyAnnotation.getByForHierarchical(fhrt) != null) {
throw new UnsupportedOperationException("A hierarchy cannot inherit from more than one other hierarchy");
}
if (this.isRoot(inheritedHierarchy)) {
throw new UnsupportedOperationException("A root node in a hierarchy cannot be inherited");
}
InheritedHierarchyAnnotation annotation = new InheritedHierarchyAnnotation();
annotation.setUniversal(this.universal);
annotation.setInheritedHierarchicalRelationshipType(ihrt);
annotation.setForHierarchicalRelationshipType(fhrt);
annotation.apply();
return annotation;
}
use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.
the class ServerHierarchyType method removeFromHierarchy.
@Transaction
private void removeFromHierarchy(ServerGeoObjectType parentType, ServerGeoObjectType childType, boolean migrateChildren) {
ServerGeoObjectService service = new ServerGeoObjectService();
List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByInheritedHierarchy(childType.getUniversal(), this.hierarchicalRelationship);
if (annotations.size() > 0) {
List<String> codes = new ArrayList<String>();
for (InheritedHierarchyAnnotation annot : annotations) {
String code = buildHierarchyKeyFromMdTermRelUniversal(annot.getForHierarchy().getKey());
codes.add(code);
}
CantRemoveInheritedGOT ex = new CantRemoveInheritedGOT();
ex.setGotCode(childType.getCode());
ex.setHierCode(this.getCode());
ex.setInheritedHierarchyList(StringUtils.join(codes, ", "));
throw ex;
}
// hierarchy.
if (parentType instanceof RootGeoObjectType) {
List<ServerGeoObjectType> children = childType.getChildren(this);
if (children.size() == 1) {
ServerGeoObjectType nextRoot = children.get(0);
List<? extends InheritedHierarchyAnnotation> results = InheritedHierarchyAnnotation.getByInheritedHierarchy(nextRoot.getUniversal(), this.hierarchicalRelationship);
if (results.size() > 0) {
throw new RootNodeCannotBeInheritedException("Cannot remove the root Geo-Object Type of a hierarchy if the new root Geo-Object Type is inherited by another hierarchy");
}
}
}
this.hierarchicalRelationship.removeFromHierarchy(parentType, childType, migrateChildren);
service.removeAllEdges(this, childType);
// MasterList.markAllAsInvalid(this, childType);
ListType.markAllAsInvalid(this, childType);
InheritedHierarchyAnnotation annotation = InheritedHierarchyAnnotation.get(childType.getUniversal(), this.hierarchicalRelationship);
if (annotation != null) {
annotation.delete();
}
}
use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.
the class InheritedHierarchyAnnotationTest method testGetTypeAncestorsInherited.
@Test
@Request
public void testGetTypeAncestorsInherited() {
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(), true);
Assert.assertEquals(2, results.size());
} finally {
annotation.delete();
}
}
use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.
the class InheritedHierarchyAnnotationTest method testFindHierarchy.
@Test
@Request
public void testFindHierarchy() {
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();
ServerHierarchyType hierarchy = childType.findHierarchy(forHierarchy, FastTestDataset.COUNTRY.getServerObject());
Assert.assertEquals(FastTestDataset.HIER_ADMIN.getCode(), hierarchy.getCode());
} finally {
annotation.delete();
}
}
use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.
the class InheritedHierarchyAnnotationTest method testGetByUniversal.
@Test
@Request
public void testGetByUniversal() {
ServerGeoObjectType sGOT = FastTestDataset.PROVINCE.getServerObject();
InheritedHierarchyAnnotation annotation = sGOT.setInheritedHierarchy(TEST_HT.getServerObject(), FastTestDataset.HIER_ADMIN.getServerObject());
try {
List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByUniversal(sGOT.getUniversal());
Assert.assertEquals(1, annotations.size());
InheritedHierarchyAnnotation test = annotations.get(0);
Assert.assertEquals(test.getOid(), annotation.getOid());
} finally {
annotation.delete();
}
}
Aggregations