/g' \
15 | | tee ${output}
16 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/rich/CDARichNode.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.rich;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * A leaf node of the rich text hierarchy.
7 | */
8 | public class CDARichNode implements Serializable {
9 | private String nodeType;
10 |
11 | /**
12 | * Get the original node type from the API response.
13 | * @return the node type (e.g., "embedded-entry-block", "embedded-entry-inline", etc.)
14 | */
15 | public String getNodeType() {
16 | return nodeType;
17 | }
18 |
19 | /**
20 | * Set the node type from the API response.
21 | * @param nodeType the original node type
22 | */
23 | public void setNodeType(String nodeType) {
24 | this.nodeType = nodeType;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/resources/demo/content_types_fake.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "fields": [
11 | {
12 | "id": "name",
13 | "name": "Name",
14 | "type": "Text"
15 | }
16 | ],
17 | "name": "Fake",
18 | "sys": {
19 | "space": {
20 | "sys": {
21 | "type": "Link",
22 | "linkType": "Space",
23 | "id": "cfexampleapi"
24 | }
25 | },
26 | "type": "ContentType",
27 | "id": "fake",
28 | "revision": 2,
29 | "createdAt": "2013-06-27T22:46:12.852Z",
30 | "updatedAt": "2013-09-02T13:14:47.863Z"
31 | }
32 | }
33 | ]
34 | }
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/Logger.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | /**
4 | * Custom logger interface, used for logging network traffic.
5 | */
6 | public interface Logger {
7 | /**
8 | * Determine the level of logging
9 | */
10 | enum Level {
11 | /**
12 | * Do not log anything.
13 | */
14 | NONE,
15 |
16 | /**
17 | * Do basic logging, not all requests will be logged.
18 | */
19 | BASIC,
20 |
21 | /**
22 | * Log all requests.
23 | */
24 | FULL
25 | }
26 |
27 | /**
28 | * Abstract method to be implemented by client.
29 | *
30 | * This method gets called, once an event needs to
31 | *
32 | * @param message to be delivered to the logger.
33 | */
34 | void log(String message);
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/resources/locales/space.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Space",
4 | "id": "7dh3w86is8ls"
5 | },
6 | "name": "Fallback Locales",
7 | "locales": [
8 | {
9 | "code": "default",
10 | "default": true,
11 | "name": "default locale",
12 | "fallbackCode": null
13 | },
14 | {
15 | "code": "first",
16 | "default": false,
17 | "name": "first locale",
18 | "fallbackCode": "inbetween"
19 | },
20 | {
21 | "code": "inbetween",
22 | "default": false,
23 | "name": "inbetween locale",
24 | "fallbackCode": "default"
25 | },
26 | {
27 | "code": "null",
28 | "default": false,
29 | "name": "locale with fallback set to null",
30 | "fallbackCode": null
31 | }
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/resources/locales_fallback/space.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Space",
4 | "id": "7dh3w86is8ls"
5 | },
6 | "name": "Fallback Locales",
7 | "locales": [
8 | {
9 | "code": "default",
10 | "default": true,
11 | "name": "default locale",
12 | "fallbackCode": null
13 | },
14 | {
15 | "code": "first",
16 | "default": false,
17 | "name": "first locale",
18 | "fallbackCode": "inbetween"
19 | },
20 | {
21 | "code": "inbetween",
22 | "default": false,
23 | "name": "inbetween locale",
24 | "fallbackCode": "default"
25 | },
26 | {
27 | "code": "null",
28 | "default": false,
29 | "name": "locale with fallback set to null",
30 | "fallbackCode": null
31 | }
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/rich/CDARichHeading.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.rich;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Defines a headline of the text.
7 | *
8 | * Can have an arbitrary level assigned, but useful probably between 1 and 6.
9 | */
10 | public class CDARichHeading extends CDARichBlock implements Serializable {
11 | private final int level;
12 |
13 | /**
14 | * Create a heading block, describing a level elements deep nested heading.
15 | *
16 | * @param level a number indicating the level of this heading.
17 | */
18 | public CDARichHeading(int level) {
19 | this.level = level;
20 | }
21 |
22 | /**
23 | * @return the current nesting level of this heading.
24 | */
25 | public int getLevel() {
26 | return level;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/.github/workflows/codeql.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: "CodeQL Scan for GitHub Actions Workflows"
3 |
4 | on:
5 | push:
6 | branches: [master]
7 | paths: [".github/workflows/**"]
8 | pull_request:
9 | branches: [master]
10 | paths: [".github/workflows/**"]
11 |
12 | jobs:
13 | analyze:
14 | name: Analyze GitHub Actions workflows
15 | runs-on: ubuntu-latest
16 | permissions:
17 | actions: read
18 | contents: read
19 | security-events: write
20 |
21 | steps:
22 | - uses: actions/checkout@v4
23 |
24 | - name: Initialize CodeQL
25 | uses: github/codeql-action/init@v3
26 | with:
27 | languages: actions
28 |
29 | - name: Run CodeQL Analysis
30 | uses: github/codeql-action/analyze@v3
31 | with:
32 | category: actions
33 |
--------------------------------------------------------------------------------
/src/test/resources/demo/entries_nofields.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": "cfexampleapi"
16 | }
17 | },
18 | "type": "Entry",
19 | "contentType": {
20 | "sys": {
21 | "type": "Link",
22 | "linkType": "ContentType",
23 | "id": "cat"
24 | }
25 | },
26 | "id": "foo",
27 | "revision": 5,
28 | "createdAt": "2013-06-27T22:46:19.513Z",
29 | "updatedAt": "2013-09-04T09:19:39.027Z",
30 | "locale": "en-US"
31 | }
32 | }
33 | ]
34 | }
--------------------------------------------------------------------------------
/src/test/resources/cda/content_types_bar.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "name": "bar",
11 | "fields": [
12 | {
13 | "name": "name",
14 | "id": "name",
15 | "type": "Text"
16 | }
17 | ],
18 | "displayField": "name",
19 | "sys": {
20 | "space": {
21 | "sys": {
22 | "type": "Link",
23 | "linkType": "Space",
24 | "id": "amjnj7ldpank"
25 | }
26 | },
27 | "type": "ContentType",
28 | "id": "3lYaFZKDgQCUwWy6uEoQYi",
29 | "revision": 1,
30 | "createdAt": "2015-07-06T14:55:25.655Z",
31 | "updatedAt": "2015-07-06T14:55:25.655Z"
32 | }
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/src/test/resources/cda/content_types_foo.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "name": "foo",
11 | "fields": [
12 | {
13 | "name": "link",
14 | "id": "link",
15 | "type": "Link",
16 | "linkType": "Entry"
17 | }
18 | ],
19 | "sys": {
20 | "space": {
21 | "sys": {
22 | "type": "Link",
23 | "linkType": "Space",
24 | "id": "amjnj7ldpank"
25 | }
26 | },
27 | "type": "ContentType",
28 | "id": "3XN5y2aye44m0Yioko6K6k",
29 | "revision": 1,
30 | "createdAt": "2015-07-06T14:55:11.166Z",
31 | "updatedAt": "2015-07-06T14:55:11.166Z"
32 | }
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/src/test/resources/demo/entries_fake.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "fields": {
11 | },
12 | "sys": {
13 | "space": {
14 | "sys": {
15 | "type": "Link",
16 | "linkType": "Space",
17 | "id": "cfexampleapi"
18 | }
19 | },
20 | "type": "Entry",
21 | "contentType": {
22 | "sys": {
23 | "type": "Link",
24 | "linkType": "ContentType",
25 | "id": "foo"
26 | }
27 | },
28 | "id": "bar",
29 | "revision": 8,
30 | "createdAt": "2013-06-27T22:46:20.171Z",
31 | "updatedAt": "2013-11-18T15:58:02.018Z",
32 | "locale": "en-US"
33 | }
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.Locale;
4 |
5 | /**
6 | * RuntimeException indicating a resource was not found on Contentful.
7 | */
8 | public class CDAResourceNotFoundException extends RuntimeException {
9 |
10 | private static final long serialVersionUID = -7419778969492055048L;
11 |
12 | /**
13 | * Create a new exception
14 | *
15 | * @param resourceType the type of the resource not found (Entry,Asset,Space)
16 | * @param resourceId the actual id of the resource not found.
17 | */
18 | public CDAResourceNotFoundException(
19 | Class extends CDAResource> resourceType,
20 | String resourceId) {
21 | super(String.format(
22 | Locale.getDefault(), "Could not find id '%s' of type '%s'.",
23 | resourceId,
24 | resourceType.getSimpleName())
25 | );
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/java/com/contentful/java/cda/lib/TestResponse.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.lib;
2 |
3 | import okhttp3.Headers;
4 |
5 | public class TestResponse {
6 | private final int code;
7 | private final String fileName;
8 | private final Headers headers;
9 |
10 | TestResponse(int code, String fileName, String[] headers) {
11 | this.code = code;
12 | this.fileName = fileName;
13 | this.headers = createHeaders(headers);
14 | }
15 |
16 | private Headers createHeaders(String[] headers) {
17 | final Headers.Builder builder = new Headers.Builder();
18 | for (final String line : headers) {
19 | builder.add(line);
20 | }
21 | return builder.build();
22 | }
23 |
24 | public int getCode() {
25 | return code;
26 | }
27 |
28 | public String getFileName() {
29 | return fileName;
30 | }
31 |
32 | public Headers headers() {
33 | return headers;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/Constants.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.Locale;
4 |
5 | /**
6 | * This class holds specific constants, used throughout the sdk, not accessible by mere mortals.
7 | */
8 | class Constants {
9 | static final Locale LOCALE = Locale.US;
10 |
11 | static final String SCHEME = "https";
12 |
13 | static final String ENDPOINT_PREVIEW = SCHEME + "://preview.contentful.com/";
14 |
15 | static final String ENDPOINT_PROD = SCHEME + "://cdn.contentful.com/";
16 |
17 | static final String PATH_ASSETS = "assets";
18 |
19 | static final String PATH_CONTENT_TYPES = "content_types";
20 |
21 | static final String PATH_ENTRIES = "entries";
22 |
23 | static final String PATH_LOCALES = "locales";
24 |
25 | static final String PATH_TAGS = "tags";
26 |
27 | static final String PATH_TAXONOMY_CONCEPTS = "taxonomy/concepts";
28 |
29 | static final String DEFAULT_ENVIRONMENT = "master";
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/ArrayResource.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | /**
7 | * An abstraction of CDAResources combined into one array.
8 | *
9 | * @see CDAResource
10 | */
11 | public abstract class ArrayResource extends CDAResource {
12 | private static final long serialVersionUID = -2702554830040250962L;
13 | List items;
14 |
15 | Map assets;
16 |
17 | Map entries;
18 |
19 | /**
20 | * @return items in this resource.
21 | */
22 | public List items() {
23 | return items;
24 | }
25 |
26 | /**
27 | * @return assets mapped by asset id (includes linked resources).
28 | */
29 | public Map assets() {
30 | return assets;
31 | }
32 |
33 | /**
34 | * @return entries mapped by entry id (includes linked resources).
35 | */
36 | public Map entries() {
37 | return entries;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/com/contentful/java/cda/lib/TestCallback.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.lib;
2 |
3 | import com.contentful.java.cda.CDACallback;
4 | import com.contentful.java.cda.CDAResource;
5 |
6 | import java.util.concurrent.CountDownLatch;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | public class TestCallback extends CDACallback {
10 | private T result;
11 |
12 | private Throwable error;
13 |
14 | final CountDownLatch latch = new CountDownLatch(1);
15 |
16 | @Override protected void onSuccess(T result) {
17 | this.result = result;
18 | latch.countDown();
19 | }
20 |
21 | @Override protected void onFailure(Throwable error) {
22 | this.error = error;
23 | latch.countDown();
24 | }
25 |
26 | public TestCallback await() throws InterruptedException {
27 | latch.await(1, TimeUnit.SECONDS);
28 | return this;
29 | }
30 |
31 | public T result() {
32 | return result;
33 | }
34 |
35 | public Throwable error() {
36 | return error;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/resources/demo/assets_no_image.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 6,
6 | "skip": 0,
7 | "limit": 1,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": "arqlnkt58eul"
16 | }
17 | },
18 | "id": "6OpsQmtnl6uYyeUmkOiYYq",
19 | "type": "Asset",
20 | "createdAt": "2016-07-29T14:04:28.343Z",
21 | "updatedAt": "2016-07-29T14:04:28.343Z",
22 | "revision": 1,
23 | "locale": "en-US"
24 | },
25 | "fields": {
26 | "title": "budah",
27 | "file": {
28 | "url": "//assets.contentful.com/arqlnkt58eul/6OpsQmtnl6uYyeUmkOiYYq/e4156f9d089bd539fd482554945517e4/budah.obj",
29 | "details": {
30 | "size": 932240
31 | },
32 | "fileName": "budah-small.obj",
33 | "contentType": "application/x-tgif"
34 | }
35 | }
36 | }
37 | ]
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/SynchronizedSpace.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.Set;
4 |
5 | /**
6 | * Represents results for synchronization via the Sync API.
7 | */
8 | public class SynchronizedSpace extends ArrayResource {
9 | private static final long serialVersionUID = 8618757744312417604L;
10 | String nextPageUrl;
11 |
12 | String nextSyncUrl;
13 |
14 | Set deletedAssets;
15 |
16 | Set deletedEntries;
17 |
18 | /**
19 | * @return url to the next sync.
20 | */
21 | public String nextSyncUrl() {
22 | return nextSyncUrl;
23 | }
24 |
25 | /**
26 | * @return url of next page, containing more data.
27 | */
28 | String nextPageUrl() {
29 | return nextPageUrl;
30 | }
31 |
32 | /**
33 | * @return deleted asset ids.
34 | */
35 | public Set deletedAssets() {
36 | return deletedAssets;
37 | }
38 |
39 | /**
40 | * @return deleted entry ids.
41 | */
42 | public Set deletedEntries() {
43 | return deletedEntries;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/resources/demo/assets_jake.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "fields": {
11 | "title": "Jake",
12 | "file": {
13 | "fileName": "jake.png",
14 | "contentType": "image/png",
15 | "details": {
16 | "image": {
17 | "width": 100,
18 | "height": 161
19 | },
20 | "size": 20480
21 | },
22 | "url": "//images.contentful.com/cfexampleapi/4hlteQAXS8iS0YCMU6QMWg/2a4d826144f014109364ccf5c891d2dd/jake.png"
23 | }
24 | },
25 | "sys": {
26 | "space": {
27 | "sys": {
28 | "type": "Link",
29 | "linkType": "Space",
30 | "id": "cfexampleapi"
31 | }
32 | },
33 | "type": "Asset",
34 | "id": "jake",
35 | "revision": 2,
36 | "createdAt": "2013-09-02T14:56:34.260Z",
37 | "updatedAt": "2013-09-02T15:22:39.466Z",
38 | "locale": "en-US"
39 | }
40 | }
41 | ]
42 | }
--------------------------------------------------------------------------------
/src/test/resources/demo/sync_initial_p1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "items": [
6 | {
7 | "sys": {
8 | "space": {
9 | "sys": {
10 | "type": "Link",
11 | "linkType": "Space",
12 | "id": "cfexampleapi"
13 | }
14 | },
15 | "type": "Entry",
16 | "contentType": {
17 | "sys": {
18 | "type": "Link",
19 | "linkType": "ContentType",
20 | "id": "1t9IbcfdCk6m04uISSsaIK"
21 | }
22 | },
23 | "id": "5ETMRzkl9KM4omyMwKAOki",
24 | "revision": 3,
25 | "createdAt": "2014-02-21T13:42:57.752Z",
26 | "updatedAt": "2014-08-23T14:42:35.207Z"
27 | },
28 | "fields": {
29 | "name": {
30 | "en-US": "London"
31 | },
32 | "center": {
33 | "en-US": {
34 | "lat": 51.508515,
35 | "lon": -0.12548719999995228
36 | }
37 | }
38 | }
39 | }
40 | ],
41 | "nextPageUrl": "http://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=foo"
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/rich/CDARichList.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.rich;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Parent class for all list classes
7 | */
8 | public class CDARichList extends CDARichBlock implements Serializable {
9 | final CharSequence decoration;
10 |
11 | /**
12 | * Create a list of the given symbols per nesting level
13 | *
14 | * @param decoration a symbol to be added for differentiation. Can be [1,A,a,I,i] for
15 | * prefixing each node with an arabic number (1., 2., …), a capitalized letter
16 | * (A., B., …), a lowercase letter (a., b., …) or roman numerals in capital
17 | * (I, II, …) or non capitalized form (i, ii, …). Alternatively unordered
18 | * symbols can be used: `*` for bullets, `-` for dashes and `⭐` for stars etc.
19 | */
20 | public CDARichList(CharSequence decoration) {
21 | this.decoration = decoration;
22 | }
23 |
24 | /**
25 | * @return decoration for this list.
26 | */
27 | public CharSequence getDecoration() {
28 | return decoration;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/resources/links/sync_empty_links.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "items": [
6 | {
7 | "sys": {
8 | "space": {
9 | "sys": {
10 | "type": "Link",
11 | "linkType": "Space",
12 | "id": "75oea9kejr52"
13 | }
14 | },
15 | "type": "Entry",
16 | "contentType": {
17 | "sys": {
18 | "type": "Link",
19 | "linkType": "ContentType",
20 | "id": "2s9novBkP2G0oasUaG8kCs"
21 | }
22 | },
23 | "id": "3vyEoAvlkk8yE4a8gCCkiu",
24 | "revision": 1,
25 | "createdAt": "2015-07-10T11:56:10.469Z",
26 | "updatedAt": "2015-07-10T11:56:10.469Z"
27 | },
28 | "fields": {
29 | "entry": {
30 | "en-US": null
31 | },
32 | "asset": {
33 | "en-US": null
34 | },
35 | "entries": {
36 | "en-US": []
37 | },
38 | "assets": {
39 | "en-US": []
40 | },
41 | "symbols": {
42 | "en-US": []
43 | }
44 | }
45 | }
46 | ]
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/resources/demo/sync_initial_preview_p1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "items": [
6 | {
7 | "sys": {
8 | "space": {
9 | "sys": {
10 | "type": "Link",
11 | "linkType": "Space",
12 | "id": "cfexampleapi"
13 | }
14 | },
15 | "type": "Entry",
16 | "contentType": {
17 | "sys": {
18 | "type": "Link",
19 | "linkType": "ContentType",
20 | "id": "1t9IbcfdCk6m04uISSsaIK"
21 | }
22 | },
23 | "id": "5ETMRzkl9KM4omyMwKAOki",
24 | "revision": 3,
25 | "createdAt": "2014-02-21T13:42:57.752Z",
26 | "updatedAt": "2014-08-23T14:42:35.207Z",
27 | "locale": "en-US"
28 | },
29 | "fields": {
30 | "name": {
31 | "en-US": "London"
32 | },
33 | "center": {
34 | "en-US": {
35 | "lat": 51.508515,
36 | "lon": -0.12548719999995228
37 | }
38 | }
39 | }
40 | }
41 | ],
42 | "nextPageUrl": "http://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=foo"
43 | }
44 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: java
3 |
4 | dist: trusty
5 |
6 | jdk:
7 | - oraclejdk8
8 | - openjdk8
9 |
10 | script:
11 | - mvn jacoco:prepare-agent test jacoco:report
12 |
13 | after_success:
14 | - .buildscript/deploy_snapshot.sh
15 | - .buildscript/integration_tests.sh
16 |
17 | env:
18 | global:
19 | - secure: ZkYu76rxDUUgoUSIz12CReNZHd2c5O2LBWCHnuQpqfJfcCXBr1J24F7WftiFXH+9Od43qHdF4hQ9Vy0vWEHSJ1hxZnCIy5yYsvqV4GJ94DIJhvNqmo48QPkA3tFUsqd48rEeBXMUsON30m89KDp1se2+l3UJaX+R27RUi47nraU=
20 | - secure: jKXD1hYVgJypaQHRSm4gshxMhB+T+UibaLDLCSfGWSaGzogDsWnPXf9qqG3jtozKHyH0BkANaaO6rRgNQNfbaklm4jopL1bdRkd47JO/nibNwuVcG07TQyCPQR6jv/WoRAkxXOGdMSwwS2+puM7FJqLarbzY7uBEJtNsZn5JT48=
21 | - secure: k2FkpJUg0FxfTeTadPc4xDA7xPmheZg6+u4DLn7kRP3bfHNG8lP57pYq/b1iDN+3VBXOkQtGttUyS1EExUubmeoQk4JwOUuePv6Ru24Mi5YoEdlkBzu2KZXV0o7aZZookYdsQTOQ/Jd576sn3oiXbAtW6n93h7h6SRCFIAG/nmc=
22 |
23 |
24 | branches:
25 | except:
26 | - gh-pages
27 |
28 | notifications:
29 | slack:
30 | - secure: Wq9lfTl+SSlfe+4OSLIINsUJZKEN0jYC07nI6PL1Sv4wZCUHmkvXNvsDj+0QLYkKkdEao2Yg3CLHSU5GdvZ2eQpY1mut6i+DxUHnICDQp6liS73UfW3KZIw7zkAMrlXYgVKtIUCUVjZFVyZ7AOxdt8Z6y5oKuXQiGC6h8vmi2Qk=
31 |
--------------------------------------------------------------------------------
/src/test/resources/locales/content_types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": "7dh3w86is8ls"
16 | }
17 | },
18 | "id": "sampleType",
19 | "type": "ContentType",
20 | "createdAt": "2016-06-21T08:53:55.767Z",
21 | "updatedAt": "2016-06-21T13:16:34.507Z",
22 | "revision": 5
23 | },
24 | "displayField": "title",
25 | "name": "Sample Type",
26 | "description": "af → zu-ZA →en-US*\nne-NP → NULL\nbs_BA⁰ → en-US*\n\n(→if not found, look at the following locale)\n(* = default locale)\n(⁰ = can include empty elements)\n(NULL = No default)",
27 | "fields": [
28 | {
29 | "id": "title",
30 | "name": "title",
31 | "type": "Symbol",
32 | "localized": true,
33 | "required": true,
34 | "disabled": false,
35 | "omitted": false
36 | }
37 | ]
38 | }
39 | ]
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/resources/locales_fallback/content_types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": "7dh3w86is8ls"
16 | }
17 | },
18 | "id": "sampleType",
19 | "type": "ContentType",
20 | "createdAt": "2016-06-21T08:53:55.767Z",
21 | "updatedAt": "2016-06-21T13:16:34.507Z",
22 | "revision": 5
23 | },
24 | "displayField": "title",
25 | "name": "Sample Type",
26 | "description": "af → zu-ZA →en-US*\nne-NP → NULL\nbs_BA⁰ → en-US*\n\n(→if not found, look at the following locale)\n(* = default locale)\n(⁰ = can include empty elements)\n(NULL = No default)",
27 | "fields": [
28 | {
29 | "id": "title",
30 | "name": "title",
31 | "type": "Symbol",
32 | "localized": true,
33 | "required": true,
34 | "disabled": false,
35 | "omitted": false
36 | }
37 | ]
38 | }
39 | ]
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAService.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import io.reactivex.rxjava3.core.Flowable;
4 | import retrofit2.Response;
5 | import retrofit2.http.GET;
6 | import retrofit2.http.Path;
7 | import retrofit2.http.Query;
8 | import retrofit2.http.QueryMap;
9 |
10 | import java.util.Map;
11 |
12 | interface CDAService {
13 | @GET("spaces/{space}")
14 | Flowable> space(
15 | @Path("space") String space);
16 |
17 | @GET("spaces/{space}/environments/{environment}/{type}")
18 | Flowable> array(
19 | @Path("space") String space,
20 | @Path("environment") String environment,
21 | @Path("type") String type,
22 | @QueryMap Map query);
23 |
24 | @GET("spaces/{space}/environments/{environment}/sync")
25 | Flowable> sync(
26 | @Path("space") String space,
27 | @Path("environment") String environment,
28 | @Query("initial") Boolean initial,
29 | @Query("sync_token") String syncToken,
30 | @Query("type") String type,
31 | @Query("content_type") String contentType,
32 | @Query("limit") Integer limit);
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDATaxonomyConcept.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import java.util.Map;
6 |
7 | public class CDATaxonomyConcept extends CDAResource {
8 | private static final long serialVersionUID = -2852530837647669036L;
9 |
10 | @SerializedName("prefLabel")
11 | protected Map prefLabel;
12 |
13 | /**
14 | * @return the preferred label map containing locale-to-label mappings.
15 | */
16 | public Map prefLabel() {
17 | return prefLabel;
18 | }
19 |
20 | /**
21 | * Get the preferred label for a specific locale.
22 | * @param locale the locale code (e.g., "en-US")
23 | * @return the label for the specified locale, or null if not found
24 | */
25 | public String getPrefLabel(String locale) {
26 | return prefLabel != null ? prefLabel.get(locale) : null;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "CDATaxonomyConcept{"
32 | + "attrs=" + attrs + '\''
33 | + ", prefLabel=" + prefLabel
34 | + '}';
35 | }
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/rich/CDARichText.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.rich;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | /**
8 | * A leaf element of the rich text node graph: Render a given text with the given markings.
9 | */
10 | public class CDARichText extends CDARichNode implements Serializable {
11 | private final List marks = new ArrayList<>();
12 | private final CharSequence text;
13 |
14 | /**
15 | * Create a text with the given marks
16 | *
17 | * @param text the text to be displayed
18 | * @param marks the marks to be used if any
19 | */
20 | public CDARichText(CharSequence text, List marks) {
21 | if (text == null) {
22 | text = "";
23 | }
24 |
25 | this.marks.addAll(marks);
26 | this.text = text;
27 | }
28 |
29 | /**
30 | * @return the text of this node.
31 | */
32 | public CharSequence getText() {
33 | return text;
34 | }
35 |
36 | /**
37 | * @return the marks of this text.
38 | *
39 | * @see CDARichMark.CDARichMarkBold
40 | */
41 | public List getMarks() {
42 | return marks;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/resources/shallow/types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "name": "foo",
11 | "fields": [
12 | {
13 | "name": "name",
14 | "id": "name",
15 | "type": "Symbol"
16 | },
17 | {
18 | "name": "image",
19 | "id": "image",
20 | "type": "Link",
21 | "linkType": "Asset"
22 | },
23 | {
24 | "name": "array",
25 | "id": "array",
26 | "type": "Array",
27 | "items": {
28 | "type": "Link",
29 | "linkType": "Asset"
30 | }
31 | }
32 | ],
33 | "description": "",
34 | "displayField": "name",
35 | "sys": {
36 | "space": {
37 | "sys": {
38 | "type": "Link",
39 | "linkType": "Space",
40 | "id": "tamu5dc7eas0"
41 | }
42 | },
43 | "type": "ContentType",
44 | "id": "15hKDLsTB28isKMAuaQy4A",
45 | "revision": 2,
46 | "createdAt": "2015-07-14T12:18:11.976Z",
47 | "updatedAt": "2015-07-14T12:57:51.262Z"
48 | }
49 | }
50 | ]
51 | }
--------------------------------------------------------------------------------
/proguard-cda.cfg:
--------------------------------------------------------------------------------
1 | # contentful.java
2 | -keep class com.contentful.java.cda.** { *; }
3 |
4 | # RxJava
5 | -dontwarn sun.misc.**
6 |
7 | -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
8 | long producerIndex;
9 | long consumerIndex;
10 | }
11 |
12 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
13 | rx.internal.util.atomic.LinkedQueueNode producerNode;
14 | }
15 |
16 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
17 | rx.internal.util.atomic.LinkedQueueNode consumerNode;
18 | }
19 |
20 | # OkHttp
21 | -keepattributes Signature
22 | -keepattributes *Annotation*
23 | -keep class okhttp3.** { *; }
24 | -keep interface okhttp3.** { *; }
25 | -dontwarn okhttp3.**
26 |
27 | # Retrofit
28 | -dontwarn retrofit2.**
29 | -keep class retrofit2.** { *; }
30 | -keepclasseswithmembers class * {
31 | @retrofit2.http.* ;
32 | }
33 |
34 | # Okio
35 | -dontwarn java.nio.file.*
36 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
37 | -dontwarn okio.**
38 |
39 | # Gson
40 | -keepattributes EnclosingMethod
41 | -keep class com.google.gson.stream.** { *; }
42 |
43 | # Android warnings
44 | -dontwarn android.support.v4.**
45 |
46 | # Kotlin
47 | -dontwarn org.junit.**
48 |
--------------------------------------------------------------------------------
/src/test/bash/rich_text-all.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | folder="../resources/$(basename $(echo $0) | cut -d'-' -f1)"
4 | file="$(basename $0 | cut -d'-' -f2)"
5 |
6 | mkdir --parent ${folder}
7 |
8 | for id in $(curl \
9 | --silent \
10 | -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \
11 | "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/environments/human-readable/entries?content_type=rich&fields.name\[match\]=simple&select=sys.id" \
12 | | grep id | cut -d'"' -f4); do
13 | name="$(curl \
14 | --silent \
15 | -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \
16 | "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/environments/human-readable/entries?content_type=rich&sys.id=${id}&select=fields.name" \
17 | | grep name | cut -d'"' -f4)"
18 | output="$(echo ${folder}/${name}.json)"
19 | echo ${name}
20 |
21 | curl --silent \
22 | -H "Authorization: Bearer ${RICH_TEXT_DELIVERY_TOKEN}" \
23 | "https://cdn.contentful.com/spaces/${RICH_TEXT_SPACE_ID}/environments/human-readable/entries?sys.id=${id}" \
24 | | sed 's/'${RICH_TEXT_SPACE_ID}'//g' \
25 | | sed 's/'${RICH_TEXT_DELIVERY_TOKEN}'//g' \
26 | | tee ${output}
27 | done
28 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/interceptor/ErrorInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.interceptor;
2 |
3 | import com.contentful.java.cda.CDAHttpException;
4 |
5 | import java.io.IOException;
6 |
7 | import okhttp3.Interceptor;
8 | import okhttp3.Request;
9 | import okhttp3.Response;
10 |
11 | /**
12 | * This interceptor will only be used for throwing an exception, once the server returns an error.
13 | */
14 | public class ErrorInterceptor implements Interceptor {
15 | private final boolean logSensitiveData;
16 |
17 | public ErrorInterceptor(boolean logSensitiveData) {
18 | this.logSensitiveData = logSensitiveData;
19 | }
20 |
21 |
22 | /**
23 | * Intercepts chain to check for unsuccessful requests.
24 | *
25 | * @param chain provided by the framework to check
26 | * @return the response if no error occurred
27 | * @throws IOException will get thrown if response code is unsuccessful
28 | */
29 | @Override public Response intercept(Chain chain) throws IOException {
30 | final Request request = chain.request();
31 | final Response response = chain.proceed(request);
32 |
33 | if (!response.isSuccessful()) {
34 | throw new CDAHttpException(request, response, logSensitiveData);
35 | }
36 |
37 | return response;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/resources/locales_fallback/fetch_all_locales.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 4,
6 | "skip": 0,
7 | "limit": 1000,
8 | "items": [
9 | {
10 | "code": "default",
11 | "default": true,
12 | "name": "default locale",
13 | "fallbackCode": null,
14 | "sys": {
15 | "id": "2oQPjMCL9bQkylziydLh57",
16 | "type": "Locale",
17 | "version": 1
18 | }
19 | },
20 | {
21 | "code": "first",
22 | "default": false,
23 | "name": "first locale",
24 | "fallbackCode": "inbetween",
25 | "sys": {
26 | "id": "2oQPjMCL9bQkylziydLh57",
27 | "type": "Locale",
28 | "version": 1
29 | }
30 | },
31 | {
32 | "code": "inbetween",
33 | "default": false,
34 | "name": "inbetween locale",
35 | "fallbackCode": "default",
36 | "sys": {
37 | "id": "2oQPjMCL9bQkylziydLh57",
38 | "type": "Locale",
39 | "version": 1
40 | }
41 | },
42 | {
43 | "code": "null",
44 | "default": false,
45 | "name": "locale with fallback set to null",
46 | "fallbackCode": null,
47 | "sys": {
48 | "id": "2oQPjMCL9bQkylziydLh57",
49 | "type": "Locale",
50 | "version": 1
51 | }
52 | }
53 | ]
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAArray.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Collection of CDA resources.
9 | */
10 | public class CDAArray extends ArrayResource {
11 | private static final long serialVersionUID = 6596224363025698245L;
12 | int total;
13 |
14 | int skip;
15 |
16 | int limit;
17 |
18 | Includes includes;
19 |
20 | private List errors;
21 |
22 | /**
23 | * @return total number of resources (linked excluded).
24 | */
25 | public int total() {
26 | return total;
27 | }
28 |
29 | /**
30 | * @return number of resources to be skipped.
31 | */
32 | public int skip() {
33 | return skip;
34 | }
35 |
36 | /**
37 | * @return limit attribute. How many max resources got requested?
38 | */
39 | public int limit() {
40 | return limit;
41 | }
42 |
43 | /**
44 | * @return a list of errors if any present
45 | */
46 | public List getErrors() {
47 | return errors;
48 | }
49 |
50 | public void setErrors(List errors) {
51 | this.errors = errors;
52 | }
53 |
54 | static class Includes {
55 | @SerializedName("Asset") List assets;
56 |
57 | @SerializedName("Entry") List entries;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/resources/demo/sync_initial_staging_p1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "items": [
6 | {
7 | "sys": {
8 | "space": {
9 | "sys": {
10 | "type": "Link",
11 | "linkType": "Space",
12 | "id": "cfexampleapi"
13 | }
14 | },
15 | "type": "Entry",
16 | "contentType": {
17 | "sys": {
18 | "type": "Link",
19 | "linkType": "ContentType",
20 | "id": "1t9IbcfdCk6m04uISSsaIK"
21 | }
22 | },
23 | "id": "5ETMRzkl9KM4omyMwKAOki",
24 | "revision": 3,
25 | "createdAt": "2014-02-21T13:42:57.752Z",
26 | "updatedAt": "2014-08-23T14:42:35.207Z",
27 | "environment": {
28 | "sys": {
29 | "id": "staging",
30 | "type": "Link",
31 | "linkType": "Environment"
32 | }
33 | },
34 | "locale": "en-US"
35 | },
36 | "fields": {
37 | "name": {
38 | "en-US": "London"
39 | },
40 | "center": {
41 | "en-US": {
42 | "lat": 51.508515,
43 | "lon": -0.12548719999995228
44 | }
45 | }
46 | }
47 | }
48 | ],
49 | "nextPageUrl": "http://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=foo"
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAContentTypeNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import static java.lang.String.format;
4 | import static java.util.Locale.getDefault;
5 |
6 | /**
7 | * RuntimeException indicating an entry linking to a non existing Content Type.
8 | *
9 | * A content type must be requestable from an entry in order to link the includes.
10 | */
11 | public class CDAContentTypeNotFoundException extends RuntimeException {
12 |
13 | private static final long serialVersionUID = -5839900656195732862L;
14 |
15 | /**
16 | * Create a new exception.
17 | *
18 | * @param resourceId the actual id of the resource requested.
19 | * @param resourceType the type of the resource not found.
20 | * @param resourceTypeId the id of the content type not found.
21 | * @param throwable the cause of this exception.
22 | */
23 | public CDAContentTypeNotFoundException(
24 | String resourceId,
25 | Class extends CDAResource> resourceType,
26 | String resourceTypeId,
27 | Throwable throwable) {
28 | super(format(
29 | getDefault(),
30 | "Could not find content type '%s' for resource with id '%s' of type '%s'.",
31 | resourceTypeId,
32 | resourceId,
33 | resourceType.getSimpleName()),
34 | throwable
35 | );
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.buildscript/deploy_snapshot.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Deploy a jar, source jar, and javadoc jar to Sonatype's snapshot repo.
4 | #
5 | # Adapted from https://coderwall.com/p/9b_lfq and
6 | # http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/
7 |
8 | SLUG="contentful/contentful.java"
9 | JDK="oraclejdk8"
10 | BRANCH="master"
11 |
12 | set -e
13 |
14 | if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then
15 | echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'."
16 | elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then
17 | echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'."
18 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
19 | echo "Skipping snapshot deployment: was pull request."
20 | elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then
21 | echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'."
22 | else
23 | echo "Deploying snapshot to maven ..."
24 | mvn clean source:jar javadoc:jar deploy --settings=".buildscript/settings.xml" -Dmaven.test.skip=true
25 | echo "Snapshot deployed to maven!"
26 | fi
27 |
28 | echo "Deploying snapshot to jitpack ..."
29 | curl --verbose --location "https://jitpack.io/com/github/contentful/contentful.java/${TRAVIS_BRANCH}-SNAPSHOT/"
30 | echo "Snapshot deployed to jitpack!"
31 |
32 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAContentType.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Represents a single content type.
7 | */
8 | public class CDAContentType extends CDAResource {
9 | private static final long serialVersionUID = 7901798878659781364L;
10 | protected List fields;
11 |
12 | String name;
13 |
14 | String displayField;
15 |
16 | String description;
17 |
18 | /**
19 | * @return list of fields.
20 | */
21 | public List fields() {
22 | return fields;
23 | }
24 |
25 | /**
26 | * @return name of this content type.
27 | */
28 | public String name() {
29 | return name;
30 | }
31 |
32 | /**
33 | * @return field to be used for displaying.
34 | */
35 | public String displayField() {
36 | return displayField;
37 | }
38 |
39 | /**
40 | * @return description of this content type.
41 | */
42 | public String description() {
43 | return description;
44 | }
45 |
46 | /**
47 | * Convert this object into a human readable string.
48 | *
49 | * @return a string, containing id, name and description of this type.
50 | */
51 | @Override public String toString() {
52 | return "CDAContentType{"
53 | + "id='" + id() + '\''
54 | + ", name='" + name + '\''
55 | + ", description='" + description + '\''
56 | + '}';
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/resources/demo/links_unresolved.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "fields": {
11 | "name": "Happy Cat",
12 | "bestFriend": {
13 | "sys": {
14 | "type": "Link",
15 | "linkType": "Entry",
16 | "id": "nyancat"
17 | }
18 | },
19 | "likes": [
20 | "cheezburger"
21 | ],
22 | "color": "gray",
23 | "birthday": "2003-10-28T23:00:00+00:00",
24 | "lives": 1,
25 | "image": {
26 | "sys": {
27 | "type": "Link",
28 | "linkType": "Asset",
29 | "id": "happycat"
30 | }
31 | }
32 | },
33 | "sys": {
34 | "space": {
35 | "sys": {
36 | "type": "Link",
37 | "linkType": "Space",
38 | "id": "cfexampleapi"
39 | }
40 | },
41 | "type": "Entry",
42 | "contentType": {
43 | "sys": {
44 | "type": "Link",
45 | "linkType": "ContentType",
46 | "id": "cat"
47 | }
48 | },
49 | "id": "happycat",
50 | "revision": 8,
51 | "createdAt": "2013-06-27T22:46:20.171Z",
52 | "updatedAt": "2013-11-18T15:58:02.018Z",
53 | "locale": "en-US"
54 | }
55 | }
56 | ]
57 | }
--------------------------------------------------------------------------------
/src/test/resources/rich_text/content_types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": ""
16 | }
17 | },
18 | "id": "rich",
19 | "type": "ContentType",
20 | "createdAt": "2018-10-17T13:19:01.984Z",
21 | "updatedAt": "2018-10-17T13:32:19.221Z",
22 | "environment": {
23 | "sys": {
24 | "id": "master",
25 | "type": "Link",
26 | "linkType": "Environment"
27 | }
28 | },
29 | "revision": 3
30 | },
31 | "displayField": "name",
32 | "name": "Rich",
33 | "description": "",
34 | "fields": [
35 | {
36 | "id": "name",
37 | "name": "name",
38 | "type": "Symbol",
39 | "localized": false,
40 | "required": false,
41 | "disabled": false,
42 | "omitted": false
43 | },
44 | {
45 | "id": "rich",
46 | "name": "rich",
47 | "type": "RichText",
48 | "localized": false,
49 | "required": false,
50 | "disabled": false,
51 | "omitted": false
52 | }
53 | ]
54 | }
55 | ]
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/resources/customs/locales.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 2,
6 | "skip": 0,
7 | "limit": 1000,
8 | "items": [
9 | {
10 | "name": "English (United States)",
11 | "code": "en-US",
12 | "fallbackCode": null,
13 | "default": true,
14 | "contentManagementApi": true,
15 | "contentDeliveryApi": true,
16 | "optional": false,
17 | "sys": {
18 | "type": "Locale",
19 | "id": "1g7GsNqzbuJyDbi4kkn8AE",
20 | "version": 1,
21 | "space": {
22 | "sys": {
23 | "type": "Link",
24 | "linkType": "Space",
25 | "id": "wr6gvsml8b51"
26 | }
27 | },
28 | "environment": {
29 | "sys": {
30 | "type": "Link",
31 | "linkType": "Environment",
32 | "id": "master"
33 | }
34 | },
35 | "createdBy": {
36 | "sys": {
37 | "type": "Link",
38 | "linkType": "User",
39 | "id": "7uJNojWP0gbuP7Pplz7Syo"
40 | }
41 | },
42 | "createdAt": "2019-05-14T14:40:37Z",
43 | "updatedBy": {
44 | "sys": {
45 | "type": "Link",
46 | "linkType": "User",
47 | "id": "7uJNojWP0gbuP7Pplz7Syo"
48 | }
49 | },
50 | "updatedAt": "2019-05-14T14:40:37Z"
51 | }
52 | }
53 | ]
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/com/contentful/java/cda/EnvironmentTest.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.contentful.java.cda.lib.Enqueue;
4 |
5 | import org.junit.Test;
6 |
7 | import okhttp3.mockwebserver.RecordedRequest;
8 |
9 | import static com.google.common.truth.Truth.assertThat;
10 |
11 | public class EnvironmentTest extends BaseTest {
12 |
13 | @Test @Enqueue("demo/entries.json")
14 | public void creatingDefaultClientTalksToMaster() throws InterruptedException {
15 |
16 | createBuilder()
17 | .setSpace(DEFAULT_SPACE)
18 | .build()
19 | .fetch(CDAEntry.class)
20 | .all();
21 |
22 | assertThat(server.getRequestCount()).isEqualTo(3);
23 |
24 | final RecordedRequest recordedRequest = server.takeRequest();
25 | assertThat(recordedRequest.getRequestUrl().toString()).contains("/environments/master/");
26 | }
27 |
28 | @Test @Enqueue("demo/entries.json")
29 | public void settingEnvironmentUpdatesRequestURI() throws InterruptedException {
30 | createBuilder()
31 | .setSpace(DEFAULT_SPACE)
32 | .setEnvironment(STAGING_ENVIRONMENT)
33 | .build()
34 | .fetch(CDAEntry.class)
35 | .all();
36 |
37 | assertThat(server.getRequestCount()).isEqualTo(3);
38 |
39 | final RecordedRequest recordedRequest = server.takeRequest();
40 | assertThat(recordedRequest.getRequestUrl().toString()).contains("/environments/" + STAGING_ENVIRONMENT + "/");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAEntry.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * The class represents a basic entry in the space.
7 | */
8 | public class CDAEntry extends LocalizedResource {
9 | private static final long serialVersionUID = 5902790363045498307L;
10 | protected CDAContentType contentType;
11 | @SerializedName("metadata")
12 | private CDAMetadata metadata;
13 |
14 | /**
15 | * @return the metadata set.
16 | */
17 | public CDAMetadata metadata() {
18 | return metadata;
19 | }
20 |
21 | /**
22 | * @return the contentType set.
23 | */
24 | public CDAContentType contentType() {
25 | return contentType;
26 | }
27 |
28 | /**
29 | * Set the contentType of this entry.
30 | * @param contentType the type to be set.
31 | */
32 | protected void setContentType(CDAContentType contentType) {
33 | this.contentType = contentType;
34 | }
35 |
36 | public CDAMetadata getMetadata() {
37 | return metadata;
38 | }
39 |
40 | public void setMetadata(CDAMetadata metadata) {
41 | this.metadata = metadata;
42 | }
43 |
44 | /**
45 | * Create a human readable string of this object.
46 | * @return a string, containing the id of this content type.
47 | */
48 | @Override public String toString() {
49 | return "CDAEntry{"
50 | + "id='" + id() + '\''
51 | + "metadata='" + metadata() + '\''
52 | + '}';
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/ResourceDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.google.gson.JsonDeserializationContext;
4 | import com.google.gson.JsonDeserializer;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonParseException;
7 |
8 | import java.lang.reflect.Type;
9 | import java.util.Collections;
10 |
11 | import static com.contentful.java.cda.CDAType.ASSET;
12 | import static com.contentful.java.cda.CDAType.ENTRY;
13 | import static com.contentful.java.cda.Constants.LOCALE;
14 | import static com.contentful.java.cda.Util.classForType;
15 |
16 | final class ResourceDeserializer implements JsonDeserializer {
17 | @Override public CDAResource deserialize(JsonElement json, Type classType,
18 | JsonDeserializationContext context) throws JsonParseException {
19 | CDAType cdaType = extractType(json);
20 | CDAResource result = context.deserialize(json, classForType(cdaType));
21 | if (ASSET.equals(cdaType) || ENTRY.equals(cdaType)) {
22 | LocalizedResource localized = (LocalizedResource) result;
23 | if (localized.fields == null) {
24 | localized.fields = Collections.emptyMap();
25 | }
26 | }
27 | return result;
28 | }
29 |
30 | private CDAType extractType(JsonElement json) {
31 | String type = json.getAsJsonObject().get("sys").getAsJsonObject()
32 | .get("type")
33 | .getAsString();
34 |
35 | return CDAType.valueOf(type.toUpperCase(LOCALE));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/Cache.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | class Cache {
7 | private List locales;
8 |
9 | protected CDALocale defaultLocale;
10 |
11 | private Map types;
12 |
13 | private final Object localesLock = new Object();
14 |
15 | private final Object typesLock = new Object();
16 |
17 | List locales() {
18 | return locales;
19 | }
20 |
21 | protected CDALocale defaultLocale() {
22 | return defaultLocale;
23 | }
24 |
25 | void setLocales(List locales) {
26 | synchronized (localesLock) {
27 | this.locales = locales;
28 |
29 | updateDefaultLocale();
30 | }
31 | }
32 |
33 | void updateDefaultLocale() {
34 | if (this.locales != null) {
35 | for (final CDALocale locale : this.locales) {
36 | if (locale.isDefaultLocale()) {
37 | this.defaultLocale = locale;
38 | }
39 | }
40 | }
41 | }
42 |
43 | Map types() {
44 | synchronized (typesLock) {
45 | return types;
46 | }
47 | }
48 |
49 | void setTypes(Map types) {
50 | synchronized (typesLock) {
51 | this.types = types;
52 | }
53 | }
54 |
55 | void clear() {
56 | synchronized (localesLock) {
57 | locales = null;
58 | defaultLocale = null;
59 | }
60 |
61 | synchronized (typesLock) {
62 | types = null;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDALocale.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Represents a single locale.
7 | */
8 | public class CDALocale extends CDAResource {
9 | private static final long serialVersionUID = -5710267672379169621L;
10 | String code;
11 |
12 | String name;
13 |
14 | @SerializedName("fallbackCode")
15 | String fallbackLocaleCode;
16 |
17 | @SerializedName("default")
18 | boolean defaultLocale;
19 |
20 | /**
21 | * @return code of this locale. ('en-US' or similar).
22 | */
23 | public String code() {
24 | return code;
25 | }
26 |
27 | /**
28 | * @return human readable name of this locale.
29 | */
30 | public String name() {
31 | return name;
32 | }
33 |
34 | /**
35 | * @return the code of a locale to be used for falling back.
36 | */
37 | public String fallbackLocaleCode() {
38 | return fallbackLocaleCode;
39 | }
40 |
41 | /**
42 | * @return true if this is the default locale.
43 | */
44 | public boolean isDefaultLocale() {
45 | return defaultLocale;
46 | }
47 |
48 | /**
49 | * @return a human readable string, representing the object.
50 | */
51 | @Override public String toString() {
52 | return "CDALocale { " + super.toString() + " "
53 | + "code = " + code() + ", "
54 | + "defaultLocale = " + isDefaultLocale() + ", "
55 | + "fallbackLocaleCode = " + fallbackLocaleCode() + ", "
56 | + "name = " + name() + " "
57 | + "}";
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/resources/rich_text/simple_text.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": ""
16 | }
17 | },
18 | "id": "ybxKk5Avzqam6KymAOgIG",
19 | "type": "Entry",
20 | "createdAt": "2018-10-17T13:32:26.926Z",
21 | "updatedAt": "2018-10-17T13:32:26.926Z",
22 | "environment": {
23 | "sys": {
24 | "id": "human-readable",
25 | "type": "Link",
26 | "linkType": "Environment"
27 | }
28 | },
29 | "revision": 1,
30 | "contentType": {
31 | "sys": {
32 | "type": "Link",
33 | "linkType": "ContentType",
34 | "id": "rich"
35 | }
36 | },
37 | "locale": "en-US"
38 | },
39 | "fields": {
40 | "name": "simple_text",
41 | "rich": {
42 | "content": [
43 | {
44 | "data": {},
45 | "content": [
46 | {
47 | "marks": [],
48 | "value": "This is some simple text",
49 | "nodeType": "text"
50 | }
51 | ],
52 | "nodeType": "paragraph"
53 | }
54 | ],
55 | "nodeType": "document"
56 | }
57 | }
58 | }
59 | ]
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/interceptor/HeaderInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda.interceptor;
2 |
3 | import java.io.IOException;
4 |
5 | import okhttp3.Interceptor;
6 | import okhttp3.Request;
7 | import okhttp3.Response;
8 |
9 | /**
10 | * This class adds custom headers to all requests it intercepts.
11 | */
12 | public class HeaderInterceptor implements Interceptor {
13 | private final String name;
14 | private final String value;
15 |
16 | /**
17 | * Create an arbitrary header adding interceptor.
18 | *
19 | * @param name of the header to be used.
20 | * @param value value of the new header.
21 | */
22 | public HeaderInterceptor(String name, String value) {
23 | this.name = name;
24 | this.value = value;
25 | }
26 |
27 | /**
28 | * Method called by framework, to enrich current request chain with the header information
29 | * requested.
30 | *
31 | * @param chain the execution chain for the request.
32 | * @return the response received.
33 | * @throws IOException in case of failure down the line.
34 | */
35 | @Override public Response intercept(Chain chain) throws IOException {
36 | final Request request = chain.request();
37 |
38 | return chain.proceed(request.newBuilder()
39 | .addHeader(name, value)
40 | .build());
41 | }
42 |
43 | /**
44 | * @return the name of this header.
45 | */
46 | public String getName() {
47 | return name;
48 | }
49 |
50 | /**
51 | * @return the value of this header.
52 | */
53 | public String getValue() {
54 | return value;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/resources/arrays/content_types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 2,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "name": "parent",
11 | "fields": [
12 | {
13 | "name": "child",
14 | "id": "child",
15 | "type": "Link",
16 | "linkType": "Entry",
17 | "localized": false
18 | }
19 | ],
20 | "description": "",
21 | "sys": {
22 | "space": {
23 | "sys": {
24 | "type": "Link",
25 | "linkType": "Space",
26 | "id": "dc9j5zkjikxm"
27 | }
28 | },
29 | "type": "ContentType",
30 | "id": "Jm9AuzgH8OyocaMQSMwKC",
31 | "revision": 1,
32 | "createdAt": "2015-10-22T20:52:53.122Z",
33 | "updatedAt": "2015-10-22T20:52:53.122Z"
34 | }
35 | },
36 | {
37 | "name": "child",
38 | "fields": [
39 | {
40 | "name": "name",
41 | "id": "name",
42 | "type": "Symbol",
43 | "localized": false
44 | }
45 | ],
46 | "description": "",
47 | "displayField": "name",
48 | "sys": {
49 | "space": {
50 | "sys": {
51 | "type": "Link",
52 | "linkType": "Space",
53 | "id": "dc9j5zkjikxm"
54 | }
55 | },
56 | "type": "ContentType",
57 | "id": "71tYS0GavSkUMsokUWmAW4",
58 | "revision": 1,
59 | "createdAt": "2015-10-22T20:53:20.595Z",
60 | "updatedAt": "2015-10-22T20:53:20.595Z"
61 | }
62 | }
63 | ]
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/resources/links_invalid/content_types.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 2,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "name": "child",
11 | "fields": [
12 | {
13 | "name": "name",
14 | "id": "name",
15 | "type": "Symbol",
16 | "localized": false
17 | }
18 | ],
19 | "description": "",
20 | "displayField": "name",
21 | "sys": {
22 | "space": {
23 | "sys": {
24 | "type": "Link",
25 | "linkType": "Space",
26 | "id": "dc9j5zkjikxm"
27 | }
28 | },
29 | "type": "ContentType",
30 | "id": "71tYS0GavSkUMsokUWmAW4",
31 | "revision": 1,
32 | "createdAt": "2015-10-22T20:53:20.595Z",
33 | "updatedAt": "2015-10-22T20:53:20.595Z"
34 | }
35 | },
36 | {
37 | "name": "parent",
38 | "fields": [
39 | {
40 | "name": "child",
41 | "id": "child",
42 | "type": "Link",
43 | "linkType": "Entry",
44 | "localized": true
45 | }
46 | ],
47 | "description": "",
48 | "sys": {
49 | "space": {
50 | "sys": {
51 | "type": "Link",
52 | "linkType": "Space",
53 | "id": "dc9j5zkjikxm"
54 | }
55 | },
56 | "type": "ContentType",
57 | "id": "59TAIUBW5OaOSS4WgE8M4s",
58 | "revision": 1,
59 | "createdAt": "2015-10-28T17:47:44.061Z",
60 | "updatedAt": "2015-10-28T17:47:44.061Z"
61 | }
62 | }
63 | ]
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/resources/shallow/update.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "items": [
6 | {
7 | "sys": {
8 | "space": {
9 | "sys": {
10 | "type": "Link",
11 | "linkType": "Space",
12 | "id": "tamu5dc7eas0"
13 | }
14 | },
15 | "type": "Entry",
16 | "contentType": {
17 | "sys": {
18 | "type": "Link",
19 | "linkType": "ContentType",
20 | "id": "15hKDLsTB28isKMAuaQy4A"
21 | }
22 | },
23 | "id": "2k5aHpfw7m0waMKYksC2Ww",
24 | "revision": 3,
25 | "createdAt": "2015-07-14T12:58:05.066Z",
26 | "updatedAt": "2015-07-14T12:59:11.589Z"
27 | },
28 | "fields": {
29 | "name": {
30 | "en-US": "foo"
31 | },
32 | "image": {
33 | "en-US": {
34 | "sys": {
35 | "type": "Link",
36 | "linkType": "Asset",
37 | "id": "m5pDQF5IRiIicMmg2ukmQ"
38 | }
39 | }
40 | },
41 | "array": {
42 | "en-US": [
43 | {
44 | "sys": {
45 | "type": "Link",
46 | "linkType": "Asset",
47 | "id": "m5pDQF5IRiIicMmg2ukmQ"
48 | }
49 | }
50 | ]
51 | }
52 | }
53 | }
54 | ],
55 | "nextSyncUrl": "https://cdn.contentful.com/spaces/tamu5dc7eas0/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdyYRw4xSScOWb8KVfyrDs8K7RgHCnsOLwpjDu8KMw6VsCcKnQcO9w6zDlAxqRXhJNsKZBsOsw7LCv8KQw4vCoENqw7rDtGhGMsOCw4xuEcKkw4JrAMOww7HCp8OLYy_CpsKcKQ"
56 | }
--------------------------------------------------------------------------------
/src/test/resources/rich_text/simple_text_code.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": ""
16 | }
17 | },
18 | "id": "6VkkamQ5zO4qWIugKkWowK",
19 | "type": "Entry",
20 | "createdAt": "2018-10-17T13:32:33.090Z",
21 | "updatedAt": "2019-01-04T14:05:26.322Z",
22 | "environment": {
23 | "sys": {
24 | "id": "human-readable",
25 | "type": "Link",
26 | "linkType": "Environment"
27 | }
28 | },
29 | "revision": 3,
30 | "contentType": {
31 | "sys": {
32 | "type": "Link",
33 | "linkType": "ContentType",
34 | "id": "rich"
35 | }
36 | },
37 | "locale": "en-US"
38 | },
39 | "fields": {
40 | "name": "simple_text_code",
41 | "rich": {
42 | "data": {},
43 | "content": [
44 | {
45 | "data": {},
46 | "content": [
47 | {
48 | "data": {},
49 | "marks": [
50 | {
51 | "type": "code"
52 | }
53 | ],
54 | "value": "This is code",
55 | "nodeType": "text"
56 | }
57 | ],
58 | "nodeType": "paragraph"
59 | }
60 | ],
61 | "nodeType": "document"
62 | }
63 | }
64 | }
65 | ]
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/resources/rich_text/simple_text_bold.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": ""
16 | }
17 | },
18 | "id": "6VTkaiufQck4wyMwCu4u4E",
19 | "type": "Entry",
20 | "createdAt": "2018-10-17T13:32:31.957Z",
21 | "updatedAt": "2019-01-04T14:09:56.326Z",
22 | "environment": {
23 | "sys": {
24 | "id": "human-readable",
25 | "type": "Link",
26 | "linkType": "Environment"
27 | }
28 | },
29 | "revision": 2,
30 | "contentType": {
31 | "sys": {
32 | "type": "Link",
33 | "linkType": "ContentType",
34 | "id": "rich"
35 | }
36 | },
37 | "locale": "en-US"
38 | },
39 | "fields": {
40 | "name": "simple_text_bold",
41 | "rich": {
42 | "data": {},
43 | "content": [
44 | {
45 | "data": {},
46 | "content": [
47 | {
48 | "data": {},
49 | "marks": [
50 | {
51 | "type": "bold"
52 | }
53 | ],
54 | "value": "This is bold text",
55 | "nodeType": "text"
56 | }
57 | ],
58 | "nodeType": "paragraph"
59 | }
60 | ],
61 | "nodeType": "document"
62 | }
63 | }
64 | }
65 | ]
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/resources/rich_text/simple_text_italic.json:
--------------------------------------------------------------------------------
1 | {
2 | "sys": {
3 | "type": "Array"
4 | },
5 | "total": 1,
6 | "skip": 0,
7 | "limit": 100,
8 | "items": [
9 | {
10 | "sys": {
11 | "space": {
12 | "sys": {
13 | "type": "Link",
14 | "linkType": "Space",
15 | "id": ""
16 | }
17 | },
18 | "id": "1eIWMi8RNEO0ii4OsAUeow",
19 | "type": "Entry",
20 | "createdAt": "2018-10-17T13:32:33.252Z",
21 | "updatedAt": "2019-01-04T14:09:14.741Z",
22 | "environment": {
23 | "sys": {
24 | "id": "human-readable",
25 | "type": "Link",
26 | "linkType": "Environment"
27 | }
28 | },
29 | "revision": 2,
30 | "contentType": {
31 | "sys": {
32 | "type": "Link",
33 | "linkType": "ContentType",
34 | "id": "rich"
35 | }
36 | },
37 | "locale": "en-US"
38 | },
39 | "fields": {
40 | "name": "simple_text_italic",
41 | "rich": {
42 | "data": {},
43 | "content": [
44 | {
45 | "data": {},
46 | "content": [
47 | {
48 | "data": {},
49 | "marks": [
50 | {
51 | "type": "italic"
52 | }
53 | ],
54 | "value": "This is italic text",
55 | "nodeType": "text"
56 | }
57 | ],
58 | "nodeType": "paragraph"
59 | }
60 | ],
61 | "nodeType": "document"
62 | }
63 | }
64 | }
65 | ]
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/contentful/java/cda/CDAField.java:
--------------------------------------------------------------------------------
1 | package com.contentful.java.cda;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | /** Represents a single content type field. */
8 | public class CDAField implements Serializable {
9 | private static final long serialVersionUID = -2852530837647669035L;
10 | String name;
11 |
12 | protected String id;
13 |
14 | protected String type;
15 |
16 | String linkType;
17 |
18 | boolean disabled;
19 |
20 | boolean required;
21 |
22 | boolean localized;
23 |
24 | Map items;
25 |
26 | List