Interface ResourceCollectionManager
- All Known Subinterfaces:
ConfigurationManager,ProjectManager
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ResourceCollectionListener listener) Add aResourceCollectionListener.default StringCreate a copy of the resource collection namedname, usingnewNameas the new collection name, if possible.voidcreate(String name, ResourceCollectionManifest manifest, List<Resource> resources) Create a new resource collection with the provided manifest and resources.voidcreateOrReplace(String name, ResourceCollectionManifest manifest, List<Resource> resources) Create a new resource collection with the provided manifests and resources, or replace an existing collection bynameif it already exists.default StringcreateSafe(String name, ResourceCollectionManifest manifest, List<Resource> resources) Create a new resource collection with the provided manifests and resources.default StringcreateSafe(String name, ResourceCollectionManifest manifest, List<Resource> resources, String namePattern) Create a new resource collection with the provided manifests and resources.voidDelete the resource collection namedname, if it exists.voidexport(String name, OutputStream destination) Export a copy of resource collection by writing the contents to thedestinationOutputStream.default Optional<RuntimeResourceCollection>Get a theRuntimeResourceCollectionfor the given name with all resources in all scopes, if it exists, if it exists, or else empty.default Optional<RuntimeResourceCollection>Returns aRuntimeResourceCollectionfor the given name loaded with all resources that meet the given application scope, if it exists, or else empty.find(String name, ResourceFilter resourceFilter) Returns aRuntimeResourceCollectionfor the givennamecontaining only resources that pass the providedResourceFilter, if it exists, or else empty.getDefiningCollectionNames(ResourcePath resourcePath) Return the set of resource collections which have a definition for the given resource path.Get aMapofResourceCollectionManifests for all current resource collections.getNames()Get aListof all current resource collection names.getResource(String collectionName, ResourcePath resourcePath) Find a resource defined in a specific collection, ignoring inheritance.default booleanChecks the mutability status of a resource collection.Pull any changes for the givensnapshots.pull(List<Snapshot> snapshots, ResourceFilter filter) Pull any changes for the givensnapshots, but only changes for resources that match thefilter.push(PushOperation pushOperation) Attempt to push a list ofChangeOperations.default CompletableFuture<Void>push(List<ChangeOperation> changeOperations) Push a list of changes, with no associated context object.pushPartial(PushOperation operation) Alternative version ofpush(List)that allows for some operations to succeed even if others fail.voidremoveListener(ResourceCollectionListener listener) Remove a previously-registeredResourceCollectionListener.Requests that a scan for changed resources on the filesystem be performed immediately.
-
Field Details
-
DEFAULT_NAME_PATTERN
- See Also:
-
-
Method Details
-
addListener
Add aResourceCollectionListener.- Parameters:
listener- theResourceCollectionListener.
-
removeListener
Remove a previously-registeredResourceCollectionListener.- Parameters:
listener- theResourceCollectionListener.
-
isMutable
Checks the mutability status of a resource collection. A mutable collection is one that can be modified by the user, through the disk, api, designer, scripting, etc. An immutable collection is managed programmatically, not represented on disk, and cannot be modified, removed, copied, or exported by the user or designer.- Parameters:
collectionName- the name of the resource collection to check.- Returns:
- The mutability state of the given collection, if it exists. If the name doesn't represent a collection, this method will return true.
-
create
void create(String name, ResourceCollectionManifest manifest, List<Resource> resources) throws IllegalArgumentException, IOException, NameInUseException Create a new resource collection with the provided manifest and resources. The new collection will be stored to disk and will be available for use immediately. Listeners will be notified.- Parameters:
name- the name of the resource collection to create.manifest- theResourceCollectionManifest.resources- the resources, if any, to include in the collection- Throws:
IllegalArgumentException- if any of the resources indicate they belong to another collection other thanname.IOException- if the collection files could not be created.NameInUseException- if a resource collection bynamealready exists.- See Also:
-
createSafe
default String createSafe(String name, ResourceCollectionManifest manifest, List<Resource> resources) throws IllegalArgumentException, IOException Create a new resource collection with the provided manifests and resources.If a collection by
namealready exists, the suffix "_N", where N increases monotonically from 1, is appended tonameuntil a name that isn't already used is found.- Parameters:
name- the name of the collection to create.manifest- theResourceCollectionManifest.resources- the resources, if any, to include in the collection.- Returns:
- the actual name of the new collection that was created.
- Throws:
IllegalArgumentException- if any of the resources indicate they belong to a collection other thanname.IOException- if the collection files could not be created.
-
createSafe
default String createSafe(String name, ResourceCollectionManifest manifest, List<Resource> resources, String namePattern) throws IllegalArgumentException, IOException Create a new resource collection with the provided manifests and resources.If a collection by
namealready exists thenamePatternis applied to the name viaString.format(String, Object...), with a monotonically increasing integer value supplied, until a suitable name is found.- Parameters:
name- the name of the collection to create.manifest- theResourceCollectionManifest.resources- the resources, if any, to include in the collection.namePattern- the name pattern to apply ifnamealready exists.- Returns:
- the actual name of the new collection that was created.
- Throws:
IllegalArgumentException- if any of the resources indicate they belong to a collection other thanname.IOException- if the collection files could not be created.
-
createOrReplace
void createOrReplace(String name, ResourceCollectionManifest manifest, List<Resource> resources) throws IllegalArgumentException, IOException, ResourceCollectionImmutableException Create a new resource collection with the provided manifests and resources, or replace an existing collection bynameif it already exists.Replacing an existing collection is modeled as a
push(List)of create, modify, and deleteChangeOperations, as opposed to deleting the existing collection and creating a new one.- Parameters:
name- the name of the collection to create or replace.manifest- theResourceCollectionManifest.resources- the resources, if any, to include in the resource collection.- Throws:
IllegalArgumentException- if any of the resources indicate they belong to a collection other thanname.IOException- if the resource collection files could not be created.ResourceCollectionImmutableException- if the resource collection being replaced is immutable.
-
copy
default String copy(String name, String newName) throws IOException, ResourceCollectionNotFoundException, ResourceCollectionInvalidException, ResourceCollectionImmutableException Create a copy of the resource collection namedname, usingnewNameas the new collection name, if possible.If
newNamealready exists a suitable name will be chosen automatically viacreateSafe(String, ResourceCollectionManifest, List).- Parameters:
name- the name of the existing resource collection to copy.newName- the name for the new resource collection.- Returns:
- the actual name used for the new collection.
- Throws:
IOException- if the resource collection files could not be created.ResourceCollectionNotFoundException- if a collectionnamedoes not exist.ResourceCollectionInvalidException- if the collectionnameexists but its configuration is not valid.ResourceCollectionImmutableException- if the resource collection being copied is immutable.
-
delete
void delete(String name) throws IOException, ResourceCollectionNotFoundException, ResourceCollectionImmutableException Delete the resource collection namedname, if it exists.- Parameters:
name- the name of the resource collection to delete- Throws:
IOException- if the resource collection files could not be deleted.ResourceCollectionNotFoundException- if a collection namednamedoes not exist.ResourceCollectionImmutableException- if the resource collection being deleted is immutable.
-
find
Get a theRuntimeResourceCollectionfor the given name with all resources in all scopes, if it exists, if it exists, or else empty.The resource collection returned will not have been validated. See
RuntimeResourceCollection.validateOrThrow().- Parameters:
name- the name of the resource collection to find.- Returns:
- the
RuntimeResourceCollectionfor the given name with all resources in all scopes, orOptional.empty()if not found.
-
find
Returns aRuntimeResourceCollectionfor the given name loaded with all resources that meet the given application scope, if it exists, or else empty.The resource collection returned will not have been validated. See
RuntimeResourceCollection.validateOrThrow().- Parameters:
name- the name of the resource collection to find.applicationScope- theApplicationScoperesources must belong to.- Returns:
- a
RuntimeResourceCollectionfor the given name loaded with all resources that meet the given application scope, orOptional.empty()if not found.
-
find
Returns aRuntimeResourceCollectionfor the givennamecontaining only resources that pass the providedResourceFilter, if it exists, or else empty.The resource collection returned will not have been validated. See
RuntimeResourceCollection.validateOrThrow().- Parameters:
name- the name of the resource collection to find.resourceFilter- theResourceFilterthat all resources must pass- Returns:
- a
RuntimeResourceCollectionfor the givennamecontaining only resources that pass the providedResourceFilter, orOptional.empty()if not found.
-
getResource
Find a resource defined in a specific collection, ignoring inheritance. -
getDefiningCollectionNames
Return the set of resource collections which have a definition for the given resource path. -
export
void export(String name, OutputStream destination) throws IOException, ResourceCollectionNotFoundException, ResourceCollectionImmutableException Export a copy of resource collection by writing the contents to thedestinationOutputStream.The bytes written are composed of a zip formatted resource collection folder that could be uncompressed and placed directly in a resource collection root directory (e.g projects/) resulting in a functional resource collection.
- Parameters:
name- the name of the resource collection to export.destination- anOutputStreamto write the export to.- Throws:
IOExceptionResourceCollectionNotFoundExceptionResourceCollectionImmutableException- See Also:
-
getManifests
Map<String,ResourceCollectionManifest> getManifests()Get aMapofResourceCollectionManifests for all current resource collections.- Returns:
- a
MapofResourceCollectionManifests, keyed by collection name.
-
getNames
Get aListof all current resource collection names.- Returns:
- a
Listof all current resource collection names.
-
push
Push a list of changes, with no associated context object.Returns after disk is updated but before listeners are notified. Wait on the returned future to ensure all listeners have been notified.
- Returns:
- a
CompletableFuturethat completes when all listeners have been notified. - Throws:
PushException
-
push
Attempt to push a list ofChangeOperations.If any changes conflict with the current state a
PushExceptionwill be thrown. For example, a CREATE operation for a path that already exists, or a MODIFY or DELETE operation whose signature is not current.It is expected that consumers of this API will then pull and resolve any conflicts before attempting to push again.
Returns after disk is updated but before listeners are notified. Wait on the returned future to ensure all listeners have been notified.
- Parameters:
pushOperation- A push operation that contains a list ofChangeOperations to apply, with an optional context object.- Returns:
- a
CompletableFuturethat completes when all listeners have been notified. - Throws:
PushException- if any changes conflict with the current state.
-
pushPartial
Alternative version ofpush(List)that allows for some operations to succeed even if others fail. Instead of throwing aPushException, this method returns aPartialPushResultthat contains information about which changes succeeded and which failed, as well as the future that can be waited upon to ensure all listeners have been notified.Important note: It is the responsibility of the caller to ensure that the operations are independent of one another. In other words, no one operation should rely on the success or failure of another operation. This is important because the validity checking done by this manager does not check for dependencies between operations.
-
pull
Pull any changes for the givensnapshots.- Parameters:
snapshots- theSnapshots to pull changes for.- Returns:
ResourceCollectionDiffs for eachSnapshotcontaining any resource diffs.- Throws:
PullException
-
pull
List<ResourceCollectionDiff.AbsoluteDiff> pull(List<Snapshot> snapshots, ResourceFilter filter) throws PullException Pull any changes for the givensnapshots, but only changes for resources that match thefilter.- Parameters:
snapshots- theSnapshots to pull changes for.filter- theResourceFilter.- Returns:
ResourceCollectionDiff.AbsoluteDiffs for eachSnapshotcontaining any resource diffs.- Throws:
PullException
-
requestScan
CompletableFuture<Void> requestScan()Requests that a scan for changed resources on the filesystem be performed immediately. If this method is called while a scan is already in progress, a new scan will not be initiated and will complete when the current scan is done.- Returns:
- a
CompletableFuturethat completes when a new scan or currently running scan has completed.
-