Attachments are one of the breezy UI aspects of Openbravo, where you can attach any number of attachments to any record in the application. The beauty of the feature lies in the fact that you can restrict the access to the attachments for a specific users/roles. An use case is provided here. From 3.0MP26 there are some improvements in the way Attachments are implemented. 



Change in architecture

Before 3.0MP26, the attachments were stored in the attachments directory (the attach.path property in Openbravo.properties). They were stored in this folder structure
  • AttachDirectory
    • tableId-recordId
      • Attachment.
But in few file systems like ext3 where there is a limit of 32k subfolders, this would exceed the maximum number of folders allowed.
To overcome this, the attachment model has been updated to save the attachment from 3.0MP26. For eg, for table Id "259", recordId "0F3A10E019754BACA5844387FB37B0D5", the file directory returned is "259/0F3/A10/E01/975/4BA/CA5/844/387/FB3/7B0/D5". i.e,
--> AttachDirectory
---> 259
----> 0F3
-----> A10
------> E01
-------> 975
--------> 4BA
---------> CA5
----------> 844
-----------> 387
------------> FB3
-------------> 7B0
--------------> D5
---------------> Attachment

Note that the attachments can be still be stored using the previous model by enabling the preference 'SaveAttachmentsOldWay' to 'Y'. For more information on using preferences refer here.


API's for Attachments Management:


Before these improvements, attachments were fetched using the standard folder name of tableId-recordId. Now API's have been introduced to fetch the attachments and also to get the directory where attachment have to be stored in the improved model based on the preference 'Save Attachments Old Way'.



API for fetching existing attachments:

The attachment can be fetched through an API method in TabAttachments. The method TabAttachments.getAttachmentDirectory can be used to fetch a particular attachment. The arguments to be passed are:
  • UUID of the ad_table
  • UUID of the record
  • fileName
It returns the path of the attachment relative to the attachment directory. The attachment directory can be fetched from Openbravo properties in java code using OBPropertiesProvider. Here is a blog on how it can be used. For eg., to fetch an attachment test.txt of recordId 0F3A10E019754BACA5844387FB37B0D5, tableId 259, the method can be used as follows:
String attachmentDirectory = TabAttachments.getAttachmentDirectory("259","0F3A10E019754BACA5844387FB37B0D5","test.txt");

API to fetch directory to save new attachments

When saving new attachments, the method TabAttachments.getAttachmentDirectoryForNewAttachments can be used to fetch the directory in which the attachment has to be stored. The arguments to be passed are, tableId and recordId . The value returned is the directory to save the record.Note that the directory returned is relative from the attachment directory of Openbravo.
TabAttachments.getAttachmentDirectoryForNewAttachments ("259","0F3A10E019754BACA5844387FB37B0D5");


Migrating existing attachments to the improved model


Existing attachments can be migrated based on the latest model using an ant task. The task can be executed using the following command,

ant migrate.attachments 


the customer instance does not have any extension that is using API to retrieve attachments, no change for them is required, no need to migrate attachments. New attachments will be saved and retrieved using new approach, old - retrieved old approach.

If there is an extension that uses the old API then two options are possible
1. Switch on the mode to save attachments old way and that is it (short-term solution).
2. Change the extension to use new API and migrate attachments (recommended for the mid-term, long-term).  Contact us through our forum or through our social network channels https://twitter.com/Openbravohttps://www.facebook.com/OpenbravoSLU  for any doubts. 
0

Add a comment

Popular Posts
Popular Posts
Blog Archive
Labels
Total Pageviews
Total Pageviews
148867
Subscribe
Subscribe
Labels
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.