Пример #1
0
 public boolean saveUser(BeanFieldGroup<User> fieldGroup, String clearPass)
     throws FieldGroup.CommitException, BLException {
   fieldGroup.commit();
   BeanItem<User> item = fieldGroup.getItemDataSource();
   try {
     return (boolean)
         DB.execWithTransaction(
             (db) -> {
               User u = item.getBean();
               db.save(u);
               if (clearPass != null && !clearPass.isEmpty()) {
                 UserManager mgr = new UserManager(db);
                 try {
                   mgr.setPassword(u, clearPass);
                 } catch (BLException e) {
                   return false;
                 }
                 addRevisionCreated(
                     db, getEntityName(), item.getItemProperty("id").getValue().toString());
                 u.setForcePasswordChange(true);
                 db.session().update(u);
                 return true;
               }
               return false;
             });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return false;
   }
 }
Пример #2
0
  void handleSaveButtonClicked() {
    getUi().getForm().commit();
    @SuppressWarnings("unchecked")
    BeanItem<Company> companyBeanItem = (BeanItem<Company>) getUi().getForm().getItemDataSource();
    Company company = companyBeanItem.getBean();

    /**
     * Avoid duplicate entry for the same email address. This has to be checked programatically as
     * GAE does not support unique constraints
     */
    if (company.getId() == null && isCompanyExisting(company.getCname())) {
      getUi().showError(Lang.getMessage("DuplicateEntryMsg", "cname"), null);
      return;
    }

    // Encrypt and set the password, only if a new one is given
    // TODO fix me
    if (company.getNewPassword() != null && company.getNewPassword().length() > 0) {
      String hashedPassword = PasswordUtil.generateHashedPassword(company.getNewPassword());
      company.setPassword(hashedPassword);
    }

    try {
      // Store the Company
      FacadeFactory.getFacade().store(company);

    } catch (Exception e) {
      getUi().showError(Lang.getMessage("ChangesSaveFailedMsg"), "Details: " + e.getMessage());
    }
    updateTable();
  }
  public void onSaveUser() {
    // get the user and add it to the container
    BeanItem<User> item = (BeanItem<User>) this.userForm.getItemDataSource();
    User u = item.getBean();
    this.container.addBean(u);

    // close dialog
    this.closeDialog();
  }
 private void loadItem(Object itemId, boolean selectFirstTab) throws EntityNotFoundException {
   try {
     getEntityForm().getFormFieldSet().restoreIsReadOnly();
     currentItemId = itemId;
     getResultsTable().clearSelection();
     getResultsTable().select(currentItemId);
     BeanItem beanItem = getResultsTable().getContainerDataSource().getItem(itemId);
     getEntityForm().load((T) beanItem.getBean(), selectFirstTab);
   } finally {
     // in case entity is not found and exception occurs, still need to apply view mode
     getEntityForm().syncCrudActions();
   }
 }
 @Override
 protected BeanItem createBeanItem(AbstractDTO dto) {
   SellerContactInfoDTO sellerContactInfoDTO = (SellerContactInfoDTO) dto;
   BeanItem<SellerContactInfoDTO> beanItem = new BeanItem<>(sellerContactInfoDTO);
   beanItem.addItemProperty(
       CONTACTINFO_FIELD, new ObjectProperty(sellerContactInfoDTO.getSellerId()));
   beanItem.addItemProperty(
       FIRST_NAME_FIELD, new ObjectProperty(sellerContactInfoDTO.getLastName()));
   beanItem.addItemProperty(
       LAST_NAME_FIELD, new ObjectProperty(sellerContactInfoDTO.getFirstName()));
   beanItem.addItemProperty(EMAIL_FIELD, new ObjectProperty(sellerContactInfoDTO.getEmail()));
   return beanItem;
 }
Пример #6
0
 @SuppressWarnings("unchecked")
 private Todo getFieldGroupTodo() {
   BeanItem<Todo> item = (BeanItem<Todo>) scheduleEventFieldGroup.getItemDataSource();
   Todo todo = item.getBean();
   // WW_TODO 保存是设置项目id和用户
   if (!StringTool.judgeBlank(todo.getProId())) {
     todo.setProId(projectId);
   }
   if (todo.getAssignedUser() == null) {
     todo.setAssignedUser(LoginHandler.getLoggedInUser().getId());
   }
   return todo;
 }
  private void deleteConfirmed() {
    Collection itemIds = (Collection) getResultsTable().getValue();
    for (Object itemId : itemIds) {
      BeanItem<T> beanItem = getResultsTable().getContainerDataSource().getItem(itemId);
      T entity = beanItem.getBean();
      preDelete(entity);
      if (getEntityDao() == null) {
        genericDao.remove(entity);
      } else {
        getEntityDao().remove(entity);
      }
    }

    showDeleteSuccessfulMessage();

    // solves tricky ConcurrentModification bug where ContextMenu handler calls delete
    // but then search removes handler
    searchImpl(false);
    clearSelection();
    syncCrudActions();
  }
Пример #8
0
 private void editSmsPurDetail() {
   logger.info(
       "Company ID : "
           + companyid
           + " | User Name : "
           + username
           + " > "
           + "Editing the selected record");
   hlUserInputLayout.setVisible(true);
   if (tblSmsEnqDtl.getValue() != null) {
     SmsPurEnqDtlDM purEnqDtlDM = beanPurEnqDtlDM.getItem(tblSmsEnqDtl.getValue()).getBean();
     lsProduct.setValue(null);
     Long prodid = purEnqDtlDM.getProductId();
     Collection<?> prodids = lsProduct.getItemIds();
     for (Iterator<?> iterator = prodids.iterator(); iterator.hasNext(); ) {
       Object itemId = (Object) iterator.next();
       BeanItem<?> item = (BeanItem<?>) lsProduct.getItem(itemId);
       // Get the actual bean and use the data
       ProductDM st = (ProductDM) item.getBean();
       if (prodid != null && prodid.equals(st.getProdid())) {
         lsProduct.select(itemId);
       }
     }
     if (cbUom.getValue() != null) {
       cbUom.setReadOnly(false);
       cbUom.setValue(purEnqDtlDM.getProductUom());
       cbUom.setReadOnly(true);
     }
     if (tfEnqQty.getValue() != null) {
       tfEnqQty.setValue(purEnqDtlDM.getEnquiryQty().toString());
     }
     if (purEnqDtlDM.getRemarks() != null) {
       taEnqDtlRem.setValue(purEnqDtlDM.getRemarks().toString());
     }
     if (purEnqDtlDM.getEnqDtlStaus() != null) {
       cbEnqDtlStatus.setValue(purEnqDtlDM.getEnqDtlStaus());
     }
   }
 }
Пример #9
0
 @Override
 public boolean removeEntity(BeanFieldGroup fieldGroup) {
   // Users have a deleted flag, they are not completely removed.
   BeanItem item = fieldGroup.getItemDataSource();
   User t = (User) item.getBean();
   try {
     return t != null
         && (boolean)
             DB.execWithTransaction(
                 (db) -> {
                   User user = db.session().get(User.class, t.getId());
                   if (user == null) return false;
                   t.setDeleted(true);
                   db.session().merge(t);
                   addRevisionRemoved(db, getEntityName(), String.valueOf(t.getId()));
                   return true;
                 });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return false;
   }
 }
  public void windowClose(CloseEvent e) {
    // Actualizo el listado de DocumentObjects

    if (((DocumentObjectSubWindow) e.getSource()).isDirty()) {
      DocumentObject d = ((DocumentObjectSubWindow) e.getSource()).getCurrentBeanItem().getBean();

      if (!isNewItem) { // Actualizacion
        beanItem.getBean().getDocumentObjectList().remove(currentFile);

        fileTable.removeItem(currentFile);
      }

      if (!d.getExtension().equals(""))
        fileTable.addItem(new Object[] {d.getName() + "." + d.getExtension(), d.getSize()}, d);
      else fileTable.addItem(new Object[] {d.getName(), d.getSize()}, d);

      beanItem.getBean().getDocumentObjectList().add(d);

      fileTable.requestRepaintAll();
      fileTable.refreshRowCache();

      dirty = true;
    }
  }
  protected Panel createTextFieldPanel(ConfigurationParameter parameter, Validator validator) {
    Panel paramPanel = new Panel();
    paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    paramPanel.setWidth("100%");

    GridLayout paramLayout = new GridLayout(3, 3);
    paramLayout.setSpacing(true);
    paramLayout.setSizeFull();
    paramLayout.setMargin(true);
    paramLayout.setColumnExpandRatio(0, .25f);
    paramLayout.setColumnExpandRatio(1, .75f);

    Label configLabel = new Label("Platform Configuration");
    configLabel.addStyleName(ValoTheme.LABEL_HUGE);
    configLabel.setSizeUndefined();
    paramLayout.addComponent(configLabel, 0, 0, 1, 0);
    paramLayout.setComponentAlignment(configLabel, Alignment.TOP_LEFT);

    Label label = new Label(parameter.getName());
    label.setIcon(VaadinIcons.COG);
    label.addStyleName(ValoTheme.LABEL_LARGE);
    label.addStyleName(ValoTheme.LABEL_BOLD);
    label.setSizeUndefined();
    paramLayout.addComponent(label, 0, 1, 1, 1);
    paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT);

    logger.info(parameter.getName() + " " + parameter.getValue());
    Label valueLabel = new Label("Value:");
    valueLabel.setSizeUndefined();
    usernameField = new TextField();
    usernameField.addValidator(validator);
    usernameField.setNullSettingAllowed(true);
    usernameField.setNullRepresentation("");
    usernameField.setValidationVisible(false);
    usernameField.setWidth("80%");
    usernameField.setId(parameter.getName());

    if (parameter instanceof ConfigurationParameterIntegerImpl) {
      StringToIntegerConverter plainIntegerConverter =
          new StringToIntegerConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      usernameField.setConverter(plainIntegerConverter);
    } else if (parameter instanceof ConfigurationParameterLongImpl) {
      StringToLongConverter plainLongConverter =
          new StringToLongConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      usernameField.setConverter(plainLongConverter);
    }

    BeanItem<ConfigurationParameter> parameterItem =
        new BeanItem<ConfigurationParameter>(parameter);

    if (parameter.getValue() != null) {
      usernameField.setPropertyDataSource(parameterItem.getItemProperty("value"));
    }

    paramLayout.addComponent(valueLabel, 0, 2);
    paramLayout.addComponent(usernameField, 1, 2);
    paramLayout.setComponentAlignment(valueLabel, Alignment.TOP_RIGHT);

    paramPanel.setContent(paramLayout);

    return paramPanel;
  }
 private Resource getResource(final Object itemId) {
   final Container container = this.getContainerDataSource();
   final BeanItem<Resource> item = (BeanItem<Resource>) container.getItem(itemId);
   return (item != null) ? item.getBean() : null;
 }
Пример #13
0
  public void buttonClick(ClickEvent event) {
    if (event.getButton() == createButton) {

      TestSession queriedSession = null;
      String wrongTitle = "";

      try {
        //						form.enableValidationMessages();
        //					title.setValidationVisible(true);

        // commit the fieldgroup
        binder.commit();

        // check SESSION title doesnt exist for THIS SESSION
        int id = 0;
        boolean titleOK = true;
        id = newSessionItem.getBean().getId(); // testsession.getId();
        // System.out.println("parentCase.getSessions() : " + parentcase.getSessions());
        for (TestSession s : parentcase.getSessions()) { // sessions.getItemIds()
          // System.out.println("Existing title -> new title : " + s.getTitle() + "->" +
          // testsession.getTitle());
          // System.out.println("Existing id -> new id : " + s.getId() + "->" + id);
          if (s.getTitle().equals(testsession.getTitle()) && !(s.getId() == id)) {
            testsession.setTitle(prevTitle);
            if (clonemode != true && editmode == true) {
              sessions.addEntity(testsession);
            }
            wrongTitle = s.getTitle();

            titleOK = false;
            break;
          }
        }

        if (titleOK == true) {
          // System.out.println("TITLE WAS FINE. EDITING");

          // add NEW bean object to db through jpa container
          if (editmode == false && (clonemode == false)) {

            // add to container
            sessions.addEntity(newSessionItem.getBean()); // jpa container

            // add created item to tree (after retrieving db generated id)
            EntityManager em =
                Persistence.createEntityManagerFactory("mbpet").createEntityManager();
            Query query =
                em.createQuery(
                    "SELECT OBJECT(t) FROM TestSession t WHERE t.title = :title AND t.parentcase = :parentcase");
            //		            query.setParameter("title", newsession.getTitle());
            query.setParameter("title", testsession.getTitle());
            query.setParameter("parentcase", testsession.getParentcase()); // MainView.sessionUser
            queriedSession = (TestSession) query.getSingleResult();
            //				            queriedSession = (TestSession) query.setParameter("title",
            // testsession.getTitle()).getSingleResult();
            // System.out.println("the generated id is: " + queriedSession.getId());
            id = queriedSession.getId(); // here is the id we need for tree

            // create session directory for test and reports
            new FileSystemUtils()
                .createSessionTestDir(
                    testsession.getParentcase().getOwner().getUsername(),
                    testsession.getParentcase().getTitle(),
                    testsession.getTitle());

            // create default parameters object
            new ParametersEditor(sessions.getItem(id).getEntity());

            // create empty adapter object
            new AdapterEditor(sessions.getItem(id).getEntity());

            // create empty adapterXML object
            new AdapterXMLEditor(sessions.getItem(id).getEntity());

            // create default models
            ModelUtils modelUtils = new ModelUtils();
            modelUtils.createDefaultModel(
                "user_types", sessions.getItem(id).getEntity()); // currmodel.getParentsession(),
            modelUtils.createDefaultModel(
                "normal_user", sessions.getItem(id).getEntity()); // currmodel.getParentsession(),

            // add to tree in right order
            if (tree.hasChildren(parentcase.getId())) {
              sortAddToTree(id);
            } else {
              tree.addItem(id);
              tree.setParent(id, parentcase.getId());
              tree.setChildrenAllowed(id, false);
              tree.setItemCaption(
                  id, sessions.getItem(id).getEntity().getTitle()); // newsession.getTitle()
              tree.expandItem(parentcase.getId());
              tree.select(id);
            }

            // update parent Case to add Session to testCase List<Session> sessions
            parentcase.addSession(queriedSession);
            testcases.addEntity(parentcase);
            //              	  	List<TestSession> listofsessions = parentCase.getSessions();
            //              	  	listofsessions.add(queriedSession);
            //	//sessions.getItem(id).getEntity()
            //              	  	parentCase.setSessions(listofsessions);

            //									System.out.println("WHAT IS NEW LIST OF SESSIONS: "
            //													+ parentcase.getSessions()); // testing purposes
            //									for (TestSession s : parentcase.getSessions()) {
            //										System.out.println(s.getId() + " - "
            //												+ s.getTitle()); // testing purposes
            //									}

          } else if (editmode == true) {
            // EDIT existing object

            //								// commit the fieldgroup
            //								binder.commit();

            // 1 UPDATE parentcase reference
            parentcase.updateSessionData(sessions.getItem(testsession.getId()).getEntity());

            // System.out.println("Test session is now: " + testsession.getTitle());

            // 2 UPDATE container
            sessions.addEntity(newSessionItem.getBean());
            // System.out.println("Entity is now: " +
            // sessions.getItem(testsession.getId()).getEntity().getTitle());

            // 3 UPDATE tree title
            tree.setItemCaption(
                testsession.getId(), sessions.getItem(testsession.getId()).getEntity().getTitle());

            // 4. UPDATE models (maybe not necessary)
            //
            //	ModelEditorTable.modelsTable.setContainerDataSource(ModelEditorTable.modelsTable.getContainerDataSource());
            //			              	  	for (Model m : testsession.getModels()) {
            //
            //	m.setParentsession(sessions.getItem(testsession.getId()).getEntity());
            //			              	  		System.out.println("Sessions' model's session title: " +
            // m.getParentsession().getTitle());
            ////
            //	m.updateSessionData(sessions.getItem(testsession.getId()).getEntity());
            //			              	  	}

            // edit session directory for test and reports
            if (!prevTitle.equals(testsession.getTitle())) {
              new FileSystemUtils()
                  .renameSessionDir(
                      testsession.getParentcase().getOwner().getUsername(),
                      testsession.getParentcase().getTitle(),
                      prevTitle,
                      testsession.getTitle());
            }

            //			              	  	// update parameters and adapter ?
            // System.out.println("Sessions' params's session title: " +
            // testsession.getParameters().getOwnersession().getTitle());
            // System.out.println("Sessions' adapter session title: " +
            // testsession.getAdapter().getOwnersession().getTitle());
            // System.out.println("Sessions' adapterXML session title: " +
            // testsession.getAdapterXML().getOwnersession().getTitle());

            id = testsession.getId();

          } else if (clonemode == true) {
            // CLONE
            // System.out.println("\n\nWE ARE IN CLONE MODE!!!!!!!!!\n\n");

            //							TestSession clone = newSessionItem.getBean();
            //								// 1 commit the fieldgroup
            //								binder.commit();

            // 2 add to container
            sessions.addEntity(newSessionItem.getBean()); // jpa container

            // 3 retrieving db generated id
            EntityManager em =
                Persistence.createEntityManagerFactory("mbpet").createEntityManager();
            Query query =
                em.createQuery("SELECT OBJECT(t) FROM TestSession t WHERE t.title = :title");
            //		            query.setParameter("title", newsession.getTitle());
            queriedSession =
                (TestSession) query.setParameter("title", testsession.getTitle()).getSingleResult();
            // System.out.println("the generated id is: " + queriedSession.getId());
            id = queriedSession.getId(); // here is the id we need for tree

            // 4 clone models
            EntityManager em2 =
                Persistence.createEntityManagerFactory("mbpet").createEntityManager();
            Query query2 =
                em2.createQuery(
                    "SELECT OBJECT(m) FROM Model m WHERE m.title = :title AND m.parentsession = :parentsession");
            for (Model m : subject.getModels()) {
              // copy over model values
              Model newmodel =
                  new Model(m.getTitle(), queriedSession, m.getParentsut()); // "(clone) " +
              newmodel.setDotschema(m.getDotschema());

              // add to container
              models.addEntity(newmodel); // jpa container

              // retrieve generated id from db
              query2.setParameter("title", newmodel.getTitle());
              query2.setParameter("parentsession", queriedSession);
              Model queriedModel = (Model) query2.getSingleResult();
              // System.out.println("the generated MODEL id is: " + queriedModel.getId() + " of
              // session ->" + queriedSession.getId());

              // update parent Case to add Session to testCase List<Session> sessions
              parentcase.addModel(queriedModel);
              queriedSession.addModel(queriedModel);

              //						            //write model to disk
              //						            FileSystemUtils fileUtils = new FileSystemUtils();
              //						            fileUtils.writeModelToDisk(
              //						            		parentcase.getOwner().getUsername(),
              //						            		parentcase.getTitle(),
              //						            		queriedSession.getTitle(),
              //						            		queriedSession.getParameters().getModels_folder(),
              //						            		queriedModel);
            }
            sessions.addEntity(queriedSession);

            // 5 clone parameters
            String cloneParams =
                "Fill in parameters for Test Session '" + queriedSession.getTitle() + "'";
            if (!(subject.getParameters().getSettings_file()
                == null)) { // || !(testsession.getParameters().getSettings_file().equals(""))
              cloneParams = subject.getParameters().getSettings_file();
            }
            //					            System.out.println("\n\n the cloned parameters are:\n" +
            //					            		cloneParams + "\n\n");
            new ParametersEditor(queriedSession, cloneParams);

            // 6 clone adapter.py
            String cloneAdapter =
                "Fill in adapter for Test Session '" + queriedSession.getTitle() + "'";
            if (!(subject.getAdapter().getAdapter_file() == null)
                || !(subject
                    .getAdapter()
                    .getAdapter_file()
                    .equals(
                        ""))) { // || !(testsession.getParameters().getSettings_file().equals(""))
              cloneAdapter = subject.getAdapter().getAdapter_file();
            }
            //					            System.out.println("\n\n the cloned adapter is:\n" +
            //					            		cloneAdapter + "\n\n");
            new AdapterEditor(queriedSession, cloneAdapter);

            // 7 clone adapter.xml
            String cloneAdapterXML =
                "Fill in adapterXML for Test Session '" + queriedSession.getTitle() + "'";
            if (!(subject.getAdapterXML().getAdapterXML_file() == null)
                || !(subject
                    .getAdapterXML()
                    .getAdapterXML_file()
                    .equals(
                        ""))) { // || !(testsession.getParameters().getSettings_file().equals(""))
              cloneAdapterXML = subject.getAdapterXML().getAdapterXML_file();
            }
            //					            System.out.println("\n\n the cloned adapterXML is:\n" +
            //					            		cloneAdapterXML + "\n\n");
            new AdapterXMLEditor(queriedSession, cloneAdapterXML);

            // 8 write models to disk
            FileSystemUtils fileUtils = new FileSystemUtils();
            fileUtils.writeModelsToDisk(
                parentcase.getOwner().getUsername(),
                parentcase.getTitle(),
                queriedSession.getTitle(),
                queriedSession.getParameters().getModels_folder(),
                subject.getModels());

            // 9 add to tree in right order
            if (tree.hasChildren(parentcase.getId())) {
              sortAddToTree(id);
            } else {
              tree.addItem(id);
              tree.setParent(id, parentcase.getId());
              tree.setChildrenAllowed(id, false);
              tree.setItemCaption(
                  id, sessions.getItem(id).getEntity().getTitle()); // newsession.getTitle()
              tree.expandItem(parentcase.getId());
              tree.select(id);
            }

            // 10 update parent Case to add Session to testCase List<Session> sessions
            parentcase.addSession(queriedSession);
            //              	  	List<TestSession> listofsessions = parentCase.getSessions();
            //              	  	listofsessions.add(queriedSession);
            //	//sessions.getItem(id).getEntity()
            //              	  	parentCase.setSessions(listofsessions);

            // 9 create session directory for test and reports
            new FileSystemUtils()
                .createSessionTestDir(
                    queriedSession.getParentcase().getOwner().getUsername(),
                    queriedSession.getParentcase().getTitle(),
                    queriedSession.getTitle());

            //				            	System.out.println("WHAT IS NEW LIST OF SESSIONS: " +
            // parentCase.getSessions()); // testing purposes
            //				            	for (TestSession s : parentCase.getSessions()) {
            //					            	System.out.println(s.getId() + " - " + s.getTitle()); // testing
            // purposes
            //				            	}
          }

          //			            	System.out.println("WHAT IS NEW LIST OF SESSIONS: " +
          // parentCase.getSessions()); // testing purposes
          //			            	for (TestSession s : parentCase.getSessions()) {
          //				            	System.out.println(s.getId() + " - " + s.getTitle()); // testing
          // purposes
          //			            	}

          if (clonemode == true && navToCasePage == true) {
            confirmNotification(queriedSession.getTitle(), "was created");
            close();

          } else if (clonemode == true && navToCasePage == false) {
            confirmNotification(queriedSession.getTitle(), "was CLONED");
            getUI()
                .getNavigator()
                .navigateTo(
                    MainView.NAME
                        + "/"
                        + parentcase.getTitle()
                        + "/"
                        + queriedSession.getTitle()
                        + "id="
                        + queriedSession
                            .getId()); // sessions.getItem(id).getEntity()
            close();

          } else if (navToCasePage == true && editmode == false) {
            // 4 UPDATE table title
            table.select(newSessionItem.getBean().getId()); // (testsession.getId());
            confirmNotification(testsession.getTitle(), "was created");
            close();

            //		            		getUI().getNavigator()
            //		            			.navigateTo(MainView.NAME + "/" +
            //		            				parentCase.getTitle());		//sessions.getItem(id).getEntity()

          } else if (navToCasePage == true && editmode == true) {
            getUI()
                .getNavigator()
                .navigateTo(
                    MainView.NAME
                        + "/"
                        + parentcase.getTitle()
                        + "-sut="
                        + parentcase.getId()); // sessions.getItem(id).getEntity()		            	
            confirmNotification(testsession.getTitle(), "was edited");
            close();

          } else if (editmode == true && navToCasePage == false) {
            getUI()
                .getNavigator()
                .navigateTo(
                    MainView.NAME
                        + "/"
                        + parentcase.getTitle()
                        + "/"
                        + newSessionItem.getBean().getTitle()
                        + "id="
                        + newSessionItem
                            .getBean()
                            .getId()); // testsession.getTitle() sessions.getItem(id).getEntity()
          } else {
            getUI()
                .getNavigator()
                .navigateTo(
                    MainView.NAME
                        + "/"
                        + parentcase.getTitle()
                        + "/"
                        + queriedSession.getTitle()
                        + "id="
                        + queriedSession
                            .getId()); // testsession.getTitle() sessions.getItem(id).getEntity()
          }

          // title already existed
        } else {
          // System.out.println("title was NOT fine.");
          //							testsession = sessions.getItem(id).getEntity();
          //							System.out.println("db session is: " + testsession.getId() + " " +
          // testsession.getTitle());

          if (editmode == false && clonemode == false) {
            binder.discard();
            Notification.show(
                "The title '"
                    + wrongTitle
                    + "' already exists for this SUT. Please rename this session.",
                Type.ERROR_MESSAGE); // testsession.getTitle()
            UI.getCurrent().addWindow(new TestSessionEditor(tree, table, parentcase, true));
          } else if (editmode == true) {
            binder.discard();
            Notification.show(
                "The title '"
                    + wrongTitle
                    + "' already exists for this SUT. Please rename this session.",
                Type.ERROR_MESSAGE);
            if (navToCasePage == true) {
              UI.getCurrent()
                  .addWindow(
                      new TestSessionEditor(
                          tree,
                          id,
                          parentcase,
                          table)); // sessions.getItem(testsession.getId()).getEntity().getId()
            } else {
              UI.getCurrent().addWindow(new TestSessionEditor(tree, id, parentcase));
            }

          } else if (clonemode == true) {
            binder.discard();
            Notification.show(
                "The title '"
                    + wrongTitle
                    + "' already exists for this SUT. Please rename this session.",
                Type.ERROR_MESSAGE);
            UI.getCurrent()
                .addWindow(
                    new TestSessionEditor(
                        tree,
                        subject.getId(), // testsession sessions.getItem(
                        parentcase,
                        table,
                        true));
          }
        }

      } catch (CommitException e) {
        binder.discard();
        Notification.show("'Title' cannot be Empty. Please try again.", Type.WARNING_MESSAGE);
        UI.getCurrent().addWindow(new TestSessionEditor(tree, parentcase, true));
      } catch (NonUniqueResultException e) {
        e.printStackTrace();
        binder.discard();
        Notification.show(
            "The title '"
                + testsession.getTitle()
                + "' already exists for this SUT. Please rename this session.",
            Type.ERROR_MESSAGE);
        UI.getCurrent().addWindow(new TestSessionEditor(tree, parentcase, true));
      }
      //					catch (NonUniqueResultException e) {
      //						binder.discard();
      //						Notification.show("'Title' must be a unique name.\n'" +
      //											queriedSession.getTitle() +
      //											"' already exists.\n\nPlease try again.", Type.WARNING_MESSAGE);
      //						UI.getCurrent().addWindow(new TestSessionEditor(tree, parentCase));
      //					}

    } else if (event.getButton() == cancelButton) {
      binder.discard();
    }
    //	        binder.clear();
    //	        form.disableValidationMessages();
    //	        setTreeItemsExpanded();

    close(); // Close the sub-window
  }
Пример #14
0
 public boolean updateUser(
     BeanFieldGroup<User> fieldGroup, String currentPass, String newClearPass)
     throws BLException, FieldGroup.CommitException, CloneNotSupportedException {
   BeanItem<User> old = fieldGroup.getItemDataSource();
   Object oldUser = old.getBean().clone();
   fieldGroup.commit();
   BeanItem<User> item = fieldGroup.getItemDataSource();
   User u = item.getBean();
   boolean userUpdated = false;
   try {
     userUpdated =
         (boolean)
             DB.execWithTransaction(
                 (db) -> {
                   User user = (User) db.session().merge(u);
                   UserManager mgr = new UserManager(db);
                   boolean updated = false;
                   if (!newClearPass.isEmpty()) {
                     boolean passwordOK = false;
                     boolean newPasswordOK = false;
                     try {
                       passwordOK = mgr.checkPassword(user, currentPass);
                       newPasswordOK = mgr.checkNewPassword(user, newClearPass);
                       if (passwordOK && newPasswordOK) {
                         mgr.setPassword(user, newClearPass);
                         updated = true;
                       } else if (!newPasswordOK) {
                         throw new BLException("This password has already been used");
                       }
                     } catch (BLException e) {
                       // do nothing
                       return false;
                     }
                   }
                   updated =
                       updated
                           || addRevisionUpdated(
                               db,
                               getEntityName(),
                               String.valueOf(u.getId()),
                               oldUser,
                               u,
                               new String[] {
                                 "nick", "name", "email", "active", "roles", "password"
                               });
                   return updated;
                 });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return false;
   }
   if (userUpdated && u.equals(getApp().getUser())) {
     try {
       DB.exec(
           (db) -> {
             db.session().refresh(getApp().getUser());
             return null;
           });
     } catch (Exception e) {
       getApp().getLog().error(e);
     }
   }
   return userUpdated;
 }