Skip to main content

Improvements in Attachment model in Openbravo

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 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  for any doubts. 


Popular posts from this blog

My 10 years in Application Development

It's been around 10 years since I started programming. May be a bit more, if I have to include my first attempts at C programming in school. But it would be a grave insult to call remembering ten lines of code and just replicating it to put a star on the screen. I also did a course on Visual basic, but it was more gimmicks that Application development. But it was truly in the year 2007 when I started my Master in Computer Applications that I found a new flare for developing applications. 
I was very late to computers in general and even when I joined my Masters, computers were not really accessible to me. But when I joined my Masters where one is actually expected to hone the skills which they already have, but in case it was were I was learning the skills, initially it was very difficult. I was not sure what computers had for me nor I had a natural flair for programming. But the thing about computers that attracted me was the visual medium it gave. Initially it was just a door t…

Changing Timezone in Postgresql, Ubuntu

Timezone and locale are integral concepts that one should be aware of when implementing a System. For example. if you create a database in PostgreSql, it will use the default System settings for the database. Lets say you have a server in UK and your client is US. If the client tries to retrieve the current date or time, it is going to show the UK time and not the US one.
Today I encountered a different issue in our client place where the Ubuntu timezone and PostgreSql timezone were showing a incorrect values. Instead of Indian Standard Time (IST) it was showing Pacific Daylight Time(PDT). These are the steps that I followed to change the timezone to IST in PostgreSql and Ubuntu.
Changing timezone in Ubuntu:
sudo dpkg-reconfigure tzdataYou will be prompted to choose the continent and then the area. Provided screen shots where we configure the location.
Use TAB key to navigate to the OK button and then press Enter.

The changes will get reflected immediately. To check it you can open a n…

Dissecting Openbravo 3.0 UI Architecture

Having been worked on Openbravo 3.0 UI for more than a year now (right from RC1) , Openbravo has leaped ahead of most contemporary ERP's in terms of UX design and usability. And a part of the credit has to go to the community too as they were actively involved in finalizing the UX and also involved enthusiastically in tested out the RC versions and providing their feedback.

In this post, I have tried to draw limelight on the basic UI components that are being used in Openbravo and their corresponding smartclient components. This is just to provide a very high level idea on how the entire architecture is coupled together. I have tried to use a single screen shot of Openbravo interface and tried to map the base components here.

The hierarchy can be visualized in simple terms as follows:

Exhaustive information on these components are provided in the Openbravo Wiki here.

Most of these components are defined and managed from individual files (or code) thereby making it really easy to …