Skip to content

Commit

Permalink
Release v1.2.0 (#5)
Browse files Browse the repository at this point in the history
* added /public/webhooks/{webhooks+} API

* added GET / POST /webhooks

* Added DELETE /webhooks/{webhookId}

* fixed Get /webhooks URL that is returned

* Updated GraalVM version to 21.0.0

* Changed GET /documents/{documentId}/content to treat application/x-www-form-urlencoded as PlainText

* Fixed text

* Updated Console to 1.3.5

* Added module-documentevent.yaml and changed module-email-notify to use it

* Added Content to SNS message if size < 256KB

* Added userId as System Defined tag

* Added AppEnvironment as Output
  • Loading branch information
mfriesen committed Jan 27, 2021
1 parent 1c83d61 commit 8d28a32
Show file tree
Hide file tree
Showing 63 changed files with 4,075 additions and 297 deletions.
2 changes: 1 addition & 1 deletion aws-s3/src/main/java/com/formkiq/aws/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public String getContentAsString(final S3Client s3, final String bucket, final S
final String versionId) {

GetObjectRequest gr =
GetObjectRequest.builder().bucket(bucket).key(key)/* .versionId(versionId) */.build();
GetObjectRequest.builder().bucket(bucket).key(key).versionId(versionId).build();
ResponseBytes<GetObjectResponse> response = s3.getObjectAsBytes(gr);

String s = response.asUtf8String();
Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'com.github.spotbugs' version '4.6.0'
id 'com.diffplug.spotless' version '5.8.2'
id 'com.github.ben-manes.versions' version '0.36.0'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.0.3'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.1.0'
}

spotless {
Expand All @@ -16,7 +16,7 @@ spotless {
}

allprojects {
version = '1.1.0'
version = '1.2.0'
group = 'com.formkiq.stacks'
}

Expand Down Expand Up @@ -172,6 +172,9 @@ task assembleTemplate {
exec {
commandLine "bash", "-c", "cp ${buildDir}/template.yaml ${buildDir}/distributions/formkiq-core/sam/template.yaml"
}
exec {
commandLine "bash", "-c", "cp src/main/resources/cloudformation/module-*.yaml ${buildDir}/distributions/formkiq-core/sam/"
}
exec {
commandLine "bash", "-c", "yq m --overwrite ${buildDir}/template.yaml ${buildDir}/template-sar-snippet.yaml > ${buildDir}/template-sar.yaml"
}
Expand Down Expand Up @@ -309,4 +312,4 @@ task buildSamZip(type: Zip) {
include 'INSTALL.md'
include 'LICENSE'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Parameters:
ConsoleVersion:
Type: String
Description: Version of FormKiQ console to deploy
Default: v1.3.3
Default: v1.3.5

DistributionBucket:
Type: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testS3Buckets() {
*/
@Test
public void testSsmParameters() {
assertEquals("v1.3.3",
assertEquals("v1.3.5",
ssmService.getParameterValue("/formkiq/" + appenvironment + "/console/version"));
assertTrue(ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/Console")
.contains(appenvironment + "-console-"));
Expand Down
Binary file modified dynamodb-documents/documentsTableSchema.numbers
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public enum MimeType {
public String getContentType() {
return this.contentType;
}

/**
* Is Content Type plain text.
*
* @param contentType {@link String}
* @return boolean
*/
public static boolean isPlainText(final String contentType) {
return contentType != null
&& (contentType.startsWith("text/") || "application/json".equals(contentType)
|| "application/x-www-form-urlencoded".equals(contentType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class DynamicObject extends HashMap<String, Object> {
*/
public DynamicObject(final Map<String, Object> map) {
super(map);
// this.object = new HashMap<>(map);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.dynamodb;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import com.formkiq.stacks.common.objects.DynamicObject;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

/**
* Convert {@link Map} {@link AttributeValue} to {@link DynamicObject}.
*
*/
public class AttributeValueToDynamicObject
implements Function<Map<String, AttributeValue>, DynamicObject> {

@Override
public DynamicObject apply(final Map<String, AttributeValue> map) {

DynamicObject o = new DynamicObject(new HashMap<>());

for (Map.Entry<String, AttributeValue> e : map.entrySet()) {
o.put(e.getKey(), e.getValue().s());
}

return o;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public interface DbKeys {
/** Composite Tag Key Deliminator. */
String TAG_DELIMINATOR = "#";

/** Webhooks Partition Key Prefix. */
String PREFIX_WEBHOOKS = "webhooks" + TAG_DELIMINATOR;
/** Webhooks Partition Key Prefix. */
String PREFIX_WEBHOOK = "webhook" + TAG_DELIMINATOR;
/** Documents Partition Key Prefix. */
String PREFIX_DOCS = "docs" + TAG_DELIMINATOR;
/** TAGS Partition Key Prefix. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface DocumentService {
int MAX_RESULTS = 10;
/** System Defined Tags. */
Set<String> SYSTEM_DEFINED_TAGS =
Set.of("untagged", "path", "CLAMAV_SCAN_STATUS", "CLAMAV_SCAN_TIMESTAMP");
Set.of("untagged", "path", "CLAMAV_SCAN_STATUS", "CLAMAV_SCAN_TIMESTAMP", "userId");

/**
* Add Tags to Document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,11 @@ private List<DocumentTag> saveDocumentItemGenerateTags(final String siteId,
DocumentTagType.SYSTEMDEFINED));
}

if (doc.getUserId() != null) {
tags.add(new DocumentTag(null, "userId", doc.getUserId(), date, username,
DocumentTagType.SYSTEMDEFINED));
}

return tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public String getDocumentId() {
* Set Document ID.
*
* @param id {@link String}
* @return {@link DocumentTag}
*/
public void setDocumentId(final String id) {
public DocumentTag setDocumentId(final String id) {
this.documentId = id;
return this;
}

/**
Expand All @@ -118,9 +120,11 @@ public String getKey() {
* Set Tag Key.
*
* @param tagkey {@link String}
* @return {@link DocumentTag}
*/
public void setKey(final String tagkey) {
public DocumentTag setKey(final String tagkey) {
this.key = tagkey;
return this;
}

/**
Expand All @@ -136,9 +140,11 @@ public String getValue() {
* Set Value.
*
* @param s {@link String}
* @return {@link DocumentTag}
*/
public void setValue(final String s) {
public DocumentTag setValue(final String s) {
this.value = s;
return this;
}

/**
Expand All @@ -154,9 +160,11 @@ public String getUserId() {
* Set User Id.
*
* @param user {@link String}
* @return {@link DocumentTag}
*/
public void setUserId(final String user) {
public DocumentTag setUserId(final String user) {
this.userId = user;
return this;
}

/**
Expand All @@ -172,9 +180,11 @@ public Date getInsertedDate() {
* Set Inserted Date.
*
* @param date {@link Date}
* @return {@link DocumentTag}
*/
public void setInsertedDate(final Date date) {
public DocumentTag setInsertedDate(final Date date) {
this.insertedDate = date != null ? (Date) date.clone() : null;
return this;
}

/**
Expand All @@ -190,8 +200,10 @@ public DocumentTagType getType() {
* Set Document Type.
*
* @param tagType {@link DocumentTagType}
* @return {@link DocumentTag}
*/
public void setType(final DocumentTagType tagType) {
public DocumentTag setType(final DocumentTagType tagType) {
this.type = tagType;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class DynamoDbHelper {
private DynamoDbClient db;
/** {@link DocumentService}. */
private DocumentService service;
/** {@link DocumentService}. */
private WebhooksService webhookService;
/** {@link DocumentSearchService}. */
private DocumentSearchService searchService;
/** {@link CacheService}. */
Expand Down Expand Up @@ -88,6 +90,7 @@ public DynamoDbHelper(final DynamoDbConnectionBuilder builder, final String docu
this.service = new DocumentServiceImpl(builder, documentTableName);
this.cacheService = new DynamoDbCacheService(builder, cacheTableName);
this.searchService = new DocumentSearchServiceImpl(this.service, builder, documentTableName);
this.webhookService = new WebhooksServiceImpl(builder, documentTableName);
}

/**
Expand Down Expand Up @@ -243,6 +246,15 @@ public DocumentService getService() {
return this.service;
}

/**
* Get {@link WebhooksService}.
*
* @return {@link WebhooksService}
*/
public WebhooksService getWebhookService() {
return this.webhookService;
}

/**
* Is Documents Table Exist.
*
Expand All @@ -257,7 +269,25 @@ public boolean isDocumentsTableExists() {
return false;
}
}


/**
* Truncate Document Dates.
*
*/
public void truncateDocumentDates() {
final int maxresults = 1000;
ScanRequest sr = ScanRequest.builder().tableName(this.documentTable)
.limit(Integer.valueOf(maxresults)).build();
ScanResponse result = this.db.scan(sr);

List<Map<String, AttributeValue>> list =
result.items().stream().filter(i -> i.get("PK").s().equals(DbKeys.PREFIX_DOCUMENT_DATE))
.collect(Collectors.toList());

list.forEach(i -> this.db.deleteItem(DeleteItemRequest.builder().tableName(this.documentTable)
.key(i).build()));
}

/**
* Truncate Documents Table.
*
Expand Down Expand Up @@ -285,20 +315,19 @@ public void truncateDocumentsTable() {
}
}
}

/**
* Truncate Document Dates.
*
* Truncate Webhooks.
*/
public void truncateDocumentDates() {
public void truncateWebhooks() {
final int maxresults = 1000;
ScanRequest sr = ScanRequest.builder().tableName(this.documentTable)
.limit(Integer.valueOf(maxresults)).build();
ScanResponse result = this.db.scan(sr);

List<Map<String, AttributeValue>> list =
result.items().stream().filter(i -> i.get("PK").s().equals(DbKeys.PREFIX_DOCUMENT_DATE))
.collect(Collectors.toList());
result.items().stream().filter(i -> i.get("PK").s().contains(DbKeys.PREFIX_WEBHOOK))
.map(m -> Map.of("PK", m.get("PK"), "SK", m.get("SK"))).collect(Collectors.toList());

list.forEach(i -> this.db.deleteItem(DeleteItemRequest.builder().tableName(this.documentTable)
.key(i).build()));
Expand Down
Loading

0 comments on commit 8d28a32

Please sign in to comment.