@Test
  public void executeWithSEOInGallery() throws IOException, ServletException {
    final Site site = TestUtil.createSite();
    final PageManager pageVersion = new PageManager(TestUtil.createPage(site));
    final Gallery gallery = TestUtil.createGallery(site);
    final WidgetItem galleryWidget = TestUtil.createWidgetItem();
    galleryWidget.setDraftItem((DraftItem) gallery);
    pageVersion.addWidget(galleryWidget);

    final DraftForm galleryForm = TestUtil.createCustomForm(site);
    TestUtil.createFormItem(FormItemName.SEO_KEYWORDS, galleryForm, 0);

    gallery.setFormId1(galleryForm.getFormId());

    final FilledForm filledForm = TestUtil.createFilledForm(galleryForm);
    final FilledFormItem filledFormItem = TestUtil.createFilledFormItem(FormItemName.SEO_KEYWORDS);
    filledFormItem.setValue("seo1;seo2;seo3");
    filledForm.addFilledFormItem(filledFormItem);

    stringBuilder.append("<!-- PAGE_HEADER -->");

    MockHttpServletRequest mockRequest = new MockHttpServletRequest("", "");
    mockRequest.setAttribute(
        "currentDisplayedFilledFormId" + gallery.getId(), filledForm.getFilledFormId());
    RenderContext context = new RenderContext(mockRequest, null, null, null, false);

    final Render render = new RenderKeywordsMetaTags(pageVersion, SiteShowOption.ON_USER_PAGES);
    render.execute(context, stringBuilder);

    Assert.assertEquals(
        "<meta name=\"keywords\" content=\"seo1, seo2, seo3\">\n" + "<!-- PAGE_HEADER -->",
        stringBuilder.toString());
  }
Exemple #2
0
 public FormData(final FilledForm filledForm) {
   description = filledForm.getFormDescription();
   final DraftForm form = ServiceLocator.getPersistance().getFormById(filledForm.getFormId());
   formId = form.getFormId();
   formName = form.getName();
   showDescription = form.isShowDescription();
   termsAndConditions =
       form instanceof DraftRegistrationForm
           ? ((DraftRegistrationForm) form).getTermsAndConditions()
           : null;
   requireTermsAndConditions =
       form instanceof DraftRegistrationForm
           && ((DraftRegistrationForm) form).isRequireTermsAndConditions();
   updateChildSiteRegistrationFields(form);
   this.formItems = FormItemsManager.createFormItemsByFilledForm(filledForm, form);
 }
  @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);
  }
  @DefaultHandler
  public Resolution upload() {
    try {
      if (fileData == null || filledFormId < 1) {
        throw new UnsupportedOperationException();
      }
      final FilledForm filledForm = persistance.getFilledFormById(filledFormId);
      final DraftForm form = persistance.getFormById(filledForm.getFormId());
      final FilledFormItem filledFormItem =
          FilledFormManager.getFilledFormItemByItemPosition(filledForm, position);
      final FormVideo formVideo = getFormVideoOrCreateNew(filledFormItem);

      final int siteId = form.getSiteId();
      final SourceVideoFileCreator sourceVideoFileCreator =
          new SourceVideoFileCreator(
              siteId,
              FileNameUtil.createExtension(fileData.getFileName()),
              fileData.getFileName(),
              fileData.getInputStream());
      final Video video = sourceVideoFileCreator.execute();

      persistanceTransaction.execute(
          new PersistanceTransactionContext<Void>() {
            public Void execute() {
              if (formItemName == FormItemName.VIDEO_FILE_UPLOAD) {
                try {
                  video.setFilledFormId(filledForm.getFilledFormId());
                  video.setFilledFormItemId(filledFormItem.getItemId());
                  formVideo.setVideoId(video.getVideoId());
                  FlvVideoManager.getFlvVideoOrCreateNew(
                      video.getVideoId(),
                      video.getSourceWidth(),
                      video.getSourceHeight(),
                      formVideo.getQuality(),
                      video.getSiteId());
                } catch (Exception exception) {
                  logger.log(Level.SEVERE, "Can`t create video file!", exception);
                }
              } else if (formItemName == FormItemName.IMAGE_FILE_UPLOAD) {
                formVideo.setImageId((new CreateFormFileUtil().createFormFile(fileData, siteId)));
              }
              return null;
            }
          });
      ServiceLocator.getPersistanceTransaction()
          .execute(
              new Runnable() {
                public void run() {
                  GalleriesManager.updateVideoFilesForGalleriesThatUseCurentForm(
                      filledForm.getFormId());
                }
              });
    } catch (Exception exception1) {
      try {
        this.getContext().getResponse().getOutputStream().println("-200");
      } catch (Exception exception2) {
        logger.log(Level.SEVERE, "Error while writing file", exception2);
      }
      logger.log(Level.SEVERE, "Error while writing file", exception1);
      return resolutionCreator.forwardToUrl("/SWFUpload/error.jsp");
    }
    return resolutionCreator.forwardToUrl("/SWFUpload/success.jsp");
  }