Class S3ResourceStorageService

java.lang.Object
net.solarnetwork.domain.BasicIdentity<String>
net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider<String>
net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String>
net.solarnetwork.common.s3.S3ResourceStorageService
All Implemented Interfaces:
Comparable<String>, net.solarnetwork.domain.Identity<String>, net.solarnetwork.service.Identifiable, net.solarnetwork.service.LocalizedServiceInfoProvider, net.solarnetwork.service.ResourceStorageService, net.solarnetwork.settings.SettingsChangeObserver, net.solarnetwork.settings.SettingSpecifierProvider

public class S3ResourceStorageService extends net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String> implements net.solarnetwork.service.ResourceStorageService, net.solarnetwork.settings.SettingSpecifierProvider, net.solarnetwork.settings.SettingsChangeObserver
AWS S3 based implementation of ResourceStorageService using the S3Client API.
Version:
2.0
Author:
matt
  • Constructor Details

    • S3ResourceStorageService

      public S3ResourceStorageService(Executor executor)
      Constructor.
      Parameters:
      executor - the executor to use
      Throws:
      IllegalArgumentException - if executor is null
    • S3ResourceStorageService

      public S3ResourceStorageService(String id, Executor executor)
      Constructor.
      Parameters:
      id - the settings UID to use
      executor - the executor to use
      Throws:
      IllegalArgumentException - if executor is null
  • Method Details

    • startup

      public void startup()
      Call after properties are configured.
    • configurationChanged

      public void configurationChanged(Map<String,Object> properties)
      Specified by:
      configurationChanged in interface net.solarnetwork.settings.SettingsChangeObserver
    • isConfigured

      public boolean isConfigured()
      Specified by:
      isConfigured in interface net.solarnetwork.service.ResourceStorageService
    • listResources

      public CompletableFuture<Iterable<org.springframework.core.io.Resource>> listResources(String pathPrefix)
      Specified by:
      listResources in interface net.solarnetwork.service.ResourceStorageService
    • resourceStorageUrl

      public URL resourceStorageUrl(String path)
      Specified by:
      resourceStorageUrl in interface net.solarnetwork.service.ResourceStorageService
    • saveResource

      public CompletableFuture<Boolean> saveResource(String path, org.springframework.core.io.Resource resource, boolean replace, net.solarnetwork.service.ProgressListener<org.springframework.core.io.Resource> progressListener)
      Specified by:
      saveResource in interface net.solarnetwork.service.ResourceStorageService
    • deleteResources

      public CompletableFuture<Set<String>> deleteResources(Iterable<String> paths)
      Specified by:
      deleteResources in interface net.solarnetwork.service.ResourceStorageService
    • postResourceSavedEvent

      protected final void postResourceSavedEvent(org.springframework.core.io.Resource resource, String path)
      Post an Event for the ResourceStorageService.EVENT_TOPIC_RESOURCE_SAVED topic.
      Parameters:
      resource - the resource to create the event for
      path - the resource path
    • createResourceSavedEvent

      protected org.osgi.service.event.Event createResourceSavedEvent(org.springframework.core.io.Resource resource, String path)
      Create a new ResourceStorageService.EVENT_TOPIC_RESOURCE_SAVED Event object out of a resource and path.
      Parameters:
      resource - the resource to create the event for
      path - the resource path
      Returns:
      the new Event instance, or null if resource is null or cannot be resolved to a URL
    • postResourcesDeletedEvent

      protected final void postResourcesDeletedEvent(Iterable<String> paths)
      Post an Event for the ResourceStorageService.EVENT_TOPIC_RESOURCES_DELETED topic.
      Parameters:
      paths - the paths that have been deleted
    • createResourcesDeletedEvent

      protected org.osgi.service.event.Event createResourcesDeletedEvent(Iterable<String> paths)
      Create a new ResourceStorageService.EVENT_TOPIC_RESOURCES_DELETED Event object out of a set of paths.
      Parameters:
      paths - the paths that have been deleted
      Returns:
      the new Event instance, or null if paths is null
    • postEvent

      protected final void postEvent(org.osgi.service.event.Event event)
      Post an Event.

      This method only works if a EventAdmin has been configured via setEventAdmin(OptionalService). Otherwise the event is silently ignored.

      Parameters:
      event - the event to post
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface net.solarnetwork.service.Identifiable
      Specified by:
      getDisplayName in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getSettingSpecifiers

      public List<net.solarnetwork.settings.SettingSpecifier> getSettingSpecifiers()
      Specified by:
      getSettingSpecifiers in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getS3Client

      public S3Client getS3Client()
      Get the S3 client.
      Returns:
      the client, never null
    • setS3Client

      public void setS3Client(S3Client s3Client)
      Set the S3 client.
      Parameters:
      s3Client - the client to set
      Throws:
      IllegalArgumentException - if s3Client is null
    • getExecutor

      public Executor getExecutor()
      Get the executor that handles asynchronous operations.
      Returns:
      the executor, never null
    • setExecutor

      public void setExecutor(Executor executor)
      Set the executor that handles asynchronous operations.
      Parameters:
      executor - the executor to set
      Throws:
      IllegalArgumentException - if Executor is null
    • getObjectKeyPrefix

      public String getObjectKeyPrefix()
      Get the S3 object key prefix.
      Returns:
      the prefix to use, or null
    • setObjectKeyPrefix

      public void setObjectKeyPrefix(String objectKeyPrefix)
      Set a S3 object key prefix to use.

      This can essentially be a folder path to prefix all data with. All keys passed to all methods that do not already start with this prefix will have the prefix added before passing the operation to S3.

      Parameters:
      objectKeyPrefix - the object key prefix to set, or null for no prefix
    • getUid

      public String getUid()
      Specified by:
      getUid in interface net.solarnetwork.service.Identifiable
    • setUid

      public void setUid(String uid)
      Set the UID.
      Parameters:
      uid - the UID to set
    • getGroupUid

      public String getGroupUid()
      Specified by:
      getGroupUid in interface net.solarnetwork.service.Identifiable
    • setGroupUid

      public void setGroupUid(String groupUid)
      Set the group UID.
      Parameters:
      groupUid - the group UID to set
    • getUID

      @Deprecated public String getUID()
      Deprecated.
      since 2.0 use getUid()
      Alias for getUid().
      Returns:
      the UID
    • setUID

      @Deprecated public void setUID(String uid)
      Deprecated.
      since 2.0 use setUid(String)
      Set the UID.

      This is an alias for setUid(String).

      Parameters:
      uid - the UID to set
    • getGroupUID

      @Deprecated public String getGroupUID()
      Deprecated.
      Alias for getGroupUid().
      Returns:
      the group UID
    • setGroupUID

      @Deprecated public void setGroupUID(String groupUid)
      Deprecated.
      since 2.0 use setGroupUid(String)
      Set the group UID.

      This is an alias for setGroupUid(String).

      Parameters:
      groupUid - the group UID to set
    • getEventAdmin

      public net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> getEventAdmin()
      Get the optional EventAdmin service.
      Returns:
      the eventAdmin the service
    • setEventAdmin

      public void setEventAdmin(net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin)
      Set the optional EventAdmin service.
      Parameters:
      eventAdmin - the service to set