Rahmadnet

add callout

Sep 2nd, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. // the package name corresponds to the module`s manual code folder
  2. // created above
  3. package org.rahmadnet.learning.AD_Callout;
  4.  
  5. import javax.servlet.ServletException;
  6.  
  7. import org.openbravo.utils.FormatUtilities;
  8. import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
  9. import org.openbravo.base.secureApp.VariablesSecureApp;
  10. // classes required to retrieve product category data from the
  11. // database using the DAL
  12. import org.openbravo.dal.service.OBDal;
  13. import org.openbravo.model.common.plm.ProductCategory;
  14.  
  15. // the name of the class corresponds to the filename that holds it
  16. // hence, modules/modules/org.rahmadnet.learning/src/org/rahmadnet/learning/ad_callouts/ProductConstructSearchKey.java.
  17. // The class must extend SimpleCallout
  18. public class ProductConstructSearchKey extends SimpleCallout {
  19.    
  20.     private static final long serialVersionUID = 1L;
  21.  
  22.     @Override
  23.     protected void execute(CalloutInfo info) throws ServletException {
  24.        
  25.         // parse input parameters here; the names derive from the column
  26.         // names of the teble prepended by inp and stripped of all
  27.         // underscore characters; letters following the underscore character
  28.         // are capitalized; this way the database column named
  29.         // M_PRODUCT_CATEGORY_ID that is shown on a tab will become
  30.         // inpmProductCategoryId html field
  31.         String strProductName = info.getStringParameter("inpname", null);
  32.         String strProductCategoryId = info.getStringParameter("inpmProductCategoryId", null);
  33.        
  34.         // inject the result into the response
  35.         info.addResult("inpvalue", getConstructedKey(info.vars, strProductName, strProductCategoryId));
  36.     }
  37.    
  38.     protected String getConstructedKey(VariablesSecureApp vars, String strProductName, String strProductCategoryId) {
  39.        
  40.         // Retrieve the product category name
  41.         final ProductCategory productCategory = OBDal.getInstance().get(ProductCategory.class, strProductCategoryId);
  42.         String strProductCategoryName = productCategory.getName();
  43.        
  44.         // construct full key
  45.         String generatedSearchKey = FormatUtilities.replaceJS(strProductName.replaceAll(" ", " "))
  46.                     + "_" + strProductCategoryName.replaceAll(" ", " ");
  47.        
  48.         // return generated key
  49.         return generatedSearchKey;
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment