Search in sources :

Example 1 with ResourceCollection

use of org.onehippo.cms7.crisp.api.resource.ResourceCollection in project hippo by NHS-digital-website.

the class JobsFeedComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final JobsFeedComponentInfo paramInfo = getComponentParametersInfo(request);
    String button1Text = paramInfo.getButton1Text();
    String button1Url = paramInfo.getButton1Url();
    String button2Text = paramInfo.getButton2Text();
    String button2Url = paramInfo.getButton2Url();
    String feedHeader = paramInfo.getHeader();
    request.setAttribute("feedHeader", feedHeader);
    request.setAttribute("button1Text", button1Text);
    request.setAttribute("button2Text", button2Text);
    request.setAttribute("button1Url", button1Url);
    request.setAttribute("button2Url", button2Url);
    String feedUrl = paramInfo.getFeedMasterUri();
    String recordLimit = paramInfo.getNumToDisplay();
    String keywordRule = paramInfo.getKeywordRule();
    String keywords = paramInfo.getKeywords();
    StringBuilder queryString = new StringBuilder(feedUrl);
    queryString.append("?Format=xml");
    queryString.append("&recordLimit=" + (StringUtils.isNotBlank(recordLimit) ? recordLimit : 4));
    if (StringUtils.isNotBlank(keywords)) {
        queryString.append("&Keywords=" + keywords);
        queryString.append("&KeywordSearchType=" + (StringUtils.isNotBlank(keywordRule) ? keywordRule : "ALL"));
    }
    String postcode = paramInfo.getPostcode();
    if (StringUtils.isNotBlank(postcode)) {
        queryString.append("&Postcode=" + postcode);
        queryString.append("&Radius=30");
    }
    String vacancyType = paramInfo.getVacancyType();
    if ("Internal only".equalsIgnoreCase(vacancyType)) {
        queryString.append("&IntApp=true");
    } else if ("External only".equalsIgnoreCase(vacancyType)) {
        queryString.append("&ExtApp=true&IntApp=false");
    } else {
        queryString.append("&ExtApp=true&IntApp=true");
    }
    ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
    Resource data = broker.findResources("eployApi", queryString.toString());
    ResourceCollection vacancies = data.getChildren();
    List<JobDetails> jobDetails = new ArrayList<>();
    for (Resource vacancy : vacancies.getCollection()) {
        JobDetails jobDetail = new JobDetails();
        String title = (String) ((Resource) vacancy.getValueMap().get("Title")).getDefaultValue();
        String location = (String) ((Resource) vacancy.getValueMap().get("Location")).getDefaultValue();
        String displaySalary = (String) ((Resource) vacancy.getValueMap().get("DisplaySalary")).getDefaultValue();
        String link = (String) ((Resource) vacancy.getValueMap().get("Link")).getDefaultValue();
        jobDetail.setTitle(title);
        jobDetail.setLocation(location);
        jobDetail.setSalary(displaySalary);
        jobDetail.setLink(link);
        jobDetails.add(jobDetail);
    }
    request.setAttribute("jobList", jobDetails);
}
Also used : Resource(org.onehippo.cms7.crisp.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) JobDetails(uk.nhs.digital.model.JobDetails) JobsFeedComponentInfo(uk.nhs.digital.common.components.info.JobsFeedComponentInfo) ResourceCollection(org.onehippo.cms7.crisp.api.resource.ResourceCollection)

Aggregations

ArrayList (java.util.ArrayList)1 ResourceServiceBroker (org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker)1 Resource (org.onehippo.cms7.crisp.api.resource.Resource)1 ResourceCollection (org.onehippo.cms7.crisp.api.resource.ResourceCollection)1 JobsFeedComponentInfo (uk.nhs.digital.common.components.info.JobsFeedComponentInfo)1 JobDetails (uk.nhs.digital.model.JobDetails)1