/** TODO: Not fully implemented SEE: DirectSearchModule.getKeywordMapLive() */ public static synchronized void refreshUserDocKeywords(Session session) throws RepositoryException { log.info("refreshUserDocKeywords({})", session); String statement = "/jcr:root/" + Repository.ROOT + "/element(*,okm:document)"; try { Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.XPATH); javax.jcr.query.QueryResult qResult = query.execute(); Map<String, Set<String>> userDocKeywords = new HashMap<String, Set<String>>(); for (NodeIterator nit = qResult.getNodes(); nit.hasNext(); ) { Node docNode = nit.nextNode(); Value[] keywords = docNode.getProperty(Property.KEYWORDS).getValues(); Set<String> keywordSet = new HashSet<String>(); for (int i = 0; i < keywords.length; i++) { keywordSet.add(keywords[i].getString()); } userDocKeywords.put(docNode.getUUID(), keywordSet); } // userDocumentKeywordsMgr.put(session.getUserID(), userDocKeywords); } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } log.info("refreshUserDocKeywords: void"); }
/** Get keyword map */ private Map<String, Integer> getKeywordMapLive(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMapLive({}, {})", token, filter); String statement = "/jcr:root//*[@jcr:primaryType eq 'okm:document' or @jcr:primaryType eq 'okm:mail' or @jcr:primaryType eq 'okm:folder']"; HashMap<String, Integer> cloud = new HashMap<String, Integer>(); Session session = null; try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.XPATH); javax.jcr.query.QueryResult qResult = query.execute(); for (NodeIterator nit = qResult.getNodes(); nit.hasNext(); ) { Node doc = nit.nextNode(); Value[] keywordsValue = doc.getProperty(com.openkm.bean.Property.KEYWORDS).getValues(); ArrayList<String> keywordCollection = new ArrayList<String>(); for (int i = 0; i < keywordsValue.length; i++) { keywordCollection.add(keywordsValue[i].getString()); } if (filter != null && keywordCollection.containsAll(filter)) { for (Iterator<String> it = keywordCollection.iterator(); it.hasNext(); ) { String keyword = it.next(); if (!filter.contains(keyword)) { Integer occurs = cloud.get(keyword) != null ? cloud.get(keyword) : 0; cloud.put(keyword, occurs + 1); } } } } } 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("getKeywordMapLive: {}", cloud); return cloud; }
public ResultSet findByStatementPaginated( String token, String statement, String type, int offset, int limit) throws RepositoryException, DatabaseException { log.debug( "findByStatement({}, {}, {}, {}, {})", new Object[] {token, statement, type, offset, limit}); ResultSet rs = new ResultSet(); Session session = null; try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } if (statement != null && !statement.equals("")) { Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, type); rs = executeQuery(session, query, offset, limit); } // Activity log UserActivity.log( session.getUserID(), "FIND_BY_STATEMENT", null, null, type + ", " + statement); } 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("findByStatement: {}", rs); return rs; }