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