Ejemplo n.º 1
0
@RemoteProxy
@Filter(
    type = SynchronizeForDwrFilter.class,
    params = {})
public class DeleteBlogPostService extends AbstractService {

  @SynchronizeByMethodParameter(entityClass = BlogPost.class, method = SynchronizeMethod.WRITE)
  @RemoteMethod
  public void execute(final int blogPostId) {
    final User user = new UsersManager().getLoginedUser();
    final Integer loginedUserId = user != null ? user.getUserId() : null;
    final BlogPost blogPost = BlogRight.getBlogPostOnEdit(loginedUserId, blogPostId);
    persistanceTransaction.execute(
        new Runnable() {

          public void run() {
            persistance.removeBlogPost(blogPost);
          }
        });
  }

  private final SessionStorage sessionStorage = ServiceLocator.getSessionStorage();
  private final Persistance persistance = ServiceLocator.getPersistance();
  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
}
Ejemplo n.º 2
0
/** @author dmitry.solomadin */
@RemoteProxy
@Filter(type = SynchronizeForDwrFilter.class)
public class TrafficPagesService extends ServiceWithExecutePage {

  @SynchronizeByMethodParameter(entityClass = Site.class)
  @RemoteMethod
  public String sort(
      final int siteId,
      final StatisticsSortType sortType,
      final boolean desc,
      final StatisticsTimePeriodType timePeriod,
      final Integer pageNumber)
      throws IOException, ServletException {
    final UserManager userManager = new UsersManager().getLogined();
    final Site site = userManager.getRight().getSiteRight().getSiteForView(siteId).getSite();

    final List<Page> sitePages = PagesWithoutSystem.get(site.getPages());
    sessionStorage.setStatisticsTimePeriodTypeInServiceForPage(this, timePeriod);

    final Paginator paginator =
        statisticsPageSort.sort(sitePages, sortType, desc, timePeriod, pageNumber);

    getContext().getHttpServletRequest().setAttribute("paginator", paginator);
    getContext().getHttpServletRequest().setAttribute("trafficPagesSortType", sortType);
    getContext().getHttpServletRequest().setAttribute("descending", desc);
    return executePage("/site/traffic/trafficPagesList.jsp");
  }

  private final SessionStorage sessionStorage = ServiceLocator.getSessionStorage();
  private final StatisticsPageSort statisticsPageSort = new StatisticsPageSort();
}
  @Test(expected = WrongVerificationCodeException.class)
  public void executeWithoutCustomForm() throws Exception {
    TestUtil.createUserAndLogin();
    final Site site = TestUtil.createSite();

    final PageManager pageVersion = TestUtil.createPageVersionSiteUser();
    Widget widgetCustomForm = TestUtil.createCustomFormWidget(pageVersion);

    final List<FilledFormItem> filledFormItems =
        TestUtil.createFilledFormItems(FormItemName.FIRST_NAME, FormItemName.LAST_NAME);
    filledFormItems.get(0).setValue("FN1");
    filledFormItems.get(1).setValue("LN1");

    final SubmitCustomFormRequest request = new SubmitCustomFormRequest();
    request.setWidgetId(widgetCustomForm.getWidgetId());
    request.setFilledFormItems(new ArrayList<FilledFormItem>());
    request.setFilledFormItems(filledFormItems);
    ServiceLocator.getSessionStorage()
        .setNoBotCode(null, "customForm" + widgetCustomForm.getWidgetId(), "aaaaaa");

    service.execute(request);
  }
  @Test
  public void execute() throws Exception {
    TestUtil.createUserAndLogin();
    final Site site = TestUtil.createSite();

    final PageManager pageVersion = TestUtil.createPageVersionSiteUser();
    Widget widgetCustomForm = TestUtil.createCustomFormWidget(pageVersion);
    final DraftCustomForm customForm = TestUtil.createCustomForm(site);

    final List<FilledFormItem> filledFormItems =
        TestUtil.createFilledFormItems(FormItemName.FIRST_NAME, FormItemName.LAST_NAME);
    filledFormItems.get(0).setValue("FN1");
    filledFormItems.get(1).setValue("LN1");

    final SubmitCustomFormRequest request = new SubmitCustomFormRequest();
    request.setFormId(customForm.getFormId());
    request.setWidgetId(widgetCustomForm.getWidgetId());
    request.setFilledFormItems(new ArrayList<FilledFormItem>());
    request.setVerificationCode("aaaaaa");
    request.setFilledFormItems(filledFormItems);
    ServiceLocator.getSessionStorage()
        .setNoBotCode(null, "customForm" + widgetCustomForm.getWidgetId(), "aaaaaa");

    final SubmitCustomFormResponse response = service.execute(request);

    Assert.assertNull(response.getNextPageHtml());

    final FilledForm filledCustomForm =
        ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId());
    Assert.assertNotNull(filledCustomForm);
    Assert.assertEquals(
        filledFormItems.get(0).getValues(),
        filledCustomForm.getFilledFormItems().get(0).getValues());
    Assert.assertEquals(
        filledFormItems.get(1).getValues(),
        filledCustomForm.getFilledFormItems().get(1).getValues());
  }
Ejemplo n.º 5
0
@RemoteProxy
public class ShowVisitorLoginService extends ServiceWithExecutePage {

  /**
   * @param widgetId - selected widget id
   * @param force - if this parameter true login show always. If false login show only if visitor
   *     not logined.
   * @return - html with login controls
   * @throws IOException
   * @throws ServletException
   */
  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String execute(final int widgetId, final boolean force)
      throws IOException, ServletException {
    this.widgetId = widgetId;
    widget = persistance.getWidget(widgetId);
    if (widget == null) {
      throw new WidgetNotFoundException("Cannot find widget by id " + widgetId);
    }
    final Cookie[] cookies = getContext().getHttpServletRequest().getCookies();
    final Site site = widget.getSite();
    if (cookies != null) {
      final Cookie crypted = ActionUtil.findCookie(cookies, "sh_cpt" + site.getSiteId());
      final Cookie visitorId = ActionUtil.findCookie(cookies, "sh_vid" + site.getSiteId());
      if (crypted != null && visitorId != null && !force) {
        // Getting our user from cookie
        user = persistance.getUserById(Integer.parseInt(visitorId.getValue()));

        // Check for rights.
        if (user == null
            || persistance.getUserOnSiteRightByUserAndSiteId(user.getUserId(), site.getSiteId())
                == null) {
          return executePage("/site/render/widgetLogin.jsp");
        }

        // Checking if user md5(login + password) matches the same form cookie
        if (MD5.crypt(user.getEmail() + user.getPassword()).equals(crypted.getValue())) {
          // If so - login our user
          new UsersManager().login(user.getUserId());
        }
      }
    }

    user = new UsersManager().getLoginedUser();
    if (user != null && !force) {
      final boolean isVisitorLogined =
          user != null && new UserRightManager(user).toSite(site) != null;

      if (isVisitorLogined) {
        return executePage("/site/render/visitorLogined.jsp");
      } else {
        return executePage("/site/render/widgetLogin.jsp");
      }
    }
    return executePage("/site/render/widgetLogin.jsp");
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForRegistration(final int widgetId) throws IOException, ServletException {
    returnToRegistration = true;
    return execute(widgetId, false);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForChildSiteRegistration(final int widgetId)
      throws IOException, ServletException {
    returnToChildSiteRegistration = true;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForManageVotes(final int widgetId, final int formId)
      throws IOException, ServletException {
    returnToManageVotes = true;
    this.formId = formId;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForGalleryWithForm(
      final int widgetId, final int formId, final Integer shouldBeRegisteredFromRightFormId)
      throws IOException, ServletException {
    returnToGallery = true;
    this.formId = formId;
    this.shouldBeRegisteredFromRightFormId = shouldBeRegisteredFromRightFormId;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForShoppingCart(final int widgetId, final int formId)
      throws IOException, ServletException {
    returnToShoppingCart = true;
    this.formId = formId;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForGallery(final int widgetId) throws IOException, ServletException {
    returnToGallery = true;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForForum(final int widgetId) throws IOException, ServletException {
    returnToForum = true;
    return execute(widgetId, true);
  }

  @RemoteMethod
  @SynchronizeByMethodParameter(entityClass = Widget.class)
  public String executeForBlog(final int widgetId) throws IOException, ServletException {
    returnToBlog = true;
    return execute(widgetId, true);
  }

  public User getVisitor() {
    return user;
  }

  public int getWidgetId() {
    return widgetId;
  }

  public void setWidgetId(int widgetId) {
    this.widgetId = widgetId;
  }

  public void setVisitor(User user) {
    this.user = user;
  }

  public Widget getWidget() {
    return widget;
  }

  public boolean isReturnToRegistration() {
    return returnToRegistration;
  }

  public boolean isReturnToChildSiteRegistration() {
    return returnToChildSiteRegistration;
  }

  public boolean isReturnToManageVotes() {
    return returnToManageVotes;
  }

  public boolean isReturnToGallery() {
    return returnToGallery;
  }

  public Integer getFormId() {
    return formId;
  }

  public boolean isReturnToForum() {
    return returnToForum;
  }

  public boolean isReturnToBlog() {
    return returnToBlog;
  }

  public Integer getShouldBeRegisteredFromRightFormId() {
    return shouldBeRegisteredFromRightFormId;
  }

  public boolean isReturnToShoppingCart() {
    return returnToShoppingCart;
  }

  private final Persistance persistance = ServiceLocator.getPersistance();
  private final SessionStorage sessionStorage = ServiceLocator.getSessionStorage();
  private int widgetId;
  private Integer formId;
  private Integer shouldBeRegisteredFromRightFormId;
  private User user;
  private Widget widget;
  private boolean returnToRegistration;
  private boolean returnToChildSiteRegistration;
  private boolean returnToManageVotes;
  private boolean returnToGallery;
  private boolean returnToForum;
  private boolean returnToBlog;
  private boolean returnToShoppingCart;
}
  @Test
  public void executeWithPageBreaks() throws Exception {
    TestUtil.createUserAndLogin();
    final Site site = TestUtil.createSite();

    final PageManager pageVersion = TestUtil.createPageVersionSiteUser();
    Widget widgetCustomForm = TestUtil.createCustomFormWidget(pageVersion);
    final DraftCustomForm customForm = TestUtil.createCustomForm(site);

    final List<DraftFormItem> formItems = new ArrayList<DraftFormItem>();
    formItems.add(TestUtil.createFormItem(FormItemName.FIRST_NAME, 0));
    formItems.add(TestUtil.createFormItem(FormItemName.PAGE_BREAK, 1));
    formItems.add(TestUtil.createFormItem(FormItemName.LAST_NAME, 2));
    customForm.setFormItems(formItems);

    // FIRST PAGE
    List<FilledFormItem> filledFormItems = TestUtil.createFilledFormItems(FormItemName.FIRST_NAME);
    filledFormItems.get(0).setValue("FN1");

    SubmitCustomFormRequest request = new SubmitCustomFormRequest();
    request.setFormId(customForm.getFormId());
    request.setWidgetId(widgetCustomForm.getWidgetId());
    request.setFilledFormItems(new ArrayList<FilledFormItem>());
    request.setRequestNextPage(true);
    request.setPageBreaksToPass(1);
    request.setVerificationCode("aaaaaa");
    request.setFilledFormItems(filledFormItems);
    ServiceLocator.getSessionStorage()
        .setNoBotCode(null, "customForm" + widgetCustomForm.getWidgetId(), "aaaaaa");

    SubmitCustomFormResponse response = service.execute(request);

    Assert.assertNotNull(response.getNextPageHtml());

    FilledForm filledContactUsForm =
        ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId());
    Assert.assertNotNull(filledContactUsForm);
    Assert.assertEquals(
        filledFormItems.get(0).getValues(),
        filledContactUsForm.getFilledFormItems().get(0).getValues());

    // SECOND PAGE
    filledFormItems = TestUtil.createFilledFormItems(FormItemName.LAST_NAME);
    filledFormItems.get(0).setValue("LN1");

    request = new SubmitCustomFormRequest();
    request.setFormId(customForm.getFormId());
    request.setWidgetId(widgetCustomForm.getWidgetId());
    request.setFilledFormItems(new ArrayList<FilledFormItem>());
    request.setRequestNextPage(true);
    request.setFilledFormId(response.getFilledFormId());
    request.setPageBreaksToPass(2);
    request.setFilledFormItems(filledFormItems);

    response = service.execute(request);

    // Ok, now after we have filled out last form page we need to show first form page again with
    // the
    // message about successfull form submit.
    Assert.assertNotNull(response.getNextPageHtml());
    Assert.assertTrue(response.isShowSuccessfullSubmitMessage());

    filledContactUsForm =
        ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId());
    Assert.assertEquals(
        filledFormItems.get(0).getValues(),
        filledContactUsForm.getFilledFormItems().get(1).getValues());
  }