Class CoreAttachImplementation
- java.lang.Object
-
- org.openbravo.client.application.attachment.AttachImplementation
-
- org.openbravo.client.application.attachment.CoreAttachImplementation
-
- All Implemented Interfaces:
ReprintableDocumentAttachHandler
@ApplicationScoped public class CoreAttachImplementation extends AttachImplementation implements ReprintableDocumentAttachHandler
Default implementation of Attachment Management. This method saves the attached files in the "attach.path" folder of Openbravo server. It is the method used when no other configuration is provided.
-
-
Constructor Summary
Constructors Constructor Description CoreAttachImplementation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteFile(Attachment attachment)
Method invoked when an attached file needs to be removed from the corresponding file management system.void
download(ReprintableDocument document, OutputStream outputStream)
Retrieves ReprintableDocument data which was saved as an attachmentFile
downloadFile(Attachment attachment)
Method invoked when an attached file needs to be downloaded from the corresponding file management system.static String
getAttachmentDirectory(String tableID, String recordID, String fileName)
Provides the directory in which the attachment is stored.static String
getAttachmentDirectoryForNewAttachments(String tableID, String recordID)
Provides the directory in which the attachment has to be stored.static String
getPath(String fileDirectory)
Provides the value to be saved in path field in c_file.boolean
isTempFile()
Method invoked to check if the downloaded file has to be deleted when the download is completed by the user.static String
splitPath(String origname)
Splits the path name component so that the resulting path name is 3 characters long sub directories.void
updateFile(Attachment attachment, String tabId, Map<String,Object> parameters)
Method invoked when an existing attachment metadata is updated.void
upload(ReprintableDocument document, InputStream inputStream)
Uploads the document the data of the ReprintableDocument as an attachmentvoid
uploadFile(Attachment attachment, String dataType, Map<String,Object> parameters, File file, String tabId)
Method in charge of File upload.
-
-
-
Method Detail
-
uploadFile
public void uploadFile(Attachment attachment, String dataType, Map<String,Object> parameters, File file, String tabId) throws OBException
Description copied from class:AttachImplementation
Method in charge of File upload. Invoked when a new file is attached to a record.- Specified by:
uploadFile
in classAttachImplementation
- Parameters:
attachment
- The attachment created in c_filedataType
- DataType of the attachmentparameters
- A map with the metadata and its values to be updated in the corresponding file management system and in the attachmentfile
- The file to be uploadedtabId
- The tabID where the file is attached- Throws:
OBException
- Thrown when any error occurs during the upload
-
downloadFile
public File downloadFile(Attachment attachment)
Description copied from class:AttachImplementation
Method invoked when an attached file needs to be downloaded from the corresponding file management system.- Specified by:
downloadFile
in classAttachImplementation
- Parameters:
attachment
- The attachment that will be downloaded- Returns:
- the attached file.
-
deleteFile
public void deleteFile(Attachment attachment)
Description copied from class:AttachImplementation
Method invoked when an attached file needs to be removed from the corresponding file management system.- Specified by:
deleteFile
in classAttachImplementation
- Parameters:
attachment
- The attachment to be removed
-
updateFile
public void updateFile(Attachment attachment, String tabId, Map<String,Object> parameters) throws OBException
Description copied from class:AttachImplementation
Method invoked when an existing attachment metadata is updated.- Specified by:
updateFile
in classAttachImplementation
- Parameters:
attachment
- The attachment to be modifiedtabId
- The tabID where the file was attachedparameters
- The metadata with the new values.- Throws:
OBException
- Thrown when any error occurs when updating the file
-
isTempFile
public boolean isTempFile()
Description copied from class:AttachImplementation
Method invoked to check if the downloaded file has to be deleted when the download is completed by the user. Some attachment methods might create temporary files in Openbravo server that should be removed when the download is completed.- Specified by:
isTempFile
in classAttachImplementation
- Returns:
- true if the downloaded File has to be deleted.
-
upload
public void upload(ReprintableDocument document, InputStream inputStream) throws IOException
Description copied from interface:ReprintableDocumentAttachHandler
Uploads the document the data of the ReprintableDocument as an attachment- Specified by:
upload
in interfaceReprintableDocumentAttachHandler
- Parameters:
document
- The ReprintableDocument whose data is uploadedinputStream
- The InputStream with the document data- Throws:
IOException
-
download
public void download(ReprintableDocument document, OutputStream outputStream) throws IOException
Description copied from interface:ReprintableDocumentAttachHandler
Retrieves ReprintableDocument data which was saved as an attachment- Specified by:
download
in interfaceReprintableDocumentAttachHandler
- Parameters:
document
- The ReprintableDocument whose data is retrievedoutputStream
- the OutputStream where the document data should be provided- Throws:
IOException
-
getAttachmentDirectoryForNewAttachments
public static String getAttachmentDirectoryForNewAttachments(String tableID, String recordID)
Provides the directory in which the attachment has to be stored. For example for tableId "259", recordId "0F3A10E019754BACA5844387FB37B0D5", the file directory returned is "259/0F3/A10/E01/975/4BA/CA5/844/387/FB3/7B0/D5". In case 'SaveAttachmentsOldWay' preference is enabled then the file directory returned is "259-0F3A10E019754BACA5844387FB37B0D5"- Parameters:
tableID
- UUID of the tablerecordID
- UUID of the record- Returns:
- file directory to save the attachment
-
getAttachmentDirectory
public static String getAttachmentDirectory(String tableID, String recordID, String fileName)
Provides the directory in which the attachment is stored. For example for tableId "259", recordId "0F3A10E019754BACA5844387FB37B0D5", and fileName "test.txt" the file directory returned is "259/0F3/A10/E01/975/4BA/CA5/844/387/FB3/7B0/D5". In case 'SaveAttachmentsOldWay' preference is enabled then the file directory returned is "259-0F3A10E019754BACA5844387FB37B0D5"- Parameters:
tableID
- UUID of the tablerecordID
- UUID of the recordfileName
- Name of the file- Returns:
- file directory in which the attachment is stored
-
getPath
public static String getPath(String fileDirectory)
Provides the value to be saved in path field in c_file. The path field is used to get the location of the attachment. For example 259/0F3/A10/E01/975/4BA/CA5/844/387/FB3/7B0/D5. This path is relative to the attachments folder- Parameters:
fileDirectory
- the directory that is retrieved from getFileDirectory()- Returns:
- value to be saved in path in c_file
-
-