public ServiceExecutionResult<SorRole> updateSorRole(
      final SorPerson sorPerson, final SorRole sorRole) {
    Assert.notNull(sorPerson, "sorPerson cannot be null.");
    Assert.notNull(sorRole, "sorRole cannot be null.");

    final Set validationErrors = this.validator.validate(sorRole);

    if (!validationErrors.isEmpty()) {
      // since because of existing design we cannot raise exception, we can only rollback the
      // transaction through code
      // OR-384
      if (TransactionAspectSupport.currentTransactionStatus() != null) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      }

      return new GeneralServiceExecutionResult<SorRole>(validationErrors);
    }

    final SorRole savedSorRole = this.personRepository.saveSorRole(sorRole);

    final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId());
    final Role role = person.findRoleBySoRRoleId(savedSorRole.getId());
    if (role != null) {
      // update calculated role only if that role was previously converted to calculated one by
      // sorRoleElector
      role.recalculate(savedSorRole);
      this.personRepository.savePerson(person);
    }
    // else //do nothing i.e. don't update the calculated role if SorRoleElector Previously decided
    // not to convert this sor role to calculated role

    return new GeneralServiceExecutionResult<SorRole>(savedSorRole);
  }
  public boolean deleteSystemOfRecordRole(
      final SorPerson sorPerson,
      final SorRole sorRole,
      final boolean mistake,
      final String terminationTypes)
      throws IllegalArgumentException {
    Assert.notNull(sorRole, "sorRole cannot be null.");
    Assert.notNull(sorPerson, "soPerson cannot be null.");
    final String terminationTypeToUse =
        terminationTypes != null ? terminationTypes : Type.TerminationTypes.UNSPECIFIED.name();

    final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId());
    Assert.notNull(person, "person cannot be null.");

    final Role role = person.findRoleBySoRRoleId(sorRole.getId());
    // delete and expire role only if it exist at calculated level
    if (role != null)
      if (mistake) {

        // let SorRoleElector remove the role
        sorRoleElector.removeCalculatedRole(
            person, role, this.personRepository.getSoRRecordsForPerson(person));

      } else {
        final Type terminationReason =
            this.referenceRepository.findType(Type.DataTypes.TERMINATION, terminationTypeToUse);
        if (!role.isTerminated()) {
          role.expireNow(terminationReason, true);
        }
      }

    sorPerson.getRoles().remove(sorRole);
    this.personRepository.saveSorPerson(sorPerson);
    this.personRepository.savePerson(person);
    return true;
  }