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