Advertisement
aadddrr

Untitled

Feb 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.15 KB | None | 0 0
  1. package org.jleaf.erp.fin.web.controller.pointernalsoigstagging;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Arrays;
  5.  
  6. import javax.annotation.PostConstruct;
  7. import javax.faces.event.AjaxBehaviorEvent;
  8.  
  9. import org.jleaf.baseweb.controller.LoginController;
  10. import org.jleaf.core.GeneralConstants;
  11. import org.jleaf.erp.fin.api.FinanceApiForIndocom;
  12. import org.jleaf.erp.fin.web.controller.model.PoInternalSoIgsTaggingLazyModel;
  13. import org.jleaf.util.DateUtil;
  14. import org.jleaf.web.helper.MessageHelper;
  15. import org.jleaf.web.jsf.FacesUtils;
  16. import org.jleaf.web.jsf.template.AbstractBrowseController;
  17. import org.jleaf.web.jsf.template.BasicController;
  18. import org.jleaf.web.jsf.util.JSONObjectUtil;
  19. import org.jleaf.web.model.ComboItem;
  20. import org.jleaf.web.model.Rules;
  21. import org.jleaf.web.util.Validator;
  22. import org.json.simple.JSONObject;
  23. import org.primefaces.context.RequestContext;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.context.ApplicationContext;
  28. import org.springframework.context.annotation.Scope;
  29. import org.springframework.stereotype.Controller;
  30.  
  31. /**
  32.  *
  33.  * @author Adrian
  34.  * Feb 23, 2017
  35.  */
  36.  
  37. @SuppressWarnings("serial")
  38. @Controller
  39. @Scope("view")
  40. public class PoInternalSoIgsTaggingController extends AbstractBrowseController implements FinanceApiForIndocom, Serializable {
  41.  
  42.     private static final Logger log = LoggerFactory.getLogger(PoInternalSoIgsTaggingController.class);
  43.    
  44.     private PoInternalSoIgsTaggingLazyModel model;
  45.    
  46.     @Autowired
  47.     ApplicationContext applicationContext;
  48.    
  49.     @SuppressWarnings("unchecked")
  50.     @PostConstruct
  51.     private void init() {
  52.        
  53.     }
  54.    
  55.     @SuppressWarnings({ "unchecked", "deprecation" })
  56.     public void doSearch() {   
  57.    
  58.         JSONObject inputJson = new JSONObject();
  59.        
  60.         inputJson.put("poInternalNo", this.filterBean.getData().get("poInternalNo"));
  61.         inputJson.put("poNo", this.filterBean.getData().get("poNo"));
  62.         inputJson.put("soNo", this.filterBean.getData().get("soNo"));
  63.        
  64.         log.debug("input Json: " + inputJson);
  65.        
  66.         try {
  67.             JSONObject output = serviceContext.executeService(
  68.                     COUNT_PO_INTERNAL_SO_IGS_TAGGING_LIST_ADVANCE, inputJson);
  69.             log.debug("output_service:" + output);
  70.             JSONObject result = JSONObjectUtil.getResult(output);
  71.             log.debug("output_result:" + result);
  72.             String status = JSONObjectUtil.getResultStatus(output);
  73.             if (status != null && status.equals(GeneralConstants.OK)) {
  74.                 log.debug("output_OK:");
  75.                 Long rowCount = Long.valueOf(result.get("count").toString());
  76.                 model = new PoInternalSoIgsTaggingLazyModel(serviceContext, inputJson);
  77.                 model.setRowCount(rowCount.intValue());            
  78.                 model.setPageSize(25);
  79.                 FacesUtils.addInfoMessage("Data Has Been Loaded");
  80.             } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  81.                 MessageHelper.displayError(result);
  82.             }
  83.         } catch (Exception ex) {
  84.             ex.printStackTrace();
  85.             FacesUtils.addErrorMessage(ex.getMessage());
  86.         }
  87.        
  88.     }
  89.    
  90.     @SuppressWarnings("unchecked")
  91.     public void initAdd() {
  92.         log.debug(">>>>>> INIT ADD");
  93.     }
  94.    
  95.     @SuppressWarnings("unchecked")
  96.     public void initEdit(JSONObject poInternalSoIgsTagging) {
  97.         setSelected((JSONObject) poInternalSoIgsTagging.clone());
  98.        
  99.         ComboItem poInternalOuCombo = new ComboItem("id", getSelected().get("poInternalOuId"));
  100.         ComboItem soOuCombo = new ComboItem("id", getSelected().get("soOuId"));
  101.         ComboItem poInternalCombo = new ComboItem("id", getSelected().get("poInternalId"));
  102.         poInternalCombo.put("docNo", getSelected().get("poInternalNo"));
  103.         ComboItem soCombo = new ComboItem("id", getSelected().get("soId"));
  104.         soCombo.put("docNo", getSelected().get("soNo"));
  105.        
  106.         getSelected().put("poInternalOu", poInternalOuCombo);
  107.         getSelected().put("soOu", soOuCombo);
  108.         getSelected().put("poInternal", poInternalCombo);
  109.         getSelected().put("so", soCombo);
  110.     }
  111.    
  112.     @SuppressWarnings("unchecked")
  113.     public void initRemove(JSONObject poInternalSoIgsTagging) {
  114.         setSelected((JSONObject) poInternalSoIgsTagging.clone());
  115.     }
  116.    
  117.     @SuppressWarnings("unchecked")
  118.     public void addItem(){
  119.        
  120.         log.debug(">>>>>>>>> ADD ITEM");
  121.        
  122.         /*if (null == getSelected().get("poInternalOu")) {
  123.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternalOU");
  124.             return;
  125.         }
  126.        
  127.         if (null == getSelected().get("soOu")) {
  128.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSoOU");
  129.             return;
  130.         }*/
  131.        
  132.         if (null == getSelected().get("poInternal")) {
  133.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternal");
  134.             return;
  135.         }
  136.        
  137.         if (null == getSelected().get("so")) {
  138.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSo");
  139.             return;
  140.         }
  141.        
  142.         /*JSONObject poInternalOu = (JSONObject) getSelected().get("poInternalOu");
  143.         Long poInternalOuId = Long.valueOf(poInternalOu.get("id").toString());
  144.         JSONObject soOu = (JSONObject) getSelected().get("soOu");
  145.         Long soOuId = Long.valueOf(soOu.get("id").toString());*/
  146.         JSONObject poInternal = (JSONObject) getSelected().get("poInternal");
  147.         Long poInternalOuId = Long.valueOf(poInternal.get("ouId").toString());
  148.         Long poInternalId = Long.valueOf(poInternal.get("id").toString());
  149.         JSONObject so = (JSONObject) getSelected().get("so");
  150.         Long soOuId = Long.valueOf(so.get("ouId").toString());
  151.         Long soId = Long.valueOf(so.get("id").toString());
  152.        
  153.         /*if (GeneralConstants.NULL_REF_VALUE_LONG.equals(poInternalId)) {
  154.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternal");
  155.             return;
  156.         }
  157.        
  158.         if (GeneralConstants.NULL_REF_VALUE_LONG.equals(soId)) {
  159.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSo");
  160.             return;
  161.         }*/
  162.        
  163.         JSONObject input = new JSONObject();
  164.         input.put("poInternalOuId", poInternalOuId);
  165.         input.put("poInternalId", poInternalId);
  166.         input.put("soOuId", soOuId);
  167.         input.put("soId", soId);
  168.        
  169.         log.debug(">>>>>>>>> INPUT DTO FOR ADD ITEM = "+input);
  170.        
  171.         try {
  172.             JSONObject output = serviceContext.executeService(
  173.                     ADD_PO_INTERNAL_SO_IGS_TAGGING, input);
  174.            
  175.             JSONObject result = JSONObjectUtil.getResult(output);
  176.             String status = JSONObjectUtil.getResultStatus(output);
  177.             log.debug("statusnya" + result);
  178.             if (status != null && status.equals(GeneralConstants.OK)) {
  179.                 MessageHelper.displayEditSuccess();
  180.                 RequestContext.getCurrentInstance().addCallbackParam("success", true);
  181.             } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  182.                 MessageHelper.displayError(result);
  183.                 RequestContext.getCurrentInstance().addCallbackParam("success", false);
  184.             }
  185.         } catch (Exception ex) {
  186.             ex.printStackTrace();
  187.             FacesUtils.addErrorMessage(ex.getMessage());
  188.         }
  189.     }
  190.    
  191.     @SuppressWarnings("unchecked")
  192.     public void editItem(){
  193.        
  194.         if (null == getSelected().get("poInternalOu")) {
  195.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternalOU");
  196.             return;
  197.         }
  198.        
  199.         if (null == getSelected().get("soOu")) {
  200.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSoOU");
  201.             return;
  202.         }
  203.        
  204.         if (null == getSelected().get("poInternal")) {
  205.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternal");
  206.             return;
  207.         }
  208.        
  209.         if (null == getSelected().get("so")) {
  210.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSo");
  211.             return;
  212.         }
  213.        
  214.         JSONObject poInternalOu = (JSONObject) getSelected().get("poInternalOu");
  215.         Long poInternalOuId = Long.valueOf(poInternalOu.get("id").toString());
  216.         JSONObject soOu = (JSONObject) getSelected().get("soOu");
  217.         Long soOuId = Long.valueOf(soOu.get("id").toString());
  218.         JSONObject poInternal = (JSONObject) getSelected().get("poInternal");
  219.         Long poInternalId = Long.valueOf(poInternal.get("id").toString());
  220.         JSONObject so = (JSONObject) getSelected().get("so");
  221.         Long soId = Long.valueOf(so.get("id").toString());
  222.        
  223.         if (GeneralConstants.NULL_REF_VALUE_LONG.equals(poInternalId)) {
  224.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectPoInternal");
  225.             return;
  226.         }
  227.        
  228.         if (GeneralConstants.NULL_REF_VALUE_LONG.equals(soId)) {
  229.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseSelectSo");
  230.             return;
  231.         }
  232.        
  233.         JSONObject input = new JSONObject();
  234.         input.put("id", getSelected().get("id"));
  235.         input.put("version", getSelected().get("version"));
  236.         input.put("poInternalOuId", poInternalOuId);
  237.         input.put("poInternalId", poInternalId);
  238.         input.put("soOuId", soOuId);
  239.         input.put("soId", soId);
  240.        
  241.         try {
  242.             JSONObject output = serviceContext.executeService(
  243.                     EDIT_PO_INTERNAL_SO_IGS_TAGGING, input);
  244.            
  245.             JSONObject result = JSONObjectUtil.getResult(output);
  246.             String status = JSONObjectUtil.getResultStatus(output);
  247.             log.debug("statusnya" + result);
  248.             if (status != null && status.equals(GeneralConstants.OK)) {
  249.                 MessageHelper.displayEditSuccess();
  250.                 RequestContext.getCurrentInstance().addCallbackParam("success", true);
  251.             } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  252.                 MessageHelper.displayError(result);
  253.                 RequestContext.getCurrentInstance().addCallbackParam("success", false);
  254.             }
  255.         } catch (Exception ex) {
  256.             ex.printStackTrace();
  257.             FacesUtils.addErrorMessage(ex.getMessage());
  258.         }
  259.     }
  260.    
  261.     @SuppressWarnings("unchecked")
  262.     public void removeItem(){
  263.        
  264.         JSONObject input = new JSONObject();
  265.         input.put("id", getSelected().get("id"));
  266.         input.put("version", getSelected().get("version"));
  267.        
  268.         try {
  269.             JSONObject output = serviceContext.executeService(
  270.                     REMOVE_PO_INTERNAL_SO_IGS_TAGGING, input);
  271.            
  272.             JSONObject result = JSONObjectUtil.getResult(output);
  273.             String status = JSONObjectUtil.getResultStatus(output);
  274.             log.debug("statusnya" + result);
  275.             if (status != null && status.equals(GeneralConstants.OK)) {
  276.                 MessageHelper.displayEditSuccess();
  277.                 RequestContext.getCurrentInstance().addCallbackParam("success", true);
  278.             } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  279.                 MessageHelper.displayError(result);
  280.                 RequestContext.getCurrentInstance().addCallbackParam("success", false);
  281.             }
  282.         } catch (Exception ex) {
  283.             ex.printStackTrace();
  284.             FacesUtils.addErrorMessage(ex.getMessage());
  285.         }
  286.     }
  287.    
  288.     @SuppressWarnings("unchecked")
  289.     public void onFilterChanged(AjaxBehaviorEvent event) {
  290.         log.debug(">>>>>>>>>>>> FILTER CHANGED ");
  291.        
  292.         /*JSONObject poInternalOu = (JSONObject) getSelected().get("poInternalOu");
  293.         Long poInternalOuId = Long.valueOf(poInternalOu.get("id").toString());
  294.         JSONObject soOu = (JSONObject) getSelected().get("soOu");
  295.         Long soOuId = Long.valueOf(soOu.get("id").toString());
  296.        
  297.         log.debug(">>>>>>>>>>>>>> poInternalOuId = " +poInternalOuId);
  298.         log.debug(">>>>>>>>>>>>>> soOuId = " +soOuId);*/
  299.     }  
  300.  
  301.     @Override
  302.     public String searchTaskName() {
  303.         // TODO Auto-generated method stub
  304.         return null;
  305.     }
  306.  
  307.     @Override
  308.     public JSONObject getJsonForSearch() {
  309.         // TODO Auto-generated method stub
  310.         return null;
  311.     }
  312.  
  313.     @Override
  314.     public void afterSearch(JSONObject result, boolean isOk) {
  315.         // TODO Auto-generated method stub
  316.        
  317.     }
  318.  
  319.     public PoInternalSoIgsTaggingLazyModel getModel() {
  320.         return model;
  321.     }
  322.  
  323.     public void setModel(PoInternalSoIgsTaggingLazyModel model) {
  324.         this.model = model;
  325.     }
  326.    
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement