コード例 #1
0
  public ServiceExecutionResult<Person> addPerson(
      final ReconciliationCriteria reconciliationCriteria)
      throws ReconciliationException, IllegalArgumentException, SorPersonAlreadyExistsException {
    Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null");
    logger.info("addPerson start");
    if (reconciliationCriteria.getSorPerson().getSorId() != null
        && this.findBySorIdentifierAndSource(
                reconciliationCriteria.getSorPerson().getSourceSor(),
                reconciliationCriteria.getSorPerson().getSorId())
            != null) {
      // throw new IllegalStateException("CANNOT ADD SAME SOR RECORD.");
      throw new SorPersonAlreadyExistsException(
          this.findBySorIdentifierAndSource(
              reconciliationCriteria.getSorPerson().getSourceSor(),
              reconciliationCriteria.getSorPerson().getSorId()));
    }

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

    if (!validationErrors.isEmpty()) {
      Iterator iter = validationErrors.iterator();
      while (iter.hasNext()) {
        logger.info("validation errors: " + iter.next());
      }
      // 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<Person>(validationErrors);
    }

    final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria);

    switch (result.getReconciliationType()) {
      case NONE:
        return new GeneralServiceExecutionResult<Person>(
            saveSorPersonAndConvertToCalculatedPerson(reconciliationCriteria));

      case EXACT:
        return new GeneralServiceExecutionResult<Person>(
            addNewSorPersonAndLinkWithMatchedCalculatedPerson(reconciliationCriteria, result));
    }

    this.criteriaCache.put(reconciliationCriteria, result);
    logger.info("addPerson start");
    throw new ReconciliationException(result);
  }
コード例 #2
0
  protected Person addNewSorPersonAndLinkWithMatchedCalculatedPerson(
      final ReconciliationCriteria reconciliationCriteria, final ReconciliationResult result)
      throws SorPersonAlreadyExistsException {
    Assert.isTrue(
        result.getMatches().size() == 1,
        "ReconciliationResult should be 'EXACT' and there should only be one person.  The result is '"
            + result.getReconciliationType()
            + "' and the number of people is "
            + result.getMatches().size()
            + ".");

    final Person person = result.getMatches().iterator().next().getPerson();
    return addSorPersonAndLink(reconciliationCriteria, person);
  }
コード例 #3
0
  public ServiceExecutionResult<Person> addPersonAndLink(
      final ReconciliationCriteria reconciliationCriteria, final Person person)
      throws IllegalArgumentException, IllegalStateException, SorPersonAlreadyExistsException {
    Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null.");
    Assert.notNull(person, "person cannot be null.");
    logger.info(" addPersonAndLink start");
    final ReconciliationResult result = this.criteriaCache.get(reconciliationCriteria);

    if (result == null) {
      throw new IllegalStateException("No ReconciliationResult found for provided criteria.");
    }

    for (final PersonMatch personMatch : result.getMatches()) {
      if (personMatch.getPerson().getId().equals(person.getId())) {
        addSorPersonAndLink(reconciliationCriteria, person);
        final Person savedPerson = this.personRepository.findByInternalId(person.getId());
        return new GeneralServiceExecutionResult<Person>(savedPerson);
      }
    }
    logger.info("addPersonAndLink end");
    throw new IllegalStateException("Person not found in ReconciliationResult.");
  }