Search in sources :

Example 1 with S3Connector

use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.

the class S3ConnectorServiceRegistrationModule method doInitialize.

@Override
protected void doInitialize(final Session session) throws RepositoryException {
    s3Connector = new S3ConnectorImpl(getAmazonS3(), s3Bucket, new S3ObjectKeyGenerator(this::newRandomString));
    HippoServiceRegistry.registerService(s3Connector, S3Connector.class);
}
Also used : S3ObjectKeyGenerator(uk.nhs.digital.externalstorage.s3.S3ObjectKeyGenerator) S3ConnectorImpl(uk.nhs.digital.externalstorage.s3.S3ConnectorImpl)

Example 2 with S3Connector

use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.

the class ResourceUploadPlugin method handleUpload.

/**
 * Handles the file upload from the form.
 *
 * @param upload the {@link FileUpload} containing the upload information
 */
private void handleUpload(FileUpload upload) throws FileUploadViolationException {
    S3Connector s3Connector = HippoServiceRegistry.getService(S3Connector.class);
    String fileName = upload.getClientFileName();
    String mimeType = upload.getContentType();
    JcrNodeModel nodeModel = (JcrNodeModel) this.getDefaultModel();
    Node node = nodeModel.getNode();
    try {
        S3ObjectMetadata metadata = s3Connector.uploadFile(upload.getInputStream(), fileName, mimeType);
        setResourceProperties(node, metadata);
    } catch (Exception ex) {
        log.error("Cannot upload resource", ex);
        throw new FileUploadViolationException(ex.getMessage());
    }
}
Also used : FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) Node(javax.jcr.Node) S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) JcrNodeModel(org.hippoecm.frontend.model.JcrNodeModel) S3Connector(uk.nhs.digital.externalstorage.s3.S3Connector) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) RepositoryException(javax.jcr.RepositoryException)

Example 3 with S3Connector

use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.

the class ImageDisplayPlugin method createFileLink.

private ResourceLink createFileLink(S3NodeMetadata metadata) throws RepositoryException {
    final S3Connector s3ConnectorService = HippoServiceRegistry.getService(S3Connector.class);
    S3FileResourceStream s3FileResourceStream = new S3FileResourceStream(metadata, s3ConnectorService);
    ResourceStreamResource resourceStreamResource = new ResourceStreamResource(s3FileResourceStream);
    resourceStreamResource.setFileName(metadata.getFileName());
    resourceStreamResource.setContentDisposition(ContentDisposition.ATTACHMENT);
    ResourceLink filelink = new ResourceLink("link", resourceStreamResource);
    filelink.add(new Label("filename", new Model<>(metadata.getFileName())));
    return filelink;
}
Also used : ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) Label(org.apache.wicket.markup.html.basic.Label) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) S3Connector(uk.nhs.digital.externalstorage.s3.S3Connector)

Aggregations

S3Connector (uk.nhs.digital.externalstorage.s3.S3Connector)2 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Label (org.apache.wicket.markup.html.basic.Label)1 ResourceLink (org.apache.wicket.markup.html.link.ResourceLink)1 IModel (org.apache.wicket.model.IModel)1 Model (org.apache.wicket.model.Model)1 ResourceStreamResource (org.apache.wicket.request.resource.ResourceStreamResource)1 JcrNodeModel (org.hippoecm.frontend.model.JcrNodeModel)1 FileUploadViolationException (org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException)1 S3ConnectorImpl (uk.nhs.digital.externalstorage.s3.S3ConnectorImpl)1 S3ObjectKeyGenerator (uk.nhs.digital.externalstorage.s3.S3ObjectKeyGenerator)1 S3ObjectMetadata (uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)1