示例#1
0
  private void doExecuteApproveContentInSectionCommand(
      final ApproveContentInSectionCommand command) {
    Preconditions.checkNotNull(command.getSection(), "section cannot be null");
    Preconditions.checkNotNull(command.getApprover(), "approver cannot be null");
    Preconditions.checkNotNull(command.getContentToApprove(), "content to approve cannot be null");

    final MenuItemEntity section = doResolveSection(command.getSection());
    final UserEntity approver = doResolveUser(command.getApprover(), "approver");

    new MenuItemAccessResolver(groupDao)
        .checkAccessToApproveContentInSection(
            approver, section, "Cannot approve content in section.");

    final SectionContentEntity sectionContent =
        section.getSectionContent(command.getContentToApprove());
    boolean changed = false;

    if (!sectionContent.isApproved()) {
      sectionContent.setApproved(true);
      changed = true;
    }

    final int newOrder = resolveOrderValueForInsertOnTopOfApprovedContentInSection(section);
    if (sectionContent.getOrder() != newOrder) {
      sectionContent.setOrder(newOrder);
      changed = true;
    }

    if (changed) {
      sectionContent.setTimestamp(timeService.getNowAsDateTime().toDate());
      indexTransactionService.registerUpdate(command.getContentToApprove(), true);
    }
  }
示例#2
0
 private void doUnapproveContentInSection(final SectionContentEntity sectionContent) {
   boolean changed = false;
   if (sectionContent.isApproved()) {
     sectionContent.setApproved(false);
     changed = true;
   }
   if (sectionContent.getOrder() != 0) {
     sectionContent.setOrder(0);
     changed = true;
   }
   if (changed) {
     sectionContent.setTimestamp(timeService.getNowAsDateTime().toDate());
   }
 }
示例#3
0
  private void doExecuteApproveContentsInSectionCommand(
      final ApproveContentsInSectionCommand command) {
    Preconditions.checkNotNull(command.getSection(), "section cannot be null");
    Preconditions.checkNotNull(command.getApprover(), "approver cannot be null");
    Preconditions.checkNotNull(
        command.getContentsToApprove().size(), "no given content to approve in section");

    final MenuItemEntity section = doResolveSection(command.getSection());
    final UserEntity approver = doResolveUser(command.getApprover(), "approver");

    new MenuItemAccessResolver(groupDao)
        .checkAccessToApproveContentInSection(
            approver, section, "Cannot approve content in section.");

    final Set<SectionContentEntity> changedSectionContents = new HashSet<SectionContentEntity>();
    for (ContentKey contentKey : command.getContentsToApprove()) {
      final SectionContentEntity sectionContent = section.getSectionContent(contentKey);
      if (!sectionContent.isApproved()) {
        sectionContent.setApproved(true);
        changedSectionContents.add(sectionContent);
      }
    }

    // handle re-order command
    if (command.getOrderContentsInSectionCommand() != null) {
      if (section.isOrderedSection()) {
        changedSectionContents.addAll(
            new ContentsInSectionOrderer(
                    command.getOrderContentsInSectionCommand().getWantedOrder(),
                    section,
                    ORDER_SPACE)
                .order());
      }
    }

    // update timestamp of only those who have changed
    for (SectionContentEntity changedSectionContent : changedSectionContents) {
      changedSectionContent.setTimestamp(timeService.getNowAsDateTime().toDate());
    }

    for (ContentKey contentKey : command.getContentsToApprove()) {
      indexTransactionService.registerUpdate(contentKey, true);
    }
  }
示例#4
0
  private void doExecuteAddContentToSectionCommand(final AddContentToSectionCommand command) {
    Preconditions.checkNotNull(command, "a command is required");
    Preconditions.checkNotNull(
        command.getContributor(), "the command's contributor argument is required");
    Preconditions.checkNotNull(command.getContent(), "the command's content argument is required");
    Preconditions.checkNotNull(command.getSection(), "the command's section argument is required");
    if (!command.isApproveInSection()) {
      Preconditions.checkArgument(
          !command.isAddOnTop(), "no point in adding content to top when not approving");
    }

    final ContentEntity content = contentDao.findByKey(command.getContent());
    Preconditions.checkNotNull(content, "content does not exist: " + command.getContent());
    Preconditions.checkArgument(
        !content.isDeleted(), "content is deleted: " + command.getContent());

    final MenuItemEntity section = doResolveSection(command.getSection());
    if (!section.isOrderedSection()) {
      Preconditions.checkArgument(
          command.getOrderContentsInSectionCommand() == null,
          "section is not ordered, did not expect to get order specified in command");
    }

    final UserEntity contributor = doResolveUser(command.getContributor(), "contributor");
    final MenuItemAccessResolver menuItemAccessResolver = new MenuItemAccessResolver(groupDao);
    menuItemAccessResolver.checkAccessToAddContentToSection(
        contributor, section, "Cannot add content in section.");
    if (command.isApproveInSection()) {
      menuItemAccessResolver.checkAccessToApproveContentInSection(
          contributor, section, "Cannot approve content in section.");
    }

    if (section.isSection() && section.hasSectionContentTypeFilter()) {
      if (!section.supportsSectionContentType(content.getCategory().getContentType())) {
        throw new ContentTypeNotSupportedException(content.getCategory().getContentType(), section);
      }
    } else if (section.getType() == MenuItemType.PAGE
        && section.getPage().getTemplate().getContentTypes().size() > 0) {
      if (!section
          .getPage()
          .getTemplate()
          .supportsContentType(content.getCategory().getContentType())) {
        throw new ContentTypeNotSupportedException(content.getCategory().getContentType(), section);
      }
    }

    final SectionContentEntity sectionContent = new SectionContentEntity();
    sectionContent.setOrder(0);
    sectionContent.setContent(content);
    sectionContent.setMenuItem(section);
    sectionContent.setApproved(command.isApproveInSection());
    sectionContent.setTimestamp(timeService.getNowAsDateTime().toDate());
    if (command.isAddOnTop() && section.isOrderedSection()) {
      sectionContent.setOrder(resolveOrderValueForInsertOnTopOfApprovedContentInSection(section));
    }

    content.addSectionContent(sectionContent);
    sectionContentDao.getHibernateTemplate().flush();

    sectionContentDao
        .getHibernateTemplate()
        .getSessionFactory()
        .evictCollection(MenuItemEntity.class.getName() + ".sectionContents", section.getKey());
    if (!content.hasHome(section.getSite().getKey())) {
      doSetContentHome(content, section, null);
    }

    if (section.isOrderedSection()) {
      if (command.getOrderContentsInSectionCommand() != null) {
        // ensure section will have it's newly added content
        sectionContentDao.getHibernateTemplate().refresh(section);

        List<ContentKey> wantedOrder = command.getOrderContentsInSectionCommand().getWantedOrder();
        ContentsInSectionOrderer orderer =
            new ContentsInSectionOrderer(wantedOrder, section, ORDER_SPACE);
        orderer.order();
      }
    }

    indexTransactionService.registerUpdate(command.getContent(), true);
  }