/** @author Artem Stasuk */
@RemoteProxy
@Filter(type = SynchronizeForDwrFilter.class)
public class ShowRequestContentService extends ServiceWithExecutePage {

  @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");
  }

  public List<Site> getSites() {
    return sites;
  }

  public Site getTargetSite() {
    return targetSite;
  }

  public List<Site> getTargetSites() {
    return targetSites;
  }

  public String getUserSitesUrl() {
    return userSitesUrl;
  }

  private List<Site> sites;
  private List<Site> targetSites;
  private Site targetSite;
  private String userSitesUrl;
  private final Persistance persistance = ServiceLocator.getPersistance();
  private final ConfigStorage configStorage = ServiceLocator.getConfigStorage();
}
  @Before
  public void before() {
    action.setContext(new ActionBeanContext());
    action.getContext().setRequest(new MockHttpServletRequest("", ""));
    ServiceLocator.getConfigStorage().get().setApplicationUrl("www.web-deva.com");
    FileSystemMock fileSystemMock = ((FileSystemMock) ServiceLocator.getFileSystem());
    Template template = TestUtil.createTemplate();
    template.setLayouts(
        new ArrayList<Layout>() {
          {
            Layout layout = new Layout();
            layout.setName("layout");
            layout.setFile("layout");
            add(layout);
          }
        });
    fileSystemMock.putTemplate(template);

    fileSystemMock.addTemplateResource(
        "directory", "layout", "<!-- MEDIA_BLOCK --><!-- MEDIA_BLOCK --><!-- MEDIA_BLOCK -->");
  }
  @Test
  public void testExecute_WithFirstState() throws Exception {
    ServiceLocator.getConfigStorage().get().setUserSitesUrl("web-deva.com");
    User user = TestUtil.createUser();
    user.setActiveted(null);
    Site parentSite = TestUtil.createSite();
    DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite);
    ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite);
    settings.setCreatedDate(new Date());
    settings.setUserId(user.getUserId());
    settings.setConfirmCode("confirm");
    settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR);

    FilledForm filledForm = TestUtil.createFilledForm(registration.getFormId());
    FilledFormItem filledFormItemDomainName =
        TestUtil.createFilledFormItem(FormItemName.YOUR_OWN_DOMAIN_NAME);
    List<String> values = Arrays.asList("domainName");
    filledFormItemDomainName.setValues(values);

    FilledFormItem filledFormItemSiteName =
        TestUtil.createFilledFormItem(FormItemName.YOUR_PAGE_SITE_NAME);
    List<String> siteNameValues = Arrays.asList("siteName");
    filledFormItemSiteName.setValues(siteNameValues);

    filledForm.setFilledFormItems(Arrays.asList(filledFormItemDomainName, filledFormItemSiteName));
    settings.setFilledFormId(filledForm.getFilledFormId());

    action.setSettingsId(settings.getChildSiteSettingsId());
    action.setConfirmCode("confirm");

    DraftChildSiteRegistration childSiteRegistration =
        TestUtil.createChildSiteRegistration("name", "comment");
    Site blueprint = TestUtil.createBlueprint();
    childSiteRegistration.setBlueprintsId(Arrays.asList(blueprint.getSiteId()));

    settings.setRequiredToUseSiteBlueprint(true);
    final SitePaymentSettings sitePaymentSettings = new SitePaymentSettings();
    sitePaymentSettings.setSiteStatus(SiteStatus.ACTIVE);
    settings.setSitePaymentSettings(sitePaymentSettings);
    settings.setChildSiteRegistration(childSiteRegistration);

    Assert.assertNull(user.getActiveted());
    Assert.assertNull(new UsersManager().getLoginedUser());
    Assert.assertNull(ServiceLocator.getPersistance().getSiteBySubDomain("domainname"));

    ForwardResolution resolutionMock = (ForwardResolution) action.show();
    Assert.assertNotNull(new UsersManager().getLoginedUser());
    Assert.assertEquals(user, new UsersManager().getLoginedUser());
    Assert.assertEquals(
        "/account/registration/childSiteRigistrationConfirmationFirstState.jsp",
        resolutionMock.getPath());

    Assert.assertNotNull(user.getActiveted());
    Assert.assertNotNull(new UsersManager().getLoginedUser());
    Assert.assertEquals(user, new UsersManager().getLoginedUser());
    Site site = ServiceLocator.getPersistance().getSiteBySubDomain("domainname");
    Assert.assertNotNull(site);
    Assert.assertNotNull(new UserRightManager(user).toSite(site).getSiteAccessType());
    Assert.assertEquals(
        settings.getAccessLevel(), new UserRightManager(user).toSite(site).getSiteAccessType());
    Assert.assertEquals("domainname", site.getSubDomain());
    Assert.assertEquals("http://domainname.web-deva.com", action.getUrl());
    Assert.assertNotNull(action.getTellFriendHtml());
    Assert.assertEquals(2, site.getPages().size());

    Assert.assertEquals("siteName", site.getTitle());
    Assert.assertEquals(blueprint, site.getBlueprintParent());
  }
예제 #4
0
  @Test
  public void testExecute() {
    final Config config = ServiceLocator.getConfigStorage().get();

    /*--------------------------------------------------1245 Gb---------------------------------------------------*/
    config.setMaxPostSize("1245GB");
    Assert.assertEquals(1245 * 1024 * 1024 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1245Gb");
    Assert.assertEquals(1245 * 1024 * 1024 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1245gb");
    Assert.assertEquals(1245 * 1024 * 1024 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1245g");
    Assert.assertEquals(1245 * 1024 * 1024 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals(
        (1245 * 1024 * 1024 * 1024L) + " B", MaxPostSizeCreator.createMaxPostSizeString());
    /*--------------------------------------------------1245 Gb---------------------------------------------------*/

    /*--------------------------------------------------1000 Mb---------------------------------------------------*/
    config.setMaxPostSize("1000MB");
    Assert.assertEquals(1000 * 1024 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1000Mb");
    Assert.assertEquals(1000 * 1024 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1000mb");
    Assert.assertEquals(1000 * 1024 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1000m");
    Assert.assertEquals(1000 * 1024 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals((1000 * 1024 * 1024) + " B", MaxPostSizeCreator.createMaxPostSizeString());
    /*--------------------------------------------------1000 Mb---------------------------------------------------*/

    /*---------------------------------------------------10 Kb----------------------------------------------------*/
    config.setMaxPostSize("10KB");
    Assert.assertEquals(10 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("10Kb");
    Assert.assertEquals(10 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("10kb");
    Assert.assertEquals(10 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("10k");
    Assert.assertEquals(10 * 1024L, MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals((10 * 1024L) + " B", MaxPostSizeCreator.createMaxPostSizeString());
    /*---------------------------------------------------10 Kb----------------------------------------------------*/

    /*-------------------------------------------------10 bytes---------------------------------------------------*/
    config.setMaxPostSize("10B");
    Assert.assertEquals(10, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("10b");
    Assert.assertEquals(10, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("10");
    Assert.assertEquals(10, MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals((10) + " B", MaxPostSizeCreator.createMaxPostSizeString());
    /*-------------------------------------------------10 bytes---------------------------------------------------*/

    /*-----------------------------------------Without value in config--------------------------------------------*/
    config.setMaxPostSize(null);
    Assert.assertEquals(
        MaxPostSizeCreator.getDefaultMaxPostSize(), MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals(
        (MaxPostSizeCreator.getDefaultMaxPostSize()) + " B",
        MaxPostSizeCreator.createMaxPostSizeString());
    /*-----------------------------------------Without value in config--------------------------------------------*/

    /*---------------------------------------With wrong value in config-------------------------------------------*/
    config.setMaxPostSize("adfasdfwea");
    Assert.assertEquals(
        MaxPostSizeCreator.getDefaultMaxPostSize(), MaxPostSizeCreator.createMaxPostSizeInBytes());

    Assert.assertEquals(
        (MaxPostSizeCreator.getDefaultMaxPostSize()) + " B",
        MaxPostSizeCreator.createMaxPostSizeString());
    /*---------------------------------------With wrong value in config-------------------------------------------*/

    config.setMaxPostSize("100,2KB");
    Assert.assertEquals(100 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1054.2KB");
    Assert.assertEquals(1054 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());

    config.setMaxPostSize("1054.222222KB");
    Assert.assertEquals(1054 * 1024, MaxPostSizeCreator.createMaxPostSizeInBytes());
  }
예제 #5
0
  @RemoteMethod
  public String goToPaypalCSR(final PaypalRequest request) throws Exception {
    final PaymentReason paymentReason = PaymentReason.CHILD_SITE_CREATION;

    // Modifying redirect url
    // Check on hash presence. We sould remove all old hash.
    if (request.getRedirectToUrl().contains("#")) {
      request.setRedirectToUrl(
          request.getRedirectToUrl().substring(0, request.getRedirectToUrl().indexOf("#")));
    }

    if (request.getPageBreakIndex() > request.getTotalPageBreaks()) {
      // If payment page is last page then update return url with setting that will show message
      // about registration completion.
      request.setRedirectToUrl(
          request.getRedirectToUrl() + "#showSuccessMessageLastPage" + request.getWidgetId());
    } else {
      // Upadting return from paypal url with correct form page.
      request.setRedirectToUrl(
          request.getRedirectToUrl()
              + (request.getRedirectToUrl().contains("?") ? "&" : "?")
              + "pageBreaksToPass="******"&filledFormToUpdateId="
              + request.getFilledFormToUpdateId()
              + "&childSiteUserId="
              + request.getChildSiteUserId()
              + "&settingsId="
              + request.getSettingsId()
              + "#showSuccessMessage"
              + request.getWidgetId());
    }

    final PaypalPaymentInfoRequest paymentInfoRequest =
        new PaypalPaymentInfoRequest(
            request.getOwnerId(),
            PaymentSettingsOwnerType.CHILD_SITE_SETTINGS,
            request.getChargeType(),
            request.getRedirectToUrl(),
            createRedirectOnErrorUrl(request),
            paymentReason,
            request.getChildSiteUserId());
    final int requestId =
        ServiceLocator.getPaypalPaymentInfoRequestStorage().put(paymentInfoRequest);

    final ChildSiteSettings childSiteSettings =
        ServiceLocator.getPersistance().getChildSiteSettingsById(request.getSettingsId());
    // Here we should check, which paypal we should use: default Web-Deva`s or own. Tolik
    final PayPal payPal =
        (PayPal) new PaymentSettingsOwnerManager(childSiteSettings).getAppropriatePaymentSystem();

    final String networkName = childSiteSettings.getChildSiteRegistration().getName();
    final String applicationUrl =
        "http://" + ServiceLocator.getConfigStorage().get().getApplicationUrl();
    final String token =
        payPal.setCustomerBillingAgreement(
            applicationUrl + "/account/createProfile.action?requestId=" + requestId,
            request.getRedirectToUrl()
                + (request.getRedirectToUrl().contains("?") ? "&" : "?")
                + "pageBreaksToPass="******"&filledFormToUpdateId="
                + request.getFilledFormToUpdateId(),
            (networkName + " fee for child site"),
            paymentReason,
            null,
            request.getOwnerId(),
            request.getChildSiteUserId());

    return (payPal.getPaypalLink() + token);
  }
예제 #6
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;
  }