Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,4 @@ src/main/resources/
.vscode/settings.json
.vscode/
/.vscode/
.env
78 changes: 62 additions & 16 deletions src/main/java/com/contentstack/cms/stack/BulkOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* @author ***REMOVED***
* @version v1.0.0
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#bulk-publish-operation">
* Bulk Operations Queue </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#bulk-publish-operation">
* Bulk Operations Queue </a>
* @since 2023 -08-23
*/
public class BulkOperation implements BaseImplementation<BulkOperation> {
Expand All @@ -49,7 +49,7 @@ public class BulkOperation implements BaseImplementation<BulkOperation> {
*
* @param retrofit the retrofit
*/
protected BulkOperation(Retrofit retrofit,Map<String, Object> headers) {
protected BulkOperation(Retrofit retrofit, Map<String, Object> headers) {
this.headers = new HashMap<>();
this.headers.putAll(headers);
this.params = new HashMap<>();
Expand Down Expand Up @@ -88,9 +88,9 @@ protected BulkOperation(Retrofit retrofit,Map<String, Object> headers) {
* @param body The JSON object containing the data to be published.
* @return Call object for the API request.
* @see <a
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-entries-and-assets-in-bulk">
* Publish entries and assets in bulk </a>
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-entries-and-assets-in-bulk">
* Publish entries and assets in bulk </a>
* @see #addHeader(String, String) #addHeader(String, String)to add headers in
* @see #addParam(String, Object) #addParam(String, Object)to add query
* @since 1.0.0
Expand Down Expand Up @@ -130,11 +130,11 @@ public Call<ResponseBody> publish(@NotNull JSONObject body) {
* @param body the body
* @return Call call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#bulk-unpublish-operation">Bulk
* Unpublish Operation </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#bulk-unpublish-operation">Bulk
* Unpublish Operation </a>
* @see #addHeader(String, String) #addHeader(String, String)to add headers
* @see #addParam(String, Object) #addParam(String, Object)to add query
* parameters
* parameters
* @since 0.1.0
*/
public Call<ResponseBody> unpublish(@NotNull JSONObject body) {
Expand All @@ -159,11 +159,11 @@ public Call<ResponseBody> unpublish(@NotNull JSONObject body) {
* @param body the body
* @return Call call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-entries-and-assets-in-bulk">Bulk
* Delete Operation </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-entries-and-assets-in-bulk">Bulk
* Delete Operation </a>
* @see #addHeader(String, String) #addHeader(String, String)to add headers
* @see #addParam(String, Object) #addParam(String, Object)to add query
* parameters
* parameters
* @since 0.1.0
*/
public Call<ResponseBody> delete(JSONObject body) {
Expand All @@ -190,16 +190,61 @@ public Call<ResponseBody> delete(JSONObject body) {
* @param body the body
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-entries-and-assets-in-bulk">Bulk
* Delete Operation </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-entries-and-assets-in-bulk">Bulk
* Delete Operation </a>
* @see #addHeader(String, String) #addHeader(String, String)to add headers
* @see #addParam(String, Object) #addParam(String, Object)to add query
* parameters
* parameters
* @since 0.1.0
*/
public Call<ResponseBody> updateWorkflow(@NotNull JSONObject body) {
return this.service.updateWorkflowDetails(this.headers, this.params, body);
}
/**
* The Add Release items request allows you to add multiple items (entries and
* assets) to a Release.
* <p>
* When executing the API request, you need to provide the Release UID. In the
* 'Body' section, you need to provide
* the details of the items
*
* @param jsonBody requestBody for create/add single Item
* @return Call
*/
public Call<ResponseBody> addReleaseItems(@NotNull JSONObject jsonBody) {
Call<ResponseBody> addItemsCall;
this.headers.put("bulk_version", "2.0");
addItemsCall = this.service.addBulkItems(this.headers, this.params, jsonBody);
this.headers.remove("bulk_version");
return addItemsCall;
}

/**
* The Update Release items request to Update release items to latest version
*/
public Call<ResponseBody> updateReleaseItems(@NotNull JSONObject jsonBody) {
Call<ResponseBody> updateItemsCall;
this.headers.put("bulk_version", "2.0");
updateItemsCall = this.service.updateBulkItems(this.headers, this.params, jsonBody);
this.headers.remove("bulk_version");
return updateItemsCall;
}

/**
* The Get Job Status request allows you to get the status of a job.
* <p>
* When executing the API request, you need to provide the job UID.
*
* @param jobUid the job UID
* @return Call
*/
public Call<ResponseBody> jobStatus(@NotNull String jobUid) {
Call<ResponseBody> jobStatusCall;
this.headers.put("bulk_version", "2.0");
jobStatusCall = this.service.getJobStatus(this.headers, jobUid, this.params);
this.headers.remove("bulk_version");
return jobStatusCall;
}

/**
* Adds a header with the specified key and value to this location and returns
Expand Down Expand Up @@ -236,7 +281,8 @@ public BulkOperation addHeader(@NotNull String key, @NotNull String value) {
* location.
*
* @param params a {@link HashMap} containing the parameters to be added
* @return a new {@link BulkOperation} object with the specified parameters added
* @return a new {@link BulkOperation} object with the specified parameters
* added
* @throws NullPointerException if the params argument is null
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import org.json.simple.JSONObject;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.HeaderMap;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.QueryMap;

import java.util.HashMap;
Expand Down Expand Up @@ -37,4 +40,22 @@ Call<ResponseBody> updateWorkflowDetails(
@QueryMap HashMap<String, Object> params,
@Body JSONObject body);

@POST("bulk/release/items")
Call<ResponseBody> addBulkItems(
@HeaderMap Map<String, Object> headers,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@PUT("bulk/release/update_items")
Call<ResponseBody> updateBulkItems(
@HeaderMap Map<String, Object> headers,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@GET("bulk/jobs/{job_id}")
Call<ResponseBody> getJobStatus(
@HeaderMap Map<String, Object> headers,
@Path("job_id") String jobUid,
@QueryMap Map<String, Object> params);

}
37 changes: 35 additions & 2 deletions src/main/java/com/contentstack/cms/stack/ReleaseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ReleaseItem implements BaseImplementation<ReleaseItem> {
protected HashMap<String, Object> params;
private final String releaseUid;

protected ReleaseItem(Retrofit retrofit,Map<String, Object> headers, String releaseUid) {
protected ReleaseItem(Retrofit retrofit, Map<String, Object> headers, String releaseUid) {
this.headers = new HashMap<>();
this.headers.putAll(headers);
this.params = new HashMap<>();
Expand All @@ -43,7 +43,6 @@ void validate() {
throw new IllegalAccessError("Release Uid can not be null or empty");
}


/**
* @param key A string representing the key of the parameter. It cannot be
* null and must be
Expand Down Expand Up @@ -244,4 +243,38 @@ public Call<ResponseBody> delete() {
return this.service.removeItem(this.headers, this.releaseUid);
}

/**
* The Deletes a multiple items request deteles multiple items from a Release
*
* @param jsonBody requestBody for delete Items
* @return Call
*/
public Call<ResponseBody> deleteReleaseItems(@NotNull JSONObject jsonBody) {
validate();
return this.service.deleteItems(this.headers, this.releaseUid, this.params, jsonBody);
}

/**
* The Delete a single item request delete single item from a Release
*
* @param jsonBody requestBody for delete single Item
* @return Call
*/
public Call<ResponseBody> deleteReleaseItem(@NotNull JSONObject jsonBody) {
validate();
return this.service.deleteItem(this.headers, this.releaseUid, this.params, jsonBody);
}

/**
* The Move items in a Release request allows you to move one or more items
* (entries and/or assets) from one
* Release to another.
*
* @param jsonBody requestBody for move items
* @return Call
*/
public Call<ResponseBody> move(@NotNull JSONObject jsonBody) {
validate();
return this.service.moveItems(this.headers, this.releaseUid, this.params, jsonBody);
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/contentstack/cms/stack/ReleaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,24 @@ Call<ResponseBody> clone(
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@POST("/releases/{source_releaseUid}/items/move")
Call<ResponseBody> moveItems(
@HeaderMap Map<String, Object> headers,
@Path("source_releaseUid") String releaseUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@HTTP(method = "DELETE", path = "releases/{release_uid}/items", hasBody = true)
Call<ResponseBody> deleteItems(
@HeaderMap Map<String, Object> headers,
@Path("release_uid") String releaseUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@HTTP(method = "DELETE", path = "releases/{release_uid}/item", hasBody = true)
Call<ResponseBody> deleteItem(
@HeaderMap Map<String, Object> headers,
@Path("release_uid") String releaseUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Tag("unit")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class BulkOperationTest {
class BulkOperationAPITest {

protected static String AUTHTOKEN = TestClient.AUTHTOKEN;
protected static String API_KEY = TestClient.API_KEY;
Expand Down Expand Up @@ -130,4 +130,37 @@ void testUpdateWorkflow() {
request.url().toString());
}

@Test
@Order(8)
void testAddBulkItems() {
Request request = bulkOperation.addReleaseItems(new JSONObject()).request();
Assertions.assertEquals(3, request.headers().names().size());
Assertions.assertEquals("POST", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("bulk", request.url().pathSegments().get(1));
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
}

@Test
@Order(9)
void testUpdateBulkItems() {
Request request = bulkOperation.updateReleaseItems(new JSONObject()).request();
Assertions.assertEquals(3, request.headers().names().size());
Assertions.assertEquals("PUT", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("bulk", request.url().pathSegments().get(1));
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
}

@Test
@Order(10)
void testGetJobStatus() {
Request request = bulkOperation.jobStatus("jobId").request();
Assertions.assertEquals("GET", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("bulk", request.url().pathSegments().get(1));
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("jobs", request.url().pathSegments().get(2));
}

}
Loading