Search in sources :

Example 86 with DynamicObject

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

the class ApiDocumentsSitesRequestTest method testHandleGetSites04.

/**
 * Get /sites with Config.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites04() throws Exception {
    // given
    String siteId = "finance";
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
    setCognitoGroup(event, siteId);
    getAwsServices().configService().save(siteId, new DynamicObject(Map.of(MAX_DOCUMENTS, "5", MAX_WEBHOOKS, "10")));
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("200.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
    assertEquals(1, resp.getList("sites").size());
    assertEquals(siteId, resp.getList("sites").get(0).getString("siteId"));
    assertEquals("5", resp.getList("sites").get(0).getString(MAX_DOCUMENTS));
    assertEquals("10", resp.getList("sites").get(0).getString(MAX_WEBHOOKS));
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 87 with DynamicObject

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

the class ApiDocumentsSitesRequestTest method testHandleGetSites02.

/**
 * Get /sites WITHOUT SES support.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites02() throws Exception {
    // given
    removeSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain");
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("200.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
    assertNull(resp.getString("next"));
    assertNull(resp.getString("previous"));
    List<DynamicObject> sites = resp.getList("sites");
    assertEquals(2, sites.size());
    assertEquals(DEFAULT_SITE_ID, sites.get(0).get("siteId"));
    assertNull(sites.get(0).get("uploadEmail"));
    assertEquals("finance", sites.get(1).get("siteId"));
    assertNull(sites.get(1).get("uploadEmail"));
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 88 with DynamicObject

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

the class ConfigServiceImplTest method testConfig03.

/**
 * Test Finding Config.
 */
@Test
public void testConfig03() {
    // given
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString(), DEFAULT_SITE_ID)) {
        DynamicObject obj = new DynamicObject(Map.of());
        this.service.save(siteId, obj);
        // when
        DynamicObject config = this.service.get(siteId);
        // then
        final int count = 2;
        assertEquals(count, config.keySet().size());
        assertEquals("configs#", config.getString("PK"));
        if (siteId != null) {
            assertEquals(siteId, config.getString("SK"));
        } else {
            assertEquals("default", config.getString("SK"));
        }
        assertNull(config.getString(DOCUMENT_TIME_TO_LIVE));
        assertNull(config.getString(MAX_WEBHOOKS));
        assertNull(config.getString(MAX_DOCUMENTS));
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Example 89 with DynamicObject

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

the class DocumentIdRequestHandler method addFieldsToObject.

/**
 * Add field to object.
 *
 * @param event {@link ApiGatewayRequestEvent}
 * @param awsservice {@link AwsServiceCache}
 * @param siteId {@link String}
 * @param documentId {@link String}
 * @param item {@link DynamicObject}
 * @param documents {@link List} {@link DynamicObject}
 */
private void addFieldsToObject(final ApiGatewayRequestEvent event, final AwsServiceCache awsservice, final String siteId, final String documentId, final DynamicObject item, final List<DynamicObject> documents) {
    String userId = getCallingCognitoUsername(event);
    item.put("documentId", documentId);
    item.put("userId", userId);
    for (DynamicObject map : documents) {
        map.put("documentId", UUID.randomUUID().toString());
        map.put("userId", userId);
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject)

Example 90 with DynamicObject

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

the class DocumentIdRequestHandler method generateUploadUrls.

/**
 * Add field to object.
 *
 * @param awsservice {@link AwsServiceCache}
 * @param siteId {@link String}
 * @param documentId {@link String}
 * @param item {@link DynamicObject}
 * @param documents {@link List} {@link DynamicObject}
 * @return {@link Map}
 */
private Map<String, String> generateUploadUrls(final AwsServiceCache awsservice, final String siteId, final String documentId, final DynamicObject item, final List<DynamicObject> documents) {
    Map<String, String> map = new HashMap<>();
    if (!item.hasString("content")) {
        map.put(documentId, generateUploadUrl(awsservice, siteId, documentId));
    }
    for (DynamicObject o : documents) {
        if (!o.hasString("content")) {
            String docid = o.getString("documentId");
            map.put(docid, generateUploadUrl(awsservice, siteId, docid));
        }
    }
    return map;
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) HashMap(java.util.HashMap)

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