/**
  * Creates a new <code>documents.document_alias</code> resource instance.
  *
  * @param session the CoralSession
  * @param name the name of the new resource
  * @param parent the parent resource.
  * @param originalDocument the originalDocument attribute
  * @param preferences the preferences attribute
  * @param site the site attribute
  * @param title the title attribute
  * @return a new DocumentAliasResource instance.
  * @throws ValueRequiredException if one of the required attribues is undefined.
  * @throws InvalidResourceNameException if the name argument contains illegal characters.
  */
 public static DocumentAliasResource createDocumentAliasResource(
     CoralSession session,
     String name,
     Resource parent,
     DocumentNodeResource originalDocument,
     Parameters preferences,
     SiteResource site,
     String title)
     throws ValueRequiredException, InvalidResourceNameException {
   try {
     ResourceClass<DocumentAliasResource> rc =
         session
             .getSchema()
             .getResourceClass("documents.document_alias", DocumentAliasResource.class);
     Map<AttributeDefinition<?>, Object> attrs = new HashMap<AttributeDefinition<?>, Object>();
     attrs.put(rc.getAttribute("originalDocument"), originalDocument);
     attrs.put(rc.getAttribute("preferences"), preferences);
     attrs.put(rc.getAttribute("site"), site);
     attrs.put(rc.getAttribute("title"), title);
     Resource res = session.getStore().createResource(name, parent, rc, attrs);
     if (!(res instanceof DocumentAliasResource)) {
       throw new BackendException(
           "incosistent schema: created object is " + res.getClass().getName());
     }
     return (DocumentAliasResource) res;
   } catch (EntityDoesNotExistException e) {
     throw new BackendException("incompatible schema change", e);
   }
 }
 /** Performs the action. */
 public void execute(
     Context context,
     Parameters parameters,
     MVCContext mvcContext,
     TemplatingContext templatingContext,
     CoralSession coralSession)
     throws ProcessingException {
   long resClassId = parameters.getLong("res_class_id", -1L);
   try {
     ResourceClass resourceClass = coralSession.getSchema().getResourceClass(resClassId);
     coralSession.getSchema().deleteResourceClass(resourceClass);
     parameters.remove("res_class_id");
   } catch (EntityDoesNotExistException e) {
     logger.error("ARLException: ", e);
     templatingContext.put("result", "exception");
     // context.put("trace",StringUtils.stackTrace(e));
     return;
   } catch (EntityInUseException e) {
     logger.error("ARLException: ", e);
     templatingContext.put("result", "exception");
     // context.put("trace",StringUtils.stackTrace(e));
     return;
   }
   templatingContext.put("result", "deleted_successfully");
 }
示例#3
0
 /** Performs the mainteance. */
 public void run(String[] args) {
   CoralSession coralSession = sessionFactory.getRootSession();
   try {
     execute(coralSession, args);
   } finally {
     coralSession.close();
   }
 }
示例#4
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);
    }
  }
示例#5
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   RequestParameters parameters = RequestParameters.getRequestParameters(context);
   try {
     NavigationNodeResource node = getCmsData(context).getNode();
     NavigationNodeResource originalNode =
         NavigationNodeResourceImpl.getNavigationNodeResource(
             coralSession, parameters.getLong("original_node_id"));
     Permission addInboundAlias =
         coralSession.getSecurity().getUniquePermission("cms.structure.add_inbound_alias");
     return node.canAddChild(coralSession, coralSession.getUserSubject())
         && coralSession.getUserSubject().hasPermission(originalNode, addInboundAlias);
   } catch (EntityDoesNotExistException e) {
     throw new ProcessingException("missing or invalid parameters", e);
   }
 }
  public ResourceClassResource[] getResourceClasses(
      CoralSession coralSession, Parameters parameters) throws ProcessingException {
    ResourceClassResource[] resClasses;
    if (parameters.isDefined("res_class_id")) {
      try {
        ArrayList resClassesTemp = new ArrayList();
        long[] resClassIds = parameters.getLongs("res_class_id");
        for (int i = 0; i < resClassIds.length; i++) {
          Resource resClass = coralSession.getStore().getResource(resClassIds[i]);
          if (resClass instanceof ResourceClassResource) {
            resClassesTemp.add(resClass);
          } else {
            // WARN: Malicious users
            throw new ProcessingException(
                "Cannot link arbitrary resources as resource class resources");
          }
        }

        resClasses = new ResourceClassResource[resClassesTemp.size()];
        for (int i = 0; i < resClasses.length; i++) {
          resClasses[i] = (ResourceClassResource) (resClassesTemp.get(i));
        }
      } catch (EntityDoesNotExistException e) {
        throw new ProcessingException("Cannot link not existing resource class resources");
      }
    } else {
      resClasses = new ResourceClassResource[0];
    }
    return resClasses;
  }
示例#7
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   Parameters parameters = RequestParameters.getRequestParameters(context);
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   try {
     long dirId = parameters.getLong("parent_id", -1);
     if (dirId == -1) {
       return true;
     } else {
       Resource resource = coralSession.getStore().getResource(dirId);
       Permission permission = coralSession.getSecurity().getUniquePermission("cms.files.write");
       return coralSession.getUserSubject().hasPermission(resource, permission);
     }
   } catch (Exception e) {
     logger.error("Subject has no rights to view this screen", e);
     return false;
   }
 }
示例#8
0
  /** Performs the feed updates. */
  public void execute(CoralSession coralSession, String[] args) {
    // prepare for feeds updates
    deletedFeedsIds.clear();
    coralSession.getEvent().addResourceDeletionListener(this, httpFeedResourceClass);

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();

    SiteResource[] sites = siteService.getSites(coralSession);
    for (int i = 0; i < sites.length; i++) {
      try {
        HttpFeedResource[] feeds = httpFeedService.getFeeds(coralSession, sites[i]);

        for (int j = 0; j < feeds.length; j++) {
          HttpFeedResource feed = feeds[j];

          // check if feed needs to be refreshed
          boolean makeRefresh = (feed.getFailedUpdates() > 0) || (feed.getLastUpdate() == null);
          if (!makeRefresh) {
            // calculate next update time
            cal.setTime(feed.getLastUpdate());
            cal.add(Calendar.MINUTE, feed.getInterval());
            Date nextUpdate = cal.getTime();

            makeRefresh = nextUpdate.before(now);
          }

          if (makeRefresh) {
            String content = httpFeedService.getContent(feed.getUrl());
            synchronized (feed) {
              if (!deletedFeedsIds.contains(feed.getIdObject())) {
                httpFeedService.refreshFeed(feed, content, coralSession.getUserSubject());
              }
            }
          }
        }
      } catch (HttpFeedException e) {
        log.error("Cannot get http feeds for the site '" + sites[i].getName() + "'", e);
      }
    }

    // cleanup after feed updates
    coralSession.getEvent().removeResourceDeletionListener(this, httpFeedResourceClass);
    deletedFeedsIds.clear();
  }
示例#9
0
 public UpdateFeeds(
     Logger logger,
     CoralSessionFactory sessionFactory,
     HttpFeedService httpFeedService,
     SiteService siteService) {
   this.log = logger;
   this.sessionFactory = sessionFactory;
   this.siteService = siteService;
   this.httpFeedService = httpFeedService;
   CoralSession coralSession = sessionFactory.getRootSession();
   try {
     httpFeedResourceClass =
         coralSession.getSchema().getResourceClass(HttpFeedResource.CLASS_NAME);
   } catch (EntityDoesNotExistException e) {
     throw new ComponentInitializationError(
         "Could not find '" + HttpFeedResource.CLASS_NAME + "' resource class");
   } finally {
     coralSession.close();
   }
 }
示例#10
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;
   }
 }
 /**
  * Creates a new <code>cms.confirmation.email_confirmation_request</code> resource instance.
  *
  * @param session the CoralSession
  * @param name the name of the new resource
  * @param parent the parent resource.
  * @param email the email attribute
  * @return a new EmailConfirmationRequestResource instance.
  * @throws ValueRequiredException if one of the required attribues is undefined.
  * @throws InvalidResourceNameException if the name argument contains illegal characters.
  */
 public static EmailConfirmationRequestResource createEmailConfirmationRequestResource(
     CoralSession session, String name, Resource parent, String email)
     throws ValueRequiredException, InvalidResourceNameException {
   try {
     ResourceClass<EmailConfirmationRequestResource> rc =
         session
             .getSchema()
             .getResourceClass(
                 "cms.confirmation.email_confirmation_request",
                 EmailConfirmationRequestResource.class);
     Map<AttributeDefinition<?>, Object> attrs = new HashMap<AttributeDefinition<?>, Object>();
     attrs.put(rc.getAttribute("email"), email);
     Resource res = session.getStore().createResource(name, parent, rc, attrs);
     if (!(res instanceof EmailConfirmationRequestResource)) {
       throw new BackendException(
           "incosistent schema: created object is " + res.getClass().getName());
     }
     return (EmailConfirmationRequestResource) res;
   } catch (EntityDoesNotExistException e) {
     throw new BackendException("incompatible schema change", e);
   }
 }
 /**
  * Retrieves a <code>cms.confirmation.email_confirmation_request</code> resource instance from the
  * store.
  *
  * <p>This is a simple wrapper of StoreService.getResource() method plus the typecast.
  *
  * @param session the CoralSession
  * @param id the id of the object to be retrieved
  * @return a resource instance.
  * @throws EntityDoesNotExistException if the resource with the given id does not exist.
  */
 public static EmailConfirmationRequestResource getEmailConfirmationRequestResource(
     CoralSession session, long id) throws EntityDoesNotExistException {
   Resource res = session.getStore().getResource(id);
   if (!(res instanceof EmailConfirmationRequestResource)) {
     throw new IllegalArgumentException(
         "resource #"
             + id
             + " is "
             + res.getResourceClass().getName()
             + " not cms.confirmation.email_confirmation_request");
   }
   return (EmailConfirmationRequestResource) res;
 }
 /**
  * Retrieves a <code>documents.document_alias</code> resource instance from the store.
  *
  * <p>This is a simple wrapper of StoreService.getResource() method plus the typecast.
  *
  * @param session the CoralSession
  * @param id the id of the object to be retrieved
  * @return a resource instance.
  * @throws EntityDoesNotExistException if the resource with the given id does not exist.
  */
 public static DocumentAliasResource getDocumentAliasResource(CoralSession session, long id)
     throws EntityDoesNotExistException {
   Resource res = session.getStore().getResource(id);
   if (!(res instanceof DocumentAliasResource)) {
     throw new IllegalArgumentException(
         "resource #"
             + id
             + " is "
             + res.getResourceClass().getName()
             + " not documents.document_alias");
   }
   return (DocumentAliasResource) res;
 }
示例#14
0
  /** Performs the action. */
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {
    Subject subject = coralSession.getUserSubject();
    Long parentNodeId = parameters.getLong("node_id", -1L);
    Long originalNodeId = parameters.getLong("original_node_id", -1L);
    String name = parameters.get("name", "");
    String title = parameters.get("title", "");

    if (parentNodeId == -1L || originalNodeId == -1L) {
      return;
    }

    try {
      NavigationNodeResource parent =
          (NavigationNodeResource) coralSession.getStore().getResource(parentNodeId);
      DocumentNodeResource originalDocument =
          (DocumentNodeResource) coralSession.getStore().getResource(originalNodeId);
      DocumentAliasResource node =
          structureService.addDocumentAlias(
              coralSession, originalDocument, name, title, parent, subject);
      parameters.set("node_id", node.getIdString());
    } catch (Exception e) {
      templatingContext.put("result", "exception");
      logger.error("StructureException: ", e);
      templatingContext.put("trace", new StackTrace(e));
      return;
    }
    cmsDataFactory.removeCmsData(context);
    templatingContext.put("result", "added_successeditfully");
  }
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {
    try {
      long groupId = parameters.getLong("group_id");
      RoleResource group = RoleResourceImpl.getRoleResource(coralSession, groupId);

      long[] roleIds = parameters.getLongs("role_id");
      Set<Role> roles = new HashSet<Role>();
      for (int i = 0; i < roleIds.length; i++) {
        roles.add(coralSession.getSecurity().getRole(roleIds[i]));
      }
      long[] selectedRoleIds = parameters.getLongs("selected_role_id");
      Set<Role> selectedRoles = new HashSet<Role>();
      for (int i = 0; i < selectedRoleIds.length; i++) {
        selectedRoles.add(coralSession.getSecurity().getRole(selectedRoleIds[i]));
      }
      RoleImplication[] roleImplications = group.getRole().getImplications();
      Set<Role> currentRoles = new HashSet<Role>();
      for (RoleImplication ri : roleImplications) {
        if (ri.getSuperRole().equals(group.getRole())) {
          currentRoles.add(ri.getSubRole());
        }
      }

      CoralSession rootCoralSession = sessionFactory.getRootSession();
      try {
        for (Role role : roles) {
          if (selectedRoles.contains(role)) {
            if (!currentRoles.contains(role)) {
              rootCoralSession.getSecurity().addSubRole(group.getRole(), role);
            }
          } else {
            if (currentRoles.contains(role)) {
              rootCoralSession.getSecurity().deleteSubRole(group.getRole(), role);
            }
          }
        }
      } finally {
        rootCoralSession.close();
      }
      templatingContext.put("result", "updated_successfully");
    } catch (Exception e) {
      templatingContext.put("result", "exception");
      templatingContext.put("trace", new StackTrace(e));
    }
  }
示例#16
0
  /** Performs the action. */
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {

    Subject subject = coralSession.getUserSubject();

    IndexResource index = getIndex(coralSession, parameters);
    try {
      searchService.getIndexingFacility().deleteDeleted(coralSession, index);
    } catch (SearchException e) {
      templatingContext.put("result", "exception");
      templatingContext.put("trace", new StackTrace(e));
      logger.error("problem incrementally cleaning up index '" + index.getIdString() + "'", e);
      return;
    }
    templatingContext.put("result", "cleaned_up_successfully");
  }
示例#17
0
  protected void fixture(
      Implementation firstImpl, Implementation secondImpl, Implementation thirdImpl)
      throws Exception {
    CoralSchema schema = coral.getSchema();
    AttributeClass<String> stringAttr = schema.getAttributeClass("string", String.class);
    AttributeClass<Integer> intAttr = schema.getAttributeClass("integer", Integer.class);
    AttributeClass<Resource> resourceAttr = schema.getAttributeClass("resource", Resource.class);

    CoralStore store = coral.getStore();
    Resource rootRes = store.getResource(CoralStore.ROOT_RESOURCE);
    Map<AttributeDefinition<?>, Object> attributes = new HashMap<AttributeDefinition<?>, Object>();

    ResourceClass<?> firstClass;
    AttributeDefinition<String> a1;
    AttributeDefinition<Integer> a2;
    AttributeDefinition<Resource> a3;

    firstClass =
        schema.createResourceClass(
            "first",
            firstImpl.getResClass().getName(),
            firstImpl.getHandlerClass().getName(),
            firstImpl == Implementation.TABULAR ? "first" : null,
            0);
    a1 = schema.createAttribute("a1", stringAttr, "a1_", null, 0);
    schema.addAttribute(firstClass, a1, null);
    a2 = schema.createAttribute("a2", intAttr, null, null, 0);
    schema.addAttribute(firstClass, a2, 0);

    attributes.clear();
    attributes.put(a1, "foo");
    attributes.put(a2, 7);
    first1 = store.createResource("first1", rootRes, firstClass, attributes);

    attributes.clear();
    attributes.put(a1, "abab");
    attributes.put(a2, 9);
    first2 = store.createResource("first2", rootRes, firstClass, attributes);

    ResourceClass<?> secondClass =
        schema.createResourceClass(
            "second",
            secondImpl.getResClass().getName(),
            secondImpl.getHandlerClass().getName(),
            secondImpl == Implementation.TABULAR ? "second" : null,
            0);
    a1 = schema.createAttribute("a1", stringAttr, null, null, 0);
    schema.addAttribute(secondClass, a1, null);
    a2 = schema.createAttribute("a2", intAttr, null, null, 0);
    schema.addAttribute(secondClass, a2, 0);
    a3 = schema.createAttribute("a3", resourceAttr, null, "first", 0);
    schema.addAttribute(secondClass, a3, null);
    AttributeDefinition<String> a4 = schema.createAttribute("a4", stringAttr, null, null, 0);
    schema.addAttribute(secondClass, a4, null);

    attributes.clear();
    attributes.put(a1, "foo");
    attributes.put(a2, 7);
    attributes.put(a3, first1);
    attributes.put(a4, "f%");
    second1 = store.createResource("second1", rootRes, secondClass, attributes);

    attributes.clear();
    attributes.put(a1, "bam");
    attributes.put(a2, 7);
    second2 = store.createResource("second2", rootRes, secondClass, attributes);

    ResourceClass<?> thirdClass =
        schema.createResourceClass(
            "third",
            thirdImpl.getResClass().getName(),
            thirdImpl.getHandlerClass().getName(),
            thirdImpl == Implementation.TABULAR ? "third" : null,
            0);
    a3 = schema.createAttribute("a3", resourceAttr, null, "first", 0);
    schema.addAttribute(thirdClass, a3, null);
    attributes.clear();
    schema.addParentClass(thirdClass, firstClass, attributes);
    a1 = firstClass.getAttribute("a1", String.class);
    a2 = firstClass.getAttribute("a2", Integer.class);

    attributes.put(a1, "quux");
    attributes.put(a2, 11);
    attributes.put(a3, first1);
    third1 = store.createResource("third1", rootRes, thirdClass, attributes);

    validateFixture(firstImpl, secondImpl, thirdImpl);
  }
示例#18
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   coral = coralSessionFactory.getRootSession();
   query = coral.getQuery();
 }
示例#19
0
 @Override
 public void tearDown() throws Exception {
   coral.close();
   super.tearDown();
 }
示例#20
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);
    }
  }