|
| 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 | +} |
0 commit comments