コード例 #1
0
 /**
  * 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);
   }
 }
コード例 #2
0
 @Override
 protected SiteResource getSite(RewriteToViewResource resource) {
   Resource r = resource;
   while (r != null && !(r instanceof SiteResource)) {
     r = r.getParent();
   }
   return (SiteResource) r;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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);
   }
 }
コード例 #6
0
  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());
    }
  }
コード例 #7
0
  private void validateFixture(
      Implementation firstImpl, Implementation secondImpl, Implementation thirdImpl)
      throws Exception {
    expAttTable("string", "data", DataType.VARCHAR);
    if (firstImpl == Implementation.GENERIC) {
      expRow(first1.getId(), "a1", "foo");
      expRow(first2.getId(), "a1", "abab");
    }
    if (secondImpl == Implementation.GENERIC) {
      expRow(second1.getId(), "a1", "foo");
      expRow(second1.getId(), "a4", "f%");
      expRow(second2.getId(), "a1", "bam");
    }
    if (firstImpl == Implementation.GENERIC) {
      expRow(third1.getId(), "a1", "quux");
    }
    assertExpTable();

    expAttTable("integer", "data", DataType.INTEGER);
    if (firstImpl == Implementation.GENERIC) {
      expRow(first1.getId(), "a2", 7);
      expRow(first2.getId(), "a2", 9);
    }
    if (secondImpl == Implementation.GENERIC) {
      expRow(second1.getId(), "a2", 7);
      expRow(second2.getId(), "a2", 7);
    }
    if (firstImpl == Implementation.GENERIC) {
      expRow(third1.getId(), "a2", 11);
    }
    assertExpTable();

    expAttTable("resource", "ref", DataType.BIGINT);
    if (secondImpl == Implementation.GENERIC) {
      expRow(second1.getId(), "a3", first1.getId());
    }
    if (thirdImpl == Implementation.GENERIC) {
      expRow(third1.getId(), "a3", first1.getId());
    }
    assertExpTable();

    if (firstImpl == Implementation.TABULAR) {
      expTable(
          "first",
          nnCol("resource_id", DataType.BIGINT),
          col("a1_", DataType.VARCHAR),
          col("a2", DataType.INTEGER));
      expRow(first1.getId(), "foo", 7);
      expRow(first2.getId(), "abab", 9);
      expRow(third1.getId(), "quux", 11);
      assertExpTable();
    }

    if (secondImpl == Implementation.TABULAR) {
      expTable(
          "second",
          nnCol("resource_id", DataType.BIGINT),
          col("a1", DataType.VARCHAR),
          col("a2", DataType.INTEGER),
          col("a3", DataType.BIGINT),
          col("a4", DataType.VARCHAR));
      expRow(second1.getId(), "foo", 7, first1.getId(), "f%");
      expRow(second2.getId(), "bam", 7, null, null);
      assertExpTable();
    }

    if (thirdImpl == Implementation.TABULAR) {
      expTable("third", nnCol("resource_id", DataType.BIGINT), col("a3", DataType.BIGINT));
      expRow(third1.getId(), first1.getId());
      assertExpTable();
    }
  }
コード例 #8
0
 /**
  * Called when <code>Resource</code>'s data change.
  *
  * @param resource the resource that changed.
  */
 public void resourceDeleted(Resource resource) {
   deletedFeedsIds.add(resource.getIdObject());
 }
コード例 #9
0
ファイル: Statistics.java プロジェクト: Melzar/cyklotron
  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);
    }
  }