use of org.onehippo.cms7.crisp.api.resource.Resource 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);
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class ReCaptchaValidationPlugin method validate.
@Override
public Map<String, ErrorMessage> validate(HstRequest request, HstResponse response, ComponentConfiguration config, FormBean bean, Form form, FormMap map) {
final String reCaptchaSiteKey = ((ApplicationSecrets) getComponentManager().getComponent("applicationSecrets")).getValue("GOOGLE_CAPTCHA_SITE_KEY");
final String reCaptchaSecretKey = ((ApplicationSecrets) getComponentManager().getComponent("applicationSecrets")).getValue("GOOGLE_CAPTCHA_SECRET");
final Map<String, ErrorMessage> errors = new HashMap<>();
final String clientReCaptchaResponseString = request.getParameter("gRecaptchaResponse");
if (map.getFormMap().size() == 0 || clientReCaptchaResponseString == null && "RENDER_PHASE".equals(request.getLifecyclePhase()) && map.getFormMap().get("eforms_process_done") != null) {
return errors;
}
try {
// to validate response with Google ReCaptcha API
log.debug("***************************** Validate ReCaptcha *****************************");
log.debug("Recaptcha Site Key: " + reCaptchaSiteKey);
log.debug("Recaptcha Secret Key: " + ApplicationSecrets.mask(reCaptchaSecretKey));
log.debug("Recaptcha Response: " + clientReCaptchaResponseString);
Resource gRecaptchaResponse = validateReCaptcha(clientReCaptchaResponseString, reCaptchaSecretKey);
if (gRecaptchaResponse != null) {
if ((boolean) gRecaptchaResponse.getValue("success")) {
log.debug("ReCaptcha succeeded!");
log.debug("ReCaptcha Challenge TTL: " + gRecaptchaResponse.getValue("challenge_ts"));
log.debug("ReCaptcha Hostname: " + gRecaptchaResponse.getValue("hostname"));
} else {
String errorList = getReCaptchaErrors(gRecaptchaResponse);
log.debug("ReCaptcha Failed:" + errorList);
errors.put("ReCaptcha Validation", new ErrorMessage("ReCaptcha validation failed", errorList));
}
}
} catch (MissingResourceException e) {
log.warn(e.getMessage(), e.getClassName(), e.getKey(), e);
}
log.debug("ReCaptcha Error count is: " + errors.size());
log.debug("**************************** End Validate ReCaptcha ****************************");
return errors;
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class SubscriptionResourceTest method setUp.
@Before
public void setUp() {
final Map<String, ResourceResolver> resourceResolverMap = new HashMap<>();
resourceResolverMap.put("govDeliveryApi", new MockJdomResourceResolverAdapter() {
@Override
public Resource resolve(String absPath, Map<String, Object> pathVariables, ExchangeHint exchangeHint) throws ResourceException {
return urlToResource(SubscriptionResourceTest.class.getResource("/subscriber-output.xml"));
}
});
final ResourceServiceBroker mockBroker = new MockResourceServiceBroker(resourceResolverMap);
MockCrispHstServices.setDefaultResourceServiceBroker(mockBroker);
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class ApiSpecSyncFromApigeeJobIntegrationTest method crispApiConfiguredForOAuth2.
private void crispApiConfiguredForOAuth2() {
crispApiSpringApplicationContextEnvironment = new MockEnvironment().withProperty(PARAM_APIGEE_RESOURCES_SPECS_ALL_URL, apigeeAllSpecsUrl).withProperty(PARAM_APIGEE_OAUTH_TOKEN_URL, oauthTokenUrl).withProperty(PARAM_APIGEE_RESOURCES_SPECS_INDIVIDUAL_URL, apigeeSingleSpecUrlTemplate).withProperty(PARAM_APIGEE_OAUTH_USERNAME, OAUTH_USERNAME).withProperty(PARAM_APIGEE_OAUTH_PASSWORD, OAUTH_PASSWORD).withProperty(PARAM_APIGEE_OAUTH_BASICAUTHTOKEN, OAUTH_BASIC_AUTH_TOKEN).withProperty(PARAM_APIGEE_OAUTH_OTPKEY, OAUTH_OTP_KEY);
// See https://documentation.bloomreach.com/14/library/concepts/crisp-api/unit-testing.html
final ClassPathXmlApplicationContext crispApiSpringApplicationContext = new ClassPathXmlApplicationContext();
crispApiSpringApplicationContext.setEnvironment(crispApiSpringApplicationContextEnvironment);
crispApiSpringApplicationContext.setConfigLocations(testDataFileLocation("crisp-spring-context-properties-support.xml"), "/META-INF/hst-assembly/addon/crisp/overrides/custom-resource-resolvers.xml");
crispApiSpringApplicationContext.refresh();
final String apigeeManagementApiCrispApiNamespace = "apigeeManagementApi";
final SimpleJacksonRestTemplateResourceResolver simpleJacksonRestTemplateResourceResolver = crispApiSpringApplicationContext.getBean(apigeeManagementApiCrispApiNamespace, SimpleJacksonRestTemplateResourceResolver.class);
final ImmutableMap<String, ResourceResolver> resourceResolverMap = ImmutableMap.<String, ResourceResolver>builder().put(apigeeManagementApiCrispApiNamespace, simpleJacksonRestTemplateResourceResolver).build();
final MockResourceServiceBroker mockResourceServiceBroker = new MockResourceServiceBroker(resourceResolverMap);
MockCrispHstServices.setDefaultResourceServiceBroker(mockResourceServiceBroker);
}
Aggregations