use of net.geoprism.registry.RootNodeCannotBeInheritedException 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();
}
}
Aggregations