Skip to content

Commit

Permalink
Merge pull request #14 from companieshouse/feature/resolve-transform
Browse files Browse the repository at this point in the history
removed try catch block from transformer
  • Loading branch information
JpLuuCH authored Apr 26, 2023
2 parents ccaea15 + 67d0aff commit e4c2332
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,27 @@ public PscDocument transformPsc(String notificationId, FullRecordCompanyPSCApi r
PscDocument pscDocument = new PscDocument();
logger.info(String.format("transforming incoming payload with Id: %s", notificationId));

try {
pscDocument.setId(notificationId);
pscDocument.setNotificationId(notificationId);
pscDocument.setPscId(requestBody.getExternalData().getPscId());
pscDocument.setCompanyNumber(requestBody.getExternalData().getCompanyNumber());
OffsetDateTime deltaAt = requestBody.getInternalData().getDeltaAt();
pscDocument.setDeltaAt(dateTimeFormatter.format(deltaAt));
PscTransformationHelper.createDateFields(requestBody, pscDocument);
pscDocument.setUpdatedBy(requestBody.getInternalData().getUpdatedBy());
pscDocument.setData(transformDataFields(requestBody));

String kind = requestBody.getExternalData().getData().getKind();

if (IndividualPscRoles.includes(kind)) {
pscDocument.setSensitiveData(transformSensitiveDataFields(requestBody));
handleUraSameAsRo(pscDocument.getData(),
requestBody.getExternalData().getSensitiveData());
handleIndividualFields(requestBody, pscDocument.getData());
}
if (SecurePscRoles.includes(kind)) {
handleSecureFields(requestBody, pscDocument.getData());
}
} catch (Exception exception) {
throw new FailedToTransformException(String.format(
"Failed to transform API payload: %s", exception.getMessage()));
pscDocument.setId(notificationId);
pscDocument.setNotificationId(notificationId);
pscDocument.setPscId(requestBody.getExternalData().getPscId());
pscDocument.setCompanyNumber(requestBody.getExternalData().getCompanyNumber());
OffsetDateTime deltaAt = requestBody.getInternalData().getDeltaAt();
pscDocument.setDeltaAt(dateTimeFormatter.format(deltaAt));
PscTransformationHelper.createDateFields(requestBody, pscDocument);
pscDocument.setUpdatedBy(requestBody.getInternalData().getUpdatedBy());
pscDocument.setData(transformDataFields(requestBody));

String kind = requestBody.getExternalData().getData().getKind();

if (IndividualPscRoles.includes(kind)) {
pscDocument.setSensitiveData(transformSensitiveDataFields(requestBody));
handleUraSameAsRo(pscDocument.getData(),
requestBody.getExternalData().getSensitiveData());
handleIndividualFields(requestBody, pscDocument.getData());
}
if (SecurePscRoles.includes(kind)) {
handleSecureFields(requestBody, pscDocument.getData());
}

return pscDocument;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,4 @@ void testSecurePscIsTransformedSuccessfully() throws FailedToTransformException
assertThat(result.getUpdated().getAt(), is(expectedDocument.getUpdated().getAt()));
assertThat(result.getUpdatedBy(), is(expectedDocument.getUpdatedBy()));
}

@Test
void testApiThrowsExceptionWhenTransformFails() {
FullRecordCompanyPSCApi api = new FullRecordCompanyPSCApi();
try {
pscTransformer.transformPsc("id", api);
Assert.fail("Expected a FailedToTransformException to be thrown");
} catch (FailedToTransformException e) {
assert(e.getMessage().contains("Failed to transform API payload:"));
}
}



}

0 comments on commit e4c2332

Please sign in to comment.