Search in sources :

Example 1 with ResourceServiceBroker

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

the class ReCaptchaValidationPlugin method validateReCaptcha.

private Resource validateReCaptcha(String gReCaptchaResponseCode, String recaptchaSecret) throws MissingResourceException {
    Resource resource = null;
    final Map<String, Object> pathVars = new HashMap<>();
    pathVars.put("secret", recaptchaSecret);
    pathVars.put("response", gReCaptchaResponseCode);
    final ResourceServiceBroker resourceServiceBroker = CrispHstServices.getDefaultResourceServiceBroker(getComponentManager());
    if (Objects.isNull(resourceServiceBroker)) {
        throw new MissingResourceException("The CRISP Resource Service Broker is null!", "ResourceServiceBroker", "GoogleReCaptchaResourceResolver");
    } else {
        try {
            resource = resourceServiceBroker.resolve("googleReCaptchaResourceResolver", "/recaptcha/api/siteverify?secret={secret}&response={response}", pathVars);
        } catch (Exception e) {
            log.warn("Failed to find resources from '{}' resource space for ReCaptcha validation, '{}'. The message '{}'", "googleReCaptchaResourceResolver", "/recaptcha/api/siteverify/", e.getMessage(), e);
        }
    }
    return resource;
}
Also used : HashMap(java.util.HashMap) MissingResourceException(java.util.MissingResourceException) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) MissingResourceException(java.util.MissingResourceException)

Example 2 with ResourceServiceBroker

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

the class SubscriptionResource method subscribe.

public String subscribe(final String emailAddress, final List<String> topicCodes) {
    final Subscriber subscriber = SubscriberFactory.create(emailAddress, topicCodes);
    try {
        final ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
        final Map<String, Object> pathVars = new HashMap<>();
        pathVars.put("account", ACCOUNT);
        final ExchangeHint exchangeHint = ExchangeHintBuilder.create().methodName("POST").requestHeader("Content-Type", "application/xml").requestBody(XML_MAPPER.writeValueAsString(subscriber)).build();
        final Resource resource = broker.resolve("govDeliveryApi", URL, pathVars, exchangeHint);
        return (String) ((Resource) resource.getValueMap().get("to-param")).getDefaultValue();
    } catch (final JsonProcessingException e) {
        LOGGER.error("Encountered exception when serializing XML.", e);
    } catch (final ResourceException e) {
        LOGGER.error("Encountered communication exception when calling the API.", e);
    } catch (final Exception e) {
        LOGGER.error("Encountered unexpected exception when subscribing user.", e);
    }
    return null;
}
Also used : Subscriber(uk.nhs.digital.common.forms.model.Subscriber) HashMap(java.util.HashMap) ExchangeHint(org.onehippo.cms7.crisp.api.exchange.ExchangeHint) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceException(org.onehippo.cms7.crisp.api.resource.ResourceException) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ResourceException(org.onehippo.cms7.crisp.api.resource.ResourceException)

Example 3 with ResourceServiceBroker

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

the class RemoteContentService method getContentObjectFrom.

@HystrixCommand(fallbackMethod = "getReliableFallBackObject", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "400") })
public Object getContentObjectFrom(URL url, String resourceResolver, Class type) {
    LOGGER.debug("Inside RemoteContentService ");
    ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
    LOGGER.debug("Inside RemoteContentService broker  is " + broker + " URL is " + url);
    Resource r = broker.resolve(resourceResolver, url.toString());
    LOGGER.debug("Inside RemoteContentService Resource r is " + r);
    return broker.getResourceBeanMapper(resourceResolver).map(r, type);
}
Also used : Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) HystrixCommand(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)

Example 4 with ResourceServiceBroker

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

the class ApiSpecSyncFromApigeeJob method execute.

// @formatter:on
@Override
public void execute(final RepositoryJobExecutionContext context) {
    log.debug("API Specifications sync from Apigee: start.");
    Session session = null;
    try {
        final String apigeeAllSpecUrl = requireParameter(APIGEE_ALL_SPEC_URL, System.getProperty(APIGEE_ALL_SPEC_URL));
        final String apigeeSingleSpecUrl = requireParameter(APIGEE_SINGLE_SPEC_URL, System.getProperty(APIGEE_SINGLE_SPEC_URL));
        final ResourceServiceBroker resourceServiceBroker = resourceServiceBroker();
        final ApigeeService apigeeService = new ApigeeService(resourceServiceBroker, apigeeAllSpecUrl, apigeeSingleSpecUrl);
        session = context.createSystemSession();
        final ApiSpecificationPublicationService apiSpecificationPublicationService = new ApiSpecificationPublicationService(apigeeService, new ApiSpecificationDocumentJcrRepository(session), new ApiSpecificationImportImportMetadataJcrRepository(session));
        apiSpecificationPublicationService.syncEligibleSpecifications();
        log.debug("API Specifications sync from Apigee: done.");
    } catch (final Exception ex) {
        log.error("Failed to sync specifications from Apigee.", ex);
    } finally {
        Optional.ofNullable(session).ifPresent(Session::logout);
    }
}
Also used : ApigeeService(uk.nhs.digital.apispecs.apigee.ApigeeService) ApiSpecificationImportImportMetadataJcrRepository(uk.nhs.digital.apispecs.jcr.ApiSpecificationImportImportMetadataJcrRepository) ApiSpecificationDocumentJcrRepository(uk.nhs.digital.apispecs.jcr.ApiSpecificationDocumentJcrRepository) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) Session(javax.jcr.Session) ApiSpecificationPublicationService(uk.nhs.digital.apispecs.ApiSpecificationPublicationService)

Example 5 with ResourceServiceBroker

use of org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker 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

ResourceServiceBroker (org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker)8 Resource (org.onehippo.cms7.crisp.api.resource.Resource)5 HashMap (java.util.HashMap)4 Before (org.junit.Before)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 ArrayList (java.util.ArrayList)1 MissingResourceException (java.util.MissingResourceException)1 Session (javax.jcr.Session)1 ResourceCollection (org.onehippo.cms7.crisp.api.resource.ResourceCollection)1 SimpleJacksonRestTemplateResourceResolver (org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver)1 MockJdomResourceResolverAdapter (org.onehippo.cms7.crisp.mock.resource.MockJdomResourceResolverAdapter)1 ApiSpecificationPublicationService (uk.nhs.digital.apispecs.ApiSpecificationPublicationService)1 ApigeeService (uk.nhs.digital.apispecs.apigee.ApigeeService)1 ApiSpecificationDocumentJcrRepository (uk.nhs.digital.apispecs.jcr.ApiSpecificationDocumentJcrRepository)1 ApiSpecificationImportImportMetadataJcrRepository (uk.nhs.digital.apispecs.jcr.ApiSpecificationImportImportMetadataJcrRepository)1