Пример #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;
  }
Пример #2
0
  @Override
  public List<Document> getCategorizedDocuments(String token, String categoryId)
      throws RepositoryException, DatabaseException {
    log.debug("getCategorizedDocuments({}, {})", token, categoryId);
    List<Document> documents = new ArrayList<Document>();
    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(Document.TYPE)) {
            Document doc = BaseDocumentModule.getProperties(session, node);
            documents.add(doc);
          }
        }
      }
    } 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("getCategorizedDocuments: {}", documents);
    return documents;
  }