Package com.storedobject.core
Interface ContentProducer
- All Superinterfaces:
ContentType,Executable,RequiresTransactionManager,Runnable
- All Known Implementing Classes:
AbstractODTReport,AbstractSpreadSheet,AccountStatement,CombinedPDFReport,Content,CSVReport,DataDownload,Excel,ExcelReport,FileCirculationStatus,FileContent,FileExpiryReport,ImageProducer,ItemMovementReport,IteratorODTReport,JournalReport,ObjectGridReport,ObjectList,ObjectListExcel,ODS,ODSReport,ODT,ODTObjectReport,ODTReport,PDF,PDFContent,PDFObjectReport,PDFReport,StockAvailability,StockMovementReport,StockReport,StockReportExcel,StreamContentProducer,StreamDataContent,SVGContentGenerator,TextContentProducer,TextReport,TrialBalance
The ContentProducer interface defines a contract for producing and managing content.
It supports functionality for generating content, handling file-related metadata,
managing transactions, and providing stream-based access to the content.
ContentProducer implementations may handle content generation processes,
error handling, and saving content to file storage.
- Author:
- Syam
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidThis method may be called when the content generation is aborted due to some error.default voidexecute()Executes the operation associated with the content producer.default InputStreamExtracts and retrieves the content as an InputStream.Retrieves the content as an InputStream.default EntityRetrieves theEntityassociated with the current context.default ThrowablegetError()Get the current error (set viaabort(Throwable)).Retrieves the file extension associated with the content.Retrieves the name of the file associated with the content.default StreamDataCreates and returns a new instance ofStreamData, populating it with the content type and stream data provider associated with this instance.default StreamDataProviderRetrieves a default implementation of theStreamDataProvider.default SystemEntityRetrieves the system entity associated with the current transaction manager.default TransactionManagerRetrieves the transaction manager associated with this object.voidproduce()Certain types of content may have to be produced.default voidready()Signals that the content is ready to consume.default FileDatasaveTo(FileData fileData, Transaction transaction) Saves the givenFileDatainstance using the content produced by this instance and associates it with the specifiedTransaction.default FileDatasaveTo(FileData fileData, TransactionManager tm) Saves the givenFileDatainstance using the content produced by this instance and associates it with the specifiedTransactionManager.default FileDatasaveTo(String folderPath, Transaction transaction) Saves the content produced by this instance to the specified folder path and associates it with the provided transaction.default FileDatasaveTo(String folderPath, TransactionManager tm) Saves the current content to a specified folder path using the providedTransactionManager.Methods inherited from interface com.storedobject.core.ContentType
getContentType, getLink, getMimeType, isAudio, isHTML, isImage, isLink, isMedia, isPDF, isText, isVideoMethods inherited from interface com.storedobject.common.Executable
act, runMethods inherited from interface com.storedobject.core.RequiresTransactionManager
setTransactionManager
-
Method Details
-
produce
void produce()Certain types of content may have to be produced. This method is used to do that. -
getContent
Retrieves the content as an InputStream.Note: This may not invoke
produce()and it may just return the content if it is already available. It is implementation-dependent.- Returns:
- an InputStream representing the content. This may be null if the content is not yet available.
- Throws:
Exception- if there is an error during content retrieval
-
getFileExtension
String getFileExtension()Retrieves the file extension associated with the content.- Returns:
- a String representing the file extension, or an empty string if no extension is available.
-
getFileName
String getFileName()Retrieves the name of the file associated with the content.- Returns:
- a String representing the name of the file, or null if the file name is unavailable.
-
ready
default void ready()Signals that the content is ready to consume. The exact behavior or implications of this readiness state are dependent on the implementation. -
getTransactionManager
Description copied from interface:RequiresTransactionManagerRetrieves the transaction manager associated with this object.- Specified by:
getTransactionManagerin interfaceRequiresTransactionManager- Returns:
- the transaction manager responsible for managing transaction boundaries
-
getSystemEntity
Retrieves the system entity associated with the current transaction manager. This method checks if aTransactionManagerinstance is available and, if so, retrieves the associatedSystemEntity. If no transaction manager is available, it returns null.- Returns:
- the
SystemEntityassociated with the current transaction manager, or null if the transaction manager is not available.
-
getEntity
Retrieves theEntityassociated with the current context. This method internally checks for aSystemEntityusinggetSystemEntity(), and if it exists, retrieves the correspondingEntity.- Returns:
- an
Entityobject if aSystemEntityis available and associated with anEntity, or null if no such association exists.
-
extractContent
Extracts and retrieves the content as an InputStream. If the content is not immediately available, this method triggers the production of the content in a separate virtual thread and waits for the content to become available.- Returns:
- an InputStream representing the extracted content, or null if the content cannot be produced or retrieved.
- Throws:
Exception- if there is an error during content production or retrieval.
-
getStreamDataProvider
Retrieves a default implementation of theStreamDataProvider. The returnedStreamDataProvidersuitable for saving content to the database viaStreamData.- Returns:
- An instance of
StreamDataProvidertailored to provide data of this producer for saving to the database.
-
getStreamData
Creates and returns a new instance ofStreamData, populating it with the content type and stream data provider associated with this instance.- Returns:
- an instance of
StreamDatacontaining the content type and stream data provider of this producer.
-
execute
default void execute()Executes the operation associated with the content producer. This method serves as the entry point for triggering the production of content. The implementation calls theproduce()method to perform the content production.- Specified by:
executein interfaceExecutable
-
saveTo
Saves the content produced by this instance to the specified folder path and associates it with the provided transaction. The content is retrieved using theStreamDatagenerated by this instance.- Parameters:
folderPath- The folder path where the content should be saved. This must be a valid directory path of the SO platform database.transaction- The transaction to associate with the saved content.- Returns:
- A
FileDataobject representing the saved file, including metadata and a reference to the stored content. - Throws:
Exception- If an error occurs during the save operation, such as invalid parameters, failure during content production, or failure to save the data to the provided path.
-
saveTo
Saves the givenFileDatainstance using the content produced by this instance and associates it with the specifiedTransaction. The process involves generating aStreamDataobject, saving it, assigning it to the providedFileDatainstance, and then saving theFileDataitself.- Parameters:
fileData- TheFileDataobject to save. This object will be populated with the produced content and metadata during the operation.transaction- TheTransactionto associate with the save operation.- Returns:
- The updated
FileDataobject containing the saved content and metadata. - Throws:
Exception- If an error occurs during the save operation, such as failure to generate or save theStreamData, or issues related to theTransaction.
-
saveTo
Saves the current content to a specified folder path using the providedTransactionManager. This method handles the transaction lifecycle, including committing or rolling back in case of exceptions. The content is saved by creating aStreamDataobject retrieved from this producer, associating it with the transaction, and then saving it to the given folder path in the SO platform database.- Parameters:
folderPath- The folder path where the content should be saved. It must be a valid directory path.tm- TheTransactionManagerused to manage the transaction during the save operation.- Returns:
- A
FileDataobject representing the saved file, including metadata and a reference to the stored content. - Throws:
Exception- If an error occurs during the save operation, including invalid parameters, transaction creation failure, failure in content production, or writing issues.
-
saveTo
Saves the givenFileDatainstance using the content produced by this instance and associates it with the specifiedTransactionManager. This method manages the transaction lifecycle and delegates the actual save operation to the underlying transaction.- Parameters:
fileData- TheFileDataobject to save. This object will be populated with the produced content and metadata during the operation.tm- TheTransactionManagerused to manage the transaction during the save operation. Ensures proper transaction handling, including rollback in case of failure.- Returns:
- The updated
FileDataobject containing the saved content and metadata. - Throws:
Exception- If an error occurs during the save operation, including errors in transaction handling, content generation, or saving process.
-
abort
This method may be called when the content generation is aborted due to some error.Note: This could be invoked multiple times.
- Parameters:
error- Error.
-
getError
Get the current error (set viaabort(Throwable)).- Returns:
- Current error, if any.
-