Skip to content

Commit

Permalink
Merge pull request #122 from cabinetoffice/bug/add-logic-for-local-au…
Browse files Browse the repository at this point in the history
…thority

add local authority logic in the odt file generation
  • Loading branch information
a-lor-cab authored Feb 20, 2024
2 parents 84b34a2 + bac23bf commit a685fb4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class OdtService {
private static final String APPLICANT_AMOUNT = "APPLICANT_AMOUNT";
private static final String BENEFITIARY_LOCATION = "BENEFITIARY_LOCATION";
private static final String APPLICANT_ORG_TYPE_INDIVIDUAL = "I am applying as an individual";
private static final String APPLICANT_ORG_TYPE_LOCAL_AUTHORITY = "Local authority";
private static final String Heading_20_1 = "Heading_20_1";
private static final String Heading_20_2 = "Heading_20_2";
private static final String Heading_20_3 = "Heading_20_3";
Expand Down Expand Up @@ -311,10 +312,11 @@ private static TableTableElement generateEssentialTable(
OdfTextDocument doc) {
final String orgType = section.getQuestionById(APPLICANT_TYPE).getResponse();
final boolean isIndividual = Objects.equals(orgType, APPLICANT_ORG_TYPE_INDIVIDUAL);
final boolean isLocalAuthority = Objects.equals(orgType, APPLICANT_ORG_TYPE_LOCAL_AUTHORITY);
final String orgNameHeading = isIndividual ? "Applicant name" : "Organisation Name";
OdfTable odfTable;

if(isIndividual) {
if(isIndividual || isLocalAuthority) {
odfTable = OdfTable.newTable(doc, 7, 2);
} else {
odfTable = OdfTable.newTable(doc, 9, 2);
Expand All @@ -339,7 +341,7 @@ private static TableTableElement generateEssentialTable(
odfTable.getRowByIndex(6).getCellByIndex(1)
.setStringValue(applicantOrgAddress[4]);

if(isIndividual){
if(isIndividual || isLocalAuthority){
return odfTable.getOdfElement();
}
int index = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,39 @@ void compareTestGenerateSingleOdtForIndividualForSchemeVersion2() throws Excepti
assertThat(generatedContent).doesNotContain("My Custom Section");
}

@Test
void compareTestGenerateSingleOdtForLocalAuthorityForSchemeVersion2() throws Exception {
final OdfDocument generatedDoc = odtService.generateSingleOdt(V2_SUBMISSION_LOCAL_AUTHORITY, "testFileName5");
final String generatedContent = docToString(generatedDoc.getContentDom());


assertThat(generatedContent).contains("Organisation Name");
assertThat(generatedContent).contains("V2_Company name");
assertThat(generatedContent).contains("Eligibility");
assertThat(generatedContent).contains("Due diligence information");
assertThat(generatedContent).contains("Organisation details");
assertThat(generatedContent).contains("Test Org Name v2");
assertThat(generatedContent).contains("V2_test address");
assertThat(generatedContent).contains("V2_Edinburgh");
assertThat(generatedContent).contains("V2_POSTCODE");
assertThat(generatedContent).contains("Local authority");
assertThat(generatedContent).doesNotContain(
"Companies House number if the organisation has one (if blank, number has not been entered)");
assertThat(generatedContent).doesNotContain("V2_CHN");
assertThat(generatedContent).doesNotContain(
"Charities Commission number if the organisation has one (if blank, number has not been entered)");
assertThat(generatedContent).doesNotContain("V2_CMSN_NO");
assertThat(generatedContent).contains("V2_Scotland", "V2_North East England");
assertThat(generatedContent).doesNotContain("V1_test address");
assertThat(generatedContent).doesNotContain("V1_Edinburgh");
assertThat(generatedContent).doesNotContain("V1_TEST_POSTCODE");
assertThat(generatedContent).doesNotContain("V1_Limited company");
assertThat(generatedContent).doesNotContain("V1_CHN");
assertThat(generatedContent).doesNotContain("V1_CMSN_NO");
assertThat(generatedContent).doesNotContain("V1_Scotland", "V1_North East England");
assertThat(generatedContent).doesNotContain("My Custom Section");
}

private String docToString(Document document) throws Exception {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,28 @@ public class TestData {
.response("I am applying as an individual")
.build();

public static final SubmissionQuestion V2_ORG_TYPE_SUBMISSION_QUESTION_LOCAL_AUTHORITY = SubmissionQuestion.builder()
.questionId("APPLICANT_TYPE").fieldTitle("Choose your organisation type").
profileField("ORG_TYPE")
.hintText("Choose the option that best describes your organisation")
.responseType(SubmissionQuestionResponseType.Dropdown)
.validation(
SubmissionQuestionValidation
.builder()
.mandatory(true)
.build()
).options(new String[]{
"Limited company",
"Non-limited company",
"Registered charity",
"Unregistered charity",
"Other",
"Local authority",
"I am applying as an individual"
})
.response("Local authority")
.build();

public static final SubmissionQuestion V2_ORG_NAME_SUBMISSION_QUESTION = SubmissionQuestion.builder()
.questionId("APPLICANT_ORG_NAME")
.profileField("ORG_NAME")
Expand Down Expand Up @@ -439,6 +461,17 @@ public class TestData {
))
.build();

public static final SubmissionSection ORGANISATION_DETAILS_SECTION_SUBMISSION_LOCAL_AUTHORITY = SubmissionSection.builder()
.sectionId("ORGANISATION_DETAILS")
.sectionTitle("Your details")
.sectionStatus(SubmissionSectionStatus.COMPLETED)
.questions(Arrays.asList(
V2_ORG_TYPE_SUBMISSION_QUESTION_LOCAL_AUTHORITY,
V2_ORG_NAME_SUBMISSION_QUESTION,
V2_ORG_ADDRESS_SUBMISSION_QUESTION
))
.build();

public static final SubmissionSection FUNDING_DETAILS_SECTION_SUBMISSION = SubmissionSection
.builder()
.sectionId("FUNDING_DETAILS")
Expand Down Expand Up @@ -497,6 +530,12 @@ public class TestData {
FUNDING_DETAILS_SECTION_SUBMISSION
);

public static final List<SubmissionSection> V2_SUBMISSION_SECTIONS_LIST_LOCAL_AUTHORITY = Arrays.asList(
ELIGIBILITY_SECTION_SUBMISSION,
ORGANISATION_DETAILS_SECTION_SUBMISSION_LOCAL_AUTHORITY,
FUNDING_DETAILS_SECTION_SUBMISSION
);

public static final Submission V2_SUBMISSION_INDIVIDUAL = Submission
.builder()
.scheme(GrantScheme.builder().version(2).name("Test Org Name v2").build())
Expand All @@ -505,6 +544,15 @@ public class TestData {
.definition(SubmissionDefinition.builder().sections((V2_SUBMISSION_SECTIONS_LIST_INDIVIDUAL)).build())
.version(2)
.build();

public static final Submission V2_SUBMISSION_LOCAL_AUTHORITY = Submission
.builder()
.scheme(GrantScheme.builder().version(2).name("Test Org Name v2").build())
.gapId("GAP-2")
.submittedDate(ZonedDateTime.parse("2022-02-15T18:35:24.00Z"))
.definition(SubmissionDefinition.builder().sections((V2_SUBMISSION_SECTIONS_LIST_LOCAL_AUTHORITY)).build())
.version(2)
.build();
public static final SubmissionSection V1_CUSTOM_SECTION_SUBMISSION = SubmissionSection
.builder()
.sectionId("26215de2-2211-48e4-9c82-835cd227daad").sectionTitle("My Custom Section")
Expand Down Expand Up @@ -536,3 +584,5 @@ public class TestData {

}



0 comments on commit a685fb4

Please sign in to comment.