use of net.geoprism.registry.NoChildForLeafGeoObjectType in project geoprism-registry by terraframe.
the class ServerHierarchyType method addToHierarchy.
public void addToHierarchy(ServerGeoObjectType parentType, ServerGeoObjectType childType, boolean refresh) {
if (parentType.getIsAbstract()) {
AbstractParentException exception = new AbstractParentException();
exception.setChildGeoObjectTypeLabel(childType.getUniversal().getDisplayLabel().getValue());
exception.setHierarchyTypeLabel(this.getDisplayLabel().getValue());
exception.setParentGeoObjectTypeLabel(parentType.getUniversal().getDisplayLabel().getValue());
exception.apply();
throw exception;
}
if (parentType.getUniversal().getIsLeafType()) {
NoChildForLeafGeoObjectType exception = new NoChildForLeafGeoObjectType();
exception.setChildGeoObjectTypeLabel(childType.getUniversal().getDisplayLabel().getValue());
exception.setHierarchyTypeLabel(this.getDisplayLabel().getValue());
exception.setParentGeoObjectTypeLabel(parentType.getUniversal().getDisplayLabel().getValue());
exception.apply();
throw exception;
}
if (parentType.getIsPrivate() && !childType.getIsPrivate()) {
AssignPublicChildOfPrivateType ex = new AssignPublicChildOfPrivateType();
throw ex;
}
// Check to see if the child type is already in the hierarchy
List<ServerHierarchyType> hierarchies = childType.getHierarchies(true);
if (hierarchies.contains(this)) {
GeoObjectTypeAlreadyInHierarchyException ex = new GeoObjectTypeAlreadyInHierarchyException();
ex.setGotCode(childType.getCode());
throw ex;
}
// Ensure a subtype is not already in the hierarchy
if (childType.getIsAbstract()) {
Set<ServerHierarchyType> hierarchiesOfSubTypes = childType.getHierarchiesOfSubTypes();
if (hierarchiesOfSubTypes.contains(this)) {
GeoObjectTypeAlreadyInHierarchyException ex = new GeoObjectTypeAlreadyInHierarchyException();
ex.setGotCode(childType.getCode());
throw ex;
}
}
this.hierarchicalRelationship.addToHierarchy(parentType, childType);
// relationships.
if (refresh) {
this.refresh();
}
}
Aggregations