Search in sources :

Example 1 with InheritedHierarchyAnnotation

use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.

the class PatchInheritedAnnotation method transaction.

@Transaction
private void transaction() {
    InheritedHierarchyAnnotationQuery query = new InheritedHierarchyAnnotationQuery(new QueryFactory());
    query.ORDER_BY(query.getForHierarchicalRelationshipType(), SortOrder.DESC);
    query.ORDER_BY(query.getCreateDate(), SortOrder.DESC);
    try (OIterator<? extends InheritedHierarchyAnnotation> iterator = query.getIterator()) {
        InheritedHierarchyAnnotation prev = null;
        while (iterator.hasNext()) {
            InheritedHierarchyAnnotation annotation = iterator.next();
            if (prev != null && prev.getForHierarchicalRelationshipTypeOid().equals(annotation.getForHierarchicalRelationshipTypeOid())) {
                annotation.delete();
            } else if (annotation.getForHierarchicalRelationshipTypeOid() == null || annotation.getForHierarchicalRelationshipTypeOid().length() == 0) {
                annotation.delete();
            } else {
                // Determine if the inherited hierarchy and for hierarchy have the
                // same root
                ServerGeoObjectType inheritedNode = ServerGeoObjectType.get(annotation.getUniversal());
                HierarchicalRelationshipType inheritedHierarchicalType = annotation.getInheritedHierarchicalRelationshipType();
                ServerHierarchyType inheritedHierarchy = new ServerHierarchyTypeBuilder().get(inheritedHierarchicalType);
                Set<String> rootCodes = inheritedHierarchy.getRootGeoObjectTypes().stream().map(type -> type.getGeoObjectType().getCode()).collect(Collectors.toSet());
                if (rootCodes.contains(inheritedNode.getCode())) {
                    annotation.delete();
                } else {
                    prev = annotation;
                }
            }
        }
    }
}
Also used : InheritedHierarchyAnnotationQuery(net.geoprism.registry.InheritedHierarchyAnnotationQuery) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) Set(java.util.Set) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with InheritedHierarchyAnnotation

use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.

the class InheritedHierarchyAnnotationTest method testGetByUniversalAndHierarchy.

@Test
@Request
public void testGetByUniversalAndHierarchy() {
    ServerGeoObjectType sGOT = FastTestDataset.PROVINCE.getServerObject();
    ServerHierarchyType forHierarchy = TEST_HT.getServerObject();
    ServerHierarchyType inheritedHierarchy = FastTestDataset.HIER_ADMIN.getServerObject();
    InheritedHierarchyAnnotation annotation = sGOT.setInheritedHierarchy(forHierarchy, inheritedHierarchy);
    try {
        InheritedHierarchyAnnotation test = InheritedHierarchyAnnotation.get(sGOT.getUniversal(), forHierarchy.getHierarchicalRelationshipType());
        Assert.assertNotNull(test);
        Assert.assertEquals(test.getOid(), annotation.getOid());
    } 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 3 with InheritedHierarchyAnnotation

use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.

the class InheritedHierarchyAnnotationTest method testRemove.

@Test
@Request
public void testRemove() {
    ServerGeoObjectType sGOT = FastTestDataset.PROVINCE.getServerObject();
    ServerHierarchyType forHierarchy = TEST_HT.getServerObject();
    ServerHierarchyType inheritedHierarchy = FastTestDataset.HIER_ADMIN.getServerObject();
    sGOT.setInheritedHierarchy(forHierarchy, inheritedHierarchy);
    sGOT.removeInheritedHierarchy(forHierarchy);
    InheritedHierarchyAnnotation test = InheritedHierarchyAnnotation.get(sGOT.getUniversal(), forHierarchy.getHierarchicalRelationshipType());
    try {
        Assert.assertNull(test);
    } finally {
        if (test != null) {
            test.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 4 with InheritedHierarchyAnnotation

use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.

the class InheritedHierarchyAnnotationTest method testGetTypeAncestors.

@Test
@Request
public void testGetTypeAncestors() {
    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(), false);
        Assert.assertEquals(1, 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 5 with InheritedHierarchyAnnotation

use of net.geoprism.registry.InheritedHierarchyAnnotation in project geoprism-registry by terraframe.

the class ServerGeoObjectType method deleteInTransaction.

@Transaction
private void deleteInTransaction() {
    List<ServerHierarchyType> hierarchies = this.getHierarchies(true);
    if (hierarchies.size() > 0) {
        StringBuilder codes = hierarchies.stream().collect(StringBuilder::new, (x, y) -> x.append(y.getCode()), (a, b) -> a.append(",").append(b));
        throw new TypeInUseException("Cannot delete a GeoObjectType used in the hierarchies: " + codes);
    }
    // for (String hierarchy : hierarchies)
    // {
    // OIterator<com.runwaysdk.business.ontology.Term> it =
    // this.universal.getDirectDescendants(hierarchy);
    // 
    // try
    // {
    // if (it.hasNext())
    // {
    // }
    // }
    // finally
    // {
    // it.close();
    // }
    // }
    /*
     * Delete all subtypes
     */
    List<ServerGeoObjectType> subtypes = this.getSubtypes();
    for (ServerGeoObjectType subtype : subtypes) {
        subtype.deleteInTransaction();
    }
    /*
     * Delete all inherited hierarchies
     */
    List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByUniversal(getUniversal());
    for (InheritedHierarchyAnnotation annotation : annotations) {
        annotation.delete();
    }
    GeoVertexType.remove(this.universal.getUniversalId());
    /*
     * Delete all Attribute references
     */
    // AttributeHierarchy.deleteByUniversal(this.universal);
    this.getMetadata().delete();
    // This deletes the {@link MdBusiness} as well
    this.universal.delete(false);
    // Delete the term root
    Classifier classRootTerm = TermConverter.buildIfNotExistdMdBusinessClassifier(this.mdBusiness);
    classRootTerm.delete();
    // roles specified on the super type.
    if (this.getSuperType() == null) {
        Actor ownerActor = this.universal.getOwner();
        if (ownerActor instanceof Roles) {
            Roles ownerRole = (Roles) ownerActor;
            String roleName = ownerRole.getRoleName();
            if (RegistryRole.Type.isOrgRole(roleName)) {
                String organizationCode = RegistryRole.Type.parseOrgCode(roleName);
                String geoObjectTypeCode = this.type.getCode();
                String rmRoleName = RegistryRole.Type.getRM_RoleName(organizationCode, geoObjectTypeCode);
                Roles role = Roles.findRoleByName(rmRoleName);
                role.delete();
                String rcRoleName = RegistryRole.Type.getRC_RoleName(organizationCode, geoObjectTypeCode);
                role = Roles.findRoleByName(rcRoleName);
                role.delete();
                String acRoleName = RegistryRole.Type.getAC_RoleName(organizationCode, geoObjectTypeCode);
                role = Roles.findRoleByName(acRoleName);
                role.delete();
            }
        }
    }
    ListType.markAllAsInvalid(null, this);
    new SearchService().clear(this.getCode());
    new ChangeRequestService().markAllAsInvalid(this);
    // Delete the transition and transition events
    TransitionEvent.removeAll(this);
    Transition.removeAll(this);
}
Also used : InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) Roles(com.runwaysdk.system.Roles) Classifier(net.geoprism.ontology.Classifier) TypeInUseException(net.geoprism.registry.TypeInUseException) ChangeRequestService(net.geoprism.registry.service.ChangeRequestService) Actor(com.runwaysdk.system.Actor) SearchService(net.geoprism.registry.service.SearchService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

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