Search in sources :

Example 6 with Resource

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

Example 7 with Resource

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;
}
Also used : HashMap(java.util.HashMap) ApplicationSecrets(uk.nhs.digital.toolbox.secrets.ApplicationSecrets) MissingResourceException(java.util.MissingResourceException) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ErrorMessage(com.onehippo.cms7.eforms.hst.model.ErrorMessage)

Example 8 with Resource

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);
}
Also used : MockJdomResourceResolverAdapter(org.onehippo.cms7.crisp.mock.resource.MockJdomResourceResolverAdapter) MockResourceServiceBroker(org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker) HashMap(java.util.HashMap) Resource(org.onehippo.cms7.crisp.api.resource.Resource) MockResourceServiceBroker(org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) ExchangeHint(org.onehippo.cms7.crisp.api.exchange.ExchangeHint) ResourceResolver(org.onehippo.cms7.crisp.api.resource.ResourceResolver) ResourceException(org.onehippo.cms7.crisp.api.resource.ResourceException) Before(org.junit.Before)

Example 9 with Resource

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);
}
Also used : SimpleJacksonRestTemplateResourceResolver(org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver) MockResourceServiceBroker(org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ResourceResolver(org.onehippo.cms7.crisp.api.resource.ResourceResolver) SimpleJacksonRestTemplateResourceResolver(org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver)

Aggregations

Resource (org.onehippo.cms7.crisp.api.resource.Resource)7 ResourceServiceBroker (org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker)5 HashMap (java.util.HashMap)4 MissingResourceException (java.util.MissingResourceException)2 ExchangeHint (org.onehippo.cms7.crisp.api.exchange.ExchangeHint)2 ResourceException (org.onehippo.cms7.crisp.api.resource.ResourceException)2 ResourceResolver (org.onehippo.cms7.crisp.api.resource.ResourceResolver)2 MockResourceServiceBroker (org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HystrixCommand (com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)1 ErrorMessage (com.onehippo.cms7.eforms.hst.model.ErrorMessage)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1 ResourceCollection (org.onehippo.cms7.crisp.api.resource.ResourceCollection)1 JacksonResource (org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource)1 SimpleJacksonRestTemplateResourceResolver (org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver)1 MockJdomResourceResolverAdapter (org.onehippo.cms7.crisp.mock.resource.MockJdomResourceResolverAdapter)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1