Skip to content

Commit

Permalink
#170 - Add "notification" action
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Sep 16, 2023
1 parent 151ccce commit 5685198
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum ActionType {
DOCUMENTTAGGING,
/** Full Text. */
FULLTEXT,
/** Notification Action. */
NOTIFICATION,
/** OCR. */
OCR,
/** WebHook. */
Expand Down
10 changes: 10 additions & 0 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,7 @@
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: '#/components/schemas/AddActionParameters'
AddActionParameters:
Expand All @@ -4105,6 +4106,15 @@
description: 'DocumentTagging: Engine to use for document tagging generation'
enum:
- chatgpt
notificationType:
type: string
description: Notification Type
enum:
- email
notificationTo:
description: Who to send the notification to
items:
type: string
tags:
description: 'DocumentTagging: Comma-deliminted list of keywords to generate tags for'
type: string
Expand Down
10 changes: 10 additions & 0 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,7 @@
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: '#/components/schemas/AddActionParameters'
AddActionParameters:
Expand All @@ -4105,6 +4106,15 @@
description: 'DocumentTagging: Engine to use for document tagging generation'
enum:
- chatgpt
notificationType:
type: string
description: Notification Type
enum:
- email
notificationTo:
description: Who to send the notification to
items:
type: string
tags:
description: 'DocumentTagging: Comma-deliminted list of keywords to generate tags for'
type: string
Expand Down
10 changes: 10 additions & 0 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,7 @@
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: '#/components/schemas/AddActionParameters'
AddActionParameters:
Expand All @@ -4105,6 +4106,15 @@
description: 'DocumentTagging: Engine to use for document tagging generation'
enum:
- chatgpt
notificationType:
type: string
description: Notification Type
enum:
- email
notificationTo:
description: Who to send the notification to
items:
type: string
tags:
description: 'DocumentTagging: Comma-deliminted list of keywords to generate tags for'
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import org.mockserver.mock.action.ExpectationResponseCallback;
import org.mockserver.model.Header;
Expand All @@ -50,11 +51,21 @@
*/
public abstract class AbstractFormKiqApiResponseCallback implements ExpectationResponseCallback {

/** {@link Random}. */
private static final Random NUM_RAND = new Random();
/** {@link Context}. */
private Context context = new LambdaContextRecorder();

/** {@link Gson}. */
private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
/** Port to run Test server. */
private int port = -1;

/**
* constructor.
*/
public AbstractFormKiqApiResponseCallback() {
this.port = generatePort();
}

/**
* Create {@link HttpResponse} from {@link String} response.
Expand All @@ -75,6 +86,12 @@ private HttpResponse createResponse(final String response) {
.withStatusCode(Integer.valueOf(statusCode)).withBody(map.get("body").toString());
}

private int generatePort() {
final int topPort = 8000;
final int bottomPort = 7000;
return NUM_RAND.nextInt(topPort - bottomPort) + bottomPort;
}

/**
* Get {@link RequestStreamHandler}.
*
Expand All @@ -97,6 +114,15 @@ private HttpResponse createResponse(final String response) {
*/
public abstract Collection<String> getResourceUrls();

/**
* Get Server Port.
*
* @return int
*/
public int getServerPort() {
return this.port;
}

/**
* Handle transforming {@link HttpRequest} to {@link HttpResponse}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import java.util.Random;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.mock.action.ExpectationResponseCallback;

/**
*
Expand All @@ -39,36 +37,37 @@
public class FormKiqApiExtension
implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {

/** {@link Random}. */
private static final Random NUM_RAND = new Random();
/** {@link AbstractFormKiqApiResponseCallback}. */
private AbstractFormKiqApiResponseCallback callback;

/** {@link ClientAndServer}. */
private ClientAndServer formkiqServer;

/** Port to run Test server. */
private int port = -1;

/** {@link ExpectationResponseCallback}. */
private ExpectationResponseCallback responseCallback;
/** Is server running. */
private boolean running = false;

/**
* constructor.
*
* @param callback {@link ExpectationResponseCallback}
* @param responseCallback {@link AbstractFormKiqApiResponseCallback}
*/
public FormKiqApiExtension(final ExpectationResponseCallback callback) {
this.responseCallback = callback;
public FormKiqApiExtension(final AbstractFormKiqApiResponseCallback responseCallback) {
this.callback = responseCallback;
this.port = responseCallback.getServerPort();
this.callback = responseCallback;
}

@Override
public void beforeAll(final ExtensionContext context) throws Exception {

final int topPort = 8000;
final int bottomPort = 7000;
this.port = NUM_RAND.nextInt(topPort - bottomPort) + bottomPort;

this.formkiqServer = startClientAndServer(Integer.valueOf(this.port));
if (!this.running) {
this.formkiqServer = startClientAndServer(Integer.valueOf(this.port));

this.formkiqServer.when(request()).respond(this.responseCallback);
this.formkiqServer.when(request()).respond(this.callback);
this.running = true;
}
}

@Override
Expand All @@ -78,6 +77,7 @@ public void close() throws Throwable {
this.formkiqServer.stop();
}
this.formkiqServer = null;
this.running = false;
}

/**
Expand All @@ -88,4 +88,13 @@ public void close() throws Throwable {
public String getBasePath() {
return "http://localhost:" + this.port;
}

/**
* Get callback.
*
* @return {@link AbstractFormKiqApiResponseCallback}
*/
public AbstractFormKiqApiResponseCallback getCallback() {
return this.callback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,7 @@ Resources:
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: "#/components/schemas/AddActionParameters"
AddActionParameters:
Expand All @@ -4108,6 +4109,15 @@ Resources:
description: "DocumentTagging: Engine to use for document tagging generation"
enum:
- chatgpt
notificationType:
type: "string"
description: "Notification Type"
enum:
- email
notificationTo:
description: "Who to send the notification to"
items:
type: "string"
tags:
description: "DocumentTagging: Comma-deliminted list of keywords to generate tags for"
type: "string"
Expand Down
10 changes: 10 additions & 0 deletions lambda-api-graalvm/src/main/resources/cloudformation/api-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,7 @@ Resources:
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: "#/components/schemas/AddActionParameters"
AddActionParameters:
Expand All @@ -4108,6 +4109,15 @@ Resources:
description: "DocumentTagging: Engine to use for document tagging generation"
enum:
- chatgpt
notificationType:
type: "string"
description: "Notification Type"
enum:
- email
notificationTo:
description: "Who to send the notification to"
items:
type: "string"
tags:
description: "DocumentTagging: Comma-deliminted list of keywords to generate tags for"
type: "string"
Expand Down
10 changes: 10 additions & 0 deletions lambda-api-graalvm/src/main/resources/cloudformation/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,7 @@ Resources:
- ANTIVIRUS
- WEBHOOK
- DOCUMENTTAGGING
- NOTIFICATION
parameters:
$ref: "#/components/schemas/AddActionParameters"
AddActionParameters:
Expand All @@ -4108,6 +4109,15 @@ Resources:
description: "DocumentTagging: Engine to use for document tagging generation"
enum:
- chatgpt
notificationType:
type: "string"
description: "Notification Type"
enum:
- email
notificationTo:
description: "Who to send the notification to"
items:
type: "string"
tags:
description: "DocumentTagging: Comma-deliminted list of keywords to generate tags for"
type: "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@
@ExtendWith(DynamoDbExtension.class)
@ExtendWith(TypeSenseExtension.class)
public class ApiDocumentsFulltextRequestTest {

/** {@link FormKiQResponseCallback}. */
private static final FormKiQResponseCallback CALLBACK = new FormKiQResponseCallback();
/** FormKiQ Server. */
@RegisterExtension
static FormKiqApiExtension server = new FormKiqApiExtension(new FormKiQResponseCallback());
static FormKiqApiExtension server = new FormKiqApiExtension(CALLBACK);
/** {@link ApiClient}. */
private ApiClient client =
Configuration.getDefaultApiClient().setReadTimeout(0).setBasePath(server.getBasePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@
import com.formkiq.testutils.aws.LocalStackExtension;

/** Unit Tests for request /indices/{type}/{key}. */
@ExtendWith(LocalStackExtension.class)
@ExtendWith(DynamoDbExtension.class)
@ExtendWith(LocalStackExtension.class)
public class IndicesRequestHandlerTest {

/** {@link FormKiQResponseCallback}. */
private static final FormKiQResponseCallback CALLBACK = new FormKiQResponseCallback();
/** FormKiQ Server. */
@RegisterExtension
static FormKiqApiExtension server = new FormKiqApiExtension(new FormKiQResponseCallback());
static FormKiqApiExtension server = new FormKiqApiExtension(CALLBACK);
/** {@link ApiClient}. */
private ApiClient client =
Configuration.getDefaultApiClient().setReadTimeout(0).setBasePath(server.getBasePath());
Expand Down
Loading

0 comments on commit 5685198

Please sign in to comment.