All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.contentstack.cms.stack.Workflow Maven / Gradle / Ivy

Go to download

Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach

There is a newer version: 1.6.1
Show newest version
package com.contentstack.cms.stack;

import com.contentstack.cms.BaseImplementation;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONObject;
import retrofit2.Call;
import retrofit2.Retrofit;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Workflow is a tool that allows you to streamline the process of content
 * creation and publishing, and lets you manage
 * the content lifecycle of your project smoothly.
 * 

* Read more about Workflow * Note: You cannot create workflows in a stack that supports branches * when using the classic Contentstack interface. * * @author ***REMOVED*** * @version v01.0 * @since 2022-10-22 */ public class Workflow implements BaseImplementation { protected final WorkflowService service; protected HashMap headers; protected HashMap params; private String workflowUid; protected Workflow(Retrofit retrofit,Map headers) { this.headers = new HashMap<>(); this.headers.putAll(headers); this.params = new HashMap<>(); this.service = retrofit.create(WorkflowService.class); } protected Workflow(Retrofit retrofit,Map headers, @NotNull String uid) { this.workflowUid = uid; this.headers = new HashMap<>(); this.headers.putAll(headers); this.params = new HashMap<>(); this.service = retrofit.create(WorkflowService.class); } void validate() { if (this.workflowUid == null || this.workflowUid.isEmpty()) throw new IllegalAccessError("Workflow uid can not be null or empty"); } /** * Set header for the request * * @param key Removes query param using key of request */ public void removeParam(@NotNull String key) { this.params.remove(key); } /** * To clear all the query params */ protected void clearParams() { this.params.clear(); } /** * Get a Single Workflow request retrieves the comprehensive details of a * specific Workflow of a stack. * * @return Call * @see Get * all workflow * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call find() { return this.service.fetch(this.headers, this.params); } /** * Get a Single Workflow request retrieves the comprehensive details of a * specific Workflow of a stack. * * @return Call * @see Get * a singel * workflow * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call fetch() { this.validate(); return this.service.single(this.headers, this.workflowUid); } /** * The Create a Workflow request allows you to create a Workflow. *

* In the 'Body' section, you can provide the details of the workflow that * includes name, content types, owners, * description, and workflow stages of your Workflow. To define the branch * scope, specify the unique IDs of the * branches for which the workflow will be applicable in the following schema in * the request body: * *

     *     "branches":[
     *     "main",
     *     "development"
     * ]
     * 
*

* To control who can edit an entry at different stages of the workflow, you can * pass the entry_lock parameter * inside each workflow stage. * Note: Workflow superusers, organization owners, and stack * owners/admins can edit or delete the entry in any workflow stage, * irrespective of the stage access rules set for * that stage. *

* Read more about Create-Workflow * * @param requestBody The details of the workflow in @{@link JSONObject} * @return Call * @see Create * workflow * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call create(@NotNull JSONObject requestBody) { return this.service.create(this.headers, requestBody); } /** * The Add or Update Workflow request allows you to add a workflow stage or * update the details of the existing * stages of a workflow. *

* In the 'Body' section, you can provide the updated details of the name, * content types, owners, description, and * workflow stages of your Workflow. To define the branch scope, specify the * unique IDs of the branches for which * the workflow will be applicable in the following schema in the request body: * *

     *     "branches":[
     *     "main",
     *     "development"
     * ]
     * 
*

* To control who can edit an entry at different stages of the workflow, you can * pass the entry_lock parameter * inside each workflow stage. *

* Note: Workflow superusers, organization owners, and stack owners/admins can * edit or delete the entry in any * workflow stage, irrespective of the stage access rules set for that stage. * * @param requestBody The body should be of @{@link JSONObject} type * @return Call * @see Update * Workflow * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call update(@NotNull JSONObject requestBody) { this.validate(); return this.service.update(this.headers, this.workflowUid, requestBody); } /** * Disable Workflow request allows you to disable a workflow. * * @return Call * @see Disable * workflow * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call disable() { this.validate(); return this.service.disable(this.headers, this.workflowUid); } /** * Enable Workflow request allows you to enable a workflow. * * @return Call * @see Enable * Workflow * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call enable() { this.validate(); return this.service.enable(this.headers, this.workflowUid); } /** * Delete Workflow request allows you to delete a workflow. * * @return Call * @see Delete * Workflow * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call delete() { this.validate(); return this.service.delete(this.headers, this.workflowUid); } /** * The Create Publish Rules request allows you to create publish rules for the * workflow of a stack. *

* To define the branch scope, specify the unique IDs of the branches for which * the publishing rule will be * applicable in the following schema in the request body: * *

     *     "branches":[
     *     "main",
     *     "development"
     * ]
     * 
* * Note: You cannot create publish rules in a stack that supports * branches when using the classic Contentstack interface. * * @param requestBody Specify the unique IDs of the branches for which the * publishing rule will be applicable in the schema in * the request body * @return Call * @see Create * Publish * Rule * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call createPublishRule(@NotNull JSONObject requestBody) { return this.service.createPublishRules(this.headers, requestBody); } /** * Add or Update Publish Rules request allows you to add a publishing rule or * update the details of the existing * publishing rules of a workflow. *

* To define the branch scope, specify the unique IDs of the branches for which * the publishing rule will be * applicable in the following schema in the request body: * * @param ruleUid The UID of the publishing rule that you want to update * @param requestBody The request body * @return Call * @see Update * Publish * Rules * * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call updatePublishRule(@NotNull String ruleUid, @NotNull JSONObject requestBody) { return this.service.updatePublishRules(this.headers, ruleUid, requestBody); } /** * To Delete Publish Rules request allows you to delete an existing publish * rule. * * @param ruleUid The UID of the publishing rule that you want to delete * @return Call * @see Delete * Publish * Rules * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call deletePublishRule(@NotNull String ruleUid) { return this.service.deletePublishRules(this.headers, ruleUid); } /** * The Get all Publish Rules request retrieves the details of all the Publishing * rules of a workflow. * * @param contentTypes comma-separated list of content type UIDs for filtering * publish rules on its basis * @return Call * @see Get * all publish * rule * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call fetchPublishRules(@NotNull List contentTypes) { this.params.put("content_types", contentTypes); this.params.put("include_count", true); return this.service.fetchPublishRules(this.headers, this.params); } /** * The Get a Single Publish Rule request retrieves the comprehensive details of * a specific publish rule of a * Workflow. * * @param ruleUid The UID of the publishing rule that you want to fetch * @return Call * @see Get * all publish * rules * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call fetchPublishRule(@NotNull String ruleUid) { return this.service.fetchPublishRules(this.headers, ruleUid); } /** * The Get Publish Rules by Content Types request allows you to retrieve details * of a Publish Rule applied to a * specific content type of your stack. *

* 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. * * @param contentTypeUid The UID of the content type of which you want to * retrieve the Publishing Rule. * @return Call * @see Get * Publish Rules By Content Types * * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ public Call fetchPublishRuleContentType(@NotNull String contentTypeUid) { if (contentTypeUid.isEmpty()) { throw new IllegalArgumentException("Content Type can not be empty"); } return this.service.fetchPublishRuleContentType(this.headers, contentTypeUid, this.params); } /** * The Get all Tasks request retrieves a list of all tasks assigned to you. *

* 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. * * @return Call * @see Get * all * Tasks * @since 0.1.0 */ public Call fetchTasks() { return this.service.fetchTasks(this.headers, this.params); } /** * @param key A string representing the key of the parameter. It cannot be * null and must be * provided as a non-null value. * @param value The "value" parameter is of type Object, which means it can * accept any type of * object as its value. * @return instance of the {@link Workflow} */ @Override public Workflow addParam(@NotNull String key, @NotNull Object value) { this.params.put(key, value); return this; } /** * @param key The key parameter is a string that represents the name or * identifier of the header. * It is used to specify the type of information being sent in the * header. * @param value The value parameter is a string that represents the value of the * header. * @return instance of the {@link Workflow} */ @Override public Workflow addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); return this; } /** * @param params The "params" parameter is a HashMap that maps String keys to * Object values. It is * annotated with @NotNull, indicating that it cannot be null. * @return instance of the {@link Workflow} */ @Override public Workflow addParams(@NotNull HashMap params) { this.params.putAll(params); return this; } /** * @param headers A HashMap containing key-value pairs of headers, where the key * is a String * representing the header name and the value is a String * representing the header value. * @return instance of the {@link Workflow} */ @Override public Workflow addHeaders(@NotNull HashMap headers) { this.headers.putAll(headers); return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy