Skip to content

Commit

Permalink
v1.11.0 (#136)
Browse files Browse the repository at this point in the history
* #123 - Add AWS XRay Support to Lambda functions

* #124 - OCR Tessaract Support

* #126 - add GET/PATCH /configs API endpoints

* #125 - ChatGPT Tag "documentTagging" Support

* #127 - Add "apiKey" access support

* #126 add GET/PATCH /configuration API endpoints

* #128 - Add GET/POST/DELETE /configuration/apiKeys

* added contentLength to GET /documents/{documentId}/fulltext, POST /searchFulltext

* #10 - Version delete corrupts all other versions of file, including current

* moved awstests under integration src package
  • Loading branch information
mfriesen committed Jun 15, 2023
1 parent 1d424b8 commit 89e43cc
Show file tree
Hide file tree
Showing 278 changed files with 21,107 additions and 1,526 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules
*.tmp
!console/src/test/resources/test.zip
websocket-api/src/coverage
.settings
3 changes: 1 addition & 2 deletions actions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ dependencies {

test {
failFast = true
useJUnitPlatform()
exclude 'com/formkiq/module/actions/awstest/**'
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
public enum ActionType {
/** AntiVirus. */
ANTIVIRUS,
/** Document Tagging. */
DOCUMENTTAGGING,
/** Full Text. */
FULLTEXT,
/** OCR. */
Expand Down
6 changes: 3 additions & 3 deletions aws-cognito/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
description = "AWS Cognito"

dependencies {
api group: 'software.amazon.awssdk', name: 'cognitoidentity', version: '2.19.2'
api group: 'software.amazon.awssdk', name: 'cognitoidentityprovider', version: '2.19.2'
implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.19.2'
api group: 'software.amazon.awssdk', name: 'cognitoidentity', version: '2.20.33'
api group: 'software.amazon.awssdk', name: 'cognitoidentityprovider', version: '2.20.33'
implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.20.33'

configurations.all {
exclude group: 'software.amazon.awssdk', module: 'apache-client'
Expand Down
7 changes: 4 additions & 3 deletions aws-dynamodb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
description = "AWS DynamoDB"

dependencies {
api group: 'software.amazon.awssdk', name: 'dynamodb', version: '2.19.2'
api group: 'software.amazon.awssdk', name: 'dynamodb', version: '2.20.33'
implementation project(':fkq-lambda-services')
implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.19.2'
implementation group: 'com.formkiq', name: 'graalvm-annotations', version: '1.1.0'
implementation project(':aws-xray')
implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.20.33'
implementation group: 'com.formkiq', name: 'graalvm-annotations', version: '1.2.0'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.9.1'

Expand Down
4 changes: 4 additions & 0 deletions aws-dynamodb/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<allow pkg="software.amazon.awssdk.core.client.config" />
<allow pkg="software.amazon.awssdk.regions" />
<allow pkg="software.amazon.awssdk.services.dynamodb" />
<allow pkg="com.amazonaws.xray.interceptors" />

<subpackage name="objects">
<allow pkg="java.time" />
</subpackage>
</subpackage>

</import-control>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
package com.formkiq.aws.dynamodb;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

/**
Expand All @@ -41,10 +43,20 @@ public DynamicObject apply(final Map<String, AttributeValue> map) {
DynamicObject o = new DynamicObject(new HashMap<>());

for (Map.Entry<String, AttributeValue> e : map.entrySet()) {
String s = e.getValue().s();
String n = e.getValue().n();
String v = s == null && n != null ? n : s;
o.put(e.getKey(), v);

if (e.getValue().hasL()) {

List<String> values =
e.getValue().l().stream().map(s -> s.s()).collect(Collectors.toList());
o.put(e.getKey(), values);

} else {

String s = e.getValue().s();
String n = e.getValue().n();
String v = s == null && n != null ? n : s;
o.put(e.getKey(), v);
}
}

return o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public interface DbKeys {
/** Config Partition Key Prefix. */
String PREFIX_CONFIG = "configs" + TAG_DELIMINATOR;

/** API Keys Partition Key Prefix. */
String PREFIX_API_KEYS = "apikeys" + TAG_DELIMINATOR;

/** API Key Partition Key Prefix. */
String PREFIX_API_KEY = "apikey" + TAG_DELIMINATOR;

/** Documents Partition Key Prefix. */
String PREFIX_DOCS = "docs" + TAG_DELIMINATOR;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
package com.formkiq.aws.dynamodb;

import java.net.URI;
import com.amazonaws.xray.interceptors.TracingInterceptor;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration.Builder;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
Expand All @@ -45,12 +47,19 @@ public class DynamoDbConnectionBuilder {

/**
* constructor.
*
* @param enableAwsXray Enables AWS X-Ray
*/
public DynamoDbConnectionBuilder() {
public DynamoDbConnectionBuilder(final boolean enableAwsXray) {
System.setProperty("software.amazon.awssdk.http.service.impl",
"software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService");
this.builder = DynamoDbClient.builder()
.overrideConfiguration(ClientOverrideConfiguration.builder().build());
Builder clientConfig = ClientOverrideConfiguration.builder();

if (enableAwsXray) {
clientConfig.addExecutionInterceptor(new TracingInterceptor());
}

this.builder = DynamoDbClient.builder().overrideConfiguration(clientConfig.build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.formkiq.aws.dynamodb;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.QueryResponse;
Expand Down Expand Up @@ -60,6 +62,14 @@ public interface DynamoDbService {
*/
Map<String, AttributeValue> get(AttributeValue pk, AttributeValue sk);

/**
* Batch Get a number of Keys.
*
* @param keys {@link Collection}
* @return {@link List}
*/
List<Map<String, AttributeValue>> getBatch(Collection<Map<String, AttributeValue>> keys);

/**
* Put DynamoDb Record.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@

import static com.formkiq.aws.dynamodb.DbKeys.PK;
import static com.formkiq.aws.dynamodb.DbKeys.SK;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate;
import software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest;
import software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse;
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
import software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes;
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
import software.amazon.awssdk.services.dynamodb.model.QueryRequest;
import software.amazon.awssdk.services.dynamodb.model.QueryResponse;
Expand Down Expand Up @@ -103,6 +108,20 @@ public Map<String, AttributeValue> get(final AttributeValue pk, final AttributeV
.consistentRead(Boolean.TRUE).build()).item();
}

@Override
public List<Map<String, AttributeValue>> getBatch(
final Collection<Map<String, AttributeValue>> keys) {

Map<String, KeysAndAttributes> items =
Map.of(this.tableName, KeysAndAttributes.builder().keys(keys).build());

BatchGetItemResponse response =
this.dbClient.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());

List<Map<String, AttributeValue>> list = response.responses().get(this.tableName);
return list;
}

@Override
public void putItem(final Map<String, AttributeValue> attributes) {
putItem(this.tableName, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.dynamodb;
package com.formkiq.aws.dynamodb.objects;

import java.text.SimpleDateFormat;
import java.time.DateTimeException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.common.formats;
package com.formkiq.aws.dynamodb.objects;

import static com.formkiq.stacks.common.formats.MimeType.MIME_DOCX;
import static com.formkiq.stacks.common.formats.MimeType.MIME_HTML;
import static com.formkiq.stacks.common.formats.MimeType.MIME_JPEG;
import static com.formkiq.stacks.common.formats.MimeType.MIME_JSON;
import static com.formkiq.stacks.common.formats.MimeType.MIME_PDF;
import static com.formkiq.stacks.common.formats.MimeType.MIME_PNG;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_DOCX;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_HTML;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_JPEG;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_JSON;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_PDF;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_PNG;
import java.util.Set;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,52 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.common.formats;
package com.formkiq.aws.dynamodb.objects;

/**
* Supported Conversion Formats.
*
*/
public enum MimeType {

/** text/html. */
MIME_HTML("text/html"),
/** image/bmp. */
MIME_BMP("image/bmp"),
/** application/vnd.openxmlformats-officedocument.wordprocessingml.document. */
MIME_DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
/** application/pdf. */
MIME_PDF("application/pdf"),
/** image/png. */
MIME_PNG("image/png"),
/** image/gif. */
MIME_GIF("image/gif"),
/** text/html. */
MIME_HTML("text/html"),
/** image/jpeg. */
MIME_JPEG("image/jpeg"),
/** image/jpg. */
MIME_JPG("image/jpg"),
/** application/json. */
MIME_JSON("application/json"),
/** application/pdf. */
MIME_PDF("application/pdf"),
/** image/png. */
MIME_PNG("image/png"),
/** image/tif. */
MIME_TIF("image/tif"),
/** image/tiff. */
MIME_TIFF("image/tiff"),
/** Unknown Mime. */
MIME_UNKNOWN("UNKNOWN");
MIME_UNKNOWN("UNKNOWN"),
/** image/webp. */
MIME_WEBP("image/webp");

/**
* 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));
}

/** Content Type. */
private String contentType;
Expand All @@ -66,14 +90,34 @@ public String getContentType() {
}

/**
* Is Content Type plain text.
* Get File Extension.
*
* @param contentType {@link String}
* @return boolean
* @return {@link String}
*/
public static boolean isPlainText(final String contentType) {
return contentType != null
&& (contentType.startsWith("text/") || "application/json".equals(contentType)
|| "application/x-www-form-urlencoded".equals(contentType));
public String getExtension() {
int pos = this.contentType.lastIndexOf("/");
return pos > -1 ? this.contentType.substring(pos + 1).toLowerCase() : null;
}

/**
* Find {@link MimeType} from Content-Type.
*
* @param ct {@link String}
* @return {@link MimeType}
*/
public static MimeType fromContentType(final String ct) {

MimeType type = MimeType.MIME_UNKNOWN;

if (ct != null) {
for (MimeType mt : MimeType.values()) {
if (ct.equals(mt.getContentType())) {
type = mt;
break;
}
}
}

return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.aws.dynamodb.objects;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
*
* Unit Test for {@link MimeType}.
*
*/
class MimeTypeTest {

/**
* Test fromContentType.
*/
@Test
void testFromContentType() {
assertEquals(MimeType.MIME_PNG, MimeType.fromContentType("image/png"));
assertEquals(MimeType.MIME_UNKNOWN, MimeType.fromContentType(null));
}

}
Loading

0 comments on commit 89e43cc

Please sign in to comment.