Skip to content

Commit 1b01d59

Browse files
💡 🔥 release, role and releaseItems
💡 🔥 release, role and releaseItems
1 parent 2b6c1ae commit 1b01d59

File tree

17 files changed

+1432
-9
lines changed

17 files changed

+1432
-9
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
## v0.1.0
2+
## v1.0.0
33
#### 03-SEP-2021
44
Initial release for Contentstack CMA base Java management SDK

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5-
<groupId>com.contentstack</groupId>
5+
<groupId>com.contentstack.sdk</groupId>
66
<artifactId>cms</artifactId>
77
<name>contentstack-management-java</name>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>${sdk.version}</version>
99
<description>Contentstack Java Management SDK for Content Management API,
1010
Contentstack is a headless CMS with an API-first approach
1111
</description>
@@ -22,7 +22,7 @@
2222
<connection>scm:git:git://github.com/contentstack/contentstack-management-java.git</connection>
2323
<developerConnection>scm:git:ssh://github.com:contentstack/contentstack-management-java.git
2424
</developerConnection>
25-
<tag>v0.0.1-alpha</tag>
25+
<tag>${sdk.version}</tag>
2626
</scm>
2727

2828
<issueManagement>
@@ -70,7 +70,7 @@
7070
</distributionManagement>
7171

7272
<properties>
73-
<sdk.version>0.0.1</sdk.version>
73+
<sdk.version>1.0.0-SNAPSHOT</sdk.version>
7474
<sdk.version.snapshot>${sdk.version}-SNAPSHOT</sdk.version.snapshot>
7575
<maven.compiler.target>1.8</maven.compiler.target>
7676
<maven.compiler.source>1.8</maven.compiler.source>

src/main/java/com/contentstack/cms/core/CSResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class CSResponse {
1515
private static final String RESPONSE_NULL = "response == null";
1616
private final Response<ResponseBody> response;
1717

18+
//Request request;
19+
//ResponseBody response; // JSONResponse/ JSON/ String / model
20+
21+
1822
public CSResponse(Response<ResponseBody> response) {
1923
this.response = response;
2024
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.contentstack.cms.core;
2+
3+
import org.json.simple.JSONObject;
4+
5+
/**
6+
* The class Json contains methods to create the builder object. The example code below shows how to build an empty
7+
* JsonObject instance
8+
* <p>
9+
* JsonObject object = Json.createObjectBuilder().build();
10+
*/
11+
final class ObjectModel {
12+
13+
// final instance fields
14+
private final int id;
15+
private final String name;
16+
private final String address;
17+
18+
public ObjectModel(Builder builder) {
19+
this.id = builder.id;
20+
this.name = builder.name;
21+
this.address = builder.address;
22+
}
23+
24+
// Static class Builder
25+
public static class Builder {
26+
27+
/// instance fields
28+
private int id;
29+
private String name;
30+
private String address;
31+
32+
public static Builder newInstance() {
33+
return new Builder();
34+
}
35+
36+
private Builder() {
37+
}
38+
39+
// Setter methods
40+
public Builder setId(int id) {
41+
this.id = id;
42+
return this;
43+
}
44+
45+
public Builder setName(String name) {
46+
this.name = name;
47+
return this;
48+
}
49+
50+
public Builder setAddress(String address) {
51+
this.address = address;
52+
return this;
53+
}
54+
55+
// build method to deal with outer class
56+
// to return outer instance
57+
public ObjectModel build() {
58+
return new ObjectModel(this);
59+
}
60+
}
61+
62+
63+
@Override
64+
public String toString() {
65+
return "ObjectModel{" +
66+
"id=" + id +
67+
", name='" + name + '\'' +
68+
", address='" + address + '\'' +
69+
'}';
70+
}
71+
}

src/main/java/com/contentstack/cms/core/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Util {
2424
public static final String VERSION = "v3";
2525
public static final int TIMEOUT = 30;
2626
public static final String SDK_NAME = "contentstack-management-java";
27-
public static final String SDK_VERSION = "0.0.1";
27+
public static final String SDK_VERSION = "1.0.0";
2828
public static final String ILLEGAL_USER = "Please Login to access stack instance";
2929
public static final String USER_ALREADY_LOGGED_IN = "User is already loggedIn, "
3030
+ "Please logout then try to login again";
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.json.simple.JSONObject;
6+
import retrofit2.Call;
7+
import retrofit2.Retrofit;
8+
9+
import java.util.HashMap;
10+
11+
12+
/**
13+
* You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a ‘release’, and
14+
* then deploy this release to an environment. This will publish/unpublish all the the items of the release to the
15+
* specified environment. Read more about Releases.
16+
* <p>
17+
* You can now pass the branch header in the API request to fetch or manage modules located within specific branches of
18+
* the stack. Additionally, you can also set the include_branch query parameter to true to include the _branch top-level
19+
* key in the response. This key specifies the unique ID of the branch where the concerned Contentstack module resides
20+
* <p>
21+
* Read more about <a
22+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#releases">Releases</a>
23+
*
24+
* @author ***REMOVED***
25+
* @version 1.0.0
26+
* @since 2022-05-19
27+
*/
28+
public class Release {
29+
30+
protected final ReleaseService service;
31+
protected HashMap<String, Object> headers;
32+
protected HashMap<String, Object> params;
33+
private final Retrofit retrofit;
34+
35+
protected Release(Retrofit retrofit, HashMap<String, Object> stackHeaders) {
36+
this.headers = new HashMap<>();
37+
this.params = new HashMap<>();
38+
this.headers.putAll(stackHeaders);
39+
this.retrofit = retrofit;
40+
this.service = this.retrofit.create(ReleaseService.class);
41+
}
42+
43+
/**
44+
* Sets header for the request
45+
*
46+
* @param key
47+
* header key for the request
48+
* @param value
49+
* header value for the request
50+
*/
51+
public void addHeader(@NotNull String key, @NotNull Object value) {
52+
this.headers.put(key, value);
53+
}
54+
55+
/**
56+
* Sets header for the request
57+
*
58+
* @param key
59+
* header key for the request
60+
* @param value
61+
* header value for the request
62+
*/
63+
public void addParam(@NotNull String key, @NotNull Object value) {
64+
this.params.put(key, value);
65+
}
66+
67+
68+
/**
69+
* Sets header for the request
70+
*
71+
* @param key
72+
* header key for the request
73+
*/
74+
public void removeParam(@NotNull String key) {
75+
this.params.remove(key);
76+
}
77+
78+
/**
79+
* The Get all Releases request retrieves a list of all Releases of a stack along with details of each Release.
80+
* <p>
81+
*
82+
* @return Call
83+
*/
84+
public Call<ResponseBody> getAll() {
85+
return this.service.getReleases(this.headers, this.params);
86+
}
87+
88+
/**
89+
* The Get a single Release request gets the details of a specific Release in a stack.
90+
* <p>
91+
* When executing the API request, provide the Release UID as parameter
92+
*
93+
* @param releaseUid
94+
* The unique ID of the release of which you want to retrieve the details
95+
* @return Call
96+
*/
97+
public Call<ResponseBody> fetch(@NotNull String releaseUid) {
98+
return this.service.getRelease(this.headers, releaseUid);
99+
}
100+
101+
/**
102+
* To <b>Create a Release request</b> allows you to create a new Release in your stack. To add entries/assets to a
103+
* Release, you need to provide the UIDs of the entries/assets in <b>items</b> in the request body.
104+
*
105+
* @param requestBody
106+
* The details of the delivery role in @{@link JSONObject} format
107+
* @return Call
108+
*/
109+
public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
110+
return this.service.createRelease(this.headers, requestBody);
111+
}
112+
113+
/**
114+
* To Update a Release call allows you to update the details of a Release, i.e., the ‘name’ and ‘description’.
115+
* <p>
116+
* When executing this API request, provide the Release UID as parameter. In the 'Body' section, you need to provide
117+
* the new name and description of the Release that you want to update.
118+
*
119+
* @param releaseUid
120+
* The UID of the role that you want to retrieve
121+
* @param requestBody
122+
* The body should be of @{@link JSONObject} type
123+
* @return Call
124+
*/
125+
public Call<ResponseBody> update(
126+
@NotNull String releaseUid, @NotNull JSONObject requestBody) {
127+
return this.service.updateRelease(this.headers, releaseUid, requestBody);
128+
}
129+
130+
/**
131+
* To Delete a Release request allows you to delete a specific Release from a stack.
132+
* <p>
133+
* When executing the API request, provide the Release UID.
134+
*
135+
* @param releaseUid
136+
* The UID of the role that you want to retrieve
137+
* @return Call
138+
*/
139+
public Call<ResponseBody> delete(@NotNull String releaseUid) {
140+
return this.service.deleteRelease(this.headers, releaseUid);
141+
}
142+
143+
144+
/**
145+
* The Get all items in a Release request retrieves a list of all items (entries and assets) that are part of a
146+
* specific Release and perform CRUD operations on it.
147+
* <p>
148+
* Read more about <a
149+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#release-items">Release Items</a>
150+
*
151+
* @param releaseUid
152+
* The UID of the role that you want to retrieve
153+
*/
154+
public ReleaseItem item(@NotNull String releaseUid) {
155+
return new ReleaseItem(this.retrofit, this.headers, releaseUid);
156+
}
157+
158+
159+
/**
160+
* The Deploy a Release request deploys a specific Release to specific environment(s) and locale(s).
161+
* <p>
162+
* When executing the API request, provide the Release UID. In the <b>Body</b> section, you need to provide the
163+
* details of the Release that you want to deploy. For example, you need to provide the action, environment(s), and
164+
* the locale(s) on which the Release should be deployed.
165+
* <p>
166+
*
167+
* @param releaseUid
168+
* unique ID of the release that you want to deploy
169+
* @param requestBody
170+
* The JSONObject request body
171+
* @return Call
172+
*/
173+
public Call<ResponseBody> deploy(
174+
@NotNull String releaseUid, @NotNull JSONObject requestBody) {
175+
return this.service.deploy(this.headers, releaseUid, requestBody);
176+
}
177+
178+
/**
179+
* The Clone a Release request allows you to clone (make a copy of) a specific Release in a stack.
180+
* <p>
181+
* When executing the API request, provide the Release UID. In the <b>Body</b> section, you need to provide the new
182+
* name and description of the cloned Release.
183+
*
184+
* @param releaseUid
185+
* unique ID of the release that you want to clone
186+
* @param requestBody
187+
* The JSONObject request body
188+
* @return Call
189+
*/
190+
public Call<ResponseBody> clone(
191+
@NotNull String releaseUid, @NotNull JSONObject requestBody) {
192+
return this.service.clone(this.headers, releaseUid, requestBody);
193+
}
194+
195+
196+
}

0 commit comments

Comments
 (0)