Search in sources :

Example 1 with InheritedHierarchyAnnotationQuery

use of net.geoprism.registry.InheritedHierarchyAnnotationQuery 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 InheritedHierarchyAnnotationQuery

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

the class PatchHierarchicalRelationshipType method migrateInheritedHierarchyAnnotation.

public void migrateInheritedHierarchyAnnotation() {
    InheritedHierarchyAnnotationQuery query = new InheritedHierarchyAnnotationQuery(new QueryFactory());
    try (OIterator<? extends InheritedHierarchyAnnotation> it = query.getIterator()) {
        it.getAll().forEach(annotation -> {
            HierarchicalRelationshipType forHierarchicalRelationshipType = HierarchicalRelationshipType.getByMdTermRelationship(annotation.getForHierarchy());
            HierarchicalRelationshipType inheritedHierarchicalRelationshipType = HierarchicalRelationshipType.getByMdTermRelationship(annotation.getInheritedHierarchy());
            annotation.appLock();
            annotation.setForHierarchicalRelationshipType(forHierarchicalRelationshipType);
            annotation.setInheritedHierarchicalRelationshipType(inheritedHierarchicalRelationshipType);
            annotation.apply();
        });
    }
}
Also used : InheritedHierarchyAnnotationQuery(net.geoprism.registry.InheritedHierarchyAnnotationQuery) QueryFactory(com.runwaysdk.query.QueryFactory) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType)

Aggregations

QueryFactory (com.runwaysdk.query.QueryFactory)2 HierarchicalRelationshipType (net.geoprism.registry.HierarchicalRelationshipType)2 InheritedHierarchyAnnotationQuery (net.geoprism.registry.InheritedHierarchyAnnotationQuery)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 Set (java.util.Set)1 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)1 ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)1