use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class StagingS3Create method handleRequest.
@SuppressWarnings("unchecked")
@Override
public Void handleRequest(final Map<String, Object> map, final Context context) {
String json = null;
Date date = new Date();
try {
LambdaLogger logger = context.getLogger();
if ("true".equals(System.getenv("DEBUG"))) {
json = this.gson.toJson(map);
logger.log(json);
}
List<Map<String, Object>> records = (List<Map<String, Object>>) map.get("Records");
processRecords(logger, date, records);
} catch (Exception e) {
e.printStackTrace();
if (json == null) {
json = this.gson.toJson(map);
}
if (this.sqsErrorQueue != null) {
this.sqsService.sendMessage(this.sqsErrorQueue, json);
}
}
return null;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class ConsoleInstallHandler method handleRequest.
/**
* Handle Console Installation.
*
* @param input {@link Map}
* @param context {@link Context}
* @return {@link Object}
*/
@Override
public Object handleRequest(final Map<String, Object> input, final Context context) {
LambdaLogger logger = context.getLogger();
logger.log("received input: " + input);
try {
final String requestType = (String) input.get("RequestType");
boolean unzip = requestType != null && ("Create".equalsIgnoreCase(requestType) || "Update".equalsIgnoreCase(requestType));
boolean delete = requestType != null && "Delete".equalsIgnoreCase(requestType);
if (unzip) {
unzipConsole(input, requestType, context, logger);
createCognitoConfig(logger);
sendResponse(input, logger, context, "SUCCESS", "Request " + requestType + " was successful!");
} else if (delete) {
sendResponse(input, logger, context, "SUCCESS", "Request " + requestType + " was successful!");
} else {
sendResponse(input, logger, context, "FAILURE", "received RequestType " + requestType + " skipping unpacking");
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sendResponse(input, logger, context, "FAILURE", sw.toString());
}
return null;
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class DocumentTagsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
CacheService cacheService = awsservice.documentCacheService();
ApiPagination pagination = getPagination(cacheService, event);
int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
String siteId = authorizer.getSiteId();
String documentId = event.getPathParameters().get("documentId");
PaginationResults<DocumentTag> results = awsservice.documentService().findDocumentTags(siteId, documentId, ptoken, limit);
results.getResults().forEach(r -> r.setDocumentId(null));
ApiPagination current = createPagination(cacheService, event, pagination, results.getToken(), limit);
List<DocumentTag> tags = subList(results.getResults(), limit);
List<ApiDocumentTagItemResponse> list = tags.stream().map(t -> {
ApiDocumentTagItemResponse r = new ApiDocumentTagItemResponse();
r.setDocumentId(t.getDocumentId());
r.setInsertedDate(t.getInsertedDate());
r.setKey(t.getKey());
r.setValue(t.getValue());
r.setValues(t.getValues());
r.setUserId(t.getUserId());
r.setType(t.getType() != null ? t.getType().name().toLowerCase() : null);
return r;
}).collect(Collectors.toList());
ApiDocumentTagsItemResponse resp = new ApiDocumentTagsItemResponse();
resp.setTags(list);
resp.setPrevious(current.getPrevious());
resp.setNext(current.hasNext() ? current.getNext() : null);
return new ApiRequestHandlerResponse(SC_OK, resp);
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class DocumentVersionsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
SimpleDateFormat df = new SimpleDateFormat(GsonUtil.DATE_FORMAT);
String siteId = authorizer.getSiteId();
String documentId = event.getPathParameters().get("documentId");
String next = getParameter(event, "next");
String tz = getParameter(event, "tz");
ZoneOffset offset = DateUtil.getZoneOffset(tz);
df.setTimeZone(TimeZone.getTimeZone(offset));
String s3key = createDatabaseKey(siteId, documentId);
S3Service s3service = awsservice.s3Service();
try (S3Client s3 = s3service.buildClient()) {
ListObjectVersionsResponse response = s3service.getObjectVersions(s3, awsservice.documents3bucket(), s3key, next);
List<ApiDocumentVersion> list = response.versions().stream().map(v -> {
ApiDocumentVersion dv = new ApiDocumentVersion();
dv.setVersionId(v.versionId());
Date date = Date.from(v.lastModified());
dv.setLastModifiedDate(df.format(date));
return dv;
}).collect(Collectors.toList());
ApiDocumentVersionsResponse resp = new ApiDocumentVersionsResponse();
resp.setNext(response.nextKeyMarker());
resp.setVersions(list);
return new ApiRequestHandlerResponse(SC_OK, resp);
}
}
use of com.amazonaws.services.lambda.runtime.LambdaLogger in project formkiq-core by formkiq.
the class DocumentsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
ApiPagination pagination = getPagination(awsservice.documentCacheService(), event);
final int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
final PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
String tz = getParameter(event, "tz");
String dateString = getParameter(event, "date");
if (StringUtils.isBlank(dateString)) {
if (StringUtils.isNotBlank(tz)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
ZoneOffset offset = DateUtil.getZoneOffset(tz);
sdf.setTimeZone(TimeZone.getTimeZone(offset));
dateString = sdf.format(new Date());
} else {
dateString = this.df.format(new Date());
}
}
ZonedDateTime date = transformToDate(logger, awsservice, dateString, tz);
String siteId = authorizer.getSiteId();
final PaginationResults<DocumentItem> results = awsservice.documentService().findDocumentsByDate(siteId, date, ptoken, limit);
ApiPagination current = createPagination(awsservice.documentCacheService(), event, pagination, results.getToken(), limit);
List<DocumentItem> documents = subList(results.getResults(), limit);
List<DynamicDocumentItem> items = documents.stream().map(m -> new DocumentItemToDynamicDocumentItem().apply(m)).collect(Collectors.toList());
items.forEach(i -> i.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID));
Map<String, Object> map = new HashMap<>();
map.put("documents", items);
map.put("previous", current.getPrevious());
map.put("next", current.hasNext() ? current.getNext() : null);
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(map));
}
Aggregations