@Override public void updateSearch(String token, QueryParams params) throws AccessDeniedException, RepositoryException, DatabaseException { log.debug("updateSearch({}, {})", token, params); Session session = null; if (Config.SYSTEM_READONLY) { throw new AccessDeniedException("System is in read-only mode"); } try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } params.setUser(session.getUserID()); QueryParamsDAO.update(params); // Activity log UserActivity.log( session.getUserID(), "UPDATE_SEARCH", params.getName(), null, params.toString()); } catch (javax.jcr.RepositoryException e) { throw new RepositoryException(e.getMessage(), e); } catch (DatabaseException e) { throw e; } finally { if (token == null) JCRUtils.logout(session); } log.debug("updateSearch: void"); }
@Override public ResultSet findSimpleQueryPaginated(String token, String statement, int offset, int limit) throws RepositoryException, DatabaseException { log.debug( "findSimpleQueryPaginated({}, {}, {}, {})", new Object[] {token, statement, offset, limit}); ResultSet rs = new ResultSet(); Session session = null; try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } rs = executeSimpleQuery(session, statement, offset, limit); } 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("findSimpleQueryPaginated: {}", rs); return rs; }
/** 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; }
/** Get keyword map */ private Map<String, Integer> getKeywordMapCached(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMapCached({}, {})", token, filter); HashMap<String, Integer> keywordMap = new HashMap<String, Integer>(); Session session = null; try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Collection<UserNodeKeywords> userDocKeywords = UserNodeKeywordsManager.get(session.getUserID()).values(); for (Iterator<UserNodeKeywords> kwIt = userDocKeywords.iterator(); kwIt.hasNext(); ) { Set<String> docKeywords = kwIt.next().getKeywords(); if (filter != null && docKeywords.containsAll(filter)) { for (Iterator<String> itDocKeywords = docKeywords.iterator(); itDocKeywords.hasNext(); ) { String keyword = itDocKeywords.next(); if (!filter.contains(keyword)) { Integer occurs = keywordMap.get(keyword) != null ? keywordMap.get(keyword) : 0; keywordMap.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("getKeywordMapCached: {}", keywordMap); return keywordMap; }
@Override public void deleteSearch(String token, long qpId) throws AccessDeniedException, RepositoryException, DatabaseException { log.debug("deleteSearch({}, {})", token, qpId); Session session = null; if (Config.SYSTEM_READONLY) { throw new AccessDeniedException("System is in read-only mode"); } try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } QueryParams qp = QueryParamsDAO.findByPk(qpId); QueryParamsDAO.delete(qpId); // Purge visited nodes table if (qp.isDashboard()) { DashboardDAO.deleteVisitedNodes(session.getUserID(), qp.getName()); } // Activity log UserActivity.log(session.getUserID(), "DELETE_SAVED_SEARCH", Long.toString(qpId), null, null); } catch (DatabaseException e) { log.warn(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } 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("deleteSearch: void"); }
@Override public QueryParams getSearch(String token, int qpId) throws PathNotFoundException, RepositoryException, DatabaseException { log.debug("getSearch({}, {})", token, qpId); QueryParams qp = new QueryParams(); Session session = null; try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } qp = QueryParamsDAO.findByPk(qpId); // If this is a dashboard user search, dates are used internally if (qp.isDashboard()) { qp.setLastModifiedFrom(null); qp.setLastModifiedTo(null); } // Activity log UserActivity.log( session.getUserID(), "GET_SAVED_SEARCH", Integer.toString(qpId), null, qp.toString()); } catch (javax.jcr.PathNotFoundException e) { log.warn(e.getMessage(), e); throw new PathNotFoundException(e.getMessage(), e); } 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("getSearch: {}", qp); return qp; }
@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; }
@Override public List<QueryParams> getAllSearchs(String token) throws RepositoryException, DatabaseException { log.debug("getAllSearchs({})", token); List<QueryParams> ret = new ArrayList<QueryParams>(); Session session = null; try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } List<QueryParams> qParams = QueryParamsDAO.findByUser(session.getUserID()); for (Iterator<QueryParams> it = qParams.iterator(); it.hasNext(); ) { QueryParams qp = it.next(); if (!qp.isDashboard()) { ret.add(qp); } } // Activity log UserActivity.log(session.getUserID(), "GET_ALL_SEARCHS", null, null, null); } catch (javax.jcr.RepositoryException e) { throw new RepositoryException(e.getMessage(), e); } catch (DatabaseException e) { throw e; } finally { if (token == null) JCRUtils.logout(session); } log.debug("getAllSearchs: {}", ret); return ret; }
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; }