From 38c775b7cb6401d2bf401b2458669d0f7c907aa3 Mon Sep 17 00:00:00 2001 From: JAndrewCH Date: Mon, 20 Nov 2023 15:44:17 +0000 Subject: [PATCH 1/2] fix type errors and tests --- .../pscdataapi/steps/PscDataSteps.java | 5 +- .../pscdataapi/service/CompanyPscService.java | 119 +---------------- .../transform/CompanyPscTransformer.java | 124 ++++++++++++++++++ .../service/CompanyPscServiceTest.java | 24 ++++ .../pscdataapi/util/TestHelper.java | 8 +- 5 files changed, 156 insertions(+), 124 deletions(-) diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java index 05fc60dc..2eac8ff9 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java @@ -1317,8 +1317,9 @@ public void iSendAGETStatementListRequestForCompanyNumberInRegisterView(String c @And("Company Metrics API is available for company number {string}") public void companyMetricsAPIIsAvailableForCompanyNumber(String companyNumber) throws IOException { - File metricsFile = new ClassPathResource("resources/json/input/company_metrics_34777777.json").getFile(); - MetricsApi metrics = objectMapper.readValue(metricsFile, MetricsApi.class); + + String data = FileCopyUtils.copyToString(new InputStreamReader(new FileInputStream("src/itest/resources/json/input/company_metrics_34777777.json"))); + MetricsApi metrics = objectMapper.readValue(data, MetricsApi.class); Optional metricsApi = Optional.ofNullable(metrics); diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java b/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java index 843e1238..211b1024 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java @@ -478,7 +478,7 @@ private PscList createPscDocumentList(List pscDocuments, List documents = new ArrayList<>(); for (PscDocument pscDocument : pscDocuments) { - ListSummary listSummary = transformPscDocToListSummary(pscDocument); + ListSummary listSummary = this.transformer.transformPscDocToListSummary(pscDocument); documents.add(listSummary); } @@ -525,122 +525,5 @@ private PscList createPscDocumentList(List pscDocuments, } - private ListSummary transformPscDocToListSummary(PscDocument pscDocument) { - ListSummary listSummary = new ListSummary(); - - PscData getDocument = pscDocument.getData(); - - if (getDocument.getEtag() != null) { - listSummary.setEtag(getDocument.getEtag()); - } - listSummary.setKind(listSummary.getKind()); - - if (getDocument.getName() != null) { - listSummary.setName(getDocument.getName()); - } - if (getDocument.getNameElements() != null) { - NameElements nameElements = new NameElements(); - if (getDocument.getNameElements().getTitle() != null) { - nameElements.setTitle(getDocument.getNameElements().getTitle()); - } - if (getDocument.getNameElements().getForename() != null) { - nameElements.setForename(getDocument.getNameElements().getForename()); - } - if (getDocument.getNameElements().getMiddleName() != null) { - nameElements.setMiddleName(getDocument - .getNameElements().getMiddleName()); - } - if (getDocument.getNameElements().getSurname() != null) { - nameElements.setSurname(getDocument.getNameElements().getSurname()); - } - listSummary.setNameElements(nameElements); - } - if (getDocument.getAddress() != null) { - Address address = new Address(); - - if (getDocument.getAddress().getAddressLine1() != null) { - address.setAddressLine1(getDocument.getAddress().getAddressLine1()); - } - if (getDocument.getAddress().getAddressLine2() != null) { - address.setAddressLine2(getDocument.getAddress().getAddressLine2()); - } - if (getDocument.getAddress().getCountry() != null) { - address.setCountry(getDocument.getAddress().getCountry()); - } - if (getDocument.getAddress().getLocality() != null) { - address.setLocality(getDocument.getAddress().getLocality()); - } - if (getDocument.getAddress().getPostalCode() != null) { - address.setPostalCode(getDocument.getAddress().getPostalCode()); - } - if (getDocument.getAddress().getPremises() != null) { - address.setPremises(getDocument.getAddress().getPremises()); - } - if (getDocument.getAddress().getRegion() != null) { - address.setRegion(getDocument.getAddress().getRegion()); - } - if (getDocument.getAddress().getCareOf() != null) { - address.setCareOf(getDocument.getAddress().getCareOf()); - } - if (getDocument.getAddress().getPoBox() != null) { - address.setPoBox(getDocument.getAddress().getPoBox()); - } - listSummary.setAddress(address); - listSummary.setPrincipalOfficeAddress(address); - } - if (getDocument.getNaturesOfControl() != null) { - listSummary - .setNaturesOfControl(getDocument.getNaturesOfControl()); - } - if (getDocument.getLinks() != null) { - listSummary.setLinks(getDocument.getLinks()); - } - if (getDocument.getCeasedOn() != null) { - listSummary.setCeasedOn(getDocument.getCeasedOn()); - } - if (getDocument.getSanctioned() != null) { - listSummary.setIsSanctioned(getDocument.getSanctioned()); - } - if (getDocument.getNationality() != null) { - listSummary.setNationality(getDocument.getNationality()); - } - if (getDocument.getCountryOfResidence() != null) { - listSummary.setCountryOfResidence(getDocument.getCountryOfResidence()); - } - if (getDocument.getDescription() != null) { - listSummary.setDescription( - ListSummary.DescriptionEnum.SUPER_SECURE_PERSONS_WITH_SIGNIFICANT_CONTROL); - } - if (pscDocument.getIdentification() != null) { - Identification identification = new Identification(); - if (pscDocument.getIdentification().getCountryRegistered() != null) { - identification.setCountryRegistered( - pscDocument.getIdentification().getCountryRegistered()); - } - if (pscDocument.getIdentification().getLegalAuthority() != null) { - identification.setLegalAuthority( - pscDocument.getIdentification().getLegalAuthority()); - } - if (pscDocument.getIdentification().getLegalForm() != null) { - identification.setLegalForm( - pscDocument.getIdentification().getLegalForm()); - } - if (pscDocument.getIdentification().getPlaceRegistered() != null) { - identification.setPlaceRegistered( - pscDocument.getIdentification().getPlaceRegistered()); - } - if (pscDocument.getIdentification().getRegistrationNumber() != null) { - identification.setRegistrationNumber( - pscDocument.getIdentification().getRegistrationNumber()); - } - if (pscDocument.getData().getNaturesOfControl() != null) { - listSummary - .setNaturesOfControl(pscDocument.getData().getNaturesOfControl()); - } - listSummary.setIdentification(identification); - } - - return listSummary; - } } 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 dd761414..ce5e35f1 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java @@ -822,6 +822,130 @@ public LegalPersonBeneficialOwner transformPscDocToLegalPersonBeneficialOwner( throw new ResourceNotFoundException(HttpStatus.NOT_FOUND,"PscDocument not found"); } } + + /** + * Transform Legal person Beneficial Owner. + * @param pscDocument PSC. + * @return ListSummary mongo Document. + */ + public ListSummary transformPscDocToListSummary(PscDocument pscDocument) { + + ListSummary listSummary = new ListSummary(); + + PscData getDocument = pscDocument.getData(); + + if (getDocument.getEtag() != null) { + listSummary.setEtag(getDocument.getEtag()); + } + listSummary.setKind(listSummary.getKind()); + + if (getDocument.getName() != null) { + listSummary.setName(getDocument.getName()); + } + if (getDocument.getNameElements() != null) { + NameElements nameElements = new NameElements(); + if (getDocument.getNameElements().getTitle() != null) { + nameElements.setTitle(getDocument.getNameElements().getTitle()); + } + if (getDocument.getNameElements().getForename() != null) { + nameElements.setForename(getDocument.getNameElements().getForename()); + } + if (getDocument.getNameElements().getMiddleName() != null) { + nameElements.setMiddleName(getDocument + .getNameElements().getMiddleName()); + } + if (getDocument.getNameElements().getSurname() != null) { + nameElements.setSurname(getDocument.getNameElements().getSurname()); + } + listSummary.setNameElements(nameElements); + } + if (getDocument.getAddress() != null) { + Address address = new Address(); + + if (getDocument.getAddress().getAddressLine1() != null) { + address.setAddressLine1(getDocument.getAddress().getAddressLine1()); + } + if (getDocument.getAddress().getAddressLine2() != null) { + address.setAddressLine2(getDocument.getAddress().getAddressLine2()); + } + if (getDocument.getAddress().getCountry() != null) { + address.setCountry(getDocument.getAddress().getCountry()); + } + if (getDocument.getAddress().getLocality() != null) { + address.setLocality(getDocument.getAddress().getLocality()); + } + if (getDocument.getAddress().getPostalCode() != null) { + address.setPostalCode(getDocument.getAddress().getPostalCode()); + } + if (getDocument.getAddress().getPremises() != null) { + address.setPremises(getDocument.getAddress().getPremises()); + } + if (getDocument.getAddress().getRegion() != null) { + address.setRegion(getDocument.getAddress().getRegion()); + } + if (getDocument.getAddress().getCareOf() != null) { + address.setCareOf(getDocument.getAddress().getCareOf()); + } + if (getDocument.getAddress().getPoBox() != null) { + address.setPoBox(getDocument.getAddress().getPoBox()); + } + listSummary.setAddress(convertAddress(address)); + listSummary.setPrincipalOfficeAddress(convertAddress(address)); + } + if (getDocument.getNaturesOfControl() != null) { + listSummary + .setNaturesOfControl(getDocument.getNaturesOfControl()); + } + if (getDocument.getLinks() != null) { + listSummary.setLinks(getDocument.getLinks()); + } + if (getDocument.getCeasedOn() != null) { + listSummary.setCeasedOn(getDocument.getCeasedOn()); + } + if (getDocument.getSanctioned() != null) { + listSummary.setIsSanctioned(getDocument.getSanctioned()); + } + if (getDocument.getNationality() != null) { + listSummary.setNationality(getDocument.getNationality()); + } + if (getDocument.getCountryOfResidence() != null) { + listSummary.setCountryOfResidence(getDocument.getCountryOfResidence()); + } + if (getDocument.getDescription() != null) { + listSummary.setDescription( + ListSummary.DescriptionEnum.SUPER_SECURE_PERSONS_WITH_SIGNIFICANT_CONTROL); + } + if (pscDocument.getIdentification() != null) { + Identification identification = new Identification(); + if (pscDocument.getIdentification().getCountryRegistered() != null) { + identification.setCountryRegistered( + pscDocument.getIdentification().getCountryRegistered()); + } + if (pscDocument.getIdentification().getLegalAuthority() != null) { + identification.setLegalAuthority( + pscDocument.getIdentification().getLegalAuthority()); + } + if (pscDocument.getIdentification().getLegalForm() != null) { + identification.setLegalForm( + pscDocument.getIdentification().getLegalForm()); + } + if (pscDocument.getIdentification().getPlaceRegistered() != null) { + identification.setPlaceRegistered( + pscDocument.getIdentification().getPlaceRegistered()); + } + if (pscDocument.getIdentification().getRegistrationNumber() != null) { + identification.setRegistrationNumber( + pscDocument.getIdentification().getRegistrationNumber()); + } + if (pscDocument.getData().getNaturesOfControl() != null) { + listSummary + .setNaturesOfControl(pscDocument.getData().getNaturesOfControl()); + } + listSummary.setIdentification(identification); + } + + return listSummary; + } private uk.gov.companieshouse.api.psc.Address convertAddress( uk.gov.companieshouse.pscdataapi.models.Address inputAddress) { diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java index 938cc2da..6118e2ee 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java @@ -526,11 +526,21 @@ void pscListReturnedByCompanyNumberFromRepository() throws ResourceNotFoundExcep PscList expectedPscList = testHelper.createPscList(); PscData pscData = new PscData(); document.setData(pscData); + ListSummary listSummary = new ListSummary(); + Identification identification = new Identification(); + identification.setPlaceRegistered("x"); + identification.setCountryRegistered("x"); + identification.setRegistrationNumber("x"); + identification.setLegalAuthority("x"); + identification.setLegalForm("x"); + listSummary.setIdentification(identification); when(companyMetricsApiService.getCompanyMetrics(MOCK_COMPANY_NUMBER)) .thenReturn(Optional.ofNullable(testHelper.createMetrics())); when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(document))); + when(transformer.transformPscDocToListSummary(document)) + .thenReturn(listSummary); PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25); @@ -543,12 +553,26 @@ void pscListWithNoMetricsReturnedByCompanyNumberFromRepository() throws Resource PscList expectedPscList = testHelper.createPscListWithNoMetrics(); PscData pscData = new PscData(); document.setData(pscData); + document.setId("1234"); + + ListSummary listSummary = new ListSummary(); + Identification identification = new Identification(); + identification.setPlaceRegistered("x"); + identification.setCountryRegistered("x"); + identification.setRegistrationNumber("x"); + identification.setLegalAuthority("x"); + identification.setLegalForm("x"); + listSummary.setIdentification(identification); + when(companyMetricsApiService.getCompanyMetrics(MOCK_COMPANY_NUMBER)) .thenReturn(Optional.empty()); when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(document))); + when(transformer.transformPscDocToListSummary(document)) + .thenReturn(listSummary); + PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25); assertEquals(expectedPscList, PscDocumentList); 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 b7f8dcdb..b87e4a3d 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java @@ -12,10 +12,10 @@ import uk.gov.companieshouse.api.metrics.*; import uk.gov.companieshouse.api.psc.*; import uk.gov.companieshouse.api.psc.InternalData; -import uk.gov.companieshouse.api.psc.ItemLinkTypes; -import uk.gov.companieshouse.api.psc.SensitiveData; -import uk.gov.companieshouse.api.psc.UsualResidentialAddress; import uk.gov.companieshouse.pscdataapi.models.*; +import uk.gov.companieshouse.pscdataapi.models.Address; +import uk.gov.companieshouse.pscdataapi.models.DateOfBirth; +import uk.gov.companieshouse.pscdataapi.models.NameElements; public class TestHelper { public static final String INDIVIDUAL_KIND = "individual-person-with-significant-control"; @@ -183,7 +183,7 @@ private ListSummary createListSummary() { nameElements.setMiddleName("Middle"); nameElements.setSurname("Surname"); listSummary.setNameElements(nameElements); - Address address = new Address(); + uk.gov.companieshouse.api.psc.Address address = new uk.gov.companieshouse.api.psc.Address(); address.setAddressLine1("1 street"); address.setAddressLine2("2 street"); address.setCountry("uk"); From 8c3a4c45dabccff7bff25a8474e922d570e4e002 Mon Sep 17 00:00:00 2001 From: JAndrewCH Date: Mon, 20 Nov 2023 15:51:53 +0000 Subject: [PATCH 2/2] update routes.yaml --- routes.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/routes.yaml b/routes.yaml index c06ba79f..91ed4d53 100644 --- a/routes.yaml +++ b/routes.yaml @@ -12,4 +12,5 @@ routes: 8: ^/company/(.*)/persons-with-significant-control/super-secure/(.*) 9: ^/company/(.*)/persons-with-significant-control/legal-person-beneficial-owner/(.*) 10: ^/company/(.*)/persons-with-significant-control/super-secure-beneficial-owner/(.*) + 11: ^/company/(.*)/persons-with-significant-control/