Advertisement
tko_pb

CallGenerateAutoSearchKey 1 oktober

Sep 30th, 2018
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. package org.wirabumi.gen.oez.callout;
  2.  
  3. import org.hibernate.criterion.Restrictions;
  4. import org.openbravo.dal.core.OBContext;
  5. import org.openbravo.dal.service.OBCriteria;
  6. import org.openbravo.dal.service.OBDal;
  7. import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
  8. import org.openbravo.erpCommon.utility.Utility;
  9. import org.openbravo.model.ad.system.ClientInformation;
  10. import org.openbravo.model.ad.utility.Tree;
  11. import org.openbravo.model.ad.utility.TreeNode;
  12. import org.openbravo.model.common.plm.ProductCategory;
  13.  
  14. public class CallGenerateAutoSearchKey extends SimpleCallout {
  15.  
  16.     @Override
  17.     protected void execute(CalloutInfo info) {
  18.         try {
  19.             //get parameter
  20.             String searchKeyRule = Utility.getPreference(info.vars, "ProductSearchKeyClassName", null);    
  21.             boolean strValid = searchKeyRule != null && !searchKeyRule.isEmpty();
  22.  
  23.             if (!strValid) {
  24.                 return;
  25.             }
  26.             Class cls = Class.forName(searchKeyRule);
  27.             Object clsInstance = (Object) cls.newInstance();
  28.             GenerateProductSearchKey concrete = null;
  29.             concrete = (GenerateProductSearchKey) clsInstance;
  30.             String searchKey = concrete.getProductSearchKey(info);
  31.             info.addResult("inpvalue", searchKey);
  32.  
  33.             // isi field parent product
  34.             String mainProductCategoryID = getMainProductCategoryID(info);
  35.             info.addResult("inpemOezParentgroupId", mainProductCategoryID);
  36.  
  37.         } catch (ClassNotFoundException e) {
  38.             // TODO Auto-generated catch block
  39.             e.printStackTrace();
  40.         } catch (InstantiationException e) {
  41.             // TODO Auto-generated catch block
  42.             e.printStackTrace();
  43.         } catch (IllegalAccessException e) {
  44.             // TODO Auto-generated catch block
  45.             e.printStackTrace();
  46.         }
  47.  
  48.     }
  49.    
  50.     private String getMainProductCategoryID (CalloutInfo info) {
  51.         //get key from sub category
  52.         String strProductCategoryId = info.getStringParameter("inpmProductCategoryId", null);
  53.  
  54.         //get tree
  55.         ClientInformation clientInfo = OBContext.getOBContext().getCurrentClient().getClientInformationList().get(0);
  56.         Tree adTree = clientInfo.getPrimaryTreeProductCategory();
  57.  
  58.         //get product category ID
  59.         ProductCategory pcSubId = OBDal.getInstance().get(ProductCategory.class, strProductCategoryId);
  60.         String subKey = pcSubId.getSearchKey();
  61.  
  62.         //get key from main category
  63.         OBCriteria<TreeNode> treeNodeCriteria = OBDal.getInstance().createCriteria(TreeNode.class);
  64.         treeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_TREE, adTree));
  65.         treeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_NODE, strProductCategoryId));
  66.  
  67.         TreeNode treeNode = treeNodeCriteria.list().get(0);
  68.         String pcMainId = treeNode.getReportSet();
  69.         if (pcMainId.equalsIgnoreCase("0")) {
  70.             pcMainId = subKey;
  71.         }
  72.         ProductCategory pcMain = OBDal.getInstance().get(ProductCategory.class, pcMainId);
  73.         String mainKey = pcMain.getId();
  74.         return mainKey;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement