Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.wirabumi.gen.oez.callout;
- import org.hibernate.criterion.Restrictions;
- import org.openbravo.dal.core.OBContext;
- import org.openbravo.dal.service.OBCriteria;
- import org.openbravo.dal.service.OBDal;
- import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
- import org.openbravo.erpCommon.utility.Utility;
- import org.openbravo.model.ad.system.ClientInformation;
- import org.openbravo.model.ad.utility.Tree;
- import org.openbravo.model.ad.utility.TreeNode;
- import org.openbravo.model.common.plm.ProductCategory;
- public class CallGenerateAutoSearchKey extends SimpleCallout {
- @Override
- protected void execute(CalloutInfo info) {
- try {
- //get parameter
- String searchKeyRule = Utility.getPreference(info.vars, "ProductSearchKeyClassName", null);
- boolean strValid = searchKeyRule != null && !searchKeyRule.isEmpty();
- if (!strValid) {
- return;
- }
- Class cls = Class.forName(searchKeyRule);
- Object clsInstance = (Object) cls.newInstance();
- GenerateProductSearchKey concrete = null;
- concrete = (GenerateProductSearchKey) clsInstance;
- String searchKey = concrete.getProductSearchKey(info);
- info.addResult("inpvalue", searchKey);
- // isi field parent product
- String mainProductCategoryID = getMainProductCategoryID(info);
- info.addResult("inpemOezParentgroupId", mainProductCategoryID);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private String getMainProductCategoryID (CalloutInfo info) {
- //get key from sub category
- String strProductCategoryId = info.getStringParameter("inpmProductCategoryId", null);
- //get tree
- ClientInformation clientInfo = OBContext.getOBContext().getCurrentClient().getClientInformationList().get(0);
- Tree adTree = clientInfo.getPrimaryTreeProductCategory();
- //get product category ID
- ProductCategory pcSubId = OBDal.getInstance().get(ProductCategory.class, strProductCategoryId);
- String subKey = pcSubId.getSearchKey();
- //get key from main category
- OBCriteria<TreeNode> treeNodeCriteria = OBDal.getInstance().createCriteria(TreeNode.class);
- treeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_TREE, adTree));
- treeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_NODE, strProductCategoryId));
- TreeNode treeNode = treeNodeCriteria.list().get(0);
- String pcMainId = treeNode.getReportSet();
- if (pcMainId.equalsIgnoreCase("0")) {
- pcMainId = subKey;
- }
- ProductCategory pcMain = OBDal.getInstance().get(ProductCategory.class, pcMainId);
- String mainKey = pcMain.getId();
- return mainKey;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement