|
| 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