Search in sources :

Example 6 with ApiMapResponse

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

the class VersionRequestHandler method get.

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    String key = "/formkiq/" + awsservice.appEnvironment() + "/version";
    String version = awsservice.ssmService().getParameterValue(key);
    return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("version", version, "type", awsservice.formkiqType())));
}
Also used : ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse)

Example 7 with ApiMapResponse

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

the class WebhooksRequestHandler 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 url = awsServices.ssmService().getParameterValue("/formkiq/" + awsServices.appEnvironment() + "/api/DocumentsPublicHttpUrl");
    List<DynamicObject> list = awsServices.webhookService().findWebhooks(siteId);
    List<Map<String, Object>> webhooks = list.stream().map(m -> {
        String path = "private".equals(m.getString("enabled")) ? "/private" : "/public";
        Map<String, Object> map = new HashMap<>();
        String u = url + path + "/webhooks/" + m.getString("documentId");
        if (siteId != null && !DEFAULT_SITE_ID.equals(siteId)) {
            u += "?siteId=" + siteId;
        }
        map.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);
        map.put("id", m.getString("documentId"));
        map.put("name", m.getString("path"));
        map.put("url", u);
        map.put("insertedDate", m.getString("inserteddate"));
        map.put("userId", m.getString("userId"));
        map.put("enabled", m.getString("enabled"));
        map.put("ttl", m.getString("ttl"));
        return map;
    }).collect(Collectors.toList());
    return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("webhooks", webhooks)));
}
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) 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)

Example 8 with ApiMapResponse

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

the class SearchRequestHandler method post.

@Override
public ApiRequestHandlerResponse post(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    DynamoDbCacheService cacheService = awsservice.documentCacheService();
    ApiPagination pagination = getPagination(cacheService, event);
    int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
    PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
    QueryRequest q = fromBodyToObject(logger, event, QueryRequest.class);
    if (q == null || q.query() == null || q.query().tag() == null) {
        throw new BadException("Invalid JSON body.");
    }
    Collection<String> documentIds = q.query().documentIds();
    if (documentIds != null) {
        if (documentIds.size() > MAX_DOCUMENT_IDS) {
            throw new BadException("Maximum number of DocumentIds is " + MAX_DOCUMENT_IDS);
        }
        if (!getQueryParameterMap(event).containsKey("limit")) {
            limit = documentIds.size();
        }
    }
    String siteId = authorizer.getSiteId();
    PaginationResults<DynamicDocumentItem> results = awsservice.documentSearchService().search(siteId, q.query(), ptoken, limit);
    ApiPagination current = createPagination(cacheService, event, pagination, results.getToken(), limit);
    List<DynamicDocumentItem> documents = subList(results.getResults(), limit);
    Map<String, Object> map = new HashMap<>();
    map.put("documents", documents);
    map.put("previous", current.getPrevious());
    map.put("next", current.hasNext() ? current.getNext() : null);
    ApiMapResponse resp = new ApiMapResponse(map);
    return new ApiRequestHandlerResponse(SC_OK, resp);
}
Also used : ApiPagination(com.formkiq.lambda.apigateway.ApiPagination) QueryRequest(com.formkiq.stacks.api.QueryRequest) HashMap(java.util.HashMap) BadException(com.formkiq.lambda.apigateway.exception.BadException) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamoDbCacheService(com.formkiq.stacks.dynamodb.DynamoDbCacheService) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse) PaginationMapToken(com.formkiq.stacks.dynamodb.PaginationMapToken)

Example 9 with ApiMapResponse

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

the class WebhooksIdRequestHandler 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");
    DynamicObject m = awsServices.webhookService().findWebhook(siteId, id);
    if (m == null) {
        throw new NotFoundException("Webhook 'id' not found");
    }
    String url = awsServices.ssmService().getParameterValue("/formkiq/" + awsServices.appEnvironment() + "/api/DocumentsPublicHttpUrl");
    String path = "private".equals(m.getString("enabled")) ? "/private" : "/public";
    String u = url + path + "/webhooks/" + m.getString("documentId");
    if (siteId != null && !DEFAULT_SITE_ID.equals(siteId)) {
        u += "?siteId=" + siteId;
    }
    Map<String, Object> map = new HashMap<>();
    map.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);
    map.put("id", m.getString("documentId"));
    map.put("name", m.getString("path"));
    map.put("url", u);
    map.put("insertedDate", m.getString("inserteddate"));
    map.put("userId", m.getString("userId"));
    map.put("enabled", m.getString("enabled"));
    map.put("ttl", m.getString("ttl"));
    return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(map));
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) HashMap(java.util.HashMap) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse)

Example 10 with ApiMapResponse

use of com.formkiq.lambda.apigateway.ApiMapResponse 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

ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)11 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)11 BadException (com.formkiq.lambda.apigateway.exception.BadException)5 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)5 HashMap (java.util.HashMap)5 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)4 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)4 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)4 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)4 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)4 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)4 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ApiPagination (com.formkiq.lambda.apigateway.ApiPagination)3 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)3 DynamicDocumentItem (com.formkiq.stacks.dynamodb.DynamicDocumentItem)3 DEFAULT_SITE_ID (com.formkiq.stacks.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID)3