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