コード例 #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();
}
コード例 #2
0
/** @author dmitry.solomadin */
@RemoteProxy
public class CreateItemSizeService { // todo. Add tests.

  @SynchronizeByMethodParameter(entityClass = Widget.class)
  @RemoteMethod
  public void execute(final CreateItemSizeRequest request) throws IOException, ServletException {
    final UserManager userManager = new UsersManager().getLogined();

    persistanceTransaction.execute(
        new Runnable() {

          @Override
          public void run() {
            if (request.getWidgetId()
                != null) { // Saving with widget (from Site Edit Page or from Dashboard).
              final Widget widget =
                  userManager.getRight().getSiteRight().getWidgetForEdit(request.getWidgetId());
              final WidgetManager widgetManager = new WidgetManager(widget);
              if (request.isSaveItemSizeInCurrentPlace()) {
                widgetManager.setItemSizeInCurrentPlace(request.getItemSize());
              } else {
                widgetManager.setItemSizeInAllPlaces(request.getItemSize());
              }
            } else if (request.getDraftItemId()
                != null) { // Saving with draftItem (from Manage Items).
              new ItemManager(request.getDraftItemId()).updateItemSize(request.getItemSize());
            }
          }
        });
  }

  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
}
コード例 #3
0
 @RemoteMethod
 public UpdateMenuItemResponse execute(final Integer menuId) throws Exception {
   final UpdateMenuItemResponse response = new UpdateMenuItemResponse();
   final DraftMenu menu = persistance.getMenuById(menuId);
   if (menu == null) {
     logger.warning(
         "Can`t create default structure for menu with id = " + menuId + ". Menu not found.");
     return response;
   }
   final Site site = persistance.getSite(menu.getSiteId());
   if (site == null) {
     logger.warning(
         "Can`t create default structure for menu with id = "
             + menuId
             + ". Site not found. Site id "
             + "in this menu = "
             + menu.getSiteId());
     return response;
   }
   final DraftMenu defaultMenu = site.getMenu();
   if (defaultMenu == null) {
     logger.warning(
         "Can`t create default structure for menu with id = "
             + menuId
             + ". Default menu not found"
             + " for site with id = "
             + menu.getSiteId());
     return response;
   }
   ServiceLocator.getPersistanceTransaction()
       .execute(
           new Runnable() {
             public void run() {
               MenuItemsManager.restoreDefaultStructure(defaultMenu, menu);
             }
           });
   final MenuPagesHtmlTextCreator pagesHtmlTextCreator =
       new MenuPagesHtmlTextCreator(
           menu, new MenuPageCheckSometimes(menu), SiteShowOption.getDraftOption());
   response.setTreeHtml(pagesHtmlTextCreator.getHtml());
   if (!menu.getMenuItems().isEmpty()) {
     final int selectedMenuItemId = menu.getMenuItems().get(0).getId();
     response.setInfoAboutSelectedItem(new GetInfoAboutItemService().execute(selectedMenuItemId));
     response.setSelectedMenuItemId(selectedMenuItemId);
   }
   return response;
 }
コード例 #4
0
/** @author Artem Stasuk, dmitry.solomadin */
@RemoteProxy
public class SaveScriptService extends AbstractService {

  @RemoteMethod
  public FunctionalWidgetInfo execute(final SaveScriptRequest request) throws Exception {
    final UserManager userManager = new UsersManager().getLogined();

    final WidgetItem widget;
    if (request.getWidgetId() != null) {
      widget =
          (WidgetItem)
              userManager
                  .getRight()
                  .getSiteRight()
                  .getWidgetForEditInPresentationalService(request.getWidgetId());
    } else {
      widget = null;
    }

    persistanceTransaction.execute(
        new Runnable() {

          @Override
          public void run() {
            final DraftScript draftScript = persistance.getDraftItem(request.getScriptItemId());
            if (draftScript == null || draftScript.getSiteId() <= 0) {
              throw new ScriptNotFoundException(
                  "Cannot find script item by Id=" + request.getScriptItemId());
            }

            draftScript.setText(request.getText());
            draftScript.setName(request.getName());
            draftScript.setDescription(request.getDescription());
            draftScript.setShowDescription(request.isShowDescription());
          }
        });

    return new GetFunctionalWidgetsService().createFunctionalWidgetInfo(widget, "widget", true);
  }

  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
  private Persistance persistance = ServiceLocator.getPersistance();
}
コード例 #5
0
  @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");
  }
コード例 #6
0
/** @author Balakirev Anatoliy */
@UrlBinding("/uploadFormVideoFiles.action")
public class UploadFormVideoFilesAction extends Action implements UploadedFiles {
  @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");
  }

  private FormVideo getFormVideoOrCreateNew(final FilledFormItem filledFormItem) {
    final FormVideo formVideo =
        persistance.getFormVideoById(FilledFormItemManager.getIntValue(filledFormItem));
    if (formVideo == null) {
      return persistanceTransaction.execute(
          new PersistanceTransactionContext<FormVideo>() {
            public FormVideo execute() {
              final FormVideo newFormVideo = new FormVideo();
              persistance.putFormVideo(newFormVideo);
              filledFormItem.setValue("" + newFormVideo.getFormVideoId());
              return newFormVideo;
            }
          });
    } else {
      return formVideo;
    }
  }

  public FormItemName getFormItemName() {
    return formItemName;
  }

  public void setFormItemName(FormItemName formItemName) {
    this.formItemName = formItemName;
  }

  public int getFilledFormId() {
    return filledFormId;
  }

  public void setFilledFormId(int filledFormId) {
    this.filledFormId = filledFormId;
  }

  public FileBean getFileData() {
    return fileData;
  }

  public void setFileData(FileBean fileData) {
    this.fileData = fileData;
  }

  public int getPosition() {
    return position;
  }

  public void setPosition(int position) {
    this.position = position;
  }

  private FormItemName formItemName;
  private int filledFormId;
  private int position;
  private final Persistance persistance = ServiceLocator.getPersistance();
  private final ResolutionCreator resolutionCreator = ServiceLocator.getResolutionCreator();
  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
  private static final Logger logger = Logger.getLogger(UploadFormFilesAction.class.getName());
  private FileBean fileData;

  public String getResourceUrl() {
    return null; // To change body of implemented methods use File | Settings | File Templates.
  }

  public int getResourceId() {
    return 0; // To change body of implemented methods use File | Settings | File Templates.
  }

  public ResourceType getResourceType() {
    return null; // To change body of implemented methods use File | Settings | File Templates.
  }
}
コード例 #7
0
/** @author Artem Stasuk */
public class FormFiltersManager {

  public FormFiltersManager(final UserManager userManager) {
    this.userManager = userManager;
  }

  public FormFilterManager save(final FormFilterEdit edit) {
    return persistanceTransaction.execute(
        new PersistanceTransactionContext<FormFilterManager>() {

          @Override
          public FormFilterManager execute() {
            final DraftFormFilter originalFormFilter =
                persistance.getFormFilterByNameAndFormId(edit.getName(), edit.getFormId());
            if (originalFormFilter != null && edit.getId() == null) {
              throw new FormFilterNotUniqueNameException("Not unique name " + edit.getName());
            } else if (originalFormFilter != null
                && originalFormFilter.getFormFilterId() != edit.getId()) {
              throw new FormFilterNotUniqueNameException("Not unique name " + edit.getName());
            }

            final DraftFormFilter formFilter;
            final UserRightManager userRightManager = userManager.getRight();
            if (edit.getId() == null) {
              final DraftForm form = persistance.getFormById(edit.getFormId());
              if (userRightManager.toSiteItem(form) != SiteOnItemRightType.EDIT) {
                throw new FormNotFoundException("Can't find form " + edit.getFormId());
              }

              formFilter = new DraftFormFilter();
              formFilter.setName(edit.getName());
              form.addFilter(formFilter);
              persistance.putFormFilter(formFilter);
            } else {
              formFilter = persistance.getFormFilterById(edit.getId());
              if (formFilter == null
                  || userRightManager.toSiteItem(formFilter.getForm())
                      != SiteOnItemRightType.EDIT) {
                throw new FormFilterNotFoundException("Can't find " + edit.getId());
              }
              formFilter.setName(edit.getName());
            }

            final List<DraftFormFilterRule> rules =
                new ArrayList<DraftFormFilterRule>(formFilter.getRules());
            for (final DraftFormFilterRule rule : rules) {
              persistance.removeFormFilterRule(rule);
            }

            for (final FormFilterRuleEdit ruleEdit : edit.getRules()) {
              final DraftFormFilterRule rule = new DraftFormFilterRule();
              rule.setInclude(ruleEdit.isInclude());
              rule.setCriteria(ruleEdit.getCriteria());
              rule.setFormItemId(ruleEdit.getFormItemId());
              formFilter.addRule(rule);
              persistance.putFormFilterRule(rule);
            }

            return new FormFilterManager(formFilter);
          }
        });
  }

  public List<FormFilterManager> getFilters() {
    final List<DraftFormFilter> filters =
        persistance.getFormFiltersByUserId(userManager.getUserId());
    final List<FormFilterManager> filterManagers = new ArrayList<FormFilterManager>(filters.size());
    for (final DraftFormFilter filter : filters) {
      filterManagers.add(new FormFilterManager(filter));
    }
    return filterManagers;
  }

  public FormFilterManager get(final Integer id) {
    if (id != null) {
      final DraftFormFilter formFilter = persistance.getFormFilterById(id);
      if (formFilter != null) {
        return new FormFilterManager(formFilter);
      }
    }
    throw new FormFilterNotFoundException("Can't find " + id);
  }

  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++;
      }
    }
  }

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

  private final UserManager userManager;
  private final Persistance persistance = ServiceLocator.getPersistance();
  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
}
コード例 #8
0
/**
 * @author Tolik, Dima, Artem
 * @see com.shroggle.presentation.account.accessPermissions.AddEditPermissionsService
 */
@UrlBinding("/account/createUser.action")
public class CreateUserAction extends Action implements LoginedUserInfo {

  /** @return - show page for create account */
  @SynchronizeByLoginUser
  @DefaultHandler
  public Resolution show() {
    state = new CreateUserState(request);
    request.setMode(CreateUserMode.NEW);
    return showInternal();
  }

  /**
   * It's general method.
   *
   * @return - show create account page.
   */
  private Resolution showInternal() {
    loginUser = new UsersManager().getLoginedUser();
    return resolutionCreator.forwardToUrl("/account/createUser.jsp");
  }

  /**
   * Need link /account/createUser.action ?showForInvited=true &request.confirmCode=X
   * &request.userId=X &request.invitedUserId=X
   *
   * @return - show page for accept user settings
   */
  @SynchronizeByLoginUser
  @SynchronizeByClassProperties({
    @SynchronizeByClassProperty(
        entityClass = User.class,
        entityIdFieldPath = "request.invitedUserId"),
    @SynchronizeByClassProperty(entityClass = User.class, entityIdFieldPath = "request.userId")
  })
  public Resolution showForInvited() {
    state = new CreateUserState(request);
    request.setNotWantNewUser(true);
    request.setAgree(true);
    request.setMode(CreateUserModeCreator.get(request, state));
    request.getMode().getShow().execute(this);
    return showInternal();
  }

  /**
   * Step by step:
   *
   * <p>0. validate user 1. get or create user 2. get or create or move right and activate it 3.
   * login user 4. redirect to need page
   *
   * @return - resolution to next page
   */
  @SynchronizeByAllEntity(entityClass = User.class)
  public Resolution execute() {
    state = new CreateUserState(request);
    final CreateUserMode mode = CreateUserModeCreator.next(request, state);
    request.setMode(mode);

    mode.getValidate().execute(this);
    if (getContext().getValidationErrors().size() > 0) {
      if (mode == CreateUserMode.INVITED_NEW) {
        return showForInvited();
      } else {
        return showInternal();
      }
    }

    persistanceTransaction.execute(
        new PersistanceTransactionContext<Void>() {

          @Override
          public Void execute() {
            mode.getCreateUser().execute(CreateUserAction.this);
            mode.getRight().execute(state);
            return null;
          }
        });
    mode.getLogin().execute(this);
    return mode.getRedirect().execute(state);
  }

  public void setRequest(final CreateUserRequest request) {
    this.request = request;
  }

  public CreateUserRequest getRequest() {
    return request;
  }

  public User getLoginUser() {
    return loginUser;
  }

  /**
   * This method used only in logic code for action. It don't have public modificator.
   *
   * @return - state
   */
  CreateUserState getState() {
    return state;
  }

  void setState(final CreateUserState state) { // for tests. Tolik
    this.state = state;
  }

  private final ResolutionCreator resolutionCreator = ServiceLocator.getResolutionCreator();
  private final PersistanceTransaction persistanceTransaction =
      ServiceLocator.getPersistanceTransaction();
  private CreateUserRequest request = new CreateUserRequest();
  private CreateUserState state;
  private User loginUser;
}