Search in sources :

Example 1 with RootNodeCannotBeInheritedException

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();
    }
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) RootNodeCannotBeInheritedException(net.geoprism.registry.RootNodeCannotBeInheritedException) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) ArrayList(java.util.ArrayList) CantRemoveInheritedGOT(net.geoprism.registry.graph.CantRemoveInheritedGOT) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 ArrayList (java.util.ArrayList)1 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)1 RootNodeCannotBeInheritedException (net.geoprism.registry.RootNodeCannotBeInheritedException)1 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)1 CantRemoveInheritedGOT (net.geoprism.registry.graph.CantRemoveInheritedGOT)1