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,50 @@
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.DeleteWorkflowOverrideResponse;
import co.novu.api.workflowoverrides.response.GetWorkflowOverridesResponse;
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<WorkflowOverrideResponse> createWorkflowOverride(@Body CreateWorkflowOverrideRequest request);

@GET(ENDPOINT)
Call<GetWorkflowOverridesResponse> getWorkflowOverrides(@QueryMap Map<String, Object> params);

@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<DeleteWorkflowOverrideResponse> deleteWorkflowOverride(@Path("overrideId") String overrideId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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.DeleteWorkflowOverrideResponse;
import co.novu.api.workflowoverrides.response.GetWorkflowOverridesResponse;
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 WorkflowOverrideResponse createWorkflowOverride(CreateWorkflowOverrideRequest request) throws IOException, NovuNetworkException {
Response<WorkflowOverrideResponse> response = workflowOverrideApi.createWorkflowOverride(request).execute();
return restHandler.extractResponse(response);
}

public GetWorkflowOverridesResponse 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<GetWorkflowOverridesResponse> 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 DeleteWorkflowOverrideResponse deleteWorkflowOverride(String overrideId) throws IOException, NovuNetworkException {
Response<DeleteWorkflowOverrideResponse> 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")
private String id;

@SerializedName("_organizationId")
private String organizationId;

@SerializedName("_environmentId")
private String environmentId;

@SerializedName("_workflowId")
private String workflowId;

@SerializedName("_tenantId")
private String tenantId;

private Boolean active;
private PreferenceSettings preferenceSettings;
private Boolean deleted;
private String deletedAt;
private String deletedBy;
private String createdAt;
private String updatedAt;

}
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,17 @@
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,8 @@
package co.novu.api.workflowoverrides.response;

import lombok.Data;

@Data
public class DeleteWorkflowOverrideResponse {
private Boolean data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.novu.api.workflowoverrides.response;

import lombok.Data;

@Data
public class GetWorkflowOverridesResponse {
private BulkWorkflowOverridesResponse data;
}
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;
}
76 changes: 76 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,15 @@
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.DeleteWorkflowOverrideResponse;
import co.novu.api.workflowoverrides.response.GetWorkflowOverridesResponse;
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 +125,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 +165,8 @@ public class Novu {

private final OrganizationHandler organizationHandler;

private final WorkflowOverrideHandler workflowOverrideHandler;


public Novu(String apiKey) {
this(new NovuConfig(apiKey));
Expand All @@ -179,6 +191,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 +986,67 @@ public UpdateOrganizationBrandResponse updateOrganizationBrand(UpdateOrganizatio
throw e;
}
}

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

public GetWorkflowOverridesResponse 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 DeleteWorkflowOverrideResponse deleteWorkflowOverride(String overrideId) throws IOException, NovuNetworkException {
try {
return workflowOverrideHandler.deleteWorkflowOverride(overrideId);
} catch (Exception e) {
log.error("Error deleting Workflow-Override", e);
throw e;
}
}
}
Loading