Search in sources :

Example 6 with ResourceServiceBroker

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

the class PostcodeRule method validate.

@Override
public boolean validate(Map<String, String[]> map) {
    String postcode = map.get(map.keySet().stream().findFirst().get())[0];
    String postcodeUrl = null;
    if (StringUtils.isNotBlank(postcode)) {
        if (postcode.length() >= 5) {
            postcodeUrl = postcode.replaceAll("\\s+", "").toUpperCase();
            postcodeUrl = postcodeUrl.substring(0, postcodeUrl.length() - 3) + "/" + postcodeUrl.substring(postcodeUrl.length() - 3);
            ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
            try {
                broker.findResources("postcodeApi", postcodeUrl + ".json");
            } catch (Exception e) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker)

Example 7 with ResourceServiceBroker

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

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

the class RemoteContentServiceTest method before.

@Before
public void before() {
    Map<String, ResourceResolver> resourceResolverMap = new HashMap<>();
    resourceResolverMap.put("testResourceResolver", testResourceResolver);
    ResourceServiceBroker mockBroker = new MockResourceServiceBroker(resourceResolverMap);
    MockCrispHstServices.setDefaultResourceServiceBroker(mockBroker);
}
Also used : MockResourceServiceBroker(org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker) HashMap(java.util.HashMap) ResourceResolver(org.onehippo.cms7.crisp.api.resource.ResourceResolver) SimpleJacksonRestTemplateResourceResolver(org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver) MockResourceServiceBroker(org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) Before(org.junit.Before)

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