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