Example #1
0
  public void process(
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      I18nContext i18nContext,
      CoralSession coralSession)
      throws ProcessingException {
    try {
      CmsData cmsData = cmsDataFactory.getCmsData(context);
      Parameters config = cmsData.getComponent().getConfiguration();
      CategoryQueryResource includeQuery = myDocumentsImpl.getQueryResource("include", config);
      CategoryQueryResource excludeQuery = myDocumentsImpl.getQueryResource("exclude", config);
      String whereClause = "created_by = " + coralSession.getUserSubject().getIdString();

      TableModel<DocumentNodeResource> model;
      if (includeQuery == null) {
        model = myDocumentsImpl.siteBasedModel(cmsData, i18nContext.get(), whereClause);
      } else {
        model =
            myDocumentsImpl.queryBasedModel(
                includeQuery, excludeQuery, cmsData, i18nContext.get(), whereClause);
      }

      List<TableFilter<? super DocumentNodeResource>> filters =
          myDocumentsImpl.excludeStatesFilter("expired");

      TableState state =
          tableStateManager.getState(
              context,
              this.getClass().getName()
                  + ":"
                  + cmsData.getNode().getIdString()
                  + ":"
                  + cmsData.getComponent().getInstanceName());
      if (state.isNew()) {
        state.setTreeView(false);
        state.setSortColumnName(config.get("sort_column", "creation.time"));
        state.setAscSort(config.getBoolean("sort_dir", false));
        state.setPageSize(config.getInt("page_size", 5));
      }
      templatingContext.put("table", new TableTool<DocumentNodeResource>(state, filters, model));
      templatingContext.put("documentState", new DocumentStateTool(coralSession, logger));
      templatingContext.put("header", config.get("header", ""));
      final long moreNodeId = config.getLong("more_node_id", -1l);
      if (moreNodeId != -1l) {
        templatingContext.put("moreNode", coralSession.getStore().getResource(moreNodeId));
      }
    } catch (Exception e) {
      throw new ProcessingException("internal errror", e);
    }
  }
 public void prepareDefault(Context context) throws ProcessingException {
   Parameters parameters = RequestParameters.getRequestParameters(context);
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   HttpContext httpContext = HttpContext.getHttpContext(context);
   I18nContext i18nContext = I18nContext.getI18nContext(context);
   TemplatingContext templatingContext = TemplatingContext.getTemplatingContext(context);
   SiteResource site = getSite();
   try {
     templatingContext.put("styles", Arrays.asList(styleService.getStyles(coralSession, site)));
     long parent_node_id = parameters.getLong("parent_node_id", -1);
     if (parent_node_id == -1) {
       templatingContext.put("parent_node", getHomePage());
     } else {
       templatingContext.put(
           "parent_node",
           NavigationNodeResourceImpl.getNavigationNodeResource(coralSession, parent_node_id));
     }
   } catch (Exception e) {
     throw new ProcessingException("Screen Error " + e);
   }
 }
Example #3
0
  public void process(
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      I18nContext i18nContext,
      CoralSession coralSession)
      throws ProcessingException {
    SimpleDateFormat df = new SimpleDateFormat(DateAttributeHandler.DATE_TIME_FORMAT);
    Resource[] states =
        coralSession
            .getStore()
            .getResourceByPath("/cms/workflow/automata/structure.navigation_node/states/*");
    templatingContext.put("states", states);

    SiteResource site = getSite();
    //      categories
    CategoryQueryResourceData queryData = CategoryQueryResourceData.getData(httpContext, null);
    templatingContext.put("query_data", queryData);
    Set<Long> expandedCategoriesIds = new HashSet<Long>();
    // setup pool data and table data
    if (queryData.isNew()) {
      queryData.init(coralSession, null, categoryQueryService, integrationService);
      // prepare expanded categories - includes inherited ones
      Map initialState = queryData.getCategoriesSelection().getEntities(coralSession);
      for (Iterator i = initialState.keySet().iterator(); i.hasNext(); ) {
        CategoryResource category = (CategoryResource) (i.next());
        CategoryResource[] cats = categoryService.getImpliedCategories(category, true);
        for (int j = 0; j < cats.length; j++) {
          expandedCategoriesIds.add(cats[j].getIdObject());
        }
      }
    } else {
      queryData.update(parameters);
    }

    // categories
    prepareGlobalCategoriesTableTool(
        coralSession, templatingContext, i18nContext, expandedCategoriesIds, false);
    prepareSiteCategoriesTableTool(
        coralSession, templatingContext, i18nContext, expandedCategoriesIds, site, false);
    templatingContext.put(
        "category_tool", new CategoryInfoTool(context, integrationService, categoryService));

    if (parameters.get("show", "").length() == 0) {
      return;
    }

    CategoryQueryBuilder parsedQuery =
        new CategoryQueryBuilder(
            coralSession, queryData.getCategoriesSelection(), queryData.useIdsAsIdentifiers());
    templatingContext.put("parsed_query", parsedQuery);

    Resource state = null;
    Date validityStart = null;
    Date validityEnd = null;
    Date createdStart = null;
    Date createdEnd = null;
    Subject creator = null;

    // prepare the conditions...
    if (parameters.get("validity_start", "").length() > 0) {
      validityStart = new Date(parameters.getLong("validity_start"));
      templatingContext.put("validity_start", validityStart);
    }
    if (parameters.get("validity_end", "").length() > 0) {
      validityEnd = new Date(parameters.getLong("validity_end"));
      templatingContext.put("validity_end", validityEnd);
    }
    if (parameters.get("created_start", "").length() > 0) {
      createdStart = new Date(parameters.getLong("created_start"));
      templatingContext.put("created_start", createdStart);
    }
    if (parameters.get("created_end", "").length() > 0) {
      createdEnd = new Date(parameters.getLong("created_end"));
      templatingContext.put("created_end", createdEnd);
    }
    String createdBy = parameters.get("created_by", "");
    long stateId = parameters.getLong("selected_state", -1);
    boolean selectedCategory = false;
    HashSet<Resource> fromCategorySet = new HashSet<Resource>();
    int counter = 0;
    try {
      if (stateId != -1) {
        state = coralSession.getStore().getResource(stateId);
        templatingContext.put("selected_state", state);
      }
      String catQuery = parsedQuery.getQuery();
      if (catQuery != null && catQuery.length() > 0) {
        selectedCategory = true;
        try {
          Resource[] docs = categoryQueryService.forwardQuery(coralSession, catQuery);
          for (Resource doc : docs) {
            fromCategorySet.add(doc);
          }
        } catch (Exception e) {
          throw new ProcessingException("failed to execute category query", e);
        }
      }

      /**
       * if (parameters.get("category_id","").length() > 0) { long categoryId =
       * parameters.getLong("category_id", -1); category =
       * CategoryResourceImpl.getCategoryResource(coralSession, categoryId);
       * templatingContext.put("category", category); }
       */
      if (createdBy.length() > 0) {
        try {
          String dn = userManager.getUserByLogin(createdBy).getName();
          creator = coralSession.getSecurity().getSubject(dn);
          templatingContext.put("created_by", createdBy);
        } catch (Exception e) {
          // do nothing...or maybe report that user is unknown!
          templatingContext.put("result", "unknown_user");
        }
      }
    } catch (Exception e) {
      throw new ProcessingException("Exception occured during query preparation");
    }

    boolean nextCondition = false;
    StringBuilder sb = new StringBuilder("FIND RESOURCE FROM documents.document_node");
    if (site != null) {
      nextCondition = true;
      sb.append(" WHERE site = ");
      sb.append(site.getIdString());
    }

    if (state != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("state = " + state.getIdString());
      nextCondition = true;
    }

    if (creator != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("created_by = " + creator.getIdString());
      nextCondition = true;
    }

    if (validityStart != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("validityStart > '" + df.format(validityStart) + "'");
      nextCondition = true;
    }
    if (validityEnd != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("validityStart < '" + df.format(validityEnd) + "'");
      nextCondition = true;
    }
    if (createdStart != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("creation_time > '" + df.format(createdStart) + "'");
      nextCondition = true;
    }
    if (createdEnd != null) {
      if (nextCondition) {
        sb.append(" AND ");
      } else {
        sb.append(" WHERE ");
      }
      sb.append("creation_time < '" + df.format(createdEnd) + "'");
      nextCondition = true;
    }
    String query = sb.toString();
    templatingContext.put("query", query);
    try {
      QueryResults results = coralSession.getQuery().executeQuery(query);
      List<NavigationNodeResource> nodes = (List<NavigationNodeResource>) results.getList(1);
      if (selectedCategory) {
        nodes.retainAll(fromCategorySet);
      }
      templatingContext.put("counter", nodes.size());

      if (site != null) {
        Map<Subject, StatisticsItem> statistics = new HashMap<Subject, StatisticsItem>();
        for (NavigationNodeResource node : nodes) {
          updateStatistics(statistics, node);
        }

        TableModel<StatisticsItem> model =
            new ListTableModel<StatisticsItem>(
                new ArrayList<StatisticsItem>(statistics.values()),
                new BeanTableColumn<StatisticsItem>(
                    StatisticsItem.class, "subject", new NameComparator(i18nContext.getLocale())),
                new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "redactorCount"),
                new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "acceptorCount"),
                new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "editorCount"),
                new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "creatorCount"));

        final Role teamMember = site.getTeamMember();
        TableFilter<StatisticsItem> teamMemberFilter =
            new TableFilter<StatisticsItem>() {
              @Override
              public boolean accept(StatisticsItem item) {
                return item.getSubject().hasRole(teamMember);
              }
            };

        TableState teamState = tableStateManager.getState(context, getClass().getName() + "$team");
        if (teamState.isNew()) {
          teamState.setSortColumnName("subject");
          teamState.setPageSize(0);
        }
        List<TableFilter<StatisticsItem>> filters = new ArrayList<TableFilter<StatisticsItem>>();
        filters.add(teamMemberFilter);
        TableTool<StatisticsItem> teamTable =
            new TableTool<StatisticsItem>(teamState, filters, model);
        templatingContext.put("teamTable", teamTable);

        TableState nonTeamState =
            tableStateManager.getState(context, getClass().getName() + "$nonteam");
        if (nonTeamState.isNew()) {
          nonTeamState.setSortColumnName("subject");
          nonTeamState.setPageSize(0);
        }
        filters.clear();
        filters.add(new InverseFilter<StatisticsItem>(teamMemberFilter));
        TableTool<StatisticsItem> nonTeamTable =
            new TableTool<StatisticsItem>(nonTeamState, filters, model);
        templatingContext.put("nonTeamTable", nonTeamTable);

        StatisticsItem teamTotals = new StatisticsItem(null);
        StatisticsItem nonTeamTotals = new StatisticsItem(null);
        calculateTotals(statistics, teamMember, teamTotals, nonTeamTotals);
        templatingContext.put("teamTotals", teamTotals);
        templatingContext.put("nonTeamTotals", nonTeamTotals);
      }
    } catch (Exception e) {
      throw new ProcessingException("Exception occured during query execution", e);
    }
  }
Example #4
0
 /**
  * Create CAPTCHA widget with current locale and specified options.
  *
  * @return HTML markup of CAPTCHA widget.
  */
 public String createCaptchaWidget(Map<String, String> options) {
   I18nContext i18nContext = context.getAttribute(I18nContext.class);
   Locale locale = i18nContext != null ? i18nContext.getLocale() : null;
   return captchaService.createCaptchaWidget(locale, options);
 }