Search in sources :

Example 6 with InheritedHierarchyAnnotation

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;
}
Also used : HierarchyRootException(net.geoprism.registry.HierarchyRootException) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 7 with InheritedHierarchyAnnotation

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();
    }
}
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)

Example 8 with InheritedHierarchyAnnotation

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();
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 9 with InheritedHierarchyAnnotation

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();
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 10 with InheritedHierarchyAnnotation

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();
    }
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)10 Request (com.runwaysdk.session.Request)9 Test (org.junit.Test)9 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 HierarchicalRelationshipType (net.geoprism.registry.HierarchicalRelationshipType)2 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)2 QueryFactory (com.runwaysdk.query.QueryFactory)1 Actor (com.runwaysdk.system.Actor)1 Roles (com.runwaysdk.system.Roles)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Classifier (net.geoprism.ontology.Classifier)1 HierarchyRootException (net.geoprism.registry.HierarchyRootException)1 InheritedHierarchyAnnotationQuery (net.geoprism.registry.InheritedHierarchyAnnotationQuery)1 RootNodeCannotBeInheritedException (net.geoprism.registry.RootNodeCannotBeInheritedException)1 TypeInUseException (net.geoprism.registry.TypeInUseException)1 ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)1 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)1