Skip to content

Commit

Permalink
changed Document Folders to use FolderIndexRecord object
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jul 30, 2023
1 parent d6b2771 commit 54eb09c
Show file tree
Hide file tree
Showing 43 changed files with 930 additions and 389 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 @@ -40,12 +40,15 @@
import com.formkiq.aws.dynamodb.model.DocumentItem;
import com.formkiq.module.actions.services.ActionsService;
import com.formkiq.module.actions.services.ActionsServiceDynamoDb;
import com.formkiq.module.events.EventService;
import com.formkiq.module.events.EventServiceSns;
import com.formkiq.stacks.dynamodb.DocumentItemDynamoDb;
import com.formkiq.stacks.dynamodb.DocumentService;
import com.formkiq.stacks.dynamodb.DocumentServiceImpl;
import com.formkiq.stacks.dynamodb.DocumentVersionServiceNoVersioning;
import com.formkiq.testutils.aws.DynamoDbExtension;
import com.formkiq.testutils.aws.DynamoDbTestServices;
import com.formkiq.testutils.aws.TestServices;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

/** Unit Tests for {@link ActionsServiceDynamoDbTest}. */
Expand All @@ -67,8 +70,10 @@ public static void beforeAll() throws Exception {

DynamoDbConnectionBuilder db = DynamoDbTestServices.getDynamoDbConnection();
service = new ActionsServiceDynamoDb(db, DOCUMENTS_TABLE);
documentService =
new DocumentServiceImpl(db, DOCUMENTS_TABLE, new DocumentVersionServiceNoVersioning());
EventService documentEventService =
new EventServiceSns(TestServices.getSnsConnection(null), "");
documentService = new DocumentServiceImpl(db, DOCUMENTS_TABLE,
new DocumentVersionServiceNoVersioning(), documentEventService);
}

/**
Expand Down
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"));
}
}
15 changes: 12 additions & 3 deletions document-events/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@

<import-control pkg="com.formkiq.module">

<subpackage name="documentevents">

<subpackage name="events">

<allow pkg="com.formkiq.module.events.document" />
<allow pkg="com.formkiq.module.events.folder" />
<allow pkg="java.util" />
<allow pkg="com.formkiq.aws.sns" />
<allow pkg="com.formkiq.graalvm.annotations" />
<allow pkg="com.google.gson" />
<allow pkg="software.amazon.awssdk.services.sns.model" />

<subpackage name="document">
<allow pkg="com.formkiq.graalvm.annotations" />
</subpackage>

<subpackage name="folder">
<allow pkg="com.formkiq.graalvm.annotations" />
</subpackage>

</subpackage>

</import-control>
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.module.documentevents;
package com.formkiq.module.events;

import com.formkiq.module.events.document.DocumentEvent;
import com.formkiq.module.events.folder.FolderEvent;

/**
*
* {@link DocumentEvent} Service used for notification of any type of Document Event in FormKiQ.
*
*/
public interface DocumentEventService {
public interface EventService {

/**
* Send {@link DocumentEvent} to Event System.
*
* @param topicArn {@link String}
* @param event {@link DocumentEvent}
* @return {@link String}
*/
String publish(String topicArn, DocumentEvent event);
String publish(DocumentEvent event);

/**
* Send {@link FolderEvent} to Event System.
*
* @param event {@link FolderEvent}
* @return {@link String}
*/
String publish(FolderEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,50 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.module.documentevents;
package com.formkiq.module.events;

import java.util.Map;
import com.formkiq.aws.sns.SnsConnectionBuilder;
import com.formkiq.aws.sns.SnsService;
import com.formkiq.module.events.document.DocumentEvent;
import com.formkiq.module.events.folder.FolderEvent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import software.amazon.awssdk.services.sns.model.MessageAttributeValue;

/**
*
* SQS implementation of the {@link DocumentEventService}.
* SQS implementation of the {@link EventService}.
*
*/
public class DocumentEventServiceSns implements DocumentEventService {
public class EventServiceSns implements EventService {

/** Max Sns Message Size. */
public static final int MAX_SNS_MESSAGE_SIZE = 256000;
/** {@link Gson}. */
private Gson gson = new GsonBuilder().create();
/** {@link SnsService}. */
private SnsService snsService;
/** SNS Topic Arn. */
private String topicArn;

/**
* constructor.
*
* @param snsBuilder {@link SnsConnectionBuilder}
* @param eventTopicArn {@link String}
*/
public DocumentEventServiceSns(final SnsConnectionBuilder snsBuilder) {
public EventServiceSns(final SnsConnectionBuilder snsBuilder, final String eventTopicArn) {
this.snsService = new SnsService(snsBuilder);
this.topicArn = eventTopicArn;
}

String convertToPrintableCharacters(final String s) {
return s != null ? s.replaceAll("[^A-Za-z0-9/-]", "") : null;
}

@Override
public String publish(final String topicArn, final DocumentEvent event) {
public String publish(final DocumentEvent event) {

String eventJson = this.gson.toJson(event);
if (eventJson.length() > MAX_SNS_MESSAGE_SIZE) {
Expand All @@ -75,12 +85,24 @@ public String publish(final String topicArn, final DocumentEvent event) {
tags = Map.of("type", typeAttr, "siteId", siteIdAttr, "userId", userIdAttr);
}

this.snsService.publish(topicArn, eventJson, tags);
this.snsService.publish(this.topicArn, eventJson, tags);

return eventJson;
}

String convertToPrintableCharacters(final String s) {
return s != null ? s.replaceAll("[^A-Za-z0-9/-]", "") : null;
@Override
public String publish(final FolderEvent event) {
String eventJson = this.gson.toJson(event);

MessageAttributeValue typeAttr =
MessageAttributeValue.builder().dataType("String").stringValue(event.type()).build();
MessageAttributeValue siteIdAttr = MessageAttributeValue.builder().dataType("String")
.stringValue(convertToPrintableCharacters(event.siteId())).build();

Map<String, MessageAttributeValue> tags = Map.of("type", typeAttr, "siteId", siteIdAttr);

this.snsService.publish(this.topicArn, eventJson, tags);

return eventJson;
}
}
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.module.documentevents;
package com.formkiq.module.events.document;

import com.formkiq.graalvm.annotations.Reflectable;

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.module.documentevents;
package com.formkiq.module.events.document;

/**
*
Expand Down
Loading

0 comments on commit 54eb09c

Please sign in to comment.