Skip to content

Commit

Permalink
#130 added PUT/PATCH /documents/{documentId}/tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 16, 2023
1 parent 080862e commit 886e0df
Show file tree
Hide file tree
Showing 21 changed files with 825 additions and 538 deletions.
4 changes: 2 additions & 2 deletions docker-compose-dynamodb.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3"
services:
dynamodb:
image: amazon/dynamodb-local:1.13.5
image: amazon/dynamodb-local:1.21.0
ports:
- 8000:8000
- 8000:8000
13 changes: 8 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
version: "3"
version: '3.8'
services:
dynamodb:
image: amazon/dynamodb-local:1.13.5
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
image: "amazon/dynamodb-local:latest"
ports:
- 8000:8000
- "8000:8000"
volumes:
- "./docker/dynamodb:/home/dynamodblocal/data"
working_dir: /home/dynamodblocal
localstack:
image: localstack/localstack:0.12.2
ports:
Expand All @@ -17,5 +21,4 @@ services:
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock

- DOCKER_HOST=unix:///var/run/docker.sock
42 changes: 42 additions & 0 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,48 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi201'
patch:
operationId: UpdateDocumentTags
description: Updates multiple tags to a document; this endpoint also accepts a different body parameter for updating a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
put:
operationId: SetDocumentTags
description: Set multiple tags to a document; this endpoint also accepts a different body parameter for setting a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/documents/{documentId}/tags/{tagKey}:
get:
operationId: GetDocumentTag
Expand Down
42 changes: 42 additions & 0 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,48 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi201'
patch:
operationId: UpdateDocumentTags
description: Updates multiple tags to a document; this endpoint also accepts a different body parameter for updating a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
put:
operationId: SetDocumentTags
description: Set multiple tags to a document; this endpoint also accepts a different body parameter for setting a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/documents/{documentId}/tags/{tagKey}:
get:
operationId: GetDocumentTag
Expand Down
42 changes: 42 additions & 0 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,48 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi201'
patch:
operationId: UpdateDocumentTags
description: Updates multiple tags to a document; this endpoint also accepts a different body parameter for updating a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
put:
operationId: SetDocumentTags
description: Set multiple tags to a document; this endpoint also accepts a different body parameter for setting a single tag
tags:
- Document Tags
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/siteIdParam'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddDocumentTagsRequest'
responses:
"200":
$ref: '#/components/responses/200Cors'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/documents/{documentId}/tags/{tagKey}:
get:
operationId: GetDocumentTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
*/
public class ApiGatewayRequestEventBuilder {

/** {@link ApiGatewayRequestEvent}. */
private ApiGatewayRequestEvent event = new ApiGatewayRequestEvent();
/** {@link ApiGatewayRequestContext}. */
private ApiGatewayRequestContext context = new ApiGatewayRequestContext();
/** {@link ApiGatewayRequestEvent}. */
private ApiGatewayRequestEvent event = new ApiGatewayRequestEvent();

/**
* Set Body.
Expand All @@ -48,6 +48,19 @@ public ApiGatewayRequestEventBuilder body(final String body) {
return this;
}

/**
* Set Body.
*
* @param body {@link String}
* @param isBase64 boolean
* @return {@link ApiGatewayRequestEventBuilder}
*/
public ApiGatewayRequestEventBuilder body(final String body, final boolean isBase64) {
this.event.setBody(body);
this.event.setIsBase64Encoded(Boolean.valueOf(isBase64));
return this;
}

/**
* Builds {@link ApiGatewayRequestEvent}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.formkiq.stacks.client.requests.GetDocumentActionsRequest;
import com.formkiq.stacks.client.requests.GetDocumentContentRequest;
import com.formkiq.stacks.client.requests.GetDocumentRequest;
import com.formkiq.stacks.client.requests.GetDocumentTagsKeyRequest;
import com.formkiq.stacks.client.requests.GetDocumentUploadRequest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -119,11 +120,15 @@ public static String addDocument(final FormKiqClientV1 client, final String site
* @throws InterruptedException InterruptedException
*/
public static String addDocumentWithActions(final FormKiqClient client, final String siteId,
final String path, final String content, final String contentType,
final String path, final byte[] content, final String contentType,
final List<AddDocumentAction> actions, final List<AddDocumentTag> tags)
throws IOException, InterruptedException {
return client.addDocument(new AddDocumentRequest().siteId(siteId).document(new AddDocument()
.path(path).content(content).contentType(contentType).tags(tags).actions(actions)))

String base64 = Base64.getEncoder().encodeToString(content);

return client
.addDocument(new AddDocumentRequest().siteId(siteId).document(new AddDocument().path(path)
.contentAsBase64(base64).contentType(contentType).tags(tags).actions(actions)))
.documentId();
}

Expand All @@ -142,15 +147,11 @@ public static String addDocumentWithActions(final FormKiqClient client, final St
* @throws InterruptedException InterruptedException
*/
public static String addDocumentWithActions(final FormKiqClient client, final String siteId,
final String path, final byte[] content, final String contentType,
final String path, final String content, final String contentType,
final List<AddDocumentAction> actions, final List<AddDocumentTag> tags)
throws IOException, InterruptedException {

String base64 = Base64.getEncoder().encodeToString(content);

return client
.addDocument(new AddDocumentRequest().siteId(siteId).document(new AddDocument().path(path)
.contentAsBase64(base64).contentType(contentType).tags(tags).actions(actions)))
return client.addDocument(new AddDocumentRequest().siteId(siteId).document(new AddDocument()
.path(path).content(content).contentType(contentType).tags(tags).actions(actions)))
.documentId();
}

Expand Down Expand Up @@ -253,6 +254,41 @@ public static void waitForDocumentContent(final FormKiqClientV1 client, final St
}
}

/**
* Wait For Document Content.
*
* @param client {@link FormKiqClientV1}
* @param siteId {@link String}
* @param documentId {@link String}
* @param tagKey {@link String}
* @return {@link DocumentTag}
* @throws IOException IOException
* @throws InterruptedException InterruptedException
* @throws URISyntaxException URISyntaxException
*/
public static DocumentTag waitForDocumentTag(final FormKiqClientV1 client, final String siteId,
final String documentId, final String tagKey)
throws IOException, InterruptedException, URISyntaxException {

DocumentTag tags = null;
GetDocumentTagsKeyRequest tagReq =
new GetDocumentTagsKeyRequest().siteId(siteId).documentId(documentId).tagKey(tagKey);

while (true) {

try {
tags = client.getDocumentTag(tagReq);
break;
} catch (IOException e) {
// tag not found
}

TimeUnit.SECONDS.sleep(1);
}

return tags;
}

/**
* Fetch Document Content Type.
*
Expand Down
4 changes: 4 additions & 0 deletions lambda-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ configurations {
integrationRuntime.extendsFrom testRuntime
}

tasks.processIntegrationResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

def getCmd() {
String os = System.getProperty("os.name").toLowerCase()
return os.contains("win") ? "cmd" : "bash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import com.formkiq.aws.cognito.CognitoConnectionBuilder;
import com.formkiq.aws.cognito.CognitoService;
Expand Down Expand Up @@ -110,6 +111,10 @@ public abstract class AbstractApiTest {
private static DynamoDbConnectionBuilder dbConnection;
/** Cognito FINANCE User Email. */
protected static final String FINANCE_EMAIL = "testfinance@formkiq.com";
/** {@link List} {@link FormKiqClientV1}. */
private static List<FormKiqClientV1> formkiqClientDefault;
/** {@link List} {@link FormKiqClientV1}. */
private static List<FormKiqClientV1> formkiqClientSiteId;
/** FormKiQ Http API Client. */
private static FormKiqClientV1 httpClient;
/** 1 Second. */
Expand All @@ -124,6 +129,8 @@ public abstract class AbstractApiTest {
private static String rootKeyUrl;
/** API Root Rest Url. */
private static String rootRestUrl;
/** SiteId. */
protected static final String SITE_ID = UUID.randomUUID().toString();
/** {@link SsmConnectionBuilder}. */
private static SsmConnectionBuilder ssmBuilder;
/** {@link SsmService}. */
Expand Down Expand Up @@ -211,6 +218,9 @@ public static void beforeClass() throws IOException {

setupCognito();
setupConfigService(awsprofile);

formkiqClientDefault = Arrays.asList(httpClient, restClient, getApiKeyClient(null));
formkiqClientSiteId = Arrays.asList(httpClient, restClient, getApiKeyClient(SITE_ID));
}

/**
Expand Down Expand Up @@ -283,6 +293,24 @@ public static List<FormKiqClientV1> getFormKiqClients(final String siteId) {
return Arrays.asList(httpClient, restClient, getApiKeyClient(siteId));
}

/**
* Get Default Clients.
*
* @return {@link List} {@link FormKiqClientV1}
*/
public static List<FormKiqClientV1> getFormKiqDefaultClients() {
return formkiqClientDefault;
}

/**
* Get Clients for SiteId.
*
* @return {@link List} {@link FormKiqClientV1}
*/
public static List<FormKiqClientV1> getFormKiqSiteIdClients() {
return formkiqClientSiteId;
}

/**
* Get API Root Http Url.
*
Expand Down
Loading

0 comments on commit 886e0df

Please sign in to comment.