New KOBI documentation is available: https://adeo-ccdp.gitbook.io/kobi/

Requirements

  • Maven
  • Java 8
  • Spring Context
  • Spring WebFlux

Dependency

1
2
3
4
5
<dependency>
    <groupId>io.kobi</groupId>
    <artifactId>kobi-shaper-client</artifactId>
    <version>2.6.14</version>
</dependency>

Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
    "kobi.shaper.rest": {
        "base-url": "<Shaper rest url>",
        "headers": {
          "X-API-Key": "<Shaper rest API key>"
        },
        "max-connections": 100,
        "connect-timeout": 200,
        "timeout": 5000,
        "max-in-memory-size": 1048576,
        "keep-alive": true,
        "tcp-no-delay": true,
        "insecure": false
    },
    "resilience4j.circuitbreaker": {
        "configs": {
            "shaper": {
                <See resilience4j circuit breaker configuration>
            }
        }
    }
}
If the API key security is enable on the Shaper API, you need to set the “X-API-Key” header to be authorized with the right API Key.
If you are calling the API through a gateway, and you need to send custom headers you just have to set them into the headers' property as following:
“headers”: {
“a header”: “a header value”,
“another header”: “another header value”,
}
Note that in this case it’s the gateway which should set the “X-API-Key” header, so you don’t need to add it in your configuration.

Usage

In your Spring project, you need to allow Spring to scan the package “io.kobi.shaper.client”.
After that you can import the Shaper rest client bean (qualifier: io.kobi.shaper.ShaperRestClient, class: io.kobi.shaper.client.ShaperRestClient).
Then use it:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@Service
public class Service {

    private final ShaperRestClient shaperClient;

    /**
     * Constructor with bean injection.
     * @param shaperClient Shaper rest client bean
     **/
    public Service(final ShaperRestClient shaperClient) {
        this.shaperClient = shaperClient;
    }   

    /**
     * Gets the page for the given site identifier, resource type, resource identifier, page variation identifier and version.
     * @param siteId The site identifier.   
     * @param resourceType The resource type, "PAGE" if the page isn't link to an external resource.
     * @param resourceId The resource identifier, the page identifier if the page isn't link to an external resource.
     * @param pageVariationId The page variation identifier, null for the current page variation.
     * @param version The page version as "LIVE" or "DRAFT".
     * @return a resolved page resource mono.
     **/
    public Mono<ResolvedPageResource> getPage(final String siteId, final String resourceType, final String resourceId, final String pageVariationId, final String version) {
        return shaperClient.pages(siteId)
                           .types(resourceType)
                           .id(resourceId)
                           .getPage(pageVariationId, version, Expandable.PARENTS);
    }

    /**
     * Gets the tenant root page for the given site identifier, tenant identifier, page variation identifier and version.
     * @param siteId The site identifier.   
     * @param tenantId The tenant identifier.
     * @param pageVariationId The page variation identifier, null for the current page variation.
     * @param version The page version as "LIVE" or "DRAFT".
     * @return a resolved page resource mono.
     **/
    public Mono<ResolvedPageResource> getRootPage(final String siteId, final String tenantId, final String pageVariationId, final String version) {
            return shaperClient.pages(siteId)
                               .tenants(tenantId)
                               .get(pageVariationId, version, Expandable.PARENT);
    }

    /**
     * Gets the page model for the given site identifier and page model identifier.
     * @param siteId The site identifier.   
     * @param modelId The page model identifier.
     * @return a page model resource mono.
     **/
    public Mono<PageModelResource> getPageModel(final String siteId, final String modelId) {
        return shaperClient.models(siteId, modelId)
                           .get();
    }

    /**
     * Gets the page model for the given site identifier and resource type.
     * @param siteId The site identifier.   
     * @param resourceType The resource type.
     * @return a page model resource mono.
     **/
    public Mono<PageModelResource> getPageModelByResourceType(final String siteId, final String resourceType) {
        return shaperClient.resourcesTypes(siteId, resourceType)
                           .models()
                           .get();
    }
    
    /**
     * Gets the page model for the given site identifier, resource type and resource scope.
     * @param siteId The site identifier.   
     * @param resourceType The resource type.
     * @param resourceScope The resource scope.
     * @return a page model resource mono.
     **/
    public Mono<PageModelResource> getPageModelByResourceType(final String siteId, final String resourceType, final String resourceScope) {
        return shaperClient.resourcesTypes(siteId, resourceType)
                           .models()
                           .get(resourceScope);
    }

    /**
     * Gets the page model for the given site identifier, resource type and resource scope.
     * @param siteId The site identifier.   
     * @param applicationContext The application context.
     * @return a page model resource mono.
     **/
    public Mono<PageModelResource> getPageModelByApplicationContext(final String siteId, final String applicationContext) {
        return shaperClient.applications(siteId, applicationContext)
                           .models()
                           .get();
    }

    /**
     * Gets the page model for the given site identifier, resource type and resource scope.
     * @param siteId The site identifier.   
     * @param applicationContext The application context.
     * @param version The page version as "LIVE" or "DRAFT".
     * @return a page model resource mono.
     **/
    public Mono<PageModelResource> getPageModelByApplicationContext(final String siteId, final String applicationContext, final String version) {
        return shaperClient.applications(siteId, applicationContext)
                           .models()
                           .get(version);
    }


}
What's on this Page