diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java index 9c6b9cb4..4b026a66 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/config/AbstractIntegrationTest.java @@ -5,6 +5,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import uk.gov.companieshouse.api.InternalApiClient; +import uk.gov.companieshouse.api.api.CompanyMetricsApiService; import uk.gov.companieshouse.pscdataapi.api.ChsKafkaApiService; /** @@ -18,4 +19,7 @@ public abstract class AbstractIntegrationTest extends AbstractMongoConfig { @MockBean public ChsKafkaApiService chsKafkaApiService; + @MockBean + public CompanyMetricsApiService companyMetricsApiService; + } \ No newline at end of file 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 beca314f..78871a57 100644 --- a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java +++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java @@ -9,6 +9,7 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.assertj.core.api.Assertions; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static org.mockito.Mockito.*; @@ -63,7 +64,7 @@ public class PscDataSteps { private ChsKafkaApiService chsKafkaApiService; @Autowired private CompanyPscTransformer transformer; - @Autowired + @InjectMocks private CompanyPscService companyPscService; @Mock @@ -1039,23 +1040,74 @@ public void aGetRequestHasBeenSentForAndForLegalPersonBeneficialOwner(String com CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue()); } - @And("a PSC {string} exists for {string} for List summary") - public void aPSCExistsForForListSummary(String dataFile, String companyNumber) throws JsonProcessingException { - String pscDataFile = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json"); - PscData pscData = objectMapper.readValue(pscDataFile, PscData.class); + @And("a PSC exists for {string} for List summary") + public void aPSCExistsForForListSummary(String companyNumber) throws JsonProcessingException { + PscData pscData = new PscData(); PscDocument document1 = new PscDocument(); + String notificationId1 = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX"; document1.setId(notificationId1); document1.setCompanyNumber(companyNumber); + document1.setPscId("ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX"); + pscData.setEtag("string"); + pscData.setName("string"); + pscData.setNationality("British"); + pscData.setSanctioned(true); + pscData.setKind("corporate-entity-person-with-significant-control"); + Links links = new Links(); + links.setSelf("/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX"); + pscData.setLinks(links); + Address address = new Address(); + address.setAddressLine1("ura_line1"); + address.setAddressLine2("ura_line2"); + address.setCareOf("ura_care_of"); + address.setCountry("United Kingdom"); + address.setLocality("Cardiff"); + address.setPoBox("ura_po"); + address.setPostalCode("CF2 1B6"); + address.setPremises("URA"); + address.setRegion("ura_region"); + pscData.setAddress(address); + List list = new ArrayList<>(); + list.add("part-right-to-share-surplus-assets-75-to-100-percent"); + pscData.setNaturesOfControl(list); + Identification identification = new Identification(); + identification.setRegistrationNumber("string"); + identification.setPlaceRegistered("string"); + identification.setCountryRegistered("string"); + identification.setLegalAuthority("string"); + identification.setLegalForm("string"); + document1.setIdentification(new PscIdentification(identification)); + document1.setData(pscData); mongoTemplate.save(document1); + + PscData pscData2 = new PscData(); PscDocument document2 = new PscDocument(); + String notificationId2 = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV"; document2.setId(notificationId2); document2.setCompanyNumber(companyNumber); - document2.setData(pscData); + document2.setPscId("ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0"); + pscData2.setEtag("string"); + pscData2.setName("string"); + pscData2.setNationality("British"); + pscData2.setSanctioned(true); + pscData2.setKind("corporate-entity-person-with-significant-control"); + Links links2 = new Links(); + links2.setSelf("/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0"); + pscData2.setLinks(links2); + + pscData2.setAddress(address); + pscData2.setNaturesOfControl(list); + document2.setIdentification(new PscIdentification(identification)); + + document2.setData(pscData2); + + + mongoTemplate.save(document2); assertThat(companyPscRepository.getPscByCompanyNumberAndId(companyNumber, notificationId1)).isNotEmpty(); @@ -1083,13 +1135,13 @@ public void aGetRequestIsSentForForListSummary(String companyNumber) { CucumberContext.CONTEXT.set("getResponseBody", response.getBody()); } + @And("the Get call response body should match file {string} for List Summary") public void theGetCallResponseBodyShouldMatchFileForListSummary(String result) throws IOException { String data = FileCopyUtils.copyToString(new InputStreamReader( new FileInputStream("src/itest/resources/json/output/" + result + ".json"))); PscList expected = objectMapper.readValue(data, PscList.class); PscList actual = CucumberContext.CONTEXT.get("getResponseBody"); - assertThat(expected.getItemsPerPage()).isEqualTo(actual.getItemsPerPage()); assertThat(expected.getItems()).isEqualTo(actual.getItems()); assertThat(expected.getLinks()).isEqualTo(actual.getLinks()); diff --git a/src/itest/resources/features/list_summary.feature b/src/itest/resources/features/list_summary.feature index 5aa3bd06..9622c90f 100644 --- a/src/itest/resources/features/list_summary.feature +++ b/src/itest/resources/features/list_summary.feature @@ -2,39 +2,40 @@ Feature: Get list summary Scenario Outline: Processing Psc List GET request successfully Given Psc data api service is running - And a PSC "" exists for "" for List summary + And a PSC exists for "" for List summary + And Company Metrics "company_metrics_data" is available for company number "" When a Get request is sent for "" for List summary Then I should receive 200 status code And the Get call response body should match file "" for List Summary Examples: - | data | company_number | result | - | get_super_secure | 34777777 | psc_list_output | + | company_number | result | + | 34777777 | psc_list_output | Scenario Outline: Processing Psc List GET register view request successfully Given Psc data api service is running - And a PSC "" exists for "" for List summary + And a PSC exists for "" for List summary And Company Metrics "" is available for company number "" When a Get request is sent for "" for List summary Then I should receive 200 status code And the Get call response body should match file "" for List Summary Examples: - | data | metricsData | companyNumber | result | - | get_super_secure | company_metrics_data | 34777777 | psc_list_register_view_output | + | metricsData | companyNumber | result | + | company_metrics_data | 34777777 | psc_list_register_view_output | Scenario Outline: Processing Psc List GET register view request unsuccessfully when metrics is unavailable Given Psc data api service is running - And a PSC "" exists for "" for List summary + And a PSC exists for "" for List summary And Company Metrics API is unavailable When I send a GET statement list request for company number in register view "" Then I should receive 404 status code Examples: - | data | company_number | - | get_super_secure | 34777777 | + | company_number | + | 34777777 | Scenario Outline: Processing Psc List GET register view request unsuccessfully when no company psc statements in public register @@ -50,7 +51,7 @@ Feature: Get list summary Scenario Outline: Get Psc List when sending get request without Eric headers Given Psc data api service is running - And a PSC "" exists for "" for List summary + And a PSC exists for "" for List summary When a Get request is sent for "" without ERIC headers for List summary Then I should receive 401 status code diff --git a/src/itest/resources/json/output/psc_list_output.json b/src/itest/resources/json/output/psc_list_output.json index a9e64e4b..de50dd81 100644 --- a/src/itest/resources/json/output/psc_list_output.json +++ b/src/itest/resources/json/output/psc_list_output.json @@ -2,134 +2,92 @@ "items_per_page": 25, "items": [ { - "_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "internal_data": { - "created_at" : "2021-11-02T08:47:45", - "updated_at" :"2021-09-14T10:30:16.000Z", - "updated_by" :"CHIPS", - "delta_at" : "2023-11-20T08:47:45.378Z" + "etag": "string", + "name": "string", + "name_elements": null, + "kind": "corporate-entity-person-with-significant-control", + "links": { + "self": "/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX" }, - "external_data": { - "notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "sensitive_data": { - "usual_residential_address" : { - "address_line_1" : "ura_line1", - "address_line_2" : "ura_line2", - "care_of" : "ura_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "ura_po", - "postal_code" : "CF2 1B6", - "premises" : "URA", - "region" : "ura_region" - }, - "residential_address_same_as_service_address": true, - "date_of_birth": { - "day": 21, - "year": 1995, - "month": 10 - } - }, - "data" : { - "service_address" : { - "address_line_1" : "sa_line1", - "address_line_2" : "sa_line2", - "care_of" : "sa_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "sa_po", - "postal_code" : "CF2 1B6", - "premises" : "SA", - "region" : "sa_region" - }, - "natures_of_control": [ - "part-right-to-share-surplus-assets-75-to-100-percent" - ], - "country_of_residence" : "United Kingdom", - "links" : [{ - "self" : "/company/34777777/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ" - }], - "nationality" : "British", - "is_sanctioned": true, - "kind" : "super-secure-person-with-significant-control", - "company_number": "34777777", - "name": "string", - "name_elements": { - "title":"Mr.", - "surname" : "JONES", - "forename" : "PHIL", - "middlename" : "tom" - } - } - } + "nationality": "British", + "identification": { + "legal_form": "string", + "legal_authority": "string", + "country_registered": "string", + "place_registered": "string", + "registration_number": "string" + }, + "address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "natures_of_control": ["part-right-to-share-surplus-assets-75-to-100-percent"], + "is_sanctioned": true, + "principal_office_address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "ceased": false }, { - "_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "internal_data": { - "created_at" : "2021-11-02T08:47:45", - "updated_at" :"2021-09-14T10:30:16.000Z", - "updated_by" :"CHIPS", - "delta_at" : "2023-11-20T08:47:45.378Z" + "etag": "string", + "name": "string", + "links": { + "self": "/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0" + }, + "kind": "corporate-entity-person-with-significant-control", + "nationality": "British", + "identification": { + "legal_form": "string", + "legal_authority": "string", + "country_registered": "string", + "place_registered": "string", + "registration_number": "string" }, - "external_data": { - "notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "sensitive_data": { - "usual_residential_address" : { - "address_line_1" : "ura_line1", - "address_line_2" : "ura_line2", - "care_of" : "ura_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "ura_po", - "postal_code" : "CF2 1B6", - "premises" : "URA", - "region" : "ura_region" - }, - "residential_address_same_as_service_address": true, - "date_of_birth": { - "day": 21, - "year": 1995, - "month": 10 - } - }, - "data" : { - "service_address" : { - "address_line_1" : "sa_line1", - "address_line_2" : "sa_line2", - "care_of" : "sa_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "sa_po", - "postal_code" : "CF2 1B6", - "premises" : "SA", - "region" : "sa_region" - }, - "natures_of_control": [ - "part-right-to-share-surplus-assets-75-to-100-percent" - ], - "country_of_residence" : "United Kingdom", - "links" : [{ - "self" : "/company/34777777/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ" - }], - "nationality" : "British", - "is_sanctioned": true, - "kind" : "super-secure-person-with-significant-control", - "company_number": "34777777", - "name": "string", - "name_elements": { - "title":"Mr.", - "surname" : "JONES", - "forename" : "PHIL", - "middlename" : "tom" - } - } - } + "address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "natures_of_control": [ + "part-right-to-share-surplus-assets-75-to-100-percent" + ], + "is_sanctioned": true, + "principal_office_address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "ceased": false } ], - "start_index": 0, - "links": { - "self": "/company/34777777/persons-with-significant-control" - } + "start_index": 0, + "total_results": null, + "active_count": null, + "ceased_count": null, + "links": { + "self": "/company/34777777/persons-with-significant-control" + } } \ No newline at end of file diff --git a/src/itest/resources/json/output/psc_list_register_view_output.json b/src/itest/resources/json/output/psc_list_register_view_output.json index 17d6d165..de50dd81 100644 --- a/src/itest/resources/json/output/psc_list_register_view_output.json +++ b/src/itest/resources/json/output/psc_list_register_view_output.json @@ -2,136 +2,92 @@ "items_per_page": 25, "items": [ { - "_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "internal_data": { - "created_at" : "2021-11-02T08:47:45", - "updated_at" :"2021-09-14T10:30:16.000Z", - "updated_by" :"CHIPS", - "delta_at" : "2023-11-20T08:47:45.378Z" + "etag": "string", + "name": "string", + "name_elements": null, + "kind": "corporate-entity-person-with-significant-control", + "links": { + "self": "/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX" }, - "external_data": { - "notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "sensitive_data": { - "usual_residential_address" : { - "address_line_1" : "ura_line1", - "address_line_2" : "ura_line2", - "care_of" : "ura_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "ura_po", - "postal_code" : "CF2 1B6", - "premises" : "URA", - "region" : "ura_region" - }, - "residential_address_same_as_service_address": true, - "date_of_birth": { - "day": 21, - "year": 1995, - "month": 10 - } - }, - "data" : { - "service_address" : { - "address_line_1" : "sa_line1", - "address_line_2" : "sa_line2", - "care_of" : "sa_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "sa_po", - "postal_code" : "CF2 1B6", - "premises" : "SA", - "region" : "sa_region" - }, - "natures_of_control": [ - "part-right-to-share-surplus-assets-75-to-100-percent" - ], - "country_of_residence" : "United Kingdom", - "links" : [{ - "self" : "/company/34777777/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ" - }], - "nationality" : "British", - "is_sanctioned": true, - "kind" : "super-secure-person-with-significant-control", - "company_number": "34777777", - "name": "string", - "name_elements": { - "title":"Mr.", - "surname" : "JONES", - "forename" : "PHIL", - "middlename" : "tom" - } - } - } + "nationality": "British", + "identification": { + "legal_form": "string", + "legal_authority": "string", + "country_registered": "string", + "place_registered": "string", + "registration_number": "string" + }, + "address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "natures_of_control": ["part-right-to-share-surplus-assets-75-to-100-percent"], + "is_sanctioned": true, + "principal_office_address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "ceased": false }, { - "_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "internal_data": { - "created_at" : "2021-11-02T08:47:45", - "updated_at" :"2021-09-14T10:30:16.000Z", - "updated_by" :"CHIPS", - "delta_at" : "2023-11-20T08:47:45.378Z" + "etag": "string", + "name": "string", + "links": { + "self": "/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0" + }, + "kind": "corporate-entity-person-with-significant-control", + "nationality": "British", + "identification": { + "legal_form": "string", + "legal_authority": "string", + "country_registered": "string", + "place_registered": "string", + "registration_number": "string" }, - "external_data": { - "notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX", - "sensitive_data": { - "usual_residential_address" : { - "address_line_1" : "ura_line1", - "address_line_2" : "ura_line2", - "care_of" : "ura_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "ura_po", - "postal_code" : "CF2 1B6", - "premises" : "URA", - "region" : "ura_region" - }, - "residential_address_same_as_service_address": true, - "date_of_birth": { - "day": 21, - "year": 1995, - "month": 10 - } - }, - "data" : { - "service_address" : { - "address_line_1" : "sa_line1", - "address_line_2" : "sa_line2", - "care_of" : "sa_care_of", - "country" : "United Kingdom", - "locality" : "Cardiff", - "po_box" : "sa_po", - "postal_code" : "CF2 1B6", - "premises" : "SA", - "region" : "sa_region" - }, - "natures_of_control": [ - "part-right-to-share-surplus-assets-75-to-100-percent" - ], - "country_of_residence" : "United Kingdom", - "links" : [{ - "self" : "/company/34777777/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ" - }], - "nationality" : "British", - "is_sanctioned": true, - "kind" : "super-secure-person-with-significant-control", - "company_number": "34777777", - "name": "string", - "name_elements": { - "title":"Mr.", - "surname" : "JONES", - "forename" : "PHIL", - "middlename" : "tom" - } - } - } + "address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "natures_of_control": [ + "part-right-to-share-surplus-assets-75-to-100-percent" + ], + "is_sanctioned": true, + "principal_office_address": { + "address_line_1": "ura_line1", + "address_line_2": "ura_line2", + "country": "United Kingdom", + "locality": "Cardiff", + "po_box": "ura_po", + "postal_code": "CF2 1B6", + "premises": "URA", + "region": "ura_region" + }, + "ceased": false } ], "start_index": 0, - "ceased_count": 0, - "total_results": 1, - "links": { - "self": "/company/34777777/persons-with-significant-control" - } + "total_results": null, + "active_count": null, + "ceased_count": null, + "links": { + "self": "/company/34777777/persons-with-significant-control" + } } \ No newline at end of file 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 9fafc8fb..78cbe1af 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java @@ -498,7 +498,8 @@ private PscList createPscDocumentList(List pscDocuments, List documents = new ArrayList<>(); for (PscDocument pscDocument : pscDocuments) { - ListSummary listSummary = this.transformer.transformPscDocToListSummary(pscDocument); + ListSummary listSummary = this.transformer + .transformPscDocToListSummary(pscDocument, registerView); documents.add(listSummary); } @@ -517,17 +518,17 @@ private PscList createPscDocumentList(List pscDocuments, pscList.setCeasedCount((int) withdrawnCount); pscList.setTotalResults(metricsApi.getCounts() - .getPersonsWithSignificantControl().getActiveStatementsCount() + .getPersonsWithSignificantControl().getActivePscsCount() + pscList.getCeasedCount()); pscList.setActiveCount(metricsApi.getCounts() - .getPersonsWithSignificantControl().getActiveStatementsCount()); + .getPersonsWithSignificantControl().getActivePscsCount()); } else { pscList.setActiveCount(metricsApi.getCounts() - .getPersonsWithSignificantControl().getActiveStatementsCount()); + .getPersonsWithSignificantControl().getActivePscsCount()); pscList.setCeasedCount(metricsApi.getCounts() - .getPersonsWithSignificantControl().getWithdrawnStatementsCount()); + .getPersonsWithSignificantControl().getCeasedPscsCount()); pscList.setTotalResults(metricsApi.getCounts() - .getPersonsWithSignificantControl().getStatementsCount()); + .getPersonsWithSignificantControl().getPscsCount()); } } catch (NullPointerException exp) { logger.error(String.format("No PSC data in metrics for company number %s", 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 d4d52dee..8e9ca002 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformer.java @@ -274,13 +274,25 @@ public SuperSecureBeneficialOwner transformPscDocToSuperSecureBeneficialOwner( * @param pscDocument PSC. * @return ListSummary mongo Document. */ - public ListSummary transformPscDocToListSummary(PscDocument pscDocument) { + public ListSummary transformPscDocToListSummary(PscDocument pscDocument, Boolean registerView) { ListSummary listSummary = new ListSummary(); + + + if (pscDocument.getData() != null) { PscData pscData = pscDocument.getData(); - if (pscData.getDescription() != null) { - listSummary.setDescription( - ListSummary.DescriptionEnum.SUPER_SECURE_PERSONS_WITH_SIGNIFICANT_CONTROL); + + try { + listSummary.setKind(ListSummary.KindEnum.fromValue(pscData.getKind())); + } catch (Exception ex) { + listSummary.setKind(null); + } + + try { + listSummary.setDescription(ListSummary.DescriptionEnum.fromValue( + pscData.getDescription())); + } catch (Exception ex) { + listSummary.setDescription(null); } listSummary.setEtag(pscData.getEtag()); @@ -295,6 +307,11 @@ public ListSummary transformPscDocToListSummary(PscDocument pscDocument) { listSummary.setNationality(pscData.getNationality()); listSummary.setCountryOfResidence(pscData.getCountryOfResidence()); listSummary.setNaturesOfControl(pscData.getNaturesOfControl()); + listSummary.setCeased(pscData.getCeasedOn() != null); + } + if (pscDocument.getSensitiveData() != null) { + listSummary.setDateOfBirth(mapDateOfBirth(pscDocument.getSensitiveData() + .getDateOfBirth(), registerView)); } listSummary.setIdentification(mapIdentification( pscDocument.getIdentification(), "list summary")); 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 d92e5fa0..39f66eca 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java @@ -490,7 +490,7 @@ void pscListReturnedByCompanyNumberFromRepository() throws ResourceNotFoundExcep 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)) + when(transformer.transformPscDocToListSummary(document, false)) .thenReturn(listSummary); PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25); @@ -517,7 +517,7 @@ void pscListWithNoMetricsReturnedByCompanyNumberFromRepository() throws Resource when(repository.getPscDocumentList(anyString(), anyInt(), anyInt())).thenReturn(Optional.of(Collections.singletonList(document))); - when(transformer.transformPscDocToListSummary(document)) + when(transformer.transformPscDocToListSummary(document, false)) .thenReturn(listSummary); PscList PscDocumentList = service.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER,0, false,25); 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 b273c40b..95a8903c 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/transform/CompanyPscTransformerTest.java @@ -312,7 +312,7 @@ void testEmptyPscSuperSecureBeneficialOwnerTransform(){ @Test void testEmptyListSummaryTransform(){ ListSummary listSummary = pscTransformer - .transformPscDocToListSummary(new PscDocument()); + .transformPscDocToListSummary(new PscDocument(), false); Assertions.assertNotNull(listSummary); } @@ -326,9 +326,8 @@ void testBasicListSummaryWithNullDataTransform(){ pscDocument.setSensitiveData(new PscSensitiveData()); ListSummary listSummary = pscTransformer - .transformPscDocToListSummary(pscDocument); + .transformPscDocToListSummary(pscDocument, true); Assertions.assertNotNull(listSummary); - Assertions.assertNull(listSummary.getKind()); } } 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 c1492791..15046cdc 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java @@ -291,9 +291,9 @@ public MetricsApi createMetrics() { MetricsApi metrics = new MetricsApi(); CountsApi counts = new CountsApi(); PscApi pscs = new PscApi(); - pscs.setActiveStatementsCount(1); - pscs.setWithdrawnStatementsCount(1); - pscs.setStatementsCount(2); + pscs.setActivePscsCount(1); + pscs.setCeasedPscsCount(1); + pscs.setPscsCount(2); counts.setPersonsWithSignificantControl(pscs); metrics.setCounts(counts); return metrics;