Skip to content

Commit

Permalink
Merge pull request #48 from companieshouse/DSDN-1701
Browse files Browse the repository at this point in the history
added new endpoint for Legal person Beneficial
  • Loading branch information
YaaseenR authored Oct 5, 2023
2 parents 3bfd596 + 1a9abf5 commit 8f77f82
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 0 deletions.
2 changes: 2 additions & 0 deletions routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ routes:
7: ^/company/(.*)/persons-with-significant-control/corporate-entity/(.*)
8: ^/company/(.*)/persons-with-significant-control/super-secure/(.*)

9: ^/company/(.*)/persons-with-significant-control/legal-person-beneficial-owner/(.*)

Original file line number Diff line number Diff line change
Expand Up @@ -962,5 +962,108 @@ public void aGetRequestHasBeenSentForAndForLegalPerson(String companyNumber, Str
CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue());
}

@And("a PSC exists for {string} for Legal Person Beneficial Owner")
public void aPSCExistsForForLegalPersonBeneficialOwner(String companyNumber) throws JsonProcessingException {
String pscDataFile = FileReaderUtil.readFile("src/itest/resources/json/input/"+companyNumber+".json");
PscData pscData = objectMapper.readValue(pscDataFile, PscData.class);
PscDocument document = new PscDocument();

document.setId("ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV");
document.setCompanyNumber(companyNumber);
document.setPscId("ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV");
document.setDeltaAt("20231120084745378000");
pscData.setEtag("string");
pscData.setName("string");
pscData.setNationality("British");
pscData.setSanctioned(true);
pscData.setKind("legal-person-beneficial-owner");


document.setData(pscData);

mongoTemplate.save(document);
assertThat(companyPscRepository.findById("ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV")).isNotEmpty();
}

@When("a Get request is sent for {string} and {string} for Legal Person Beneficial Owner")
public void aGetRequestIsSentForAndForLegalPersonBeneficialOwner(String companyNumber, String notification_id) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

this.contextId = "5234234234";
CucumberContext.CONTEXT.set("contextId", this.contextId);
headers.set("x-request-id", this.contextId);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");

HttpEntity<String> request = new HttpEntity<String>(null, headers);

String uri =
"/company/{company_number}/persons-with-significant-control/legal-person-beneficial-owner/{notification_id}";
ResponseEntity<LegalPersonBeneficialOwner> response = restTemplate.exchange(uri,
HttpMethod.GET, request, LegalPersonBeneficialOwner.class, companyNumber, notification_id);

CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue());
CucumberContext.CONTEXT.set("getResponseBody", response.getBody());
}

@And("the Get call response body should match {string} file for Legal Person Beneficial Owner")
public void theGetCallResponseBodyShouldMatchFileForLegalPersonBeneficialOwner(String result) throws IOException {
String data = FileCopyUtils.copyToString(new InputStreamReader(
new FileInputStream("src/itest/resources/json/output/" + result + ".json")));
LegalPersonBeneficialOwner expected = objectMapper.readValue(data, LegalPersonBeneficialOwner.class);

LegalPersonBeneficialOwner actual = CucumberContext.CONTEXT.get("getResponseBody");

assertThat(actual.getName()).isEqualTo(expected.getName());
assertThat(actual.getCeasedOn()).isEqualTo(expected.getCeasedOn());
assertThat(actual.getIsSanctioned()).isEqualTo(expected.getIsSanctioned());
}

@When("a Get request is sent for {string} and {string} without ERIC headers for Legal Person Beneficial Owner")
public void aGetRequestIsSentForAndWithoutERICHeadersForLegalPersonBeneficialOwner(String companyNumber, String notification_id) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

this.contextId = "5234234234";
CucumberContext.CONTEXT.set("contextId", this.contextId);
headers.set("x-request-id", this.contextId);


HttpEntity<String> request = new HttpEntity<String>(null, headers);

String uri = "/company/{company_number}/persons-with-significant-control/legal-person-beneficial-owner/{notification_id}";
ResponseEntity<LegalPersonBeneficialOwner> response = restTemplate.exchange(uri,
HttpMethod.GET, request, LegalPersonBeneficialOwner.class, companyNumber, notification_id);

CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue());
CucumberContext.CONTEXT.set("getResponseBody", response.getBody());
}

@When("a Get request has been sent for {string} and {string} for Legal Person Beneficial Owner")
public void aGetRequestHasBeenSentForAndForLegalPersonBeneficialOwner(String companyNumber, String notification_id) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

this.contextId = "5234234234";
CucumberContext.CONTEXT.set("contextId", this.contextId);
headers.set("x-request-id", this.contextId);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");

HttpEntity<String> request = new HttpEntity<String>(null, headers);

String uri =
"/company/{company_number}/persons-with-significant-control/legal-person-beneficial-owner/{notification_id}";
ResponseEntity<LegalPersonBeneficialOwner> response = restTemplate.exchange(uri,
HttpMethod.GET, request, LegalPersonBeneficialOwner.class, companyNumber, notification_id);

CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Get Legal Person Beneficial Owner

Scenario Outline: Get individual successfully
Given Psc data api service is running
And a PSC exists for "<company_number>" for Legal Person Beneficial Owner
When a Get request is sent for "<company_number>" and "<notificationId>" for Legal Person Beneficial Owner
And the Get call response body should match "<result>" file for Legal Person Beneficial Owner
Then I should receive 200 status code

Examples:
| company_number | notificationId | result |
| 347777755 | ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV | LPBO_get_request_result |



Scenario Outline: Get Legal Person when sending get request without Eric headers

Given Psc data api service is running
And a PSC exists for "<company_number>" for Legal Person Beneficial Owner
When a Get request is sent for "<company_number>" and "<notificationId>" without ERIC headers for Legal Person Beneficial Owner
Then I should receive 401 status code

Examples:
| company_number | notificationId |
| 347777755 | ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV |

Scenario Outline: Get PSC unsuccessfully - PSC resource does not exist
Given a PSC does not exist for "<company_number>"
When a Get request has been sent for "<company_number>" and "<notificationId>" for Legal Person Beneficial Owner
Then I should receive 404 status code

Examples:
| company_number | notificationId |
| 347777755 | ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV |

63 changes: 63 additions & 0 deletions src/itest/resources/json/input/347777755.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZVV",
"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"
},
"external_data": {
"notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV",
"psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV",
"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/34777775/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV"
}],
"nationality" : "British",
"is_sanctioned": true,
"kind" : "legal-person-beneficial-owner",
"company_number": "347777755",
"name": "string",
"name_elements": {
"title":"Mr.",
"surname" : "JONES",
"forename" : "PHIL",
"middlename" : "tom"
}
}
}
}
37 changes: 37 additions & 0 deletions src/itest/resources/json/output/LPBO_get_request_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"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"
},
"country_of_residence": "United Kingdom",
"date_of_birth": {
"day": 21,
"month": 10,
"year": 1995
},
"etag": "string",
"kind": "legal-person-beneficial-owner",
"links": {
"self": "/company/347777755/persons-with-significant-control/individual/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV",
"statement": "string"
},
"name": "string",
"is_sanctioned": true,
"name_elements": {
"forename": "PHIL",
"other_forenames": "tom",
"surname": "JONES",
"title": "Mr"
},
"nationality": "British",
"natures_of_control": [
"part-right-to-share-surplus-assets-75-to-100-percent"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.companieshouse.api.psc.Individual;
import uk.gov.companieshouse.api.psc.IndividualBeneficialOwner;
import uk.gov.companieshouse.api.psc.LegalPerson;
import uk.gov.companieshouse.api.psc.LegalPersonBeneficialOwner;
import uk.gov.companieshouse.api.psc.SuperSecure;
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.logging.LoggerFactory;
Expand Down Expand Up @@ -239,4 +240,29 @@ public ResponseEntity<LegalPerson> getLegalPersonPscData(
}
}

/**
* Get the data object for given company profile number.
*
* @param companyNumber The number of the company
* @return ResponseEntity
*/
@GetMapping("legal-person-beneficial-owner/{notification_id}")
public ResponseEntity<LegalPersonBeneficialOwner> getLegalPersonBeneficialOwnerPscData(
@PathVariable("company_number") String companyNumber,
@PathVariable("notification_id") String notificationId) {
LOGGER.info(String.format("Getting PSC data with company number %s", companyNumber));
try {
LOGGER.info(String.format("Retrieving PSC with company number %s", companyNumber));
LegalPersonBeneficialOwner legalPersonBeneficialOwner =
pscService.getLegalPersonBeneficialOwnerPsc(companyNumber, notificationId);
return new ResponseEntity<>(legalPersonBeneficialOwner, HttpStatus.OK);
} catch (ResourceNotFoundException resourceNotFoundException) {
LOGGER.error(resourceNotFoundException.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} catch (DataAccessException exception) {
LOGGER.error(exception.getMessage());
return ResponseEntity.internalServerError().build();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uk.gov.companieshouse.api.psc.Individual;
import uk.gov.companieshouse.api.psc.IndividualBeneficialOwner;
import uk.gov.companieshouse.api.psc.LegalPerson;
import uk.gov.companieshouse.api.psc.LegalPersonBeneficialOwner;
import uk.gov.companieshouse.api.psc.SuperSecure;
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.pscdataapi.api.ChsKafkaApiService;
Expand Down Expand Up @@ -312,4 +313,33 @@ public LegalPerson getLegalPersonPsc(String companyNumber, String notificationId
"Unexpected error occurred while fetching PSC document");
}
}

/** Get PSC record. */
/** and transform it into an Legal person Beneficial Owner PSC.*/
public LegalPersonBeneficialOwner getLegalPersonBeneficialOwnerPsc(
String companyNumber, String notificationId) {
try {
Optional<PscDocument> pscDocument =
repository.findById(notificationId)
.filter(document -> document.getData().getKind()
.equals("legal-person-beneficial-owner")
&& document.getCompanyNumber().equals(companyNumber));
if (pscDocument.isEmpty()) {
throw new ResourceNotFoundException(HttpStatus.NOT_FOUND,
"Legal person beneficial owner PSC document not found in Mongo with id"
+ notificationId);
}
LegalPersonBeneficialOwner legalPersonBeneficialOwner =
transformer.transformPscDocToLegalPersonBeneficialOwner(pscDocument);
if (legalPersonBeneficialOwner == null) {
throw new ResourceNotFoundException(HttpStatus.NOT_FOUND,
"Failed to transform PSCDocument to Legal Person Beneficial Owner");
}
return legalPersonBeneficialOwner;
} catch (Exception exception) {
logger.error(exception.getMessage());
throw new ResourceNotFoundException(HttpStatus.NOT_FOUND,
"Unexpected error occurred while fetching PSC document");
}
}
}
Loading

0 comments on commit 8f77f82

Please sign in to comment.