Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String createVehicle() {
- log.debug("Create Vehicle");
- ContextBean.getCurrent().setSelectedVehicleId(0);
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- ViewObject catVo = am.getVoVehicleCategoryView1();
- if (!catVo.isExecuted())
- catVo.executeQuery();
- if (catVo.getRowCount() == 0) {
- log.debug("No vehicle category found in VoVehicleCategoryView, Create aborted");
- return "";
- }
- // int remoteUnitId = createRemoteUnit(am);
- // createVehicle(am, catVo, remoteUnitId);
- createVehicle(am, catVo);
- return editVehicle();
- }
- protected void createVehicle(AppModuleImpl am, ViewObject catVo) {
- ViewObject vehicleVo = am.getEditVehicleView1();
- Row vehicleRow = vehicleVo.createRow();
- Row currentCat = catVo.getCurrentRow();
- if (null == currentCat)
- currentCat = catVo.first();
- String defaultStorePlaceIdQuery =
- "SELECT DEFAULT_STORE_PLACE_ID FROM VEHICLE_OWNER WHERE VEHICLE_OWNER_ID=" + currentCat.getAttribute("VehicleOwnerId");
- ViewObject defaultStorePlaceIdView =
- am.createViewObjectFromQueryStmt("GetDefaultStorePlaceView", defaultStorePlaceIdQuery);
- defaultStorePlaceIdView.executeQuery();
- Row defaultStorePlaceRow = defaultStorePlaceIdView.first();
- if (null != defaultStorePlaceRow && "Y".equalsIgnoreCase((String)currentCat.getAttribute("IsObject"))) {
- if (null != defaultStorePlaceRow.getAttribute(0)) {
- vehicleRow.setAttribute("LastEquipmentStorePlaceId",
- ((BigDecimal)defaultStorePlaceRow.getAttribute(0)).intValue());
- }
- }
- defaultStorePlaceIdView.remove();
- vehicleRow.setAttribute("VehicleOwnerId", currentCat.getAttribute("VehicleOwnerId"));
- vehicleRow.setAttribute("VoVehicleCategoryId", currentCat.getAttribute("VoVehicleCategoryId"));
- vehicleRow.setAttribute("VehicleCategoryId", 0);
- vehicleRow.setAttribute("VehicleSpeedTypeId", 1);
- vehicleRow.setAttribute("Numberplate", "XXXXXXXX");
- vehicleRow.setAttribute("CompanyNr", "XXXXXXXX");
- // vehicleRow.setAttribute("RemoteUnitId", remoteUnitId);
- vehicleVo.insertRow(vehicleRow);
- vehicleVo.setCurrentRow(vehicleRow);
- Integer newVehicleId = (Integer)vehicleRow.getAttribute("VehicleId");
- am.getTransaction().postChanges();
- ContextBean.getCurrent().setSelectedVehicleId(newVehicleId.intValue());
- log.debug("VehicleId? : " + vehicleRow.getAttribute("VehicleId"));
- //refresh vehicle view so the new row is added to the list
- // am.getVehicleView1().clearCache();
- }
- protected int createRemoteUnit(AppModuleImpl am) {
- ViewObject vo = am.getRemoteUnitView1();
- Row row = vo.createRow();
- row.setNewRowState(Row.STATUS_INITIALIZED);
- row.setAttribute("AdminCenterId", UserBean.getCurrent().getAdminCenterId());
- vo.insertRow(row);
- // vo.setCurrentRow(row);
- am.getTransaction().postChanges();
- log.debug("RemoteUnitId? : " + row.getAttribute("RemoteUnitId"));
- int remoteUnitId = (Integer)row.getAttribute("RemoteUnitId");
- System.out.println("REMOTE UNIT ID FROM createRemoteUnit(AppModuleImpl am) IS: " + remoteUnitId);
- return remoteUnitId;
- }
- public String editVehicle() {
- int selectedVehicleId = getIdFromContextBean();
- log.debug("Edit Vehicle : " + selectedVehicleId);
- if (selectedVehicleId == 0) {
- BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_select_veh_first}"));
- return null;
- }
- prepareThePage(selectedVehicleId);
- return "editVehicle";
- }
- protected void prepareThePage(int selectedVehicleId) {
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- ViewObject vo = am.getEditVehicleView1();
- vo.setWhereClause("Vehicle.VEHICLE_ID = " + selectedVehicleId);
- vo.executeQuery();
- Row vehicle = vo.first();
- vo.setCurrentRow(vehicle);
- initializeInputComboBoxListOfValues(am, vehicle);
- setRemoteUnit(am, vo, vehicle);
- }
- protected void initializeInputComboBoxListOfValues(AppModuleImpl am, Row vehicle) {
- setDriverNameDisplayValue(am, vehicle, "PersonName", "PersonId");
- setDriverNameDisplayValue(am, vehicle, "PrivateUseDriver", "PrivateUseAllowedPersonId");
- }
- private void setRemoteUnit(AppModuleImpl am, ViewObject vo, Row vehicle) {
- Integer remoteUnitId = (Integer)vehicle.getAttribute("RemoteUnitId");
- //Find remote unit
- if (null == remoteUnitId) {
- remoteUnitId = createRemoteUnit(am);
- vehicle.setAttribute("RemoteUnitId", remoteUnitId);
- }
- vo = am.getRemoteUnitView1();
- vo.setWhereClause("RemoteUnit.REMOTE_UNIT_ID = " + remoteUnitId);
- vo.executeQuery();
- vo.setCurrentRow(vo.first());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement