diff --git a/pom.xml b/pom.xml index 15a0dc9d..233f1f20 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 1.9.25 - 2.0.347 + 2.0.420 1.0.4 0.4.1 1.0.8 diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java b/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java index d1ab913e..25f7634f 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java @@ -323,6 +323,13 @@ public ListSummary transformPscDocToListSummary(PscDocument pscDocument, Boolean */ public PscDocument transformPscOnInsert( String notificationId, FullRecordCompanyPSCApi requestBody) { + String pscStatementId = null; + if (requestBody.getExternalData() != null) { + ExternalData externalData = requestBody.getExternalData(); + if (externalData != null) { + pscStatementId = requestBody.getExternalData().getPscStatementId(); + } + } PscDocument pscDocument = new PscDocument(); logger.info("Transforming incoming payload", DataMapHolder.getLogMap()); @@ -336,7 +343,7 @@ public PscDocument transformPscOnInsert( if (externalData.getData() != null) { Data data = externalData.getData(); PscData pscData; - pscData = transformDataFields(data); + pscData = transformDataFields(data, pscStatementId); String kind = data.getKind(); if (IndividualPscRoles.includes(kind)) { @@ -381,14 +388,14 @@ private PscSensitiveData transformSensitiveDataFields(SensitiveData sensitiveDat return pscSensitiveData; } - private PscData transformDataFields(Data data) { + private PscData transformDataFields(Data data, String pscStatementId) { PscData pscData = new PscData(); pscData.setCeasedOn(data.getCeasedOn()); pscData.setDescription(data.getDescription()); pscData.setEtag(data.getEtag()); pscData.setKind(data.getKind()); pscData.setNotifiedOn(data.getNotifiedOn()); - pscData.setLinks(PscTransformationHelper.createLinks(data)); + pscData.setLinks(PscTransformationHelper.createLinks(data, pscStatementId)); pscData.setName(data.getName()); pscData.setNationality(data.getNationality()); pscData.setNaturesOfControl(data.getNaturesOfControl()); diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/util/PscTransformationHelper.java b/src/main/java/uk/gov/companieshouse/pscdataapi/util/PscTransformationHelper.java index 6da0829e..afb90db5 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/util/PscTransformationHelper.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/util/PscTransformationHelper.java @@ -16,12 +16,17 @@ private PscTransformationHelper() { * @param data the Data in ExternalData in the request payload. * @return Links object. */ - public static Links createLinks(Data data) { + public static Links createLinks(Data data, String pscStatementId) { Links links = new Links(); if (data.getLinks() != null) { ItemLinkTypes itemLinkTypes = data.getLinks().get(0); links.setSelf(itemLinkTypes.getSelf()); - links.setStatements(itemLinkTypes.getStatements()); + + if (pscStatementId != null) { + links.setStatements(itemLinkTypes.getStatements()); + } else { + links.setStatements(null); + } } return links; } diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java index 7dc12e0d..854aaed8 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java @@ -51,8 +51,8 @@ void testInsertEmptyPscTransform(){ @Test void testInsertIndividualPscWithDateOfBirthIsTransformedSuccessfully() throws FailedToTransformException { // given - fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_KIND, SHOW_FULL_DOB_TRUE); - PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_KIND, SHOW_FULL_DOB_TRUE); + fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_KIND, SHOW_FULL_DOB_TRUE, true); + PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_KIND, SHOW_FULL_DOB_TRUE, true); // when PscDocument result = pscTransformer.transformPscOnInsert(NOTIFICATION_ID, fullRecordCompanyPSCApi); // then @@ -73,8 +73,8 @@ void testInsertIndividualPscWithDateOfBirthIsTransformedSuccessfully() throws Fa @Test void testInsertIndividualPscNoDateOfBirthIsTransformedSuccessfully() throws FailedToTransformException { // given - fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_KIND, SHOW_FULL_DOB_FALSE); - PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_KIND, SHOW_FULL_DOB_FALSE); + fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_KIND, SHOW_FULL_DOB_FALSE, true); + PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_KIND, SHOW_FULL_DOB_FALSE, true); // when PscDocument result = pscTransformer.transformPscOnInsert(NOTIFICATION_ID, fullRecordCompanyPSCApi); // then @@ -146,8 +146,8 @@ void testInsertSuperSecurePscIsTransformedSuccessfully() throws FailedToTransfor @Test void testInsertIndividualBeneficialOwnerPscIsTransformedSuccessfully() throws FailedToTransformException { // given - fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE); - PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE); + fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE, true); + PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE, true); // when PscDocument result = pscTransformer.transformPscOnInsert(NOTIFICATION_ID, fullRecordCompanyPSCApi); // then @@ -166,6 +166,31 @@ void testInsertIndividualBeneficialOwnerPscIsTransformedSuccessfully() throws Fa pscInsertAssertions(expectedDocument, result); } + @Test + void testInsertIndividualBeneficialOwnerPscIsTransformedSuccessfullyNoPscStatements() throws FailedToTransformException { + // given + fullRecordCompanyPSCApi = TestHelper.buildFullRecordPsc(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE, false); + PscDocument expectedDocument = TestHelper.buildPscDocument(INDIVIDUAL_BO_KIND, SHOW_FULL_DOB_TRUE, false); + // when + PscDocument result = pscTransformer.transformPscOnInsert(NOTIFICATION_ID, fullRecordCompanyPSCApi); + // then + Assertions.assertNotNull(result.getData()); + + Assertions.assertTrue(result.getData().getSanctioned()); + Assertions.assertNotNull(result.getData().getAddress()); + Assertions.assertNotNull(result.getSensitiveData().getDateOfBirth()); + Assertions.assertNotNull(result.getSensitiveData().getUsualResidentialAddress()); + Assertions.assertNotNull(result.getSensitiveData().getResidentialAddressIsSameAsServiceAddress()); + Assertions.assertNotNull(result.getData().getNameElements().getForename()); + Assertions.assertNotNull(result.getData().getName()); + Assertions.assertNotNull(result.getData().getNationality()); + Assertions.assertNotNull(result.getData().getCountryOfResidence()); + Assertions.assertNull(result.getData().getLinks().getStatements()); + + pscInsertAssertions(expectedDocument, result); + } + + @Test void testInsertCorporateEntityBeneficialOwnerPscIsTransformedSuccessfully() throws FailedToTransformException { // given diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java index 3e73d706..f86a71f2 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java @@ -29,20 +29,26 @@ public class TestHelper { public static final String COMPANY_NUMBER = "companyNumber"; public static final String NOTIFICATION_ID = "notificationId"; public static final String PSC_ID = "pscId"; + public static final String PSC_STATEMENT_ID = "pscStatementId"; public static final String X_REQUEST_ID = "654321"; public TestHelper(){} public static FullRecordCompanyPSCApi buildFullRecordPsc(String kind) { - return buildFullRecordPsc(kind, false); + return buildFullRecordPsc(kind, false, true); } - public static FullRecordCompanyPSCApi buildFullRecordPsc(String kind, boolean showFullDateOfBirth) { + public static FullRecordCompanyPSCApi buildFullRecordPsc(String kind, boolean showFullDateOfBirth, boolean pscStatementsExists) { FullRecordCompanyPSCApi output = new FullRecordCompanyPSCApi(); ExternalData externalData = new ExternalData(); Data data = new Data(); externalData.setPscId(PSC_ID); + + if (pscStatementsExists) { + externalData.setPscStatementId(PSC_STATEMENT_ID); + } + // Not setting the notificationId as that is passed to the Transformer externalData.setCompanyNumber(COMPANY_NUMBER); @@ -57,7 +63,11 @@ public static FullRecordCompanyPSCApi buildFullRecordPsc(String kind, boolean sh data.setName("wholeName"); ItemLinkTypes links = new ItemLinkTypes(); links.setSelf("self"); - links.setStatements("linkStatements"); + + if (pscStatementsExists) { + links.setStatements("linkStatements"); + } + data.setLinks(List.of(links)); data.serviceAddressSameAsRegisteredOfficeAddress(false); @@ -172,10 +182,10 @@ public static FullRecordCompanyPSCApi buildBasicFullRecordPsc(){ } public static PscDocument buildPscDocument(String kind) { - return buildPscDocument(kind, false); + return buildPscDocument(kind, false, true); } - public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBirth) { + public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBirth, boolean pscStatementsExists) { PscDocument output = new PscDocument(); PscData pscData = new PscData(); @@ -193,7 +203,9 @@ public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBi pscData.setName("wholeName"); Links links = new Links(); links.setSelf("self"); - links.setStatements("linkStatements"); + if (pscStatementsExists) { + links.setStatements("linkStatements"); + } pscData.setLinks(links); pscData.setServiceAddressIsSameAsRegisteredOfficeAddress(false);