public class ExportMigrationEntryImpl extends MigrationEntryImpl implements ExportMigrationEntry
ExportMigrationEntry.| Modifier and Type | Field and Description |
|---|---|
protected Boolean |
stored
Will track if store was attempted along with its result.
|
METADATA_CHECKSUM, METADATA_FILES, METADATA_FILTERED, METADATA_FOLDER, METADATA_LAST_MODIFIED, METADATA_NAME, METADATA_PROPERTY, METADATA_REFERENCE, METADATA_SOFTLINK| Modifier | Constructor and Description |
|---|---|
protected |
ExportMigrationEntryImpl(ExportMigrationContextImpl context,
Path path)
Instantiates a new migration entry given a migratable context and path.
|
protected |
ExportMigrationEntryImpl(ExportMigrationContextImpl context,
String pathname)
Instantiates a new migration entry given a migratable context and path.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o)
The superclass implementation is sufficient for our needs.
|
protected Path |
getAbsolutePath() |
protected ExportMigrationContextImpl |
getContext() |
protected File |
getFile() |
long |
getLastModifiedTime()
Gets the last modification time of the entry.
|
String |
getName()
Gets name for this entry.
|
OutputStream |
getOutputStream()
Gets an output stream for this entry which provides a low-level way for the migratable to store
its own content in the export.
|
Path |
getPath()
Gets a
Path for this entry. |
Optional<ExportMigrationEntry> |
getPropertyReferencedEntry(String name)
Creates or retrieves (if already created) a migration entry referenced from the specified
property in the properties file associated with this migration entry to be exported by the
corresponding migratable.
|
Optional<ExportMigrationEntry> |
getPropertyReferencedEntry(String pname,
BiPredicate<MigrationReport,String> validator)
Creates or retrieves (if already created) a migration entry referenced from the specified
property in the properties file associated with this migration entry to be exported by the
corresponding migratable.
|
ExportMigrationReportImpl |
getReport()
Gets the migration report associated with this entry.
|
int |
hashCode()
The superclass implementation is sufficient for our needs.
|
boolean |
isDirectory()
Tests whether this entry represents a directory.
|
boolean |
isFile()
Tests whether this entry represents a file.
|
protected MigrationException |
newError(String reason,
Object cause) |
protected MigrationWarning |
newWarning(String reason) |
protected void |
recordEntry()
Called to record that this entry is being processed.
|
boolean |
store(BiThrowingConsumer<MigrationReport,OutputStream,IOException> consumer)
Stores this entry's content in the export using the specified consumer based on this entry's
path which can include sub-directories.
|
boolean |
store(boolean required)
Stores this entry's content in the export based on this entry's path which can include
sub-directories.
|
boolean |
store(boolean required,
PathMatcher filter)
Stores all files that recursively match the provided path filter in the export based on this
entry's path which can include sub-directories.
|
protected String |
toDebugString()
Gets a debug string to represent this entry.
|
compareTo, getId, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitstore, storegetIdcompareToprotected Boolean stored
null until
store() is attempted, at which point it will start tracking the first store() result.protected ExportMigrationEntryImpl(ExportMigrationContextImpl context, Path path)
Note: In this version of the constructor, the path is either absolute or assumed to be relative to ${ddf.home}. It will also be automatically relativized to ${ddf.home}.
context - the migration context associated with this entrypath - the path for this entryIllegalArgumentException - if context or path is null
protected ExportMigrationEntryImpl(ExportMigrationContextImpl context, String pathname)
Note: In this version of the constructor, the path is either absolute or assumed to be relative to ${ddf.home}. It will also be automatically relativized to ${ddf.home}.
context - the migration context associated with this entrypathname - the path string for this entryIllegalArgumentException - if context or pathname is null
public ExportMigrationReportImpl getReport()
MigrationEntrygetReport in interface MigrationEntrygetReport in class MigrationEntryImplpublic String getName()
MigrationEntrygetName in interface MigrationEntrypublic Path getPath()
MigrationEntryPath for this entry.
Note: Absolute paths that are under ${ddf.home} are automatically relativized.
getPath in interface MigrationEntrypublic boolean isDirectory()
MigrationEntryisDirectory in interface MigrationEntrytrue if and only if the entry represents a directory; false
otherwisepublic boolean isFile()
MigrationEntryisFile in interface MigrationEntrytrue if and only if the entry represents a file; false
otherwisepublic long getLastModifiedTime()
MigrationEntrygetLastModifiedTime in interface MigrationEntrypublic OutputStream getOutputStream() throws IOException
ExportMigrationEntryNote: The output stream will automatically be closed (if not closed already) wwhen
the output stream for another entry is retrieved, when calling ExportMigrationEntry.store() on another entry,
or when the export operation completes regardless of outcome for the associated migratable.
Note: Storing an entry via the output stream returned by this method will automatically mark the entry as a file even though on disk it might have represented a directory.
getOutputStream in interface ExportMigrationEntryIOException - if an I/O error has occurredpublic boolean store(boolean required)
ExportMigrationEntryAll errors and warnings are automatically recorded with the associated migration report.
Errors can be reported in two ways:
MigrationException
(e.g. failure to write to the exported file)
false
is returned from this method. This allows for the accumulation of as many issues
as possible to report to the user before aborting the operation.
Note: Calling store() twice will not store the entry twice. The second
time it is called, the same result will be returned as the first time no matter which
store() method was called.
store in interface ExportMigrationEntryrequired - true if the file or directory is required to exist on disk and if
it doesn't an error should be recorded; false if the file or directory is
optional and may not be present in which case calling this method will do nothingtrue if no errors were recorded as a result of processing this command;
false otherwisepublic boolean store(boolean required,
PathMatcher filter)
ExportMigrationEntryrequired parameter is interpreted for recording errors
and deciding what to return.
All errors and warnings are automatically recorded with the associated migration report.
Errors can be reported in two ways:
MigrationException
(e.g. failure to write to the exported file)
false
is returned from this method. This allows for the accumulation of as many issues
as possible to report to the user before aborting the operation.
Note: Calling store() twice will not store the entry twice. The second
time it is called, the same result will be returned as the first time no matter which
store() method was called.
store in interface ExportMigrationEntryrequired - true if the file or directory is required to exist on disk and if
it doesn't an error should be recorded; false if the file or directory is
optional and may not be present in which case calling this method will do nothingfilter - the path filter to usetrue if no errors were recorded as a result of processing this command;
false otherwisepublic boolean store(BiThrowingConsumer<MigrationReport,OutputStream,IOException> consumer)
ExportMigrationEntryAll errors and warnings are automatically recorded with the associated migration report including those thrown by the consumer's logic.
Errors can be reported in two ways:
MigrationException
(e.g. failure to write to the exported file)
false
is returned from this method. This allows for the accumulation of as many issues
as possible to report to the user before aborting the operation.
Note: The output stream will automatically be closed (if not closed already) when the
output stream for another entry is retrieved, when calling ExportMigrationEntry.store() on another entry, or
when the export operation completes regardless of outcome for the associated migratable.
Note: Calling store() twice will not store the entry twice. The second
time it is called, the same result will be returned as the first time no matter which
store() method was called.
Note: Storing an entry in this fashion will automatically mark the entry as a file even though on disk it might have represented a directory.
store in interface ExportMigrationEntryconsumer - a consumer capable of exporting the content of this entry to a provided output
streamtrue if no errors were recorded as a result of processing this command;
false otherwisepublic Optional<ExportMigrationEntry> getPropertyReferencedEntry(String name)
ExportMigrationEntryAn error will be automatically recorded with the associated migration report if the property is not defined in the property file referenced by this entry or its value is blank.
Note: The file referenced from the property is assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
The entry returned would be an entry representing the file that is referenced by the specified property value in the java properties file represented by this entry on the local system. For example:
If the properties file (e.g. etc/ws-security/server/encryption.properties) represented by this entry defines the following mapping: org.apache.ws.security.crypto.merlin.x509crl.file=etc/certs/demoCA/crl/crl.pem
then the following code:
final ExportMigrationEntry entry
= context.getEntry("etc/ws-security/server/encryption.properties");
final Optional<ExportMigrationEntry> entry2
= entry.getPropertyReferenceEntry("org.apache.ws.security.crypto.merlin.x509crl.file");
would return an entry representing the local file etc/certs/demoCA/crl/crl.pem
giving the migratable a chance to export it alongside the original property value so it can be
later restored and the property value can be verified after the import operation such that it
would still be defined with the same value in the local
etc/ws-security/server/encryption.properties file.
getPropertyReferencedEntry in interface ExportMigrationEntryname - the name of the property in the corresponding java properties file referencing a
migration entry to create or retrievepublic Optional<ExportMigrationEntry> getPropertyReferencedEntry(String pname, BiPredicate<MigrationReport,String> validator)
ExportMigrationEntryThe provided predicate is always invoked (as long as the entry was not previously created)
to validate the property value which may be null if not defined. Returning
false will abort the process and yield an Optional.empty() being returned out of
this method. In such case, it is up to the validator to record any required errors or warnings.
Returning true from the predicate will allow for a new entry to be created for the
corresponding system property unless the property is not defined or its value is blank in which
case an error will be recorded and an Optional.empty() is returned from this method. In
other words:
false, no migration entry is created and no error
is recorded.
true and ...
Note: The file referenced from the property is assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
The entry returned would be an entry representing the file that is referenced by the specified property value in the java properties file represented by this entry on the local system. For example:
If the properties file (e.g. etc/ws-security/server/encryption.properties) represented by this entry defines the following mapping: org.apache.ws.security.crypto.merlin.x509crl.file=etc/certs/demoCA/crl/crl.pem
then the following code:
final ExportMigrationEntry entry
= context.getEntry("etc/ws-security/server/encryption.properties");
final Optional<ExportMigrationEntry> entry2
= entry.getPropertyReferenceEntry("org.apache.ws.security.crypto.merlin.x509crl.file");
would return an entry representing the local file etc/certs/demoCA/crl/crl.pem
allowing the migratable a chance to export it alongside the original property value so it can
be later restored and the property value can be verified after the import operation such that
it would still be defined with the same value in the local
etc/ws-security/server/encryption.properties file.
getPropertyReferencedEntry in interface ExportMigrationEntrypname - the name of the property in the corresponding java properties file referencing a
migration entry to create or retrievevalidator - a predicate to be invoked to validate the property value further which must
return true to have a migration entry createdprotected ExportMigrationContextImpl getContext()
getContext in class MigrationEntryImplprotected Path getAbsolutePath()
protected File getFile()
protected void recordEntry()
protected String toDebugString()
protected MigrationWarning newWarning(String reason)
protected MigrationException newError(String reason, Object cause)
public boolean equals(Object o)
equals in class MigrationEntryImplo - the object to checkpublic int hashCode()
hashCode in class MigrationEntryImplThis work is licensed under a Creative Commons Attribution 4.0 International License.