Search in sources :

Example 1 with SupplementaryInformation

use of uk.nhs.digital.website.beans.SupplementaryInformation in project hippo by NHS-digital-website.

the class SupplementaryInformationHubComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    final HstRequestContext context = request.getRequestContext();
    final SupplementaryInformationHub document = (SupplementaryInformationHub) context.getContentBean();
    if (document != null) {
        request.setAttribute("document", document);
    }
    List<SupplementaryInformation> si = getListOfSupplementaryInformation();
    request.setAttribute("years", years(si));
    String selectedYear = DocumentUtils.findYearOrDefault(getSelectedYear(request), Calendar.getInstance().get(Calendar.YEAR));
    request.setAttribute("selectedYear", selectedYear);
    final Month selectedMonth = findMonthOrNull(getSelectedMonth(request));
    if (Objects.nonNull(selectedMonth)) {
        request.setAttribute("selectedMonth", selectedMonth);
    }
    request.setAttribute("months", months(Integer.parseInt(selectedYear), si));
}
Also used : SupplementaryInformation(uk.nhs.digital.website.beans.SupplementaryInformation) Month(java.time.Month) SupplementaryInformationHub(uk.nhs.digital.website.beans.SupplementaryInformationHub) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 2 with SupplementaryInformation

use of uk.nhs.digital.website.beans.SupplementaryInformation in project hippo by NHS-digital-website.

the class DocumentUtilsTest method ordersByPublishedDateMostRecentFirst.

@Test
public void ordersByPublishedDateMostRecentFirst() {
    final SupplementaryInformation supp1 = Mockito.mock(SupplementaryInformation.class);
    final SupplementaryInformation supp2 = Mockito.mock(SupplementaryInformation.class);
    final SupplementaryInformation supp3 = Mockito.mock(SupplementaryInformation.class);
    given(supp1.getPublishedDate()).willReturn(new GregorianCalendar(2019, Calendar.JANUARY, 10));
    given(supp2.getPublishedDate()).willReturn(new GregorianCalendar(2020, Calendar.JANUARY, 10));
    given(supp3.getPublishedDate()).willReturn(new GregorianCalendar(2019, Calendar.JANUARY, 11));
    final List<SupplementaryInformation> sorted = DocumentUtils.getSortedSupplementaryInformation(Arrays.asList(supp1, supp2, supp3));
    assertEquals(supp2, sorted.get(0));
    assertEquals(supp3, sorted.get(1));
    assertEquals(supp1, sorted.get(2));
}
Also used : SupplementaryInformation(uk.nhs.digital.website.beans.SupplementaryInformation) Test(org.junit.Test)

Aggregations

SupplementaryInformation (uk.nhs.digital.website.beans.SupplementaryInformation)2 Month (java.time.Month)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 Test (org.junit.Test)1 SupplementaryInformationHub (uk.nhs.digital.website.beans.SupplementaryInformationHub)1