Advertisement
psi_mmobile

Untitled

Aug 12th, 2020
2,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.94 KB | None | 0 0
  1.     public String createFixedUnit() {
  2.         log.debug("Create FIXED UNIT");
  3.         ContextBean.getCurrent().setSelectedFixedUnitId(0);
  4.         ContextBean.getCurrent().setSelectedRUID(0);
  5.         AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  6.  
  7.         ViewObject voFixedUnitCategoryView = am.getVoFixedUnitCategoryView1();
  8.         if (!voFixedUnitCategoryView.isExecuted())
  9.             voFixedUnitCategoryView.executeQuery();
  10.         if (voFixedUnitCategoryView.getRowCount() == 0) {
  11.             log.debug("No fixed unit category found in VoFixedUnitCategoryView, Create aborted");
  12.             return "";
  13.         }
  14.         int remoteUnitId = createRemoteUnit(am);
  15.         createFixedUnit(am, voFixedUnitCategoryView, remoteUnitId);
  16.        
  17.         return editFixedUnit();
  18.     }
  19.  
  20.     protected void createFixedUnit(AppModuleImpl am, ViewObject voFixedUnitCategoryView, int remoteUnitId) {
  21.         ViewObject editFixedUnitVo = am.getEditFixedUnitView1();
  22.         Row newFixedUnit = editFixedUnitVo.createRow();
  23.         Row currentFixedUnitCategory = voFixedUnitCategoryView.getCurrentRow();
  24.         if (null == currentFixedUnitCategory)
  25.             currentFixedUnitCategory = voFixedUnitCategoryView.first();
  26.  
  27.         newFixedUnit.setAttribute("VoFixedUnitCategoryId",
  28.                                   currentFixedUnitCategory.getAttribute("VoFixedUnitCategoryId"));
  29.         newFixedUnit.setAttribute("RemoteUnitId", remoteUnitId);
  30.         editFixedUnitVo.insertRow(newFixedUnit);
  31.  
  32.         Integer newFixedUnitId = (Integer)newFixedUnit.getAttribute("FixedUnitId");
  33.         editFixedUnitVo.setCurrentRow(newFixedUnit);
  34.         am.getTransaction().postChanges();
  35.         ContextBean.getCurrent().setSelectedFixedUnitId(newFixedUnitId.intValue());
  36.        
  37.         log.debug("FixedUnitId? : " + newFixedUnit.getAttribute("FixedUnitId"));
  38.     }
  39.  
  40.     public String editFixedUnit() {
  41.         this.geocodeRes = null;
  42.         int selectedFixedUnitId = ContextBean.getCurrent().getSelectedFixedUnitId();
  43.         log.debug("Edit FixedUnit : " + selectedFixedUnitId);
  44.         if (selectedFixedUnitId == 0) {
  45.             BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_pls_sel_fu_first}"));
  46.  
  47.             return null;
  48.         }
  49.         //        AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  50.         //        ViewObject vo = null;
  51.         //        Row currentFixedUnit = am.getEditFixedUnitView1().getCurrentRow();
  52.         //        setRemoteUnit(am, vo, currentFixedUnit);
  53.         prepareThePage(selectedFixedUnitId);
  54.         //        isLinkedToAddress =
  55.         //                (null != currentFixedUnit.getAttribute("Wgs84Latitude") && null != currentFixedUnit.getAttribute("Wgs84Latitude"));
  56.         //        setJSON(new FixedUnitResult(currentFixedUnit), isLinkedToAddress);
  57.  
  58.         return "editFixedUnit";
  59.     }
  60.  
  61.     protected int createRemoteUnit(AppModuleImpl am) {
  62.         ViewObject vo = am.getRemoteUnitView1();
  63.         Row row = vo.createRow();
  64.         row.setNewRowState(Row.STATUS_INITIALIZED);
  65.         row.setAttribute("AdminCenterId", UserBean.getCurrent().getAdminCenterId());
  66.         vo.insertRow(row);
  67.         am.getTransaction().postChanges();
  68.         log.debug("RemoteUnitId? : " + row.getAttribute("RemoteUnitId"));
  69.         int remoteUnitId = (Integer)row.getAttribute("RemoteUnitId");
  70.         ContextBean.getCurrent().setSelectedRUID(remoteUnitId);
  71.         log.debug("REMOTE UNIT ID FROM createRemoteUnit(AppModuleImpl am) IS: " + remoteUnitId);
  72.         vo.setCurrentRow(row);
  73.         return remoteUnitId;
  74.     }
  75.  
  76.     private void setRemoteUnit(AppModuleImpl am, ViewObject vo, Row fixedUnit) {
  77.         //        Integer remoteUnitId = (Integer)fixedUnit.getAttribute("RemoteUnitId");
  78.         Integer remoteUnitId = ContextBean.getCurrent().getSelectedRUID();
  79.         //Find remote unit
  80.         if (null == remoteUnitId || remoteUnitId == 0) {
  81.             remoteUnitId = createRemoteUnit(am);
  82.             fixedUnit.setAttribute("RemoteUnitId", remoteUnitId);
  83.         }
  84.  
  85.         vo = am.getRemoteUnitView1();
  86.         vo.setWhereClause("RemoteUnit.REMOTE_UNIT_ID=" + remoteUnitId);
  87.         vo.executeQuery();
  88.     }
  89.  
  90.     protected void prepareThePage(int selectedFixedUnitId) {
  91.         AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  92.         ViewObject vo = am.getEditFixedUnitView1();
  93.         vo.setWhereClause("FixedUnit.FIXED_UNIT_ID=" + selectedFixedUnitId);
  94.         vo.executeQuery();
  95.         Row fixedUnit = vo.first();
  96.         isLinkedToAddress =
  97.                 (null != fixedUnit.getAttribute("Wgs84Latitude") && null != fixedUnit.getAttribute("Wgs84Latitude"));
  98.         setJSON(new FixedUnitResult(fixedUnit), isLinkedToAddress);
  99.  
  100.         setRemoteUnit(am, vo, fixedUnit);
  101.         log.debug("PREPARE THE PAGE " + fixedUnit);
  102.     }
  103.  
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement