Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 60eb79e
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Mon Jul 31 23:11:50 2023 -0500

    fixed JWT API gateway definition

commit acac8d6
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Mon Jul 31 00:08:30 2023 -0500

    tweaked API spec

commit 5ec3caf
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sun Jul 30 23:50:53 2023 -0500

    update sharing API

commit af9ad6d
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sun Jul 30 23:28:56 2023 -0500

    added PATCH /shares/folders/{documentId}

commit 1a245b0
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sun Jul 30 22:09:43 2023 -0500

    fixed sorting results on getBatch

commit e61cf72
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sun Jul 30 21:43:02 2023 -0500

    added ScanIndexForward to QueryConfig

commit 5a590bc
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sun Jul 30 20:35:42 2023 -0500

    added IndexName support to queryBeginsWith() method

commit 1f88cd5
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sat Jul 29 21:51:19 2023 -0500

    removed DocumentEventService

commit 54eb09c
Author: Mike Friesen <mfriesen@gmail.com>
Date:   Sat Jul 29 21:40:20 2023 -0500

    changed Document Folders to use FolderIndexRecord object
  • Loading branch information
ytsipun committed Aug 1, 2023
1 parent 9970a0c commit 6803be7
Show file tree
Hide file tree
Showing 50 changed files with 1,452 additions and 622 deletions.
3 changes: 2 additions & 1 deletion actions/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<subpackage name="services">
<allow pkg="com.formkiq.aws.sns" />
<allow pkg="com.formkiq.module.actions" />
<allow pkg="com.formkiq.module.documentevents" />
<allow pkg="com.formkiq.module.events" />
<allow pkg="com.formkiq.module.events.document" />
<allow pkg="com.formkiq.module.lambdaservices" />
<allow pkg="com.formkiq.validation" />
<allow pkg="software.amazon.awssdk.services.dynamodb" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
package com.formkiq.module.actions.services;

import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID;
import static com.formkiq.module.documentevents.DocumentEventType.ACTIONS;
import static com.formkiq.module.events.document.DocumentEventType.ACTIONS;
import static software.amazon.awssdk.utils.StringUtils.isEmpty;
import java.util.List;
import java.util.Optional;
import com.formkiq.aws.sns.SnsConnectionBuilder;
import com.formkiq.module.actions.Action;
import com.formkiq.module.documentevents.DocumentEvent;
import com.formkiq.module.documentevents.DocumentEventService;
import com.formkiq.module.documentevents.DocumentEventServiceSns;
import com.formkiq.module.events.EventService;
import com.formkiq.module.events.EventServiceSns;
import com.formkiq.module.events.document.DocumentEvent;

/**
*
Expand All @@ -41,10 +41,8 @@
*/
public class ActionsNotificationServiceImpl implements ActionsNotificationService {

/** Document Event Actions Topic. */
private String topicArn;
/** {@link DocumentEventService}. */
private DocumentEventService documentEventService;
/** {@link EventService}. */
private EventService documentEventService;

/**
* constructor.
Expand All @@ -54,8 +52,7 @@ public class ActionsNotificationServiceImpl implements ActionsNotificationServic
*/
public ActionsNotificationServiceImpl(final String documentActionsTopicArn,
final SnsConnectionBuilder snsBuilder) {
this.topicArn = documentActionsTopicArn;
this.documentEventService = new DocumentEventServiceSns(snsBuilder);
this.documentEventService = new EventServiceSns(snsBuilder, documentActionsTopicArn);
}

@Override
Expand All @@ -67,7 +64,7 @@ public void publishNextActionEvent(final List<Action> actions, final String site
if (o.isPresent()) {
String site = !isEmpty(siteId) ? siteId : DEFAULT_SITE_ID;
DocumentEvent event = new DocumentEvent().siteId(site).documentId(documentId).type(ACTIONS);
this.documentEventService.publish(this.topicArn, event);
this.documentEventService.publish(event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
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;
Expand Down Expand Up @@ -76,10 +75,10 @@ public interface DynamoDbService {
/**
* Batch Get a number of Keys.
*
* @param keys {@link Collection}
* @param keys {@link List}
* @return {@link List}
*/
List<Map<String, AttributeValue>> getBatch(Collection<Map<String, AttributeValue>> keys);
List<Map<String, AttributeValue>> getBatch(List<Map<String, AttributeValue>> keys);

/**
* Put DynamoDb Record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import static com.formkiq.aws.dynamodb.DbKeys.PK;
import static com.formkiq.aws.dynamodb.DbKeys.SK;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.formkiq.aws.dynamodb.objects.Strings;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate;
Expand Down Expand Up @@ -122,19 +125,33 @@ public Map<String, AttributeValue> get(final QueryConfig config, final Attribute
}

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

Map<String, KeysAndAttributes> items =
Map.of(this.tableName, KeysAndAttributes.builder().keys(keys).build());
List<Map<String, AttributeValue>> list = Collections.emptyList();

BatchGetItemResponse response =
this.dbClient.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());
if (!keys.isEmpty()) {
Map<String, KeysAndAttributes> items =
Map.of(this.tableName, KeysAndAttributes.builder().keys(keys).build());

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

list = response.responses().get(this.tableName);

Map<String, Map<String, AttributeValue>> data =
list.stream().collect(Collectors.toMap(l -> getKey(l), l -> l));

list = keys.stream().map(k -> data.get(getKey(k))).filter(k -> k != null)
.collect(Collectors.toList());
}

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

private String getKey(final Map<String, AttributeValue> attr) {
return attr.get(PK).s() + "#" + attr.get(SK).s();
}

@Override
public void putItem(final Map<String, AttributeValue> attributes) {
putItem(this.tableName, attributes);
Expand Down Expand Up @@ -181,14 +198,16 @@ public QueryResponse queryBeginsWith(final QueryConfig config, final AttributeVa
final AttributeValue sk, final Map<String, AttributeValue> exclusiveStartKey,
final int limit) {

String expression = PK + " = :pk and begins_with(" + SK + ",:sk)";
String gsi = Strings.isEmpty(config.indexName()) ? "" : config.indexName();
String expression = gsi + PK + " = :pk and begins_with(" + gsi + SK + ",:sk)";

Map<String, AttributeValue> values = Map.of(":pk", pk, ":sk", sk);

QueryRequest q = QueryRequest.builder().tableName(this.tableName)
.keyConditionExpression(expression).expressionAttributeValues(values)
.scanIndexForward(Boolean.FALSE).projectionExpression(config.projectionExpression())
.exclusiveStartKey(exclusiveStartKey).limit(Integer.valueOf(limit)).build();
QueryRequest q =
QueryRequest.builder().tableName(this.tableName).keyConditionExpression(expression)
.expressionAttributeValues(values).scanIndexForward(config.isScanIndexForward())
.projectionExpression(config.projectionExpression()).indexName(config.indexName())
.exclusiveStartKey(exclusiveStartKey).limit(Integer.valueOf(limit)).build();

QueryResponse response = this.dbClient.query(q);
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public class QueryConfig {

/** {@link Map}. */
private Map<String, String> expressionAttributeNames;
/** Index Name. */
private String indexName;
/** Projection Expression. */
private String projectionExpression;
/** True - ASC, False - DESC. */
private Boolean scanIndexForward = Boolean.FALSE;

/**
* constructor.
Expand Down Expand Up @@ -64,6 +68,35 @@ public QueryConfig expressionAttributeNames(final Map<String, String> expression
return this;
}

/**
* Get Index Name.
*
* @return {@link String}
*/
public String indexName() {
return this.indexName;
}

/**
* Set Index Name.
*
* @param index {@link String}
* @return {@link QueryConfig}
*/
public QueryConfig indexName(final String index) {
this.indexName = index;
return this;
}

/**
* Is ScanIndexForward.
*
* @return boolean
*/
public Boolean isScanIndexForward() {
return this.scanIndexForward;
}

/**
* Get Projection Expression.
*
Expand All @@ -84,4 +117,15 @@ public QueryConfig projectionExpression(final String projection) {
return this;
}

/**
* Set Is ScanIndexForward.
*
* @param isScanIndexForward {@link Boolean}
* @return {@link QueryConfig}
*/
public QueryConfig scanIndexForward(final Boolean isScanIndexForward) {
this.scanIndexForward = isScanIndexForward;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
*/
public class Objects {

/**
* Get Last Element of {@link List}.
*
* @param <T> Type of Object.
* @param list {@link List}
* @return {@link Object}
*/
public static <T> T last(final List<T> list) {
return !notNull(list).isEmpty() ? list.get(list.size() - 1) : null;
}

/**
* Returns a {@link Collection} that is guarantee not to be null.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public static boolean isUuid(final String s) {
}
}

/**
* Remove '/' from start/end of {@link String}.
*
* @param s {@link String}
* @return {@link String}
*/
public static String removeBackSlashes(final String s) {
return s.replaceAll("^/|/$", "");
}

/**
* Remove single/double quotes from {@link String}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
class StringsTest {

@Test
void testExtension() {
assertEquals("txt", Strings.getExtension("test.txt"));
assertEquals("txt", Strings.getExtension("/bleh/something/test.txt"));
assertEquals("txt", Strings.getExtension("/bleh/something/test (something).txt"));
void removeBackSlashes() {
assertEquals("text", Strings.removeBackSlashes("text"));
assertEquals("text", Strings.removeBackSlashes("/text"));
assertEquals("text", Strings.removeBackSlashes("/text/"));
}

@Test
void testFilename() {
assertEquals("test.txt", Strings.getFilename("test.txt"));
assertEquals("test.txt", Strings.getFilename("/bleh/something/test.txt"));
assertEquals("test (something).txt",
Strings.getFilename("/bleh/something/test (something).txt"));
void removeEndingPunctuation() {
assertEquals("text", Strings.removeEndingPunctuation("text"));
assertEquals("\"text\"", Strings.removeEndingPunctuation("\"text\","));
assertEquals("\"text", Strings.removeEndingPunctuation("\"text!"));
assertEquals("'text?'", Strings.removeEndingPunctuation("'text?'"));
assertEquals("\"text'", Strings.removeEndingPunctuation("\"text'"));
}

@Test
Expand All @@ -58,11 +59,17 @@ void replaceQuotes() {
}

@Test
void removeEndingPunctuation() {
assertEquals("text", Strings.removeEndingPunctuation("text"));
assertEquals("\"text\"", Strings.removeEndingPunctuation("\"text\","));
assertEquals("\"text", Strings.removeEndingPunctuation("\"text!"));
assertEquals("'text?'", Strings.removeEndingPunctuation("'text?'"));
assertEquals("\"text'", Strings.removeEndingPunctuation("\"text'"));
void testExtension() {
assertEquals("txt", Strings.getExtension("test.txt"));
assertEquals("txt", Strings.getExtension("/bleh/something/test.txt"));
assertEquals("txt", Strings.getExtension("/bleh/something/test (something).txt"));
}

@Test
void testFilename() {
assertEquals("test.txt", Strings.getFilename("test.txt"));
assertEquals("test.txt", Strings.getFilename("/bleh/something/test.txt"));
assertEquals("test (something).txt",
Strings.getFilename("/bleh/something/test (something).txt"));
}
}
Loading

0 comments on commit 6803be7

Please sign in to comment.