Skip to content

Commit

Permalink
Merge pull request #113 from companieshouse/feature/dsnd-2745_unset_s…
Browse files Browse the repository at this point in the history
…tatements_link

DSND-2745: Unset psc statement link on updates
  • Loading branch information
kinpang-CH authored Jun 28, 2024
2 parents 8f06b23 + 1c04851 commit 0138d4c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<!-- Internal -->
<structured-logging.version>1.9.25</structured-logging.version>
<private-api-sdk-java.version>2.0.347</private-api-sdk-java.version>
<private-api-sdk-java.version>2.0.420</private-api-sdk-java.version>
<data-sync-api-sdk-java.version>1.0.4</data-sync-api-sdk-java.version>
<api-security-java.version>0.4.1</api-security-java.version>
<api-sdk-manager-java-library.version>1.0.8</api-sdk-manager-java-library.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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)) {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand Down

0 comments on commit 0138d4c

Please sign in to comment.