Skip to content

Commit e920e8a

Browse files
authored
Merge pull request #139 from JerRMartin/fix/adding-missing-workflow_step-to-system
Adding missing workflow_step
2 parents e8c7ca5 + 559179e commit e920e8a

14 files changed

+244
-132
lines changed

kontent-delivery/README.md

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
12
# Kontent Delivery Java SDK
23

34
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
45

5-
[![javadoc](https://javadoc.io/badge2/com.github.kentico/kontent-delivery/javadoc.svg)](https://javadoc.io/doc/com.github.kentico/kontent-delivery)
6+
[![javadoc](https://javadoc.io/badge2/com.github.kentico/kontent-delivery/javadoc.svg)](https://javadoc.io/doc/com.github.kentico/kontent-delivery)
67
[![Maven Central](https://img.shields.io/maven-central/v/com.github.kentico/kontent-delivery)](https://oss.sonatype.org/content/groups/public/com/github/kentico/kontent-delivery/)
78

8-
[![GitHub Discussions](https://img.shields.io/badge/GitHub-Discussions-FE7A16.svg?style=popout&logo=github)](https://github.com/Kentico/Home/discussions)
9+
[![GitHub Discussions](https://img.shields.io/badge/GitHub-Discussions-FE7A16.svg?style=popout&logo=github)](https://github.com/Kentico/Home/discussions)
910
[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-kontent)
1011

1112
The Kontent Delivery Java SDK is a client library used for retrieving content from [Kontent by Kentico](https://kontent.ai).
@@ -16,7 +17,7 @@ You can use the SDK in the form of a Apache Maven package from [Maven Central](h
1617

1718
### Gradle
1819

19-
```groovy
20+
```groovy
2021
2122
repositories {
2223
mavenCentral()
@@ -31,14 +32,15 @@ dependencies {
3132
3233
### Maven
3334

34-
```xml
35+
```xml
3536
<dependency>
3637
<groupId>com.github.kentico</groupId>
37-
<artifactId>kontent-delivery</artifactId>
38-
<version>[0.0.2-beta.12,)</version>
38+
39+
<artifactId>kontent-delivery</artifactId>
40+
<version>[0.0.2-beta.12,)</version>
3941
<type>pom</type>
40-
</dependency>
41-
```
42+
</dependency>
43+
```
4244

4345
> You may want to change version specification - `[0.0.2-beta.12,)` - from [range one](https://cwiki.apache.org/confluence/display/MAVENOLD/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges) to specific one (i.e. `0.0.2-beta.12`).
4446
@@ -48,10 +50,10 @@ The `DeliveryClient` class is the main class of the SDK. Using this class, you c
4850

4951
To create an instance of the class, you need to provide a [project ID](https://docs.kontent.ai/tutorials/develop-apps/get-content/getting-content#a-getting-content-items).
5052

51-
```java
52-
// Initializes an instance of the DeliveryClient client
53-
DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3");
54-
```
53+
```java
54+
// Initializes an instance of the DeliveryClient client
55+
DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3");
56+
```
5557

5658
You can also provide the project ID and other parameters by passing the [`DeliveryOptions`](./src/main/java/kentico/kontent/delivery/DeliveryOptions.java) object to the class constructor. The `DeliveryOptions` object can be used to set the following parameters:
5759

@@ -68,15 +70,16 @@ You can also provide the project ID and other parameters by passing the [`Delive
6870

6971
The `DeliveryOptions.builder()` can also simplify creating a `DeliveryClient`:
7072

71-
```java
73+
```java
7274
DeliveryClient client = new DeliveryClient(
7375
DeliveryOptions
76+
7477
.builder()
7578
.projectId("975bf280-fd91-488c-994c-2f04416e5ee3")
7679
.productionApiKey("secured key")
7780
.build()
78-
);
79-
```
81+
);
82+
```
8083

8184
Once you create a `DeliveryClient`, you can start querying your project repository by calling methods on the client instance. See [Basic querying](#basic-querying) for details.
8285

@@ -91,21 +94,21 @@ DeliveryClient client = new DeliveryClient(
9194
"YOUR_PROJECT_ID",
9295
"YOUR_PREVIEW_API_KEY"
9396
);
94-
```
97+
```
9598

9699
For more details, see [Previewing unpublished content using the Delivery API](https://docs.kontent.ai/tutorials/write-and-collaborate/preview-content/previewing-unpublished-content).
97100

98101
## Basic querying
99102

100103
Once you have a `DeliveryClient` instance, you can start querying your project repository by calling methods on the instance.
101104

102-
```java
103-
// Retrieves a single content item
104-
CompletionStage<ContentItemResponse> response = client.getItem("about_us");
105-
106-
// Retrieves a list of all content items
107-
CompletionStage<ContentItemsListingResponse> listingResponse = client.getItems();
108-
```
105+
```java
106+
// Retrieves a single content item
107+
CompletionStage<ContentItemResponse> response = client.getItem("about_us");
108+
109+
// Retrieves a list of all content items
110+
CompletionStage<ContentItemsListingResponse> listingResponse = client.getItems();
111+
```
109112

110113
As you may have noticed from the example `DeliveryClient` is returning [`CompletionStage<T>`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html) that allows you to chain the requests, perform filtering, data transformation, etc.
111114

@@ -146,7 +149,7 @@ CompletionsStage<ContentItemsListingResponse> response = client.getItems(
146149
.includeTotalCount()
147150
.build()
148151
)
149-
```
152+
```
150153

151154
## Response structure
152155

@@ -172,27 +175,30 @@ When retrieving a list of content items, you get an instance of the `ContentItem
172175

173176
The `ContentItem` class provides the following:
174177

175-
- `getSystem()` returns a `System` object with metadata such as code name, display name, type, collection, or sitemap location.
178+
- `getSystem()` returns a `System` object with metadata such as code name, display name, type, collection, sitemap location, or workflow step.
176179
- `getElements()` returns a Map containing all the elements included in the response keyed by code names.
177180
- Methods for easier access to certain types of content elements such as linked items, or assets.
178181

179182
## Getting content item properties
180183

181184
You can access information about a content item (i.e., its ID, codename, name, location in sitemap, date of last modification, its collection codename, and its content type codename) by using the `System` object.
182185

183-
```java
184-
// Retrieves name of an article content item
185-
articleItem.getSystem().getName()
186-
187-
// Retrieves codename of an article content item
188-
articleItem.getSystem().getCodename()
189-
190-
// Retrieves codename of the collection of an article content item
191-
articleItem.getSystem().getCollection()
192-
193-
// Retrieves codename of the content type of an article content item
194-
articleItem.getSystem().getType()
195-
```
186+
```java
187+
// Retrieves name of an article content item
188+
articleItem.getSystem().getName()
189+
190+
// Retrieves codename of an article content item
191+
articleItem.getSystem().getCodename()
192+
193+
// Retrieves codename of the collection of an article content item
194+
articleItem.getSystem().getCollection()
195+
196+
// Retrieves codename of the content type of an article content item
197+
articleItem.getSystem().getType()
198+
199+
// Retrieves codename of the workflow step of an article content item
200+
articleItem.getSystem().getWorkflowStep()
201+
```
196202

197203
## Getting element values
198204

@@ -202,37 +208,37 @@ The SDK provides methods for retrieving content from content elements such as As
202208

203209
For text elements, you can use the `getString` method.
204210

205-
```java
206-
// Retrieves an article text from the 'body_copy' Text element
207-
articleItem.getString("body_copy")
208-
```
211+
```java
212+
// Retrieves an article text from the 'body_copy' Text element
213+
articleItem.getString("body_copy")
214+
```
209215

210216
The Rich text element can contain links to other content items within your project. See [Resolving links to content items](https://github.com/Kentico/kontent-delivery-sdk-java/wiki/Resolving-links-to-content-items) for more details.
211217

212218
### Asset
213219

214-
```java
215-
// Retrieves a teaser image URL
216-
articleItem.getAssets("teaser_image").get(0).getUrl()
217-
```
220+
```java
221+
// Retrieves a teaser image URL
222+
articleItem.getAssets("teaser_image").get(0).getUrl()
223+
```
218224

219225
### Multiple choice
220226

221227
To get a list of options defined in a Multiple choice content element, you first need to retrieve the content element itself. For this purpose, you can use the `getContentTypeElement` method, which takes the codename of a content type and the codename of a content element.
222228

223-
```java
224-
// Retrieves the 'processing' element of the 'coffee' content type
225-
MultipleChoiceElement element = (MultipleChoiceElement) client.getContentTypeElement("coffee", "processing");
226-
```
229+
```java
230+
// Retrieves the 'processing' element of the 'coffee' content type
231+
MultipleChoiceElement element = (MultipleChoiceElement) client.getContentTypeElement("coffee", "processing");
232+
```
227233

228234
After you retrieve the Multiple choice element, you can work with its list of options. Each option has the following methods:
229235

230236
Method | Description | Example
231-
---------|----------|---------
232-
getName() | The display name of the option. | `Dry (Natural)`
233-
getCodename() | The codename of the option. | `dry__natural_
237+
---------|----------|---------
238+
getName() | The display name of the option. | `Dry (Natural)`
239+
getCodename() | The codename of the option. | `dry__natural_
234240

235-
To put the element's options in a list, you can use the following code:
241+
To put the element's options in a list, you can use the following code:
236242

237243
```java
238244
List<SelectListItem> items = new List<>();
@@ -243,28 +249,28 @@ for (Option option : element.getOptions()) {
243249
item.setValue(option.getCodename());
244250
item.setSelected("semi_dry".equals(option.getCodename()));
245251
}
246-
```
252+
```
247253

248254
### Linked items
249255

250-
```java
251-
// Retrieves related articles
252-
articleItem.getLinkedItems("related_articles")
253-
```
256+
```java
257+
// Retrieves related articles
258+
articleItem.getLinkedItems("related_articles")
259+
```
254260

255261
### Custom items
256262

257-
```java
258-
// Retrieves the value of the custom element 'color'
259-
String customElementValue = ((CustomElement) articleItem.getElements().get("color")).getValue();
260-
```
263+
```java
264+
// Retrieves the value of the custom element 'color'
265+
String customElementValue = ((CustomElement) articleItem.getElements().get("color")).getValue();
266+
```
261267

262268
## Android development
263269

264-
To use this SDK for [Android](https://developer.android.com/) development, you can use any approach compatible with [Java CompletionStage API](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html). Most common is to use [Kotlin coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) for Android applications written in Kotlin and [Java RX](https://github.com/ReactiveX/RxJava) for Android applications written in Java. Both of these approaches are showcased in this repository:
265-
266-
* [Android Java sample application](../sample-app-android#readme)
267-
* [Android Kotlin Java Sample application](../sample-app-android-kotlin#readme)
270+
To use this SDK for [Android](https://developer.android.com/) development, you can use any approach compatible with [Java CompletionStage API](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html). Most common is to use [Kotlin coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) for Android applications written in Kotlin and [Java RX](https://github.com/ReactiveX/RxJava) for Android applications written in Java. Both of these approaches are showcased in this repository:
271+
272+
* [Android Java sample application](../sample-app-android#readme)
273+
* [Android Kotlin Java Sample application](../sample-app-android-kotlin#readme)
268274

269275
⚠ There are two Android-specific rules you need to follow in order for the Delivery SDK to work correctly.
270276

@@ -275,9 +281,9 @@ String customElementValue = ((CustomElement) articleItem.getElements().get("colo
275281

276282
You need to instantiate the Delivery client with the constructor that disables the template engine. The template engine is meant to be used with the web platform only. For Android development, use the constructor `DeliveryClient#DeliveryClient(DeliveryOptions, TemplateEngineConfig)` and set the second parameter to `null`.
277283

278-
```java
279-
DeliveryClient client = new DeliveryClient(new DeliveryOptions(AppConfig.KONTENT_PROJECT_ID), null);
280-
```
284+
```java
285+
DeliveryClient client = new DeliveryClient(new DeliveryOptions(AppConfig.KONTENT_PROJECT_ID), null);
286+
```
281287

282288
See it [used in a sample app](../sample-app-android/src/main/java/com/github/kentico/delivery_android_sample/data/source/DeliveryClientProvider.java)).
283289

@@ -308,7 +314,6 @@ We would like to express our thanks to the following people who contributed and
308314
- [Adam J. Weigold](https://github.com/aweigold)
309315
- [Tommaso Garuglieri](https://github.com/GaruGaru)
310316
- [Gabriel Cunha](https://github.com/cunhazera)
317+
- [Jeremy Martin](https://github.com/jerrmartin)
311318

312319
Would you like to become a hero too? Pick an [issue](https://github.com/Kentico/kontent-delivery-sdk-java/issues) and send us a pull request!
313-
314-
![Analytics](https://kentico-ga-beacon.azurewebsites.net/api/UA-69014260-4/Kentico/kontent-java-packages/kontent-delivery?pixel)

kontent-delivery/src/main/java/kentico/kontent/delivery/System.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,12 @@ public class System {
116116
@JsonProperty("last_modified")
117117
ZonedDateTime lastModified;
118118

119+
/**
120+
* The codename of the item's current workflow step.
121+
*
122+
* @param workflowStep Sets the workflowStep of this.
123+
* @return The workflow step of this.
124+
*/
125+
@JsonProperty("workflow_step")
126+
String workflowStep;
119127
}

kontent-delivery/src/test/java/kentico/kontent/delivery/DeliveryClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,9 @@ public void testGetStronglyTypedItem() throws Exception {
832832
Assert.assertNotNull(item.getArticleItems());
833833
Assert.assertEquals(2, item.getArticleItems().size());
834834
Assert.assertNotNull(item.getAllLinkedItems());
835-
Assert.assertEquals(2, item.getAllLinkedItems().size());
835+
Assert.assertEquals(3, item.getAllLinkedItems().size());
836836
Assert.assertNotNull(item.getAllLinkedItemsMap());
837-
Assert.assertEquals(2, item.getAllLinkedItemsMap().size());
837+
Assert.assertEquals(3, item.getAllLinkedItemsMap().size());
838838
}
839839

840840
@Test

kontent-delivery/src/test/java/kentico/kontent/delivery/JacksonBindingsTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testContentItemDeserialization() throws IOException {
9696
Assert.assertEquals(response, response3);
9797
Assert.assertEquals(response.hashCode(), response3.hashCode());
9898

99-
Assert.assertEquals(2, response.getLinkedItems().size());
99+
Assert.assertEquals(3, response.getLinkedItems().size());
100100

101101
ContentItem contentItem = response.getItem();
102102
Assert.assertNotNull(contentItem);
@@ -118,8 +118,9 @@ public void testContentItemDeserialization() throws IOException {
118118
Assert.assertEquals(2016, system.getLastModified().getYear());
119119
Assert.assertEquals(1, system.getSitemapLocations().size());
120120
Assert.assertEquals("articles", system.getSitemapLocations().get(0));
121+
Assert.assertEquals("published", system.getWorkflowStep());
121122

122-
Assert.assertEquals(6, contentItem.elements.size());
123+
Assert.assertEquals(7, contentItem.elements.size());
123124
Element title = contentItem.elements.get("title");
124125
Assert.assertNotNull(title);
125126
Assert.assertNotNull(title.toString());
@@ -136,14 +137,19 @@ public void testContentItemDeserialization() throws IOException {
136137
Assert.assertEquals(0, contentItem.getAssets("post_date").size());
137138

138139
Assert.assertNotNull(contentItem.getLinkedItem("coffee_processing_techniques"));
140+
Assert.assertNotNull(contentItem.getLinkedItem("origins_of_arabica_bourbon"));
141+
Assert.assertNotNull(contentItem.getLinkedItem("component_child"));
139142
Assert.assertNull(contentItem.getLinkedItem("non_existent"));
140143

144+
// Testing that Component does not have a `workflow_step`
145+
Assert.assertNotNull(contentItem.getLinkedItem("component_child").getSystem());
146+
Assert.assertNull(contentItem.getLinkedItem("component_child").getSystem().getWorkflowStep());
147+
141148
Element themeColor = contentItem.elements.get("theme_color");
142149
Assert.assertNotNull(themeColor);
143150
Assert.assertNotNull(themeColor.toString());
144151
Assert.assertEquals("custom", themeColor.getType());
145152
Assert.assertEquals("#ff0000", themeColor.getValue());
146-
147153
}
148154

149155
@Test
@@ -211,6 +217,7 @@ public void testContentTypeDeserialization() throws IOException {
211217
Assert.assertNull(system.getCollection());
212218
Assert.assertNull(system.getType());
213219
Assert.assertNull(system.getSitemapLocations());
220+
Assert.assertNull(system.getWorkflowStep());
214221

215222
Assert.assertEquals(11, contentType.getElements().size());
216223
Element element = contentType.getElements().get("processing");

0 commit comments

Comments
 (0)