protected LogEntry doCreateEntry(String docId, String eventId, String category) {
    LogEntry createdEntry = new LogEntryImpl();
    createdEntry.setEventId(eventId);
    createdEntry.setCategory(category);
    createdEntry.setDocUUID(docId);
    createdEntry.setEventDate(new Date());
    createdEntry.setDocPath("/" + docId);
    createdEntry.setRepositoryId("test");
    createdEntry.setExtendedInfos(createExtendedInfos());

    return createdEntry;
  }
Esempio n. 2
0
  @Test
  public void shouldFilterLogEntriesOnMultipleCriteria() throws Exception {
    DocumentModel doc = RestServerInit.getFile(1, session);

    DateTime firstDate = new DateTime();
    DateTime secondDate = firstDate.plusDays(10);

    List<LogEntry> logEntries = new ArrayList<>();
    LogEntry logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("firstEvent");
    logEntry.setPrincipalName("bender");
    logEntry.setEventDate(firstDate.toDate());
    logEntries.add(logEntry);
    logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("secondEvent");
    logEntry.setPrincipalName("leela");
    logEntry.setEventDate(firstDate.toDate());
    logEntries.add(logEntry);
    logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("firstEvent");
    logEntry.setPrincipalName("leela");
    logEntry.setEventDate(secondDate.toDate());
    logEntries.add(logEntry);
    logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("thirdEvent");
    logEntry.setPrincipalName("leela");
    logEntry.setEventDate(secondDate.toDate());
    logEntries.add(logEntry);
    auditLogger.addLogEntries(logEntries);

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.putSingle("category", "One");
    queryParams.add("principalName", "leela");
    ClientResponse response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    JsonNode node = mapper.readTree(response.getEntityInputStream());
    List<JsonNode> nodes = getLogEntries(node);
    assertEquals(3, nodes.size());

    queryParams = new MultivaluedMapImpl();
    queryParams.putSingle("category", "One");
    queryParams.add("principalName", "leela");
    queryParams.add("eventId", "thirdEvent");
    response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    node = mapper.readTree(response.getEntityInputStream());
    nodes = getLogEntries(node);
    assertEquals(1, nodes.size());

    queryParams = new MultivaluedMapImpl();
    queryParams.putSingle("category", "One");
    queryParams.add("principalName", "leela");
    queryParams.add("eventId", "thirdEvent");
    queryParams.add("startEventDate", ISODateTimeFormat.date().print(firstDate.plusDays(1)));
    queryParams.add("endEventDate", ISODateTimeFormat.date().print(secondDate.minus(1)));
    response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    node = mapper.readTree(response.getEntityInputStream());
    nodes = getLogEntries(node);
    assertEquals(0, nodes.size());
  }