Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX | 03-02-2025 | Hotfix Release #112

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: mvn jacoco:prepare-agent jacoco:report

- name: Upload Code Coverage Report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: target/site/jacoco
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.5.2

### Feb 03, 2025

- Feature added related to entry workflow methods

## v1.5.1

### Jan 20, 2025
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.5.1</version>
<version>1.5.2</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/contentstack/cms/stack/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,4 +825,40 @@ public Call<ResponseBody> query(@NotNull JSONObject query) {
return this.service.filterTaxonomy(this.headers, this.contentTypeUid, query);
}


/**
* The Set Entry Workflow Stage request allows you to either set a particular workflow stage of an entry or update the workflow stage details of an entry.
* To configure the permissions for your application via OAuth,
* please include the cm.entry.workflow:write scope.
* In the 'Body' section, you need to provide the details of the workflow stage.
* Enter a comment for the assigned user, if needed; provide the due date;
* set notification settings to ‘true’, so that the specified user will be notified of it;
* enter the UID of the workflow stage; and finally, enter the user details, such as UID, name, and email address of the user.
* param query the request body of type {@link JSONObject}
*/

public Call<ResponseBody> setWorkflowStage(@NotNull JSONObject workflow) {
validateCT();
validateEntry();
return this.service.setWorkflowStage(this.headers, this.contentTypeUid, this.entryUid, this.params, workflow);
}


/**
* This multipurpose request allows you to either send a publish request or accept/reject a received publish request.
* When executing the API request, in the 'Header' section,
* you need to provide the API Key of your stack and the authtoken that you receive after logging into your account.
* In the 'Body' section, you need to provide the details of the publish rule,
* such as its UID, action (‘publish’, ‘unpublish’, or ’both’),
* status (this could be ‘0’ for Approval Requested, ‘1’ for ‘Approval Accepted’, and ‘-1’ for ‘Approval Rejected’),
* notification setting, and comment for the approver.
* param query the request body of type {@link JSONObject}
*/

public Call<ResponseBody> publishRequest(@NotNull JSONObject publishing_rule) {
validateCT();
validateEntry();
return this.service.publishRequestApproval(this.headers, this.contentTypeUid, this.entryUid, this.params, publishing_rule);
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/contentstack/cms/stack/EntryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,19 @@ Call<ResponseBody> filterTaxonomy(
@Path("content_type_uid") String contentTypeUid,
@Query("query") JSONObject queryObject);

@POST("content_types/{content_type_uid}/entries/{entry_uid}/workflow")
Call<ResponseBody> setWorkflowStage(
@HeaderMap Map<String, Object> headers,
@Path("content_type_uid") String contentTypeUid,
@Path("entry_uid") String entryUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@POST("content_types/{content_type_uid}/entries/{entry_uid}/workflow")
Call<ResponseBody> publishRequestApproval(
@HeaderMap Map<String, Object> headers,
@Path("content_type_uid") String contentTypeUid,
@Path("entry_uid") String entryUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);
}
16 changes: 0 additions & 16 deletions src/main/java/com/contentstack/cms/stack/WorkflowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ Call<ResponseBody> delete(
@HeaderMap Map<String, Object> headers,
@Path("workflow_uid") String workflowUid);

@POST("content_types/{content_type_uid}/entries/{entry_uid}/workflow")
Call<ResponseBody> updateWorkflowStage(
@HeaderMap Map<String, Object> headers,
@Path("content_type_uid") String contentTypeUid,
@Path("entry_uid") String entryUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@POST("workflows/publishing_rules")
Call<ResponseBody> createPublishRules(
@HeaderMap Map<String, Object> headers,
Expand Down Expand Up @@ -85,14 +77,6 @@ Call<ResponseBody> fetchPublishRuleContentType(
@Path("content_type_uid") String contentTypeUid,
@QueryMap Map<String, Object> params);

@POST("content_types/{content_type_uid}/entries/{entry_uid}/workflow")
Call<ResponseBody> publishRequestApproval(
@HeaderMap Map<String, Object> headers,
@Path("content_type_uid") String contentTypeUid,
@Path("entry_uid") String entryUid,
@QueryMap Map<String, Object> params,
@Body JSONObject body);

@GET("workflows/content_type/{content_type_uid}")
Call<ResponseBody> fetchTasks(
@HeaderMap Map<String, Object> headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.jupiter.api.*;

import java.io.IOException;
Expand Down Expand Up @@ -818,4 +820,96 @@ void queryFiltersOnTaxonomy() {

}

@Test
void testSetWorkflowStage() throws ParseException, IOException {
String workflowStagePayload = "{\n" +
" \"workflow\": {\n" +
" \"workflow_stage\": {\n" +
" \"uid\": \"uid\",\n" +
" \"assigned_by_roles\": [{ \"uid\": \"uid\", \"name\": \"Content Manager\" }],\n" +
" \"due_date\": \"Thu Feb 06 2025\",\n" +
" \"comment\": \"Review the entry\",\n" +
" \"notify\": true,\n" +
" \"assigned_to\": [{ \"uid\": \"user_uid\", \"name\": \"name\", \"email\": \"mail.com\" }]\n" +
" }\n" +
" }\n" +
"}";
JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(workflowStagePayload);
Entry entry1 = TestClient.getClient().stack(API_KEY,MANAGEMENT_TOKEN).contentType("author").entry("entry_uid");
Request request = entry1.setWorkflowStage(body).request();
Assertions.assertNotNull(request);
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals(6, request.url().pathSegments().size());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("content_types", request.url().pathSegments().get(1));
Assertions.assertEquals("author", request.url().pathSegments().get(2));
Assertions.assertEquals("entries", request.url().pathSegments().get(3));
Assertions.assertEquals("entry_uid", request.url().pathSegments().get(4));
Assertions.assertEquals("workflow", request.url().pathSegments().get(5));
Assertions.assertEquals("https://api.contentstack.io/v3/content_types/author/entries/entry_uid/workflow", request.url().toString());
}

@Test
void setWorkflowStage_VerifyQueryParams() throws ParseException {
String payload = "{ \"workflow\": { \"workflow_stage\": { \"uid\": \"stage_uid\" } } }";
JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(payload);
Entry entry = TestClient.getClient().stack(API_KEY, MANAGEMENT_TOKEN).contentType("author").entry("entry_uid");
entry.addParam("locale", "en-us");
Request request = entry.setWorkflowStage(body).request();
Assertions.assertNotNull(request.url().encodedQuery());
Assertions.assertEquals("locale=en-us", request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/content_types/author/entries/entry_uid/workflow?locale=en-us", request.url().toString());
}

@Test
void testPublishRequest_ValidRequest() throws ParseException {
Contentstack contentstack = new Contentstack.Builder().setAuthtoken(TestClient.AUTHTOKEN).build();
Stack stack = contentstack.stack(TestClient.API_KEY, TestClient.MANAGEMENT_TOKEN);
String publishRequestPayload = "{\n" +
" \"workflow\": {\n" +
" \"publishing_rule\": {\n" +
" \"uid\": \"rule_uid\",\n" +
" \"action\": \"publish\",\n" +
" \"status\": 1,\n" +
" \"notify\": true,\n" +
" \"comment\": \"Approve this entry.\"\n" +
" }\n" +
" }\n" +
"}";
JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(publishRequestPayload);
Request request = stack.contentType("author").entry("entry_uid").publishRequest(body).request();

Assertions.assertEquals("POST", request.method());
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("content_types", request.url().pathSegments().get(1));
Assertions.assertEquals("author", request.url().pathSegments().get(2));
Assertions.assertEquals("entries", request.url().pathSegments().get(3));
Assertions.assertEquals("entry_uid", request.url().pathSegments().get(4));
Assertions.assertEquals("workflow", request.url().pathSegments().get(5));
Assertions.assertTrue(request.headers().names().contains("authorization"));
Assertions.assertTrue(request.headers().names().contains("api_key"));
}

@Test
void testPublishRequest_InvalidRequestBody() throws ParseException, IOException {
Contentstack contentstack = new Contentstack.Builder().setAuthtoken(TestClient.AUTHTOKEN).build();
Stack stack = contentstack.stack(TestClient.API_KEY, TestClient.MANAGEMENT_TOKEN);
String invalidPayload = "{ \"invalid_field\": \"invalid_value\" }";
JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(invalidPayload);
Request request = stack.contentType("author").entry("entry_uid").publishRequest(body).request();
Assertions.assertEquals("POST", request.method());
Assertions.assertTrue(request.headers().names().contains("authorization"));
Assertions.assertTrue(request.headers().names().contains("api_key"));
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
}

}
Loading