Advertisement
psi_mmobile

Untitled

May 27th, 2020
1,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.22 KB | None | 0 0
  1.     public String createVehicle() {
  2.         log.debug("Create Vehicle");
  3.         ContextBean.getCurrent().setSelectedVehicleId(0);
  4.         AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  5.  
  6.         ViewObject catVo = am.getVoVehicleCategoryView1();
  7.         if (!catVo.isExecuted())
  8.             catVo.executeQuery();
  9.         if (catVo.getRowCount() == 0) {
  10.             log.debug("No vehicle category found in VoVehicleCategoryView, Create aborted");
  11.             return "";
  12.         }
  13.  
  14.         //        int remoteUnitId = createRemoteUnit(am);
  15.         //        createVehicle(am, catVo, remoteUnitId);
  16.         createVehicle(am, catVo);
  17.         return editVehicle();
  18.     }
  19.  
  20.     protected void createVehicle(AppModuleImpl am, ViewObject catVo) {
  21.         ViewObject vehicleVo = am.getEditVehicleView1();
  22.         Row vehicleRow = vehicleVo.createRow();
  23.  
  24.         Row currentCat = catVo.getCurrentRow();
  25.         if (null == currentCat)
  26.             currentCat = catVo.first();
  27.  
  28.         String defaultStorePlaceIdQuery =
  29.             "SELECT DEFAULT_STORE_PLACE_ID FROM VEHICLE_OWNER WHERE VEHICLE_OWNER_ID=" + currentCat.getAttribute("VehicleOwnerId");
  30.         ViewObject defaultStorePlaceIdView =
  31.             am.createViewObjectFromQueryStmt("GetDefaultStorePlaceView", defaultStorePlaceIdQuery);
  32.         defaultStorePlaceIdView.executeQuery();
  33.         Row defaultStorePlaceRow = defaultStorePlaceIdView.first();
  34.         if (null != defaultStorePlaceRow && "Y".equalsIgnoreCase((String)currentCat.getAttribute("IsObject"))) {
  35.             if (null != defaultStorePlaceRow.getAttribute(0)) {
  36.                 vehicleRow.setAttribute("LastEquipmentStorePlaceId",
  37.                                         ((BigDecimal)defaultStorePlaceRow.getAttribute(0)).intValue());
  38.             }
  39.         }
  40.         defaultStorePlaceIdView.remove();
  41.  
  42.         vehicleRow.setAttribute("VehicleOwnerId", currentCat.getAttribute("VehicleOwnerId"));
  43.         vehicleRow.setAttribute("VoVehicleCategoryId", currentCat.getAttribute("VoVehicleCategoryId"));
  44.         vehicleRow.setAttribute("VehicleCategoryId", 0);
  45.         vehicleRow.setAttribute("VehicleSpeedTypeId", 1);
  46.         vehicleRow.setAttribute("Numberplate", "XXXXXXXX");
  47.         vehicleRow.setAttribute("CompanyNr", "XXXXXXXX");
  48. //        vehicleRow.setAttribute("RemoteUnitId", remoteUnitId);
  49.         vehicleVo.insertRow(vehicleRow);
  50.        
  51.         vehicleVo.setCurrentRow(vehicleRow);
  52.         Integer newVehicleId = (Integer)vehicleRow.getAttribute("VehicleId");
  53.         am.getTransaction().postChanges();
  54.         ContextBean.getCurrent().setSelectedVehicleId(newVehicleId.intValue());
  55.         log.debug("VehicleId? : " + vehicleRow.getAttribute("VehicleId"));
  56.  
  57.         //refresh vehicle view so the new row is added to the list
  58.         // am.getVehicleView1().clearCache();
  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. //        vo.setCurrentRow(row);
  68.         am.getTransaction().postChanges();
  69.         log.debug("RemoteUnitId? : " + row.getAttribute("RemoteUnitId"));
  70.         int remoteUnitId = (Integer)row.getAttribute("RemoteUnitId");
  71.         System.out.println("REMOTE UNIT ID FROM createRemoteUnit(AppModuleImpl am) IS: " + remoteUnitId);
  72.         return remoteUnitId;
  73.     }
  74.  
  75.  
  76.     public String editVehicle() {
  77.         int selectedVehicleId = getIdFromContextBean();
  78.         log.debug("Edit Vehicle : " + selectedVehicleId);
  79.         if (selectedVehicleId == 0) {
  80.             BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_select_veh_first}"));
  81.  
  82.             return null;
  83.         }
  84.  
  85.         prepareThePage(selectedVehicleId);
  86.  
  87.         return "editVehicle";
  88.     }
  89.  
  90.     protected void prepareThePage(int selectedVehicleId) {
  91.         AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  92.         ViewObject vo = am.getEditVehicleView1();
  93.         vo.setWhereClause("Vehicle.VEHICLE_ID = " + selectedVehicleId);
  94.         vo.executeQuery();
  95.         Row vehicle = vo.first();
  96.         vo.setCurrentRow(vehicle);
  97.  
  98.         initializeInputComboBoxListOfValues(am, vehicle);
  99.  
  100.         setRemoteUnit(am, vo, vehicle);
  101.     }
  102.  
  103.     protected void initializeInputComboBoxListOfValues(AppModuleImpl am, Row vehicle) {
  104.         setDriverNameDisplayValue(am, vehicle, "PersonName", "PersonId");
  105.         setDriverNameDisplayValue(am, vehicle, "PrivateUseDriver", "PrivateUseAllowedPersonId");
  106.     }
  107.  
  108.     private void setRemoteUnit(AppModuleImpl am, ViewObject vo, Row vehicle) {
  109.         Integer remoteUnitId = (Integer)vehicle.getAttribute("RemoteUnitId");
  110.         //Find remote unit
  111.         if (null == remoteUnitId) {
  112.             remoteUnitId = createRemoteUnit(am);
  113.             vehicle.setAttribute("RemoteUnitId", remoteUnitId);
  114.         }
  115.  
  116.         vo = am.getRemoteUnitView1();
  117.         vo.setWhereClause("RemoteUnit.REMOTE_UNIT_ID = " + remoteUnitId);
  118.         vo.executeQuery();
  119.         vo.setCurrentRow(vo.first());
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement