Пример #1
0
  public void delete(final int id) {
    final DraftFormFilter formFilter = persistance.getFormFilterById(id);
    final UserRightManager userRightManager = userManager.getRight();
    if (formFilter != null
        && userRightManager.toSiteItem(formFilter.getForm()) == SiteOnItemRightType.EDIT) {
      persistanceTransaction.execute(
          new Runnable() {

            @Override
            public void run() {
              persistance.removeFormFilter(formFilter);
              formFilter.getDraftForm().removeFilter(formFilter);
            }
          });
    }
  }
Пример #2
0
  public String getDefaultName(final int formId) {
    final Set<String> usedNames = new HashSet<String>();
    for (final DraftFormFilter filter : persistance.getFormById(formId).getDraftFilters()) {
      usedNames.add(filter.getName());
    }

    int number = 1;
    final String name = "Form Filter";

    while (true) {
      if (!usedNames.contains(name + number)) {
        return name + number;
      }
      if (number >= Integer.MAX_VALUE) {
        number = (int) Math.round(Math.random());
      } else {
        number++;
      }
    }
  }
  @Test
  public void getFormFiltersByUserId_and_getFormFilterByNameAndUserId() {
    User user = new User();
    user.setPassword("1");
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setSubDomain("$");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("G");
    site.setTitle("F");
    persistance.putSite(site);

    UserOnSiteRight userOnUserRight = new UserOnSiteRight();
    userOnUserRight.setActive(true);
    userOnUserRight.setSiteAccessType(SiteAccessLevel.ADMINISTRATOR);
    user.addUserOnSiteRight(userOnUserRight);
    site.addUserOnSiteRight(userOnUserRight);
    persistance.putUserOnSiteRight(userOnUserRight);

    DraftForm form = new DraftCustomForm();
    form.setSiteId(site.getSiteId());
    form.setName("name");
    persistance.putItem(form);

    DraftFormFilter filter = new DraftFormFilter();
    filter.setForm(form);
    String filterName = "filter name " + System.currentTimeMillis();
    filter.setName(filterName);
    persistance.putFormFilter(filter);

    List<DraftFormFilter> userFitlers = persistance.getFormFiltersByUserId(user.getUserId());
    Assert.assertEquals(filter, userFitlers.get(0));

    DraftFormFilter namedUserFilter =
        persistance.getFormFilterByNameAndUserId(filterName, user.getUserId());
    Assert.assertEquals(filter, namedUserFilter);
  }