Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String createFixedUnit() {
- log.debug("Create FIXED UNIT");
- ContextBean.getCurrent().setSelectedFixedUnitId(0);
- ContextBean.getCurrent().setSelectedRUID(0);
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- ViewObject voFixedUnitCategoryView = am.getVoFixedUnitCategoryView1();
- if (!voFixedUnitCategoryView.isExecuted())
- voFixedUnitCategoryView.executeQuery();
- if (voFixedUnitCategoryView.getRowCount() == 0) {
- log.debug("No fixed unit category found in VoFixedUnitCategoryView, Create aborted");
- return "";
- }
- int remoteUnitId = createRemoteUnit(am);
- createFixedUnit(am, voFixedUnitCategoryView, remoteUnitId);
- return editFixedUnit();
- }
- protected void createFixedUnit(AppModuleImpl am, ViewObject voFixedUnitCategoryView, int remoteUnitId) {
- ViewObject editFixedUnitVo = am.getEditFixedUnitView1();
- Row newFixedUnit = editFixedUnitVo.createRow();
- Row currentFixedUnitCategory = voFixedUnitCategoryView.getCurrentRow();
- if (null == currentFixedUnitCategory)
- currentFixedUnitCategory = voFixedUnitCategoryView.first();
- newFixedUnit.setAttribute("VoFixedUnitCategoryId",
- currentFixedUnitCategory.getAttribute("VoFixedUnitCategoryId"));
- newFixedUnit.setAttribute("RemoteUnitId", remoteUnitId);
- editFixedUnitVo.insertRow(newFixedUnit);
- Integer newFixedUnitId = (Integer)newFixedUnit.getAttribute("FixedUnitId");
- editFixedUnitVo.setCurrentRow(newFixedUnit);
- am.getTransaction().postChanges();
- ContextBean.getCurrent().setSelectedFixedUnitId(newFixedUnitId.intValue());
- log.debug("FixedUnitId? : " + newFixedUnit.getAttribute("FixedUnitId"));
- }
- public String editFixedUnit() {
- this.geocodeRes = null;
- int selectedFixedUnitId = ContextBean.getCurrent().getSelectedFixedUnitId();
- log.debug("Edit FixedUnit : " + selectedFixedUnitId);
- if (selectedFixedUnitId == 0) {
- BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_pls_sel_fu_first}"));
- return null;
- }
- // AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- // ViewObject vo = null;
- // Row currentFixedUnit = am.getEditFixedUnitView1().getCurrentRow();
- // setRemoteUnit(am, vo, currentFixedUnit);
- prepareThePage(selectedFixedUnitId);
- // isLinkedToAddress =
- // (null != currentFixedUnit.getAttribute("Wgs84Latitude") && null != currentFixedUnit.getAttribute("Wgs84Latitude"));
- // setJSON(new FixedUnitResult(currentFixedUnit), isLinkedToAddress);
- return "editFixedUnit";
- }
- 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);
- am.getTransaction().postChanges();
- log.debug("RemoteUnitId? : " + row.getAttribute("RemoteUnitId"));
- int remoteUnitId = (Integer)row.getAttribute("RemoteUnitId");
- ContextBean.getCurrent().setSelectedRUID(remoteUnitId);
- log.debug("REMOTE UNIT ID FROM createRemoteUnit(AppModuleImpl am) IS: " + remoteUnitId);
- vo.setCurrentRow(row);
- return remoteUnitId;
- }
- private void setRemoteUnit(AppModuleImpl am, ViewObject vo, Row fixedUnit) {
- // Integer remoteUnitId = (Integer)fixedUnit.getAttribute("RemoteUnitId");
- Integer remoteUnitId = ContextBean.getCurrent().getSelectedRUID();
- //Find remote unit
- if (null == remoteUnitId || remoteUnitId == 0) {
- remoteUnitId = createRemoteUnit(am);
- fixedUnit.setAttribute("RemoteUnitId", remoteUnitId);
- }
- vo = am.getRemoteUnitView1();
- vo.setWhereClause("RemoteUnit.REMOTE_UNIT_ID=" + remoteUnitId);
- vo.executeQuery();
- }
- protected void prepareThePage(int selectedFixedUnitId) {
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- ViewObject vo = am.getEditFixedUnitView1();
- vo.setWhereClause("FixedUnit.FIXED_UNIT_ID=" + selectedFixedUnitId);
- vo.executeQuery();
- Row fixedUnit = vo.first();
- isLinkedToAddress =
- (null != fixedUnit.getAttribute("Wgs84Latitude") && null != fixedUnit.getAttribute("Wgs84Latitude"));
- setJSON(new FixedUnitResult(fixedUnit), isLinkedToAddress);
- setRemoteUnit(am, vo, fixedUnit);
- log.debug("PREPARE THE PAGE " + fixedUnit);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement