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

Initial commit: Added POJOS and API execution endpoint for WorkflowOverride API Integration #110

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Novu's API exposes the entire Novu features via a standardized programmatic inte
* [Integrations](#integrations)
* [Notifications](#notification)
* [Workflow](#workflow)
* [Workflow Override](#workflow-override)
* [Workflow Groups](#workflow-groups)
* [Changes](#changes)
* [Environments](#environments)
Expand Down Expand Up @@ -428,6 +429,16 @@ public class Main {
- `Workflow(WorkflowId)`
- `updateWorkflowStatus(WorkflowId, body)`

### Workflow Override

- `createWorkflowOverride(createWorkflowOverrideRequest)`
- `getWorkflowOverrides(getWorkflowOverrideRequest)`
- `getWorkflowOverride(workflowId, tenantId)`
- `getWorkflowOverrideById(overrideId)`
- `updateWorkflowOverride(workflowId, tenantId)`
- `updateWorkflowOverrideById(overrideId)`
- `deleteWorkflow(overrideId)`

### Notification

- `notifications(query = {})`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package co.novu.api.workflowoverrides;

import co.novu.api.workflowoverrides.pojos.WorkflowOverride;

import co.novu.api.workflowoverrides.request.CreateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.request.UpdateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.response.BulkWorkflowOverridesResponse;
import co.novu.api.workflowoverrides.response.WorkflowOverrideResponse;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.QueryMap;

import java.util.Map;

public interface WorkflowOverrideApi {

String ENDPOINT = "workflow-overrides";

@POST(ENDPOINT)
Call<WorkflowOverride> createWorkflowOverride(@Body CreateWorkflowOverrideRequest request);
mayorJAY marked this conversation as resolved.
Show resolved Hide resolved

@GET(ENDPOINT)
Call<BulkWorkflowOverridesResponse> getWorkflowOverrides(@QueryMap Map<String, Object> params);
mayorJAY marked this conversation as resolved.
Show resolved Hide resolved

@GET(ENDPOINT + "/workflows/{workflowId}/tenants/{tenantId}")
Call<WorkflowOverrideResponse> getWorkflowOverride(@Path("workflowId") String workflowId, @Path("tenantId") String tenantId);


@GET(ENDPOINT + "/{overrideId}")
Call<WorkflowOverrideResponse> getWorkflowOverrideById(@Path("overrideId") String overrideId);


@PUT(ENDPOINT + "/{overrideId}")
Call<WorkflowOverrideResponse> updateWorkflowOverrideById(@Path("overrideId") String OverrideId, @Body UpdateWorkflowOverrideRequest request);


@PUT(ENDPOINT + "/workflows/{workflowId}/tenants/{tenantId}")
Call<WorkflowOverrideResponse> updateWorkflowOverride(@Path("workflowId") String workflowId, @Path("tenantId") String tenantId,
@Body UpdateWorkflowOverrideRequest request);

@DELETE(ENDPOINT + "/{overrideId}")
Call<WorkflowOverrideResponse> deleteWorkflowOverride(@Path("overrideId") String overrideId);
mayorJAY marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package co.novu.api.workflowoverrides;

import co.novu.api.workflowoverrides.pojos.WorkflowOverride;
import co.novu.api.workflowoverrides.request.CreateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.request.GetWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.request.UpdateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.response.BulkWorkflowOverridesResponse;
import co.novu.api.workflowoverrides.response.WorkflowOverrideResponse;
import co.novu.common.rest.NovuNetworkException;
import co.novu.common.rest.RestHandler;
import retrofit2.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class WorkflowOverrideHandler {

private final RestHandler restHandler;

private final WorkflowOverrideApi workflowOverrideApi;

public WorkflowOverrideHandler(RestHandler restHandler) {
this.restHandler = restHandler;
this.workflowOverrideApi = restHandler.buildRetrofit().create(WorkflowOverrideApi.class);
}

public WorkflowOverride createWorkflowOverride(CreateWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
Response<WorkflowOverride> response = workflowOverrideApi.createWorkflowOverride(request).execute();
return restHandler.extractResponse(response);
}

public BulkWorkflowOverridesResponse getWorkflowOverrides(GetWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
Map<String, Object> params = new HashMap<>();
if (request.getPage() != null) params.put("page", request.getPage());
if (request.getLimit() != null) params.put("limit", request.getLimit());
Response<BulkWorkflowOverridesResponse> response = workflowOverrideApi.getWorkflowOverrides(params).execute();
return restHandler.extractResponse(response);
}

public WorkflowOverrideResponse getWorkflowOverride(String workflowId, String tenantId) throws IOException, NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.getWorkflowOverride(workflowId, tenantId).execute();
return restHandler.extractResponse(response);
}

public WorkflowOverrideResponse getWorkflowOverrideById(String overrideId) throws IOException, NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.getWorkflowOverrideById(overrideId).execute();
return restHandler.extractResponse(response);
}

public WorkflowOverrideResponse updateWorkflowOverrideById(String overrideId, UpdateWorkflowOverrideRequest request) throws IOException,
NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.updateWorkflowOverrideById(overrideId, request).execute();
return restHandler.extractResponse(response);
}

public WorkflowOverrideResponse updateWorkflowOverride(String workflowId, String tenantId, UpdateWorkflowOverrideRequest request)
throws IOException, NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.updateWorkflowOverride(workflowId, tenantId, request).execute();
return restHandler.extractResponse(response);
}

public WorkflowOverrideResponse deleteWorkflowOverride(String overrideId) throws IOException, NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.deleteWorkflowOverride(overrideId).execute();
return restHandler.extractResponse(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package co.novu.api.workflowoverrides.pojos;

import co.novu.api.common.PreferenceSettings;

import com.google.gson.annotations.SerializedName;

import lombok.Data;

@Data
public class WorkflowOverride {

@SerializedName("_id")
public String id;

@SerializedName("_organizationId")
public String organizationId;

@SerializedName("_environmentId")
public String environmentId;

@SerializedName("_workflowId")
public String workflowId;

@SerializedName("_tenantId")
public String tenantId;

public boolean active;
public PreferenceSettings preferenceSettings;
public boolean deleted;
public String deletedAt;
public String deletedBy;
public String createdAt;
public String updatedAt;
mayorJAY marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.novu.api.workflowoverrides.request;

import co.novu.api.common.PreferenceSettings;
import co.novu.common.contracts.IRequest;

import lombok.Data;

@Data
public class CreateWorkflowOverrideRequest implements IRequest {
private PreferenceSettings preferenceSettings;
private boolean active;
private String tenantId;
private String workflowId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.novu.api.workflowoverrides.request;

import co.novu.common.contracts.IRequest;

import lombok.Data;

@Data
public class GetWorkflowOverrideRequest implements IRequest {
private Integer page;
private Integer limit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.novu.api.workflowoverrides.request;

import co.novu.api.common.PreferenceSettings;

import lombok.Data;

@Data
public class UpdateWorkflowOverrideRequest {
private boolean active;
private PreferenceSettings data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.novu.api.workflowoverrides.response;

import co.novu.api.workflowoverrides.pojos.WorkflowOverride;

import java.util.List;

import lombok.Data;

@Data
public class BulkWorkflowOverridesResponse {
private List<WorkflowOverride> data;
private boolean hasMore;
private Long page;
private Long pageSize;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.novu.api.workflowoverrides.response;

import co.novu.api.workflowoverrides.pojos.WorkflowOverride;

import lombok.Data;

@Data
public class WorkflowOverrideResponse {
private WorkflowOverride data;
}
74 changes: 74 additions & 0 deletions src/main/java/co/novu/common/base/Novu.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@
import co.novu.api.workflowgroups.responses.DeleteWorkflowGroup;
import co.novu.api.workflowgroups.responses.GetWorkflowGroupsResponse;
import co.novu.api.workflowgroups.responses.WorkflowGroupResponse;
import co.novu.api.workflowoverrides.WorkflowOverrideHandler;
import co.novu.api.workflowoverrides.pojos.WorkflowOverride;
import co.novu.api.workflowoverrides.request.CreateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.request.GetWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.request.UpdateWorkflowOverrideRequest;
import co.novu.api.workflowoverrides.response.BulkWorkflowOverridesResponse;
import co.novu.api.workflowoverrides.response.WorkflowOverrideResponse;
import co.novu.api.workflows.WorkflowHandler;
import co.novu.api.workflows.requests.UpdateWorkflowRequest;
import co.novu.api.workflows.requests.UpdateWorkflowStatusRequest;
Expand All @@ -116,6 +123,7 @@
import co.novu.api.workflows.responses.SingleWorkflowResponse;
import co.novu.common.rest.NovuNetworkException;
import co.novu.common.rest.RestHandler;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -155,6 +163,8 @@ public class Novu {

private final OrganizationHandler organizationHandler;

private final WorkflowOverrideHandler workflowOverrideHandler;


public Novu(String apiKey) {
this(new NovuConfig(apiKey));
Expand All @@ -179,6 +189,7 @@ public Novu(NovuConfig novuConfig) {
this.blueprintsHandler = new BlueprintsHandler(restHandler);
this.tenantsHandler = new TenantsHandler(restHandler);
this.organizationHandler = new OrganizationHandler(restHandler);
this.workflowOverrideHandler = new WorkflowOverrideHandler(restHandler);
}

public TriggerEventResponse triggerEvent(TriggerEventRequest request) throws IOException, NovuNetworkException {
Expand Down Expand Up @@ -973,4 +984,67 @@ public UpdateOrganizationBrandResponse updateOrganizationBrand(UpdateOrganizatio
throw e;
}
}

public WorkflowOverride createWorkflowOverride(CreateWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.createWorkflowOverride(request);
} catch (Exception e) {
log.error("Error creating Workflow-Override", e);
throw e;
}
}

public BulkWorkflowOverridesResponse getWorkflowOverrides(GetWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.getWorkflowOverrides(request);
} catch (Exception e) {
log.error("Error fetching Workflow-Override", e);
throw e;
}
}

public WorkflowOverrideResponse getWorkflowOverride(String workflowId, String tenantId) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.getWorkflowOverride(workflowId, tenantId);
} catch (Exception e) {
log.error("Error fetching Workflow-Override", e);
throw e;
}
}

public WorkflowOverrideResponse getWorkflowOverrideById(String overrideId) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.getWorkflowOverrideById(overrideId);
} catch (Exception e) {
log.error("Error fetching Workflow-Override", e);
throw e;
}
}

public WorkflowOverrideResponse updateWorkflowOverrideById(String overrideId, UpdateWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.updateWorkflowOverrideById(overrideId, request);
} catch (Exception e) {
log.error("Error updating Workflow-Override", e);
throw e;
}
}

public WorkflowOverrideResponse updateWorkflowOverride(String workflowId, String tenantId, UpdateWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.updateWorkflowOverride(workflowId, tenantId, request);
} catch (Exception e) {
log.error("Error updating Workflow-Override", e);
throw e;
}
}

public WorkflowOverrideResponse deleteWorkflowOverride(String overrideId) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.deleteWorkflowOverride(overrideId);
} catch (Exception e) {
log.error("Error deleting Workflow-Override", e);
throw e;
}
}
}
Loading