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);
}
Aggregations