Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
In this tutorial, we will follow the guideline for developing a plugin to develop our Amazon S3 Datalist Binder plugin. Please also refer to the very first tutorial วิธีการพัฒนา Bean Shell Hash Variable for more details steps.
We want to retrieve the files information in Amazon S3.
We can either develop a Datalist Binder Plugin or Userview Menu Plugin for this purpose. In this tutorial, we will develop a Datalist Binder Plugin to retrieve the files information and populate it using ตัวสร้างดาตาลิสต์ (Datalist Builder).
Note |
---|
Datalist Binder is not a suitable plugin type for this purpose as the Amazon S3 Client API does not able to get the total number of files and not able to support datalist action like sort, paging and filtering. We are writing this for learning purpose and not encourage for production usage as it will have performance issue. Better way to do this is to develop an Userview Menu which can display the file as a Tree Structure and load additional files when the tree expanded. |
To develop an Amazon S3 Datalist Binder plugin, we will need to provide the input as below:
...
We will do it a little bit different here as some of the inputs will be putting in a properties file and retrieve it from the properties file when needed. Please refer to how is done in File Upload Form Element Integrated with Amazon S3.
A datalist which will list the files in Amazon S3 bucket based on configuration.
We will use the AWS SDK for Java.
We need to always have our Joget Workflow Source Code ready and builded by following this guideline.
...
Open the maven project with your favourite IDE. I will be using NetBeans.
Create a "AmazonS3DatalistBinder" class under "org.joget" package. Then, extend the class with org.joget.apps.datalist.model.DataListBinderDefault abstract class. Please refer to Datalist Binder Plugin. We will need to implement org.joget.plugin.base.PluginWebSupport interface class as well to provide an Ajax validation in plugin properties page. Please refer to Web Service Plugin.
As usual, we have to implement all the abstract methods. We will using AppPluginUtil.getMessage method to support i18n and using constant variable MESSAGE_PATH for message resource bundle directory.
...
Code Block | ||
---|---|---|
| ||
public void webService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean isAdmin = WorkflowUtil.isCurrentUserInRole(WorkflowUserManager.ROLE_ADMIN); if (!isAdmin) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } String action = request.getParameter("action"); if ("validate".equals(action)) { String message = ""; boolean success = true; try { AmazonS3DatalistBinder.getClient(); } catch (Exception e) { LogUtil.error(this.getClassName(), e, ""); success = false; message = StringUtil.escapeString(e.getMessage(), StringUtil.TYPE_JAVASCIPT, null); } try { JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("status", (success?"success":"fail")); JSONArray messageArr = new JSONArray(); messageArr.put(message); jsonObject.put("message", messageArr); jsonObject.write(response.getWriter()); } catch (Exception e) { //ignore } } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } } |
We need to include "jsp-api" and "aws-java-sdk-s3" libraries in our POM file.
Code Block |
---|
<!-- Change plugin specific dependencies here --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-s3</artifactId> <version>1.10.56</version> </dependency> <!-- End change plugin specific dependencies here --> |
We are using i18n message key in getLabel and getDescription method. We will use i18n message key in our properties options definition as well. Then, we will need to create a message resource bundle properties file for our plugin.
...
Code Block |
---|
org.joget.AmazonS3DatalistBinder.pluginLabel=Amazon S3 Datalist Binder org.joget.AmazonS3DatalistBinder.pluginDesc=Used to retrieve the available files in Amazon S3. AmazonS3DatalistBinder.config=Configure Amazon S3 Datalist Binder AmazonS3DatalistBinder.configureationFileIsMissing=AWS S3 configuration file is missing. AmazonS3DatalistBinder.bucketFilToCreate=AWS Bucket fail to create. AmazonS3DatalistBinder.key=Key AmazonS3DatalistBinder.path=Path AmazonS3DatalistBinder.filename=File Name AmazonS3DatalistBinder.owner=Owner AmazonS3DatalistBinder.md5=MD5 Hash AmazonS3DatalistBinder.size=Size AmazonS3DatalistBinder.storageClass=Storage Class AmazonS3DatalistBinder.lastModified=Last Modified AmazonS3DatalistBinder.folder=Folder |
Next, we will have to register our plugin class in the Activator class (Auto generated in the same class package) to tell the Felix Framework that this is a plugin.
Code Block | ||
---|---|---|
| ||
public void start(BundleContext context) { registrationList = new ArrayList<ServiceRegistration>(); //Register plugin here registrationList.add(context.registerService(AmazonS3DatalistBinder.class.getName(), new AmazonS3DatalistBinder(), null)); } |
Let's build our plugin. Once the building process is done, we will find a "amazon_s3_datalist_binder-5.0.0.jar" file created under "amazon_s3_datalist_binder/target" directory.
...
Check the Amazon S3 Datalist Binder plugin is available in ตัวสร้างดาตาลิสต์ (Datalist Builder).
Select and configure the Amazon S3 Datalist Binder.
...
Design the datalist.
Check the result.
You can download the source code from amazon_s3_datalist_binder_src.zip.
...