Search in sources :

Example 91 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentIdRequestHandler method putObjectToStaging.

/**
 * Put Object to Staging Bucket.
 *
 * @param logger {@link LambdaLogger}
 * @param awsservice {@link AwsServiceCache}
 * @param maxDocumentCount {@link String}
 * @param siteId {@link String}
 * @param item {@link DynamicObject}
 */
private void putObjectToStaging(final LambdaLogger logger, final AwsServiceCache awsservice, final String maxDocumentCount, final String siteId, final DynamicObject item) {
    List<DynamicObject> documents = item.getList("documents");
    item.put("documents", documents);
    String s = GSON.toJson(item);
    byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
    String key = createDatabaseKey(siteId, item.getString("documentId") + FORMKIQ_DOC_EXT);
    logger.log("s3 putObject " + key + " into bucket " + awsservice.stages3bucket());
    S3Service s3 = awsservice.s3Service();
    try (S3Client client = s3.buildClient()) {
        s3.putObject(client, awsservice.stages3bucket(), key, bytes, item.getString("contentType"));
        if (maxDocumentCount != null) {
            awsservice.documentCountService().incrementDocumentCount(siteId);
        }
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service)

Example 92 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImplTest method testAddTags01.

/**
 * Add Webhook Tag.
 */
@Test
public void testAddTags01() {
    // given
    String hook0 = this.service.saveWebhook(null, "test", "joe", null, "true");
    String hook1 = this.service.saveWebhook(null, "test2", "joe2", null, "true");
    DocumentTag tag0 = new DocumentTag(hook0, "category", "person", new Date(), "joe");
    DocumentTag tag1 = new DocumentTag(hook0, "type", "person2", new Date(), "joe");
    // when
    this.service.addTags(null, hook0, Arrays.asList(tag0, tag1), null);
    // then
    assertNull(this.service.findTag(null, hook1, "category"));
    DynamicObject tag = this.service.findTag(null, hook0, "category");
    assertEquals("category", tag.getString("tagKey"));
    assertEquals("person", tag.getString("tagValue"));
    assertEquals(2, this.service.findTags(null, hook0, null).getResults().size());
    assertEquals(0, this.service.findTags(null, hook1, null).getResults().size());
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 93 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImplTest method testUpdateWebhooks01.

/**
 * Test Updating webhooks.
 */
@Test
public void testUpdateWebhooks01() {
    // given
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    Date ttl = Date.from(now.toInstant());
    ZonedDateTime tomorrow = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1);
    Date tomorrowttl = Date.from(tomorrow.toInstant());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String webhookId = this.service.saveWebhook(siteId, "test", "joe", ttl, "true");
        DynamicObject obj = new DynamicObject(Map.of("name", "test2", "TimeToLive", tomorrowttl));
        // when
        this.service.updateWebhook(siteId, webhookId, obj);
        // then
        DynamicObject result = this.service.findWebhook(siteId, webhookId);
        assertEquals("test2", result.getString("path"));
        assertNotNull(result.getString("documentId"));
        assertNotNull(result.getString("path"));
        assertNotNull(result.getString("userId"));
        assertNotNull(result.getString("inserteddate"));
        assertEquals(String.valueOf(tomorrowttl.getTime() / MILLISECONDS), result.getString("TimeToLive"));
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ZonedDateTime(java.time.ZonedDateTime) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)93 Test (org.junit.jupiter.api.Test)55 Map (java.util.Map)46 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)39 Date (java.util.Date)26 HashMap (java.util.HashMap)17 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)12 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)10 ZonedDateTime (java.time.ZonedDateTime)10 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)8 List (java.util.List)8 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)7 S3Client (software.amazon.awssdk.services.s3.S3Client)7 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)6 BadException (com.formkiq.lambda.apigateway.exception.BadException)6 Collectors (java.util.stream.Collectors)6 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)5 LocalDate (java.time.LocalDate)5 Test (org.junit.Test)5