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

com.checkout.workflows.WorkflowsClientImpl Maven / Gradle / Ivy

There is a newer version: 6.4.2
Show newest version
package com.checkout.workflows;

import com.checkout.AbstractClient;
import com.checkout.ApiClient;
import com.checkout.CheckoutConfiguration;
import com.checkout.EmptyResponse;
import com.checkout.ItemsResponse;
import com.checkout.SdkAuthorizationType;
import com.checkout.common.IdResponse;
import com.checkout.workflows.actions.request.WorkflowActionRequest;
import com.checkout.workflows.actions.response.WorkflowActionInvocationsResponse;
import com.checkout.workflows.conditions.request.WorkflowConditionRequest;
import com.checkout.workflows.events.GetEventResponse;
import com.checkout.workflows.events.SubjectEventsResponse;
import com.checkout.workflows.events.WorkflowEventTypes;
import com.checkout.workflows.reflow.ReflowRequest;
import com.checkout.workflows.reflow.ReflowResponse;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.concurrent.CompletableFuture;

import static com.checkout.common.CheckoutUtils.validateParams;

public class WorkflowsClientImpl extends AbstractClient implements WorkflowsClient {

    private static final String WORKFLOWS_PATH = "workflows";
    private static final String WORKFLOW_PATH = "workflow";
    private static final String ACTIONS_PATH = "actions";
    private static final String CONDITIONS_PATH = "conditions";
    private static final String EVENT_TYPES_PATH = "event-types";
    private static final String EVENTS_PATH = "events";
    private static final String REFLOW_PATH = "reflow";
    private static final String SUBJECT_PATH = "subject";
    private static final String WORKFLOW_ID = "workflowId";

    private static final Type WORKFLOWS_EVENT_TYPES_TYPE = new TypeToken>() {
    }.getType();

    public WorkflowsClientImpl(final ApiClient apiClient, final CheckoutConfiguration configuration) {
        super(apiClient, configuration, SdkAuthorizationType.SECRET_KEY_OR_OAUTH);
    }

    @Override
    public CompletableFuture getWorkflows() {
        return apiClient.getAsync(
                WORKFLOWS_PATH,
                sdkAuthorization(),
                GetWorkflowsResponse.class);
    }

    @Override
    public CompletableFuture createWorkflow(final CreateWorkflowRequest createWorkflowRequest) {
        validateParams("createWorkflowRequest", createWorkflowRequest);
        return apiClient.postAsync(
                WORKFLOWS_PATH,
                sdkAuthorization(),
                CreateWorkflowResponse.class,
                createWorkflowRequest,
                null);
    }

    @Override
    public CompletableFuture getWorkflow(final String workflowId) {
        validateParams(WORKFLOW_ID, workflowId);
        return apiClient.getAsync(buildPath(WORKFLOWS_PATH, workflowId), sdkAuthorization(), GetWorkflowResponse.class);
    }

    @Override
    public CompletableFuture removeWorkflow(final String workflowId) {
        validateParams(WORKFLOW_ID, workflowId);
        return apiClient.deleteAsync(buildPath(WORKFLOWS_PATH, workflowId), sdkAuthorization());
    }

    @Override
    public CompletableFuture updateWorkflow(final String workflowId,
                                                                    final UpdateWorkflowRequest updateWorkflowRequest) {
        validateParams(WORKFLOW_ID, workflowId, "updateWorkflowRequest", updateWorkflowRequest);
        return apiClient.patchAsync(
                buildPath(WORKFLOWS_PATH, workflowId),
                sdkAuthorization(),
                UpdateWorkflowResponse.class,
                updateWorkflowRequest,
                null);
    }

    @Override
    public CompletableFuture addWorkflowAction(final String workflowId,
                                                           final WorkflowActionRequest workflowActionRequest) {
        validateParams(WORKFLOW_ID, workflowId, "workflowActionRequest", workflowActionRequest);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, workflowId, ACTIONS_PATH),
                sdkAuthorization(),
                IdResponse.class,
                workflowActionRequest,
                null
        );
    }

    @Override
    public CompletableFuture updateWorkflowAction(final String workflowId,
                                                                 final String actionId,
                                                                 final WorkflowActionRequest workflowActionRequest) {
        validateParams(WORKFLOW_ID, workflowId, "actionId", actionId, "workflowActionRequest", workflowActionRequest);
        return apiClient.putAsync(
                buildPath(WORKFLOWS_PATH, workflowId, ACTIONS_PATH, actionId),
                sdkAuthorization(),
                EmptyResponse.class,
                workflowActionRequest);
    }

    @Override
    public CompletableFuture removeWorkflowAction(final String workflowId,
                                                                 final String actionId) {
        validateParams(WORKFLOW_ID, workflowId, "actionId", actionId);
        return apiClient.deleteAsync(
                buildPath(WORKFLOWS_PATH, workflowId, ACTIONS_PATH, actionId),
                sdkAuthorization()
        );
    }

    @Override
    public CompletableFuture addWorkflowCondition(final String workflowId,
                                                              final WorkflowConditionRequest workflowConditionRequest) {
        validateParams(WORKFLOW_ID, workflowId, "workflowConditionRequest", workflowConditionRequest);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, workflowId, CONDITIONS_PATH),
                sdkAuthorization(),
                IdResponse.class,
                workflowConditionRequest,
                null);
    }

    @Override
    public CompletableFuture updateWorkflowCondition(final String workflowId,
                                                                    final String conditionId,
                                                                    final WorkflowConditionRequest workflowConditionRequest) {
        validateParams(WORKFLOW_ID, workflowId, "conditionId", conditionId, "workflowConditionRequest", workflowConditionRequest);
        return apiClient.putAsync(
                buildPath(WORKFLOWS_PATH, workflowId, CONDITIONS_PATH, conditionId),
                sdkAuthorization(),
                EmptyResponse.class,
                workflowConditionRequest);
    }

    @Override
    public CompletableFuture removeWorkflowCondition(final String workflowId, final String conditionId) {
        validateParams(WORKFLOW_ID, workflowId, "conditionId", conditionId);
        return apiClient.deleteAsync(
                buildPath(WORKFLOWS_PATH, workflowId, CONDITIONS_PATH, conditionId),
                sdkAuthorization());
    }

    @Override
    public CompletableFuture> getEventTypes() {
        return apiClient.getAsync(
                buildPath(WORKFLOWS_PATH, EVENT_TYPES_PATH),
                sdkAuthorization(),
                WORKFLOWS_EVENT_TYPES_TYPE);
    }

    @Override
    public CompletableFuture getEvent(final String eventId) {
        validateParams("eventId", eventId);
        return apiClient.getAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, eventId),
                sdkAuthorization(),
                GetEventResponse.class);
    }

    @Override
    public CompletableFuture getActionInvocations(final String eventId, final String actionId) {
        validateParams("eventId", eventId, "actionId", actionId);
        return apiClient.getAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, eventId, ACTIONS_PATH, actionId),
                sdkAuthorization(),
                WorkflowActionInvocationsResponse.class);
    }

    @Override
    public CompletableFuture reflowByEvent(final String eventId) {
        validateParams("eventId", eventId);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, eventId, REFLOW_PATH),
                sdkAuthorization(),
                ReflowResponse.class,
                null,
                null);
    }

    @Override
    public CompletableFuture reflowByEventAndWorkflow(final String eventId,
                                                                      final String workflowId) {
        validateParams("eventId", eventId, WORKFLOW_ID, workflowId);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, eventId, WORKFLOW_PATH, workflowId, REFLOW_PATH),
                sdkAuthorization(),
                ReflowResponse.class,
                null,
                null);
    }

    @Override
    public CompletableFuture reflow(final ReflowRequest reflowRequest) {
        validateParams("reflowRequest", reflowRequest);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, REFLOW_PATH),
                sdkAuthorization(),
                ReflowResponse.class,
                reflowRequest,
                null);
    }

    @Override
    public CompletableFuture getSubjectEvents(final String subjectId) {
        validateParams("subjectId", subjectId);
        return apiClient.getAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, SUBJECT_PATH, subjectId),
                sdkAuthorization(),
                SubjectEventsResponse.class);
    }

    @Override
    public CompletableFuture reflowBySubject(final String subjectId) {
        validateParams("subjectId", subjectId);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, SUBJECT_PATH, subjectId, REFLOW_PATH),
                sdkAuthorization(),
                ReflowResponse.class,
                null,
                null);
    }

    @Override
    public CompletableFuture reflowBySubjectAndWorkflow(final String subjectId,
                                                                        final String workflowId) {
        validateParams("subjectId", subjectId, WORKFLOW_ID, workflowId);
        return apiClient.postAsync(
                buildPath(WORKFLOWS_PATH, EVENTS_PATH, SUBJECT_PATH, subjectId, WORKFLOW_PATH, workflowId, REFLOW_PATH),
                sdkAuthorization(),
                ReflowResponse.class,
                null,
                null);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy