Search in sources :

Example 1 with ChangeRequestService

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

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 Actor (com.runwaysdk.system.Actor)1 Roles (com.runwaysdk.system.Roles)1 Classifier (net.geoprism.ontology.Classifier)1 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)1 TypeInUseException (net.geoprism.registry.TypeInUseException)1 ChangeRequestService (net.geoprism.registry.service.ChangeRequestService)1 SearchService (net.geoprism.registry.service.SearchService)1