Skip to content

Commit 6dd2b26

Browse files
shaileshmishrashaileshmishra
authored andcommitted
🎉 v1.0.0 release
1 parent a939a96 commit 6dd2b26

File tree

3 files changed

+140
-97
lines changed

3 files changed

+140
-97
lines changed

licence.txt renamed to LICENSE

File renamed without changes.

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,125 @@
22

33
### Embedded Objects
44

5+
This guide will help you get started with Contentstack Java Utils SDK to build apps powered by Contentstack.
6+
7+
### Prerequisites
8+
- JDK 8 or later
9+
- Contentstack account
10+
- Latest version of IntelliJ IDEA / Eclipse / VSCode
11+
12+
### SDK Installation and Setup
13+
To setup Utils SDK in your Java project, add the following dependency in the pom.xml file
14+
15+
```java
16+
<dependency>
17+
<groupId>com.contentstack.sdk</groupId>
18+
<artifactId>util</artifactId>
19+
<version>1.0.0</version>
20+
</dependency>
21+
```
22+
23+
24+
If you are using Contentstack Java SDK, then the Utils SDK is already imported into your project, and the dependency snippet will look as below
25+
26+
```java
27+
<dependency>
28+
<groupId>com.contentstack.sdk</groupId>
29+
<artifactId>java</artifactId>
30+
<version>1.6.0</version> // version 1.6.0 or above
31+
</dependency>
32+
```
33+
34+
35+
### Usage
36+
Let’s learn how you can use Utils SDK to render embedded items.
37+
38+
### Create Render Option
39+
To render embedded items on the front-end, use the renderContents function, and define the UI elements you want to show in the front-end of your website, as shown in the example code below:
40+
41+
```java
42+
43+
44+
Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> {
45+
46+
switch (metadata.getStyleType()) {
47+
// in case you have embedded items using “block” option in the RTE
48+
case BLOCK:
49+
String title = embeddedObject.getString("title");
50+
String multi_line = embeddedObject.getString("multi_line");
51+
return "<p>" + title + "</p><span>" + multi_line + "</span>";
52+
53+
// in case you have embedded items using “inline” option in the RTE
54+
case INLINE:
55+
String titleInline = embeddedObject.getString("title");
56+
String mlInline = embeddedObject.getString("multi_line");
57+
return "<p>" + titleInline + "</p><span>" + mlInline + "</span>";
58+
59+
// in case you have embedded items using “link” option in the RTE
60+
case LINKED:
61+
String titleLinked = embeddedObject.getString("title");
62+
String mlLinked = embeddedObject.getString("multi_line");
63+
return "<p>" + titleLinked + "</p><span>" + mlLinked + "</span>";
64+
65+
// in case you have embedded items using “display” option in the RTE
66+
case DISPLAY:
67+
String titleDiplayable = embeddedObject.getString("title");
68+
String mlDiplayable = embeddedObject.getString("multi_line");
69+
return "<p>" + titleDiplayable + "</p><span>" + mlDiplayable + "</span>";
70+
71+
default:
72+
return null;
73+
}
74+
75+
});
76+
```
77+
78+
79+
### Basic Queries
80+
81+
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
82+
83+
#### Fetch Embedded Item(s) from a Single Entry
84+
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID and entry’s UID. Then, use the includeEmbeddedItems function as shown below:
85+
86+
```java
87+
88+
import Contentstack
89+
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
90+
ContentType contentType = stack.contentType("content_type_uid");
91+
Entry entry = contentType.entry("entry_uid");
92+
entry.includeEmbeddedItems();
93+
entry.fetch(new EntryResultCallBack() {
94+
@Override
95+
public void onCompletion(ResponseType responseType, Error error) {
96+
if (error == null) {
97+
[Success block]
98+
} else {
99+
[Error block]
100+
}}
101+
});
102+
```
103+
104+
105+
106+
#### Fetch Embedded Item(s) from Multiple Entries
107+
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
108+
109+
```java
110+
111+
import Contentstack
112+
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
113+
Query query = stack.contentType("content_type_uid").query();
114+
query.includeEmbeddedItems();
115+
query.find(new QueryResultsCallBack() {
116+
@Override
117+
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
118+
if(error == null){
119+
[Success block]
120+
}else{
121+
[Error block]
122+
}}
123+
});
124+
```
125+
126+

pom.xml

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66

77
<groupId>com.contentstack.sdk</groupId>
88
<artifactId>utils</artifactId>
9-
<version>0.1.0</version>
9+
<version>1.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111
<name>Contentstack-utils</name>
1212
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first approach</description>
1313
<url>https://www.***REMOVED***</url>
14+
1415
<properties>
15-
<!-- package version -->
1616
<util.version>0.1.0-SNAPSHOT</util.version>
17-
<!-- UTF-8 -->
1817
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1918
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
2019
<maven.compiler.source>1.8</maven.compiler.source>
2120
<maven.compiler.target>1.8</maven.compiler.target>
22-
<!-- Compilation -->
2321
<java.version>1.8</java.version>
24-
<!-- Build Dependencies -->
2522
<build-helper.version>3.0.0</build-helper.version>
2623
<surefire-report-plugin.version>2.22.0</surefire-report-plugin.version>
2724
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
2825
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
29-
<kotlin.version>1.4.10</kotlin.version>
26+
<kotlin-test-junit.version>1.4.10</kotlin-test-junit.version>
3027
<junit.version>4.13.1</junit.version>
3128
<maven-site-plugin.version>3.3</maven-site-plugin.version>
3229
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
@@ -66,6 +63,13 @@
6663
<url>http://github.com/contentstack/contentstack-utils-java/issues</url>
6764
</issueManagement>
6865

66+
<licenses>
67+
<license>
68+
<name>MIT</name>
69+
<url>http://www.opensource.org/licenses/mit-license.php</url>
70+
</license>
71+
</licenses>
72+
6973
<organization>
7074
<name>Contentstack.</name>
7175
<url>http://***REMOVED***</url>
@@ -81,12 +85,12 @@
8185
<dependency>
8286
<groupId>org.jetbrains.kotlin</groupId>
8387
<artifactId>kotlin-stdlib-jdk8</artifactId>
84-
<version>${kotlin.version}</version>
88+
<version>${kotlin-test-junit.version}</version>
8589
</dependency>
8690
<dependency>
8791
<groupId>org.jetbrains.kotlin</groupId>
88-
<artifactId>kotlin-test</artifactId>
89-
<version>${kotlin.version}</version>
92+
<artifactId>kotlin-test-junit</artifactId>
93+
<version>${kotlin-test-junit.version}</version>
9094
<scope>test</scope>
9195
</dependency>
9296
<dependency>
@@ -101,15 +105,9 @@
101105
</dependency>
102106
</dependencies>
103107

104-
105108
<build>
106109
<sourceDirectory>src/main/java</sourceDirectory>
107110
<plugins>
108-
<!--
109-
JaCoCo :: Maven Plugin
110-
The JaCoCo Maven Plugin provides the JaCoCo runtime agent to your tests and allows basic report creation.
111-
mvn clean install -P test-coverage
112-
-->
113111
<plugin>
114112
<groupId>org.jacoco</groupId>
115113
<artifactId>jacoco-maven-plugin</artifactId>
@@ -127,26 +125,18 @@
127125
<goal>report</goal>
128126
</goals>
129127
</execution>
130-
131128
</executions>
132129
</plugin>
133130

134-
135131
<plugin>
136132
<groupId>org.apache.maven.plugins</groupId>
137133
<artifactId>maven-compiler-plugin</artifactId>
138134
<version>3.8.1</version>
139135
</plugin>
140136
<!--
141-
# Run tests and generate .xml reports
142-
mvn test
143-
144-
# Convert .xml reports into .html report, but without the CSS or images
145-
mvn surefire-report:report-only
146-
147-
# Put the CSS and images where they need to be without the rest of the
148-
# time-consuming stuff
149-
mvn surefire-report:report site -DgenerateReports=false
137+
mvn test
138+
mvn surefire-report:report-only
139+
mvn surefire-report:report site -DgenerateReports=false
150140
-->
151141
<plugin>
152142
<groupId>org.apache.maven.plugins</groupId>
@@ -162,8 +152,6 @@
162152
</executions>
163153
</plugin>
164154

165-
<!--The Source Plugin creates a jar archive of the source files of
166-
the current project. The jar file is, by default, created in the project's target directory.-->
167155
<plugin>
168156
<groupId>org.apache.maven.plugins</groupId>
169157
<artifactId>maven-source-plugin</artifactId>
@@ -178,13 +166,6 @@
178166
</executions>
179167
</plugin>
180168

181-
<!--The Javadoc Plugin uses the Javadoc tool to generate javadocs for the specified project-->
182-
<!-- <plugin>-->
183-
<!-- <groupId>org.apache.maven.plugins</groupId>-->
184-
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
185-
<!-- <version>${maven-javadoc-plugin.version}</version>-->
186-
<!-- </plugin>-->
187-
188169
<plugin>
189170
<groupId>org.apache.maven.plugins</groupId>
190171
<artifactId>maven-javadoc-plugin</artifactId>
@@ -210,22 +191,12 @@
210191
</executions>
211192
</plugin>
212193

213-
214-
<!--
215-
The Site Plugin is used to generate a site for the project.
216-
The generated site also includes the project's reports that were configured in the POM.
217-
-->
218194
<plugin>
219195
<groupId>org.apache.maven.plugins</groupId>
220196
<artifactId>maven-site-plugin</artifactId>
221197
<version>${maven-site-plugin.version}</version>
222198
</plugin>
223199

224-
<!--
225-
Signs all of a project's attached artifacts with GnuPG.
226-
You need to have previously configured the default key.
227-
gpg also needs to be on the search path.
228-
-->
229200
<plugin>
230201
<groupId>org.apache.maven.plugins</groupId>
231202
<artifactId>maven-gpg-plugin</artifactId>
@@ -241,18 +212,10 @@
241212
</executions>
242213
</plugin>
243214

244-
<!--
245-
Sometimes when you may need to compile a certain project to a different
246-
version than what you are currently using. The javac can accept such command
247-
using -source and -target. The Compiler Plugin can also be configured to
248-
provide these option during compilation
249-
-->
250-
251-
<!--Provides support to access staging functionality in a remote Nexus Professional server.-->
252215
<plugin>
253216
<groupId>org.sonatype.plugins</groupId>
254217
<artifactId>nexus-staging-maven-plugin</artifactId>
255-
<version>${nexus-staging-maven-plugin.version}</version>
218+
<version>1.6.7</version>
256219
<extensions>true</extensions>
257220
<configuration>
258221
<serverId>ossrh</serverId>
@@ -261,10 +224,6 @@
261224
</configuration>
262225
</plugin>
263226

264-
<!--
265-
This plugin is used to release a project with Maven, saving a lot of repetitive, manual work.
266-
Releasing a project is made in two steps: prepare and perform.
267-
-->
268227
<plugin>
269228
<groupId>org.apache.maven.plugins</groupId>
270229
<artifactId>maven-release-plugin</artifactId>
@@ -277,46 +236,10 @@
277236
</configuration>
278237
</plugin>
279238

280-
281-
<!-- <plugin>-->
282-
<!-- <groupId>org.jacoco</groupId>-->
283-
<!-- <artifactId>jacoco-maven-plugin</artifactId>-->
284-
<!-- <version>0.8.5</version>-->
285-
<!-- </plugin>-->
286-
287-
<!-- <plugin>-->
288-
<!-- <groupId>org.apache.maven.plugins</groupId>-->
289-
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
290-
<!-- <version>3.8.0</version>-->
291-
<!-- <executions>-->
292-
<!-- <execution>-->
293-
<!-- <id>compile</id>-->
294-
<!-- <phase>compile</phase>-->
295-
<!-- <goals>-->
296-
<!-- <goal>compile</goal>-->
297-
<!-- </goals>-->
298-
<!-- </execution>-->
299-
<!-- <execution>-->
300-
<!-- <id>testCompile</id>-->
301-
<!-- <phase>test-compile</phase>-->
302-
<!-- <goals>-->
303-
<!-- <goal>testCompile</goal>-->
304-
<!-- </goals>-->
305-
<!-- </execution>-->
306-
<!-- </executions>-->
307-
<!-- <configuration>-->
308-
<!-- <source>${java.version}</source>-->
309-
<!-- <target>${java.version}</target>-->
310-
<!-- <compilerArgument>-Xlint:all</compilerArgument>-->
311-
<!-- <showWarnings>true</showWarnings>-->
312-
<!-- <showDeprecation>true</showDeprecation>-->
313-
<!-- </configuration>-->
314-
<!-- </plugin>-->
315-
316239
<plugin>
317240
<groupId>org.jetbrains.kotlin</groupId>
318241
<artifactId>kotlin-maven-plugin</artifactId>
319-
<version>${kotlin.version}</version>
242+
<version>${kotlin-test-junit.version}</version>
320243
<executions>
321244
<execution>
322245
<id>compile</id>
@@ -327,8 +250,6 @@
327250
</execution>
328251
</executions>
329252
</plugin>
330-
331-
332253
</plugins>
333254
</build>
334255

0 commit comments

Comments
 (0)