public String getFileURL(CoralSession coralSession, FileResource file) {
    Resource parent = file.getParent();
    while (parent != null && !(parent instanceof RootDirectoryResource)) {
      parent = parent.getParent();
    }
    if (parent == null) {
      throw new IllegalStateException("cannot determine root directory");
    }
    RootDirectoryResource rootDirectory = ((RootDirectoryResource) parent);

    while (parent != null && !(parent instanceof SiteResource)) {
      parent = parent.getParent();
    }
    if (parent == null) {
      throw new IllegalStateException("cannot determine site");
    }
    SiteResource site = (SiteResource) parent;

    if (rootDirectory.getExternal()) {
      String path = "";
      for (parent = file; parent != null; parent = parent.getParent()) {
        if (parent instanceof RootDirectoryResource) {
          break;
        } else {
          try {
            path = "/" + URLEncoder.encode(parent.getName(), LinkTool.PARAMETER_ENCODING) + path;
          } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      return buildPath(
          getContextURL(coralSession, site),
          "files",
          site.getName(),
          rootDirectory.getName(),
          path);
    } else {
      String path = "";
      for (parent = file; parent != null; parent = parent.getParent()) {
        if (parent instanceof RootDirectoryResource) {
          break;
        } else {
          path = "," + parent.getName() + path;
        }
      }
      path = "/" + rootDirectory.getName() + path;
      return buildPath(
          getApplicationURL(coralSession, site),
          "view/files.Download?path=" + path + "&file_id=" + file.getIdString());
    }
  }
예제 #2
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   try {
     SiteResource site = getSite();
     Role role = null;
     if (site != null) {
       CmsData cmsData = cmsDataFactory.getCmsData(context);
       if (!cmsData.isApplicationEnabled("statistics")) {
         logger.debug("Application 'statistics' not enabled in site");
         return false;
       }
       role = site.getAdministrator();
     } else {
       role = coralSession.getSecurity().getUniqueRole("cms.administrator");
     }
     return coralSession.getUserSubject().hasRole(role);
   } catch (ProcessingException e) {
     logger.error("Subject has no rights to view this screen", e);
     return false;
   }
 }
 protected String getContextURL(CoralSession coralSession, SiteResource site) {
   StringBuilder buff = new StringBuilder();
   final boolean secure = site.getRequiresSecureChannel();
   buff.append(secure ? "https" : "http").append(":");
   buff.append("//").append(getServer(coralSession, site));
   if (!secure && httpPort != HTTP_PORT_DEFAULT) {
     buff.append(':').append(httpPort);
   }
   if (secure && httpsPort != HTTPS_PORT_DEFAULT) {
     buff.append(':').append(httpsPort);
   }
   buff.append(context);
   return buff.toString();
 }
예제 #4
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);
    }
  }