Skip to content

Commit

Permalink
Merge pull request #73 from companieshouse/feature/DSND-2252-id-block…
Browse files Browse the repository at this point in the history
…-bug

Feature/dsnd 2252 id block bug
  • Loading branch information
maddytjCH authored Dec 19, 2023
2 parents faf2806 + 8cb7185 commit 03999dd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ public void theApplicationRunning() {
}

@Given("a psc data record {string} exists with notification id {string} and delta_at {string}")
public void psc_record_exists_for_company_and_id_with_delta_at(String existingDataFile, String notifcationId, String deltaAt) throws IOException {
public void psc_record_exists_for_company_and_id_with_delta_at(String existingDataFile, String notificationId, String deltaAt) throws IOException {
String pscDataFile = FileReaderUtil.readFile(
"src/itest/resources/json/input/" + existingDataFile + ".json");
PscData pscData = objectMapper.readValue(pscDataFile, PscData.class);

PscDocument document = new PscDocument();
document.setId(notifcationId);
document.setId(notificationId);
document.setCompanyNumber(COMPANY_NUMBER);
document.setData(pscData);
document.setDeltaAt(deltaAt);
mongoTemplate.save(document);
assertThat(companyPscRepository.findById(notifcationId)).isNotEmpty();
assertThat(companyPscRepository.findById(notificationId)).isNotEmpty();
}

@And("nothing is persisted to the database")
Expand Down Expand Up @@ -473,7 +473,7 @@ public void aPSCExistsForCorporateEntity(String dataFile, String companyNumber)
identification.setCountryRegistered("string");
identification.setLegalAuthority("string");
identification.setLegalForm("string");
document.setIdentification(identification);
pscData.setIdentification(identification);
document.setData(pscData);

mongoTemplate.save(document);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ public void aPSCExistsForForListSummary(String companyNumber) throws JsonProcess
identification.setCountryRegistered("string");
identification.setLegalAuthority("string");
identification.setLegalForm("string");
document1.setIdentification(new PscIdentification(identification));
pscData.setIdentification(new PscIdentification(identification));

document1.setData(pscData);
mongoTemplate.save(document1);
Expand All @@ -1102,7 +1102,7 @@ public void aPSCExistsForForListSummary(String companyNumber) throws JsonProcess

pscData2.setAddress(address);
pscData2.setNaturesOfControl(list);
document2.setIdentification(new PscIdentification(identification));
pscData2.setIdentification(new PscIdentification(identification));

document2.setData(pscData2);

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/uk/gov/companieshouse/pscdataapi/models/PscData.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public class PscData {
@Field("links")
private Links links;

@Field("identification")
private PscIdentification identification;

public PscIdentification getIdentification() {
return identification;
}

public void setIdentification(PscIdentification identification) {
this.identification = identification;
}

public LocalDate getCeasedOn() {
return ceasedOn;
}
Expand Down Expand Up @@ -204,6 +215,8 @@ public String toString() {
+ nameElements
+ ", links="
+ links
+ ", identification="
+ identification
+ '}';
}

Expand All @@ -230,14 +243,15 @@ public boolean equals(Object object) {
&& Objects.equals(ceased, pscData.ceased)
&& Objects.equals(naturesOfControl, pscData.naturesOfControl)
&& Objects.equals(nameElements, pscData.nameElements)
&& Objects.equals(links, pscData.links);
&& Objects.equals(links, pscData.links)
&& Objects.equals(identification, pscData.identification);
}

@Override
public int hashCode() {
return Objects.hash(ceasedOn, etag, address, name, nationality, countryOfResidence,
kind, description, serviceAddressIsSameAsRegisteredOfficeAddress,
isSanctioned, ceased, naturesOfControl,
nameElements, links);
nameElements, links, identification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class PscDocument {
@Field("sensitive_data")
private PscSensitiveData sensitiveData;

@Field("identification")
private PscIdentification identification;

public String getId() {
return id;
Expand Down Expand Up @@ -123,14 +121,6 @@ public void setSensitiveData(PscSensitiveData sensitiveData) {
this.sensitiveData = sensitiveData;
}

public PscIdentification getIdentification() {
return identification;
}

public void setIdentification(PscIdentification identification) {
this.identification = identification;
}

@Override
public String toString() {
return "PscDocument{"
Expand Down Expand Up @@ -160,8 +150,6 @@ public String toString() {
+ data
+ ", sensitiveData="
+ sensitiveData
+ ", identification="
+ identification
+ '}';
}

Expand All @@ -183,13 +171,12 @@ public boolean equals(Object object) {
&& Objects.equals(created, that.created)
&& Objects.equals(updated, that.updated)
&& Objects.equals(data, that.data)
&& Objects.equals(sensitiveData, that.sensitiveData)
&& Objects.equals(identification, that.identification);
&& Objects.equals(sensitiveData, that.sensitiveData);
}

@Override
public int hashCode() {
return Objects.hash(id, pscId, deltaAt, notificationId, companyNumber,
updatedBy, created, updated, data, sensitiveData, identification);
updatedBy, created, updated, data, sensitiveData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public CorporateEntity transformPscDocToCorporateEntity(PscDocument pscDocument)
corporateEntity.setLinks(pscData.getLinks());
corporateEntity.setAddress(mapAddress(pscData.getAddress()));
corporateEntity.setNaturesOfControl(pscData.getNaturesOfControl());
corporateEntity.setIdentification(
mapIdentification(pscData.getIdentification(), "corporate"));
}
corporateEntity.setIdentification(
mapIdentification(pscDocument.getIdentification(), "corporate"));
if (pscDocument.getDeltaAt() != null) {
corporateEntity.setNotifiedOn(LocalDate.parse(pscDocument.getDeltaAt(),
dateTimeFormatter));
Expand Down Expand Up @@ -156,9 +156,9 @@ public CorporateEntityBeneficialOwner transformPscDocToCorporateEntityBeneficial
corporateEntityBo.setNaturesOfControl(pscData.getNaturesOfControl());
corporateEntityBo.setLinks(pscData.getLinks());
corporateEntityBo.setIsSanctioned(pscData.getSanctioned());
corporateEntityBo.setIdentification(mapIdentification(
pscData.getIdentification(), "corporate"));
}
corporateEntityBo.setIdentification(mapIdentification(
pscDocument.getIdentification(), "corporate"));
if (pscDocument.getDeltaAt() != null) {
corporateEntityBo.setNotifiedOn(LocalDate.parse(pscDocument.getDeltaAt(),
dateTimeFormatter));
Expand All @@ -185,9 +185,9 @@ public LegalPerson transformPscDocToLegalPerson(PscDocument pscDocument) {
legalPerson.setNaturesOfControl(pscData.getNaturesOfControl());
legalPerson.setLinks(pscData.getLinks());
legalPerson.setCeasedOn(pscData.getCeasedOn());
legalPerson.setIdentification(mapIdentification(
pscData.getIdentification(), "legal"));
}
legalPerson.setIdentification(mapIdentification(
pscDocument.getIdentification(), "legal"));
if (pscDocument.getDeltaAt() != null) {
legalPerson.setNotifiedOn(LocalDate.parse(pscDocument.getDeltaAt(), dateTimeFormatter));
}
Expand Down Expand Up @@ -215,9 +215,9 @@ public LegalPersonBeneficialOwner transformPscDocToLegalPersonBeneficialOwner(
legalPersonBo.setLinks(pscData.getLinks());
legalPersonBo.setCeasedOn(pscData.getCeasedOn());
legalPersonBo.setIsSanctioned(pscData.getSanctioned());
legalPersonBo.setIdentification(mapIdentification(
pscData.getIdentification(), "legal"));
}
legalPersonBo.setIdentification(mapIdentification(
pscDocument.getIdentification(), "legal"));
if (pscDocument.getDeltaAt() != null) {
legalPersonBo.setNotifiedOn(LocalDate.parse(pscDocument.getDeltaAt(),
dateTimeFormatter));
Expand Down Expand Up @@ -307,13 +307,13 @@ public ListSummary transformPscDocToListSummary(PscDocument pscDocument, Boolean
listSummary.setCountryOfResidence(pscData.getCountryOfResidence());
listSummary.setNaturesOfControl(pscData.getNaturesOfControl());
listSummary.setCeased(pscData.getCeasedOn() != null);
listSummary.setIdentification(mapIdentification(
pscData.getIdentification(), "list summary"));
}
if (pscDocument.getSensitiveData() != null) {
listSummary.setDateOfBirth(mapDateOfBirth(pscDocument.getSensitiveData()
.getDateOfBirth(), registerView));
}
listSummary.setIdentification(mapIdentification(
pscDocument.getIdentification(), "list summary"));
return listSummary;
}

Expand All @@ -337,10 +337,6 @@ public PscDocument transformPscOnInsert(

if (externalData.getData() != null) {
Data data = externalData.getData();
if (data.getIdentification() != null) {
pscDocument.setIdentification(new PscIdentification(data.getIdentification()));
}

PscData pscData;
pscData = transformDataFields(data);

Expand Down Expand Up @@ -398,6 +394,10 @@ private PscData transformDataFields(Data data) {
pscData.setSanctioned(data.getIsSanctioned());
pscData.setServiceAddressIsSameAsRegisteredOfficeAddress(
data.getServiceAddressSameAsRegisteredOfficeAddress());
if (pscData.getKind().contains("corporate") || pscData.getKind().contains("legal")) {
PscIdentification identification = new PscIdentification(data.getIdentification());
pscData.setIdentification(identification);
}
return pscData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void testInsertCorporateEntityPscIsTransformedSuccessfully() throws FailedToTran
Assertions.assertNotNull(result.getData());

Assertions.assertNotNull(result.getData().getAddress());
Assertions.assertNotNull(result.getIdentification().getLegalForm());
Assertions.assertNotNull(result.getIdentification().getCountryRegistered());
Assertions.assertNotNull(result.getData().getIdentification().getLegalForm());
Assertions.assertNotNull(result.getData().getIdentification().getCountryRegistered());

pscInsertAssertions(expectedDocument, result);
}
Expand All @@ -120,8 +120,8 @@ void testInsertLegalPersonPscIsTransformedSuccessfully() throws FailedToTransfor
Assertions.assertNotNull(result.getData());

Assertions.assertNotNull(result.getData().getAddress());
Assertions.assertNotNull(result.getIdentification().getLegalForm());
Assertions.assertNull(result.getIdentification().getCountryRegistered());
Assertions.assertNotNull(result.getData().getIdentification().getLegalForm());
Assertions.assertNull(result.getData().getIdentification().getCountryRegistered());

pscInsertAssertions(expectedDocument, result);
}
Expand Down Expand Up @@ -178,8 +178,8 @@ void testInsertCorporateEntityBeneficialOwnerPscIsTransformedSuccessfully() thro

Assertions.assertTrue(result.getData().getSanctioned());
Assertions.assertNotNull(result.getData().getAddress());
Assertions.assertNotNull(result.getIdentification().getLegalForm());
Assertions.assertNotNull(result.getIdentification().getCountryRegistered());
Assertions.assertNotNull(result.getData().getIdentification().getLegalForm());
Assertions.assertNotNull(result.getData().getIdentification().getCountryRegistered());

pscInsertAssertions(expectedDocument, result);
}
Expand All @@ -196,8 +196,8 @@ void testInsertLegalPersonBeneficialOwnerPscIsTransformedSuccessfully() throws F

Assertions.assertTrue(result.getData().getSanctioned());
Assertions.assertNotNull(result.getData().getAddress());
Assertions.assertNotNull(result.getIdentification().getLegalForm());
Assertions.assertNull(result.getIdentification().getCountryRegistered());
Assertions.assertNotNull(result.getData().getIdentification().getLegalForm());
Assertions.assertNull(result.getData().getIdentification().getCountryRegistered());

pscInsertAssertions(expectedDocument, result);
}
Expand Down Expand Up @@ -225,7 +225,7 @@ private static void pscInsertAssertions(PscDocument expectedDocument, PscDocumen
assertThat(result.getData(), is(expectedDocument.getData()));

assertThat(result.getSensitiveData(),is(expectedDocument.getSensitiveData()));
assertThat(result.getIdentification(), is(expectedDocument.getIdentification()));
assertThat(result.getData().getIdentification(), is(expectedDocument.getData().getIdentification()));

assertThat(result.getDeltaAt(), is(expectedDocument.getDeltaAt()));
assertThat(result.getUpdatedBy(), is(expectedDocument.getUpdatedBy()));
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static PscDocument buildPscDocument(String kind) {

public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBirth) {
PscDocument output = new PscDocument();
PscData data = new PscData();
PscData pscData = new PscData();

output.setId(NOTIFICATION_ID);
output.setNotificationId(NOTIFICATION_ID);
Expand All @@ -168,15 +168,15 @@ public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBi
output.setUpdated(new Updated().setAt(LocalDate.now()));
output.setUpdatedBy("user");

data.setKind(kind);
data.setEtag("etag");
data.setName("wholeName");
pscData.setKind(kind);
pscData.setEtag("etag");
pscData.setName("wholeName");
Links links = new Links();
links.setSelf("self");
links.setStatements("linkStatements");
data.setLinks(links);
data.setServiceAddressIsSameAsRegisteredOfficeAddress(true);
data.setNaturesOfControl(List.of("part-right-to-share-surplus-assets-75-to-100-percent",
pscData.setLinks(links);
pscData.setServiceAddressIsSameAsRegisteredOfficeAddress(true);
pscData.setNaturesOfControl(List.of("part-right-to-share-surplus-assets-75-to-100-percent",
"right-to-appoint-and-remove-directors-as-trust-registered-overseas-entity",
"significant-influence-or-control-as-trust-registered-overseas-entity"));

Expand All @@ -191,10 +191,10 @@ public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBi
address.setPremises("SA");
address.setRegion("sa_region");
if (!kind.contains("secure")) {
data.setAddress(address);
pscData.setAddress(address);
}
if (kind.contains("beneficial")){
data.setSanctioned(true);
pscData.setSanctioned(true);
}

if(kind.contains("individual")) {
Expand All @@ -217,30 +217,30 @@ public static PscDocument buildPscDocument(String kind, boolean showFullDateOfBi
nameElements.setForename("John");
nameElements.setMiddleName("George");
nameElements.setSurname("Doe");
data.setNameElements(nameElements);
pscData.setNameElements(nameElements);

data.setNationality("British");
data.setCountryOfResidence("England");
pscData.setNationality("British");
pscData.setCountryOfResidence("England");
} else if(kind.contains("corporate")) {
Identification identification = new Identification();
identification.setLegalForm("Form");
identification.setLegalAuthority("Authority");
identification.setCountryRegistered("Wales");
identification.setPlaceRegistered("Cardiff");
identification.setRegistrationNumber("16102009");
output.setIdentification(new PscIdentification(identification));
pscData.setIdentification(new PscIdentification(identification));
} else if(kind.contains("legal")) {
Identification identification = new Identification();
identification.setLegalForm("Form");
identification.setLegalAuthority("Authority");
output.setIdentification(new PscIdentification(identification));
pscData.setIdentification(new PscIdentification(identification));
} else if(kind.contains("secure")) {
data.setCeasedOn(LocalDate.parse("2022-01-14"));
data.setCeased(true);
data.setDescription("description");
pscData.setCeasedOn(LocalDate.parse("2022-01-14"));
pscData.setCeased(true);
pscData.setDescription("description");
}

output.setData(data);
output.setData(pscData);
return output;
}

Expand All @@ -259,7 +259,7 @@ public static PscDocument buildBasicDocument(){
identification.setPlaceRegistered("x");
identification.setLegalAuthority("x");
identification.setRegistrationNumber("x");
document.setIdentification(identification);
pscData.setIdentification(identification);
return document;
}

Expand Down

0 comments on commit 03999dd

Please sign in to comment.