@Test public void testQueryLogs() { storage.append(jsonEntries); QueryBuilder queryBuilder = new AuditQueryBuilder(); List<LogEntry> logEntries = queryLogs(queryBuilder); assertEquals(2, logEntries.size()); queryBuilder.order(new OrderByExpr(new Reference(DirectoryAuditStorage.ID_COLUMN), true)); logEntries = queryLogs(queryBuilder); assertEquals(2, logEntries.size()); assertEquals("/My doc 2", logEntries.get(0).getDocPath()); queryBuilder = new AuditQueryBuilder(); queryBuilder.order(new OrderByExpr(new Reference(DirectoryAuditStorage.ID_COLUMN), false)); logEntries = queryLogs(queryBuilder); assertEquals(2, logEntries.size()); assertEquals("/My doc 1", logEntries.get(0).getDocPath()); queryBuilder.limit(1); logEntries = queryLogs(queryBuilder); assertEquals(1, logEntries.size()); assertEquals("/My doc 1", logEntries.get(0).getDocPath()); queryBuilder.offset(1); logEntries = queryLogs(queryBuilder); assertEquals(1, logEntries.size()); assertEquals("/My doc 2", logEntries.get(0).getDocPath()); }
protected List<String> queryLogs(QueryBuilder queryBuilder) { Map<String, Serializable> filter = new HashMap<>(); Set<String> fulltext = null; MultiExpression multiExpr = queryBuilder.predicate(); if (multiExpr.operator != Operator.AND) { throw new NuxeoException("Operator not supported: " + multiExpr.operator); } List<Predicate> predicateList = multiExpr.predicates; for (Predicate p : predicateList) { String rvalue; if (p.rvalue instanceof StringLiteral) { rvalue = ((StringLiteral) p.rvalue).asString(); } else { rvalue = p.rvalue.toString(); log.warn(String.format( "Scrolling audit logs with a query builder containing non-string literals is not supported: %s.", rvalue)); } filter.put(p.lvalue.toString(), rvalue); if (fulltext == null && Arrays.asList(Operator.LIKE, Operator.ILIKE).contains(p.operator)) { fulltext = Collections.singleton(JSON_COLUMN); } } Map<String, String> orderBy = queryBuilder.orders().stream().collect( Collectors.toMap(o -> o.reference.name, o -> o.isDescending ? "desc" : "asc")); int limit = (int) queryBuilder.limit(); int offset = (int) queryBuilder.offset(); Directory directory = getAuditDirectory(); try (Session session = directory.getSession()) { DocumentModelList jsonEntriesDocs = session.query(filter, fulltext, orderBy, false, limit, offset); String auditPropertyName = directory.getSchema() + ":" + JSON_COLUMN; return jsonEntriesDocs.stream() .map(doc -> doc.getPropertyValue(auditPropertyName)) .map(String::valueOf) .collect(Collectors.toList()); } }
DirectoryAuditStorage implements AuditStorage { protected List<String> queryLogs(QueryBuilder queryBuilder) { Map<String, Serializable> filter = new HashMap<>(); Set<String> fulltext = null; MultiExpression multiExpr = queryBuilder.predicate(); if (multiExpr.operator != Operator.AND) { throw new NuxeoException("Operator not supported: " + multiExpr.operator); } List<Predicate> predicateList = multiExpr.predicates; for (Predicate p : predicateList) { String rvalue; if (p.rvalue instanceof StringLiteral) { rvalue = ((StringLiteral) p.rvalue).asString(); } else { rvalue = p.rvalue.toString(); log.warn(String.format( "Scrolling audit logs with a query builder containing non-string literals is not supported: %s.", rvalue)); } filter.put(p.lvalue.toString(), rvalue); if (fulltext == null && Arrays.asList(Operator.LIKE, Operator.ILIKE).contains(p.operator)) { fulltext = Collections.singleton(JSON_COLUMN); } } Map<String, String> orderBy = queryBuilder.orders().stream().collect( Collectors.toMap(o -> o.reference.name, o -> o.isDescending ? "desc" : "asc")); int limit = (int) queryBuilder.limit(); int offset = (int) queryBuilder.offset(); Directory directory = getAuditDirectory(); try (Session session = directory.getSession()) { DocumentModelList jsonEntriesDocs = session.query(filter, fulltext, orderBy, false, limit, offset); String auditPropertyName = directory.getSchema() + ":" + JSON_COLUMN; return jsonEntriesDocs.stream() .map(doc -> doc.getPropertyValue(auditPropertyName)) .map(String::valueOf) .collect(Collectors.toList()); } } }
DirectoryAuditStorage implements AuditStorage { protected List<String> queryLogs(QueryBuilder queryBuilder) { Map<String, Serializable> filter = new HashMap<>(); Set<String> fulltext = null; MultiExpression multiExpr = queryBuilder.predicate(); if (multiExpr.operator != Operator.AND) { throw new NuxeoException("Operator not supported: " + multiExpr.operator); } List<Predicate> predicateList = multiExpr.predicates; for (Predicate p : predicateList) { String rvalue; if (p.rvalue instanceof StringLiteral) { rvalue = ((StringLiteral) p.rvalue).asString(); } else { rvalue = p.rvalue.toString(); log.warn(String.format( "Scrolling audit logs with a query builder containing non-string literals is not supported: %s.", rvalue)); } filter.put(p.lvalue.toString(), rvalue); if (fulltext == null && Arrays.asList(Operator.LIKE, Operator.ILIKE).contains(p.operator)) { fulltext = Collections.singleton(JSON_COLUMN); } } Map<String, String> orderBy = queryBuilder.orders().stream().collect( Collectors.toMap(o -> o.reference.name, o -> o.isDescending ? "desc" : "asc")); int limit = (int) queryBuilder.limit(); int offset = (int) queryBuilder.offset(); Directory directory = getAuditDirectory(); try (Session session = directory.getSession()) { DocumentModelList jsonEntriesDocs = session.query(filter, fulltext, orderBy, false, limit, offset); String auditPropertyName = directory.getSchema() + ":" + JSON_COLUMN; return jsonEntriesDocs.stream() .map(doc -> doc.getPropertyValue(auditPropertyName)) .map(String::valueOf) .collect(Collectors.toList()); } }  }
DirectoryAuditStorage implements AuditStorage { protected List<String> queryLogs(QueryBuilder queryBuilder) { Map<String, Serializable> filter = new HashMap<>(); Set<String> fulltext = null; MultiExpression multiExpr = queryBuilder.predicate(); if (multiExpr.operator != Operator.AND) { throw new NuxeoException("Operator not supported: " + multiExpr.operator); } List<Predicate> predicateList = multiExpr.predicates; for (Predicate p : predicateList) { String rvalue; if (p.rvalue instanceof StringLiteral) { rvalue = ((StringLiteral) p.rvalue).asString(); } else { rvalue = p.rvalue.toString(); log.warn(String.format( "Scrolling audit logs with a query builder containing non-string literals is not supported: %s.", rvalue)); } filter.put(p.lvalue.toString(), rvalue); if (fulltext == null && Arrays.asList(Operator.LIKE, Operator.ILIKE).contains(p.operator)) { fulltext = Collections.singleton(JSON_COLUMN); } } Map<String, String> orderBy = queryBuilder.orders().stream().collect( Collectors.toMap(o -> o.reference.name, o -> o.isDescending ? "desc" : "asc")); int limit = (int) queryBuilder.limit(); int offset = (int) queryBuilder.offset(); Directory directory = getAuditDirectory(); try (Session session = directory.getSession()) { DocumentModelList jsonEntriesDocs = session.query(filter, fulltext, orderBy, false, limit, offset); String auditPropertyName = directory.getSchema() + ":" + JSON_COLUMN; return jsonEntriesDocs.stream() .map(doc -> doc.getPropertyValue(auditPropertyName)) .map(String::valueOf) .collect(Collectors.toList()); } }  @Override void append(List<String> jsonEntries); @Override ScrollResult<String> scroll(String scrollId); @Override ScrollResult<String> scroll(QueryBuilder queryBuilder, int batchSize, int keepAlive); }
DirectoryAuditStorage implements AuditStorage { protected List<String> queryLogs(QueryBuilder queryBuilder) { Map<String, Serializable> filter = new HashMap<>(); Set<String> fulltext = null; MultiExpression multiExpr = queryBuilder.predicate(); if (multiExpr.operator != Operator.AND) { throw new NuxeoException("Operator not supported: " + multiExpr.operator); } List<Predicate> predicateList = multiExpr.predicates; for (Predicate p : predicateList) { String rvalue; if (p.rvalue instanceof StringLiteral) { rvalue = ((StringLiteral) p.rvalue).asString(); } else { rvalue = p.rvalue.toString(); log.warn(String.format( "Scrolling audit logs with a query builder containing non-string literals is not supported: %s.", rvalue)); } filter.put(p.lvalue.toString(), rvalue); if (fulltext == null && Arrays.asList(Operator.LIKE, Operator.ILIKE).contains(p.operator)) { fulltext = Collections.singleton(JSON_COLUMN); } } Map<String, String> orderBy = queryBuilder.orders().stream().collect( Collectors.toMap(o -> o.reference.name, o -> o.isDescending ? "desc" : "asc")); int limit = (int) queryBuilder.limit(); int offset = (int) queryBuilder.offset(); Directory directory = getAuditDirectory(); try (Session session = directory.getSession()) { DocumentModelList jsonEntriesDocs = session.query(filter, fulltext, orderBy, false, limit, offset); String auditPropertyName = directory.getSchema() + ":" + JSON_COLUMN; return jsonEntriesDocs.stream() .map(doc -> doc.getPropertyValue(auditPropertyName)) .map(String::valueOf) .collect(Collectors.toList()); } }  @Override void append(List<String> jsonEntries); @Override ScrollResult<String> scroll(String scrollId); @Override ScrollResult<String> scroll(QueryBuilder queryBuilder, int batchSize, int keepAlive); static final String NAME; static final String DIRECTORY_NAME; static final String ID_COLUMN; static final String JSON_COLUMN; }