use of com.formkiq.aws.s3.S3Service 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.formkiq.aws.s3.S3Service in project modeldb by VertaAI.
the class ServiceSet method initializeArtifactStore.
private static ArtifactStoreService initializeArtifactStore(MDBArtifactStoreConfig mdbArtifactStoreConfig) throws ModelDBException, IOException {
// ------------- Start Initialize Cloud storage base on configuration ------------------
ArtifactStoreService artifactStoreService;
if (mdbArtifactStoreConfig.getArtifactEndpoint() != null) {
System.getProperties().put("artifactEndpoint.storeArtifact", mdbArtifactStoreConfig.getArtifactEndpoint().getStoreArtifact());
System.getProperties().put("artifactEndpoint.getArtifact", mdbArtifactStoreConfig.getArtifactEndpoint().getGetArtifact());
}
if (mdbArtifactStoreConfig.getNFS() != null && mdbArtifactStoreConfig.getNFS().getArtifactEndpoint() != null) {
System.getProperties().put("artifactEndpoint.storeArtifact", mdbArtifactStoreConfig.getNFS().getArtifactEndpoint().getStoreArtifact());
System.getProperties().put("artifactEndpoint.getArtifact", mdbArtifactStoreConfig.getNFS().getArtifactEndpoint().getGetArtifact());
}
switch(mdbArtifactStoreConfig.getArtifactStoreType()) {
case "S3":
if (!mdbArtifactStoreConfig.S3.getS3presignedURLEnabled()) {
System.setProperty(ModelDBConstants.CLOUD_BUCKET_NAME, mdbArtifactStoreConfig.S3.getCloudBucketName());
System.getProperties().put(SCAN_PACKAGES, "ai.verta.modeldb.artifactStore.storageservice.s3");
startSpringServer();
artifactStoreService = App.getInstance().applicationContext.getBean(S3Service.class);
} else {
artifactStoreService = new S3Service(mdbArtifactStoreConfig.S3.getCloudBucketName());
System.getProperties().put(SCAN_PACKAGES, "dummyPackageName");
startSpringServer();
}
break;
case "NFS":
String rootDir = mdbArtifactStoreConfig.getNFS().getNfsRootPath();
LOGGER.trace("NFS server root path {}", rootDir);
System.getProperties().put("file.upload-dir", rootDir);
System.getProperties().put(SCAN_PACKAGES, "ai.verta.modeldb.artifactStore.storageservice.nfs");
startSpringServer();
artifactStoreService = App.getInstance().applicationContext.getBean(NFSService.class);
break;
default:
throw new ModelDBException("Configure valid artifact store name in config.yaml file.");
}
// ------------- Finish Initialize Cloud storage base on configuration ------------------
LOGGER.info("ArtifactStore service initialized and resolved storage dependency before server start");
return artifactStoreService;
}
use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method beforeClass.
/**
* Before Class.
*
* @throws URISyntaxException URISyntaxException
* @throws InterruptedException InterruptedException
* @throws IOException IOException
*/
@BeforeAll
public static void beforeClass() throws URISyntaxException, InterruptedException, IOException {
Region region = Region.US_EAST_1;
AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
localstack.start();
snsBuilder = new SnsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SNS).toString()).setRegion(region).setCredentials(cred);
sqsBuilder = new SqsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SQS).toString()).setRegion(region).setCredentials(cred);
sqsService = new SqsService(sqsBuilder);
s3Builder = new S3ConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.S3).toString()).setRegion(region).setCredentials(cred);
dbBuilder = DynamoDbTestServices.getDynamoDbConnection(null);
service = new DocumentServiceImpl(dbBuilder, "Documents");
if (!sqsService.exists(ERROR_SQS_QUEUE)) {
sqsService.createQueue(ERROR_SQS_QUEUE);
}
if (!sqsService.exists(SNS_SQS_CREATE_QUEUE)) {
sqsDocumentEventUrl = sqsService.createQueue(SNS_SQS_CREATE_QUEUE).queueUrl();
}
s3service = new S3Service(s3Builder);
try (S3Client s3 = s3service.buildClient()) {
s3service.createBucket(s3, "example-bucket");
}
snsService = new SnsService(snsBuilder);
snsDocumentEvent = snsService.createTopic("createDocument1").topicArn();
snsService.subscribe(snsDocumentEvent, "sqs", sqsDocumentEventUrl);
dbHelper = new DynamoDbHelper(dbBuilder);
if (!dbHelper.isDocumentsTableExists()) {
dbHelper.createDocumentsTable();
dbHelper.createCacheTable();
}
}
use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.
the class AbstractAwsTest method beforeClass.
/**
* beforeclass.
*
* @throws IOException IOException
*/
@BeforeClass
public static void beforeClass() throws IOException {
awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
appenvironment = System.getProperty("testappenvironment");
final SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final S3ConnectionBuilder s3Builder = new S3ConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final SnsConnectionBuilder snsBuilder = new SnsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
sqsService = new SqsService(sqsConnection);
s3Service = new S3Service(s3Builder);
ssmService = new SsmServiceImpl(ssmBuilder);
snsService = new SnsService(snsBuilder);
sesbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsSesS3Bucket");
documentsbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsS3Bucket");
stagingdocumentsbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsStageS3Bucket");
snsDocumentEventArn = ssmService.getParameterValue("/formkiq/" + appenvironment + "/sns/DocumentEventArn");
String documentsTable = ssmService.getParameterValue("/formkiq/" + appenvironment + "/dynamodb/DocumentsTableName");
DynamoDbConnectionBuilder dbConnection = new DynamoDbConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
documentService = new DocumentServiceImpl(dbConnection, documentsTable);
}
use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.
the class EmailSendingTest method beforeClass.
/**
* beforeclass.
*
* @throws IOException IOException
*/
@BeforeClass
public static void beforeClass() throws IOException {
Region awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
final SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final SnsConnectionBuilder snsBuilder = new SnsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
final S3ConnectionBuilder s3Builder = new S3ConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
s3Service = new S3Service(s3Builder);
sqsService = new SqsService(sqsConnection);
SsmService ssmService = new SsmServiceImpl(ssmBuilder);
snsService = new SnsService(snsBuilder);
String app = System.getProperty("testappenvironment");
snsDocumentEmailArn = ssmService.getParameterValue("/formkiq/" + app + "/sns/DocumentsEmailNotificationArn");
stagingdocumentsbucketname = ssmService.getParameterValue("/formkiq/" + app + "/s3/DocumentsStageS3Bucket");
}
Aggregations