Skip to content

Commit

Permalink
Merge pull request #47 from companieshouse/feature/get-psc-name-data
Browse files Browse the repository at this point in the history
IDVA3-2240: Get the UVID PSC name data
  • Loading branch information
eedwards0 authored Oct 16, 2024
2 parents f33b284 + 6233ede commit 40e8e49
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
<equalsverifier.version>3.15.1</equalsverifier.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<!--- CH -->
<structured-logging.version>3.0.1</structured-logging.version>
<structured-logging.version>3.0.15</structured-logging.version>
<api-security-java.version>2.0.7</api-security-java.version>
<api-helper-java.version>3.0.0</api-helper-java.version>
<api-sdk-java.version>6.0.13</api-sdk-java.version>
<api-helper-java.version>3.0.1</api-helper-java.version>
<api-sdk-java.version>6.0.20</api-sdk-java.version>
<api-sdk-manager-java-library.version>3.0.5</api-sdk-manager-java-library.version>
<private-api-sdk-java.version>4.0.207</private-api-sdk-java.version>
<api-helper-java.version>3.0.1</api-helper-java.version>
<!--sonar configuration-->
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml,
Expand Down Expand Up @@ -101,6 +102,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>private-api-sdk-java</artifactId>
<version>${private-api-sdk-java.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>api-sdk-manager-java-library</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.companieshouse.pscverificationapi.service;

import uk.gov.companieshouse.api.identityverification.model.UvidMatch;
import uk.gov.companieshouse.api.model.psc.PscApi;
import uk.gov.companieshouse.api.model.pscverification.PscVerificationData;
import uk.gov.companieshouse.api.model.transaction.Transaction;
Expand All @@ -11,15 +12,30 @@
*/
public interface PscLookupService {
/**
* Retrieve a PSC by ID.
* Retrieve a PSC by PscVerificationData.
*
* @param transaction the Transaction
* @param data the psc verification data
* @param data the PSC verification data
* @param pscType the PSC Type
* @param ericPassThroughHeader includes authorisation for transaction fetch
* @return the PSC details, if found
* @throws PscLookupServiceException if the PSC was not found or an error occurred
*/
PscApi getPsc(Transaction transaction, PscVerificationData data, PscType pscType, final String ericPassThroughHeader)
throws PscLookupServiceException;


/**
* Retrieve a UvidMatch with the PSC data.
*
* @param transaction the Transaction
* @param data the PSC verification data
* @param pscType the PSC Type
* @param ericPassThroughHeader includes authorisation for transaction fetch
* @return the UvidMatch, if found
* @throws PscLookupServiceException if the PSC was not found or an error occurred
*/
UvidMatch getUvidMatchWithPscData(Transaction transaction, PscVerificationData data, PscType pscType, final String ericPassThroughHeader)
throws PscLookupServiceException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import uk.gov.companieshouse.api.error.ApiErrorResponseException;
import uk.gov.companieshouse.api.handler.exception.URIValidationException;
import uk.gov.companieshouse.api.identityverification.model.UvidMatch;
import uk.gov.companieshouse.api.model.psc.PscApi;
import uk.gov.companieshouse.api.model.pscverification.PscVerificationData;
import uk.gov.companieshouse.api.model.transaction.Transaction;
Expand All @@ -15,6 +20,7 @@
import uk.gov.companieshouse.pscverificationapi.exception.FilingResourceNotFoundException;
import uk.gov.companieshouse.pscverificationapi.exception.PscLookupServiceException;
import uk.gov.companieshouse.pscverificationapi.service.PscLookupService;
import uk.gov.companieshouse.pscverificationapi.utils.LogHelper;

@Service
public class PscLookupServiceImpl implements PscLookupService {
Expand All @@ -28,11 +34,22 @@ public PscLookupServiceImpl(final ApiClientService apiClientService, Logger logg
this.logger = logger;
}

/**
* Retrieve a PSC by PscVerificationData.
*
* @param transaction the Transaction
* @param data the PSC verification data
* @param pscType the PSC Type
* @param ericPassThroughHeader includes authorisation for transaction fetch
* @return the PSC details, if found
* @throws PscLookupServiceException if the PSC was not found or an error occurred
*/
@Override
public PscApi getPsc(final Transaction transaction, final PscVerificationData data,
final PscType pscType, final String ericPassThroughHeader)
throws PscLookupServiceException {

final var logMap = LogHelper.createLogMap(transaction.getId());
String pscAppointmentId = data.pscAppointmentId();

try {
Expand All @@ -51,6 +68,7 @@ public PscApi getPsc(final Transaction transaction, final PscVerificationData da

} catch (final ApiErrorResponseException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
logger.errorContext(transaction.getId(), UNEXPECTED_STATUS_CODE, e, logMap);
throw new FilingResourceNotFoundException(
MessageFormat.format("PSC Details not found for {0}: {1} {2}", pscAppointmentId,
e.getStatusCode(), e.getStatusMessage()), e);
Expand All @@ -60,9 +78,53 @@ public PscApi getPsc(final Transaction transaction, final PscVerificationData da
e.getStatusCode(), e.getStatusMessage()), e);

} catch (URIValidationException | IOException e) {
logger.errorContext(transaction.getId(), UNEXPECTED_STATUS_CODE, e, logMap);
throw new PscLookupServiceException(
MessageFormat.format("Error Retrieving PSC details for {0}: {1}", pscAppointmentId,
e.getMessage()), e);
}
}

/**
* Retrieve a UvidMatch with the PSC data.
*
* @param transaction the Transaction
* @param data the PSC verification data
* @param pscType the PSC Type
* @param ericPassThroughHeader includes authorisation for transaction fetch
* @return the UvidMatch, if found
* @throws PscLookupServiceException if the PSC was not found or an error occurred
*/
@Override
public UvidMatch getUvidMatchWithPscData(final Transaction transaction,
final PscVerificationData data, final PscType pscType, final String ericPassThroughHeader)
throws PscLookupServiceException {

UvidMatch uvidMatch = new UvidMatch();
Optional<String> uvid = Optional.ofNullable(data.verificationDetails().uvid());
uvidMatch.setUvid(uvid.orElse(""));

PscApi pscData = getPsc(transaction, data, pscType, ericPassThroughHeader);
setUvidDataFromPsc(uvidMatch, pscData);

return uvidMatch;
}

//TODO Update UvidMatch with the full DOB when available from the PscDetails
private void setUvidDataFromPsc(UvidMatch uvidMatch, PscApi pscData) {

List<String> forenames = new ArrayList<>();
Optional<String> forename = Optional.ofNullable(pscData.getNameElements().getForename());
//Note: In live, the middleName field may contain multiple names,
//but there is no data populated in the otherForenames field
Optional<String> middleName = Optional.ofNullable(pscData.getNameElements().getMiddleName());
Optional<String> surname = Optional.ofNullable(pscData.getNameElements().getSurname());

forename.ifPresent(forenames::addFirst);
middleName.ifPresent(names -> forenames.addAll(Arrays.asList(names.split("\\s+"))));

uvidMatch.setForenames(forenames);
uvidMatch.setSurname(surname.orElse(""));

}
}
Loading

0 comments on commit 40e8e49

Please sign in to comment.