Search in sources :

Example 6 with AwsServiceCache

use of com.formkiq.lambda.apigateway.AwsServiceCache in project formkiq-core by formkiq.

the class WebhooksRequestHandler method saveWebhook.

private String saveWebhook(final ApiGatewayRequestEvent event, final AwsServiceCache awsservice, final String siteId, final DynamicObject o) {
    Date ttlDate = getTtlDate(awsservice, siteId, o);
    String name = o.getString("name");
    String userId = getCallingCognitoUsername(event);
    String enabled = o.containsKey("enabled") ? o.getString("enabled") : "true";
    String id = awsservice.webhookService().saveWebhook(siteId, name, userId, ttlDate, enabled);
    if (o.containsKey("tags")) {
        List<DynamicObject> dtags = o.getList("tags");
        Date date = new Date();
        Collection<DocumentTag> tags = dtags.stream().map(d -> new DocumentTag(null, d.getString("key"), d.getString("value"), date, userId)).collect(Collectors.toList());
        awsservice.webhookService().addTags(siteId, id, tags, ttlDate);
    }
    return id;
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) WEBHOOK_TIME_TO_LIVE(com.formkiq.stacks.dynamodb.ConfigService.WEBHOOK_TIME_TO_LIVE) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Collection(java.util.Collection) ApiGatewayRequestHandler(com.formkiq.lambda.apigateway.ApiGatewayRequestHandler) DEFAULT_SITE_ID(com.formkiq.stacks.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse) HashMap(java.util.HashMap) AwsServiceCache(com.formkiq.lambda.apigateway.AwsServiceCache) ApiAuthorizer(com.formkiq.lambda.apigateway.ApiAuthorizer) Collectors(java.util.stream.Collectors) BadException(com.formkiq.lambda.apigateway.exception.BadException) TooManyRequestsException(com.formkiq.lambda.apigateway.exception.TooManyRequestsException) MAX_WEBHOOKS(com.formkiq.stacks.dynamodb.ConfigService.MAX_WEBHOOKS) List(java.util.List) ApiGatewayRequestEventUtil(com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) Map(java.util.Map) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ZoneOffset(java.time.ZoneOffset) SC_OK(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Date(java.util.Date)

Example 7 with AwsServiceCache

use of com.formkiq.lambda.apigateway.AwsServiceCache in project formkiq-core by formkiq.

the class DocumentsRestrictionsMaxContentLengthTest method before.

/**
 * Before Tests.
 * @throws URISyntaxException URISyntaxException
 * @throws IOException IOException
 */
@BeforeEach
public void before() throws URISyntaxException, IOException {
    DynamoDbConnectionBuilder adb = DynamoDbTestServices.getDynamoDbConnection(null);
    DynamoDbHelper dbhelper = new DynamoDbHelper(adb);
    this.awsservice = new AwsServiceCache().dbConnection(adb, dbhelper.getDocumentTable(), "").appEnvironment("unittest");
}
Also used : DynamoDbHelper(com.formkiq.stacks.dynamodb.DynamoDbHelper) AwsServiceCache(com.formkiq.lambda.apigateway.AwsServiceCache) DynamoDbConnectionBuilder(com.formkiq.stacks.dynamodb.DynamoDbConnectionBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with AwsServiceCache

use of com.formkiq.lambda.apigateway.AwsServiceCache in project formkiq-core by formkiq.

the class WebhooksTagsRequestHandler method get.

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
    String siteId = authorizer.getSiteId();
    String id = getPathParameter(event, "webhookId");
    PaginationResults<DynamicObject> list = awsServices.webhookService().findTags(siteId, id, null);
    List<Map<String, Object>> tags = list.getResults().stream().map(m -> {
        Map<String, Object> map = new HashMap<>();
        map.put("insertedDate", m.getString("inserteddate"));
        map.put("webhookId", id);
        map.put("type", m.getString("type"));
        map.put("userId", m.getString("userId"));
        map.put("value", m.getString("tagValue"));
        map.put("key", m.getString("tagKey"));
        return map;
    }).collect(Collectors.toList());
    return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("tags", tags)));
}
Also used : SC_CREATED(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_CREATED) Arrays(java.util.Arrays) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Date(java.util.Date) ApiGatewayRequestHandler(com.formkiq.lambda.apigateway.ApiGatewayRequestHandler) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse) HashMap(java.util.HashMap) AwsServiceCache(com.formkiq.lambda.apigateway.AwsServiceCache) ApiAuthorizer(com.formkiq.lambda.apigateway.ApiAuthorizer) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) Collectors(java.util.stream.Collectors) BadException(com.formkiq.lambda.apigateway.exception.BadException) ApiResponse(com.formkiq.lambda.apigateway.ApiResponse) List(java.util.List) ApiGatewayRequestEventUtil(com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) Map(java.util.Map) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiMessageResponse(com.formkiq.lambda.apigateway.ApiMessageResponse) SC_OK(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK) DocumentTagType(com.formkiq.stacks.dynamodb.DocumentTagType) PaginationResults(com.formkiq.stacks.dynamodb.PaginationResults) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)8 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)7 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)7 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)7 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)7 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)7 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)7 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Date (java.util.Date)6 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)5 BadException (com.formkiq.lambda.apigateway.exception.BadException)5 Map (java.util.Map)5 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)4 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)4 DEFAULT_SITE_ID (com.formkiq.stacks.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID)4 ZoneOffset (java.time.ZoneOffset)4 HashMap (java.util.HashMap)4 PaginationResults (com.formkiq.stacks.dynamodb.PaginationResults)3