Search in sources :

Example 1 with NoChildForLeafGeoObjectType

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();
    }
}
Also used : GeoObjectTypeAlreadyInHierarchyException(net.geoprism.registry.graph.GeoObjectTypeAlreadyInHierarchyException) NoChildForLeafGeoObjectType(net.geoprism.registry.NoChildForLeafGeoObjectType) AssignPublicChildOfPrivateType(net.geoprism.registry.geoobjecttype.AssignPublicChildOfPrivateType) AbstractParentException(net.geoprism.registry.AbstractParentException)

Aggregations

AbstractParentException (net.geoprism.registry.AbstractParentException)1 NoChildForLeafGeoObjectType (net.geoprism.registry.NoChildForLeafGeoObjectType)1 AssignPublicChildOfPrivateType (net.geoprism.registry.geoobjecttype.AssignPublicChildOfPrivateType)1 GeoObjectTypeAlreadyInHierarchyException (net.geoprism.registry.graph.GeoObjectTypeAlreadyInHierarchyException)1