Ejemplo n.º 1
0
  /** Convert Row to QueryResult */
  private QueryResult queryRowResultDigester(Session session, Row row)
      throws javax.jcr.PathNotFoundException, javax.jcr.RepositoryException {
    String path = row.getValue(JcrConstants.JCR_PATH).getString();
    log.debug("queryRowResultDigester: {}", path);
    Node node = session.getRootNode().getNode(path.substring(1));
    QueryResult qr = new QueryResult();

    if (node.isNodeType(Document.CONTENT_TYPE)) {
      Document doc = BaseDocumentModule.getProperties(session, node.getParent());
      qr.setDocument(doc);
    } else if (node.isNodeType(Document.TYPE)) {
      Document doc = BaseDocumentModule.getProperties(session, node);

      try {
        if (node.getParent().isNodeType(Mail.TYPE)) {
          qr.setAttachment(doc);
        } else {
          qr.setDocument(doc);
        }
      } catch (javax.jcr.AccessDeniedException e) {
        qr.setDocument(doc);
      }
    } else if (node.isNodeType(Folder.TYPE)) {
      Folder fld = BaseFolderModule.getProperties(session, node);
      qr.setFolder(fld);
    } else if (node.isNodeType(Mail.TYPE)) {
      Mail mail = BaseMailModule.getProperties(session, node);
      qr.setMail(mail);
    }

    qr.setScore(row.getValue(JcrConstants.JCR_SCORE).getLong());
    Value excerpt = row.getValue("rep:excerpt(okm:content)");

    if (excerpt != null) {
      qr.setExcerpt(excerpt.getString());
    }

    return qr;
  }
Ejemplo n.º 2
0
  @Override
  public List<Mail> getCategorizedMails(String token, String categoryId)
      throws RepositoryException, DatabaseException {
    log.debug("getCategorizedMails({}, {})", token, categoryId);
    List<Mail> mails = new ArrayList<Mail>();
    Session session = null;

    try {
      if (token == null) {
        session = JCRUtils.getSession();
      } else {
        session = JcrSessionManager.getInstance().get(token);
      }

      Node category = session.getNodeByUUID(categoryId);

      for (PropertyIterator it = category.getReferences(); it.hasNext(); ) {
        Property refProp = it.nextProperty();

        if (com.openkm.bean.Property.CATEGORIES.equals(refProp.getName())) {
          Node node = refProp.getParent();

          if (node.isNodeType(Mail.TYPE)) {
            Mail mail = BaseMailModule.getProperties(session, node);
            mails.add(mail);
          }
        }
      }
    } catch (javax.jcr.RepositoryException e) {
      log.error(e.getMessage(), e);
      throw new RepositoryException(e.getMessage(), e);
    } finally {
      if (token == null) JCRUtils.logout(session);
    }

    log.debug("getCategorizedMails: {}", mails);
    return mails;
  }