Skip to content

Commit 29027c5

Browse files
Workflow, AuditLog, PublishQueue & Webhooks
Workflow, AuditLog, PublishQueue & Webhooks
1 parent 1b01d59 commit 29027c5

File tree

13 files changed

+1842
-4
lines changed

13 files changed

+1842
-4
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import retrofit2.Call;
6+
import retrofit2.Retrofit;
7+
8+
import java.util.HashMap;
9+
10+
11+
/**
12+
* Audit log displays a record of all the activities performed in a stack and helps you keep a track of all published
13+
* items, updates, deletes, and current status of the existing content. Read more about Audit Log.
14+
* <p>
15+
* You can now pass the branch header in the API request to fetch or manage modules located within specific branches of
16+
* the stack. Additionally, you can also set the include_branch query parameter to true to include the branch top-level
17+
* key in the response. This key specifies the unique ID of the branch where the concerned Contentstack module resides.
18+
* <p>
19+
* Read more about <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#audit-log">Audit
20+
* Log</a>
21+
*
22+
* @author ***REMOVED***
23+
* @version 1.0.0
24+
* @since 2022-05-19
25+
*/
26+
public class AuditLog {
27+
28+
protected final AuditLogService service;
29+
protected HashMap<String, Object> headers;
30+
protected HashMap<String, Object> params;
31+
private final Retrofit retrofit;
32+
33+
protected AuditLog(Retrofit retrofit, HashMap<String, Object> stackHeaders) {
34+
this.headers = new HashMap<>();
35+
this.params = new HashMap<>();
36+
this.headers.putAll(stackHeaders);
37+
this.retrofit = retrofit;
38+
this.service = this.retrofit.create(AuditLogService.class);
39+
}
40+
41+
/**
42+
* Sets header for the request
43+
*
44+
* @param key
45+
* header key for the request
46+
* @param value
47+
* header value for the request
48+
*/
49+
public void addHeader(@NotNull String key, @NotNull Object value) {
50+
this.headers.put(key, value);
51+
}
52+
53+
/**
54+
* Sets header for the request
55+
*
56+
* @param key
57+
* header key for the request
58+
* @param value
59+
* header value for the request
60+
*/
61+
public void addParam(@NotNull String key, @NotNull Object value) {
62+
this.params.put(key, value);
63+
}
64+
65+
66+
/**
67+
* Sets header for the request
68+
*
69+
* @param key
70+
* header key for the request
71+
*/
72+
public void removeParam(@NotNull String key) {
73+
this.params.remove(key);
74+
}
75+
76+
77+
/**
78+
* The Get audit log request is used to retrieve the audit log of a stack.
79+
* <p>
80+
* You can apply queries to filter the results. Refer to the Queries section for more details.
81+
*
82+
* @return Call
83+
*/
84+
public Call<ResponseBody> fetch() {
85+
return this.service.fetch(this.headers, this.params);
86+
}
87+
88+
89+
/**
90+
* The Get audit log item request is used to retrieve a specific item from the audit log of a stack.
91+
*
92+
* @param logItemUid
93+
* The UID of a specific log item you want to retrieve the details of
94+
* @return Call
95+
*/
96+
public Call<ResponseBody> fetchAuditLog(@NotNull String logItemUid) {
97+
return this.service.fetch(this.headers, logItemUid);
98+
}
99+
100+
101+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.json.simple.JSONObject;
5+
import retrofit2.Call;
6+
import retrofit2.http.*;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
public interface AuditLogService {
12+
13+
@GET("audit-logs")
14+
Call<ResponseBody> fetch(
15+
@HeaderMap Map<String, Object> headers,
16+
@QueryMap HashMap<String, Object> params);
17+
18+
@GET("audit-logs/{log_item_uid}")
19+
Call<ResponseBody> fetch(
20+
@HeaderMap Map<String, Object> headers,
21+
@Path("log_item_uid") String logItemUid);
22+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import retrofit2.Call;
6+
import retrofit2.Retrofit;
7+
8+
import java.util.HashMap;
9+
10+
11+
/**
12+
* The Publish Queue displays the historical and current details of activities such as publish, unpublish, or delete
13+
* that can be performed on entries and/or assets. It also shows details of Release deployments. These details include
14+
* time, entry, content type, version, language, user, environment, and status.
15+
* <p>
16+
* For more details, refer the Publish Queue documentation.
17+
* <p>
18+
* You can now pass the branch header in the API request to fetch or manage modules located within specific branches of
19+
* the stack. Additionally, you can also set the include_branch query parameter to true to include the branch top-level
20+
* key in the response. This key specifies the unique ID of the branch where the concerned Contentstack module resides.
21+
* <p>
22+
* Read more about <a
23+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-queue">Publish Queue</a>
24+
*
25+
* @author ***REMOVED***
26+
* @version 1.0.0
27+
* @since 2022-05-19
28+
*/
29+
public class PublishQueue {
30+
31+
protected final PublishQueueService service;
32+
protected HashMap<String, Object> headers;
33+
protected HashMap<String, Object> params;
34+
private final Retrofit retrofit;
35+
36+
protected PublishQueue(Retrofit retrofit, HashMap<String, Object> stackHeaders) {
37+
this.headers = new HashMap<>();
38+
this.params = new HashMap<>();
39+
this.headers.putAll(stackHeaders);
40+
this.retrofit = retrofit;
41+
this.service = this.retrofit.create(PublishQueueService.class);
42+
}
43+
44+
/**
45+
* Sets header for the request
46+
*
47+
* @param key
48+
* header key for the request
49+
* @param value
50+
* header value for the request
51+
*/
52+
public void addHeader(@NotNull String key, @NotNull Object value) {
53+
this.headers.put(key, value);
54+
}
55+
56+
/**
57+
* Sets header for the request
58+
*
59+
* @param key
60+
* header key for the request
61+
* @param value
62+
* header value for the request
63+
*/
64+
public void addParam(@NotNull String key, @NotNull Object value) {
65+
this.params.put(key, value);
66+
}
67+
68+
69+
/**
70+
* Sets header for the request
71+
*
72+
* @param key
73+
* header key for the request
74+
*/
75+
public void removeParam(@NotNull String key) {
76+
this.params.remove(key);
77+
}
78+
79+
80+
/**
81+
* The Get publish queue request returns comprehensive information on activities such as publish, unpublish, and
82+
* delete that have performed on entries and/or assets. This request also includes the details of the release
83+
* deployments in the response body.
84+
* <p>
85+
* <b>Note:</b> You can retrieve the publish queue details for activities performed on entries and/or assets of
86+
* your stack in the last 30 days.
87+
* <p>
88+
* You can apply queries to filter the results. Refer to the Queries section for more details.
89+
* <p>
90+
* Note: In the Header, you need to pass either the stacks Management Token (highly recommended) or the user
91+
* Authtoken, along with the stack API key, to make valid Content Management API requests. For more information,
92+
* refer to Authentication.
93+
* <p>
94+
* You can add headers to the request by using {@link #addParam(String, Object)}
95+
*
96+
* @return Call
97+
*/
98+
public Call<ResponseBody> fetch() {
99+
return this.service.fetch(this.headers, this.params);
100+
}
101+
102+
103+
/**
104+
* Get publish queue activity request returns comprehensive information on a specific publish, unpublish, or delete
105+
* action that was performed on an entry and/or asset. You can also retrieve details of a specific release
106+
* deployment.
107+
* <p>
108+
* Add addional query parameters to the request using {@link #addParam(String, Object)}
109+
*
110+
* @param publishQueueUid
111+
* the UID of a specific publish queue activity of which you want to retrieve the details. Execute the Get
112+
* publish queue API request to retrieve the UID of a particular publish queue activity.
113+
* @return Call
114+
*/
115+
public Call<ResponseBody> fetchActivity(@NotNull String publishQueueUid) {
116+
return this.service.fetchActivity(this.headers, publishQueueUid, this.params);
117+
}
118+
119+
120+
/**
121+
* The <b>Cancel Scheduled Action</b> request will allow you to cancel any scheduled publishing or unpublishing
122+
* activity of entries and/or assets and also cancel the deployment of releases
123+
*
124+
* @param publishQueueUid
125+
* The UID of the event to be cancelled in the publish queue.
126+
* @return Call
127+
*/
128+
public Call<ResponseBody> cancelScheduledAction(String publishQueueUid) {
129+
return this.service.cancelScheduledAction(this.headers, publishQueueUid, this.params);
130+
}
131+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import retrofit2.Call;
5+
import retrofit2.http.*;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public interface PublishQueueService {
11+
12+
@GET("publish-queue")
13+
Call<ResponseBody> fetch(@HeaderMap Map<String, Object> headers, @QueryMap HashMap<String, Object> params);
14+
15+
@GET("publish-queue/{publish_queue_uid}")
16+
Call<ResponseBody> fetchActivity(@HeaderMap Map<String, Object> headers, @Path("publish_queue_uid") String publishQueueUid,
17+
@QueryMap HashMap<String, Object> params);
18+
19+
@GET("publish-queue/{publish_queue_uid}/unschedule")
20+
Call<ResponseBody> cancelScheduledAction(@HeaderMap Map<String, Object> headers, @Path("publish_queue_uid") String publishQueueUid,
21+
@QueryMap HashMap<String, Object> params);
22+
}

src/main/java/com/contentstack/cms/stack/Stack.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import retrofit2.Call;
99
import retrofit2.Retrofit;
1010

11-
import javax.management.relation.Role;
11+
1212
import java.util.HashMap;
1313
import java.util.Map;
1414

@@ -216,16 +216,56 @@ public Roles roles() {
216216
}
217217

218218
/**
219-
* You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a ‘release’,
220-
* and then deploy this release to an environment. This will publish/unpublish all the the items of the release to
221-
* the specified environment. Read more about Releases.
219+
* You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a
220+
* <b>release</b>, and then deploy this release to an environment. This will publish/unpublish all the the items of
221+
* the release to the specified environment. Read more about Releases.
222222
*
223223
* @return Release
224224
*/
225225
public Release releases() {
226226
return new Release(this.client, this.headers);
227227
}
228228

229+
230+
/**
231+
* <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#workflows">Workflow</a> is a
232+
* tool that allows you to streamline the process of content creation and publishing, and lets you manage the
233+
* content lifecycle of your project smoothly.
234+
*
235+
* @return Workflow
236+
*/
237+
public Workflow workflow() {
238+
return new Workflow(this.client, this.headers);
239+
}
240+
241+
242+
/**
243+
* Audit log displays a record of all the activities performed in a stack and helps you keep a track of all
244+
* published items, updates, deletes, and current status of the existing content. Read more about <a
245+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#audit-log">AuditLog</a>.
246+
*
247+
* @return AuditLog
248+
*/
249+
public AuditLog auditLog() {
250+
return new AuditLog(this.client, this.headers);
251+
}
252+
253+
254+
/**
255+
* The Publish Queue displays the historical and current details of activities such as publish, unpublish, or delete
256+
* that can be performed on entries and/or assets. It also shows details of Release deployments. These details
257+
* include time, entry, content type, version, language, user, environment, and status.
258+
* <p>
259+
* For more details, refer the <a
260+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-queue">Publish Queue</a>
261+
* documentation.
262+
*
263+
* @return PublishQueue
264+
*/
265+
public PublishQueue publishQueue() {
266+
return new PublishQueue(this.client, this.headers);
267+
}
268+
229269
/**
230270
* <b>Get a single stack</b>
231271
* <br>

0 commit comments

Comments
 (0)