@Test
  public void getForumsByUserId() {
    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);

    DraftForum forum = new DraftForum();
    forum.setSiteId(site.getSiteId());
    forum.setName("name");
    persistance.putItem(forum);

    List<DraftItem> userForums =
        persistance.getDraftItemsByUserId(user.getUserId(), ItemType.FORUM);
    Assert.assertEquals(forum, userForums.get(0));
  }
  @SynchronizeByAllEntity(entityClass = Site.class)
  @RemoteMethod
  public String execute(final Integer targetSiteId) throws IOException, ServletException {
    userSitesUrl = configStorage.get().getUserSitesUrl();

    final UserManager userManager = new UsersManager().getLogined();

    if (targetSiteId != null) {
      targetSite = userManager.getRight().getSiteRight().getSiteForEdit(targetSiteId).getSite();
      targetSites = Arrays.asList(targetSite);
    } else {
      targetSites =
          persistance.getSites(userManager.getUserId(), SiteAccessLevel.getUserAccessLevels());
      Collections.sort(targetSites, new SiteByTitleComparator());
    }

    sites = new ArrayList<Site>();
    for (final Site site : persistance.getAllSites()) {
      if (site.getType() == SiteType.COMMON
          && site.getSitePaymentSettings().getSiteStatus() == SiteStatus.ACTIVE) {
        sites.add(site);
      }
    }
    Collections.sort(sites, new SiteByTitleComparator());
    return executePage("/site/showRequestContent.jsp");
  }
  @Test
  public void removeForumFromForumWidget() {
    DraftForum forum = new DraftForum();
    forum.setName("name");
    persistance.putItem(forum);

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

    Page page = TestUtil.createPage(site);
    PageManager pageVersion = new PageManager(page);

    WidgetItem widgetForum = new WidgetItem();
    widgetForum.setDraftItem(forum);
    persistance.putWidget(widgetForum);
    pageVersion.addWidget(widgetForum);

    persistance.removeDraftItem(forum);

    Assert.assertNull(persistance.getDraftItem(forum.getId()));
    Assert.assertNotNull(widgetForum.getDraftItem());
  }
  @Test
  public void getForumsByUserIdWithoutActive() {
    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);

    DraftForum forum = new DraftForum();
    forum.setSiteId(site.getSiteId());
    forum.setName("name");
    persistance.putItem(forum);

    List<DraftItem> userForums =
        persistance.getDraftItemsByUserId(user.getUserId(), ItemType.FORUM);
    Assert.assertEquals(0, userForums.size());
  }
  @Test
  public void putSiteOnForumRight() {
    DraftForum forum = new DraftForum();
    forum.setName("aa");
    persistance.putItem(forum);

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

    SiteOnItem siteOnForumRight = new SiteOnItem();
    siteOnForumRight.getId().setItem(forum);
    siteOnForumRight.getId().setSite(site);
    persistance.putSiteOnItem(siteOnForumRight);
  }
  @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);
  }
Exemplo n.º 7
0
  @RemoteMethod
  public GoToPaypalResponse goToPaypal(final PaypalRequest request) throws Exception {
    final PaymentReason paymentReason = PaymentReason.SHROGGLE_MONTHLY_PAYMENT;
    final Site site = ServiceLocator.getPersistance().getSite(request.getOwnerId());

    if (site == null) {
      throw new PaymentException(
          "Cannot pay for null site. Site by Id=" + request.getOwnerId() + " not found.");
    }

    final GoToPaypalResponse response = new GoToPaypalResponse();
    if (site.getSitePaymentSettings().getSiteStatus() == SiteStatus.ACTIVE
        && site.getSitePaymentSettings().getChargeType() == ChargeType.SITE_ONE_TIME_FEE) {
      response.setActivatedWithOneTimeFee(true);
      return response;
    }

    final String redirectOnErrorUrl = "/account/updatePaymentInfo.action?showPaypalError=true";
    final PaypalPaymentInfoRequest paymentInfoRequest =
        new PaypalPaymentInfoRequest(
            request.getOwnerId(),
            PaymentSettingsOwnerType.SITE,
            request.getChargeType(),
            request.getRedirectToUrl(),
            redirectOnErrorUrl,
            paymentReason,
            null);
    final int requestId =
        ServiceLocator.getPaypalPaymentInfoRequestStorage().put(paymentInfoRequest);

    final String description;
    if (request.getChargeType().getPaymentPeriod().equals(PaymentPeriod.MONTH)) {
      description = "Monthly cost of " + site.getTitle() + " site.";
    } else {
      description = "Annual cost of " + site.getTitle() + " site.";
    }
    // Here we should check, which paypal we should use: default Web-Deva`s or own. Tolik
    final PayPal payPal =
        (PayPal) new PaymentSettingsOwnerManager(site).getAppropriatePaymentSystem();

    final String applicationUrl =
        "http://" + ServiceLocator.getConfigStorage().get().getApplicationUrl();
    final String token =
        payPal.setCustomerBillingAgreement(
            applicationUrl + "/account/createProfile.action?requestId=" + requestId,
            applicationUrl + "/account/updatePaymentInfo.action",
            description,
            paymentReason,
            site.getSiteId(),
            null,
            null);

    response.setPaypalLink(payPal.getPaypalLink() + token);

    if (site.getSitePaymentSettings().getSiteStatus() == SiteStatus.ACTIVE) {
      if (site.getSitePaymentSettings().getPaymentMethod() == PaymentMethod.AUTHORIZE_NET) {
        response.setJavienActivated(true);
      } else if (payPal.getProfileStatus(site.getSitePaymentSettings().getRecurringPaymentId())
          == PayPalRecurringProfileStatus.ACTIVE) {
        response.setActiveProfile(true);
      }
    }
    return response;
  }