@Test
  public void canLogMultipleLifecycleTransitionsInSameTx() throws ClientException {
    // generate events
    DocumentModel doc = repo.createDocumentModel("/", "a-file", "File");
    doc = repo.createDocument(doc);
    String initialLifeCycle = doc.getCurrentLifeCycleState();
    doc.followTransition(LifeCycleConstants.DELETE_TRANSITION);
    String deletedLifeCycle = doc.getCurrentLifeCycleState();
    doc.followTransition(LifeCycleConstants.UNDELETE_TRANSITION);
    String undeletedLifeCycle = doc.getCurrentLifeCycleState();
    TransactionHelper.commitOrRollbackTransaction();
    Framework.getLocalService(EventService.class).waitForAsyncCompletion();

    // test audit trail
    AuditReader reader = Framework.getLocalService(AuditReader.class);
    List<LogEntry> trail = reader.getLogEntriesFor(doc.getId());

    assertThat(trail, notNullValue());
    assertThat(trail.size(), is(3));

    boolean seenDocCreated = false;
    boolean seenDocDeleted = false;
    boolean seenDocUndeleted = false;

    for (LogEntry entry : trail) {
      String lifeCycle = entry.getDocLifeCycle();
      String id = entry.getEventId();
      if (DocumentEventTypes.DOCUMENT_CREATED.equals(id)) {
        if (initialLifeCycle.equals(lifeCycle)) {
          seenDocCreated = true;
        }
      } else if (LifeCycleConstants.TRANSITION_EVENT.equals(id)) {
        if (undeletedLifeCycle.equals(lifeCycle)) {
          seenDocUndeleted = true;
        } else if (deletedLifeCycle.equals(lifeCycle)) {
          seenDocDeleted = true;
        }
      }
    }

    assertThat(seenDocUndeleted, is(true));
    assertThat(seenDocDeleted, is(true));
    assertThat(seenDocCreated, is(true));
  }
Beispiel #2
0
 @Override
 protected void writeEntityBody(JsonGenerator jg, LogEntry logEntry) throws IOException {
   jg.writeStringField("entity-type", "logEntry");
   jg.writeStringField("category", logEntry.getCategory());
   jg.writeStringField("principalName", logEntry.getPrincipalName());
   jg.writeStringField("comment", logEntry.getComment());
   jg.writeStringField("docLifeCycle", logEntry.getDocLifeCycle());
   jg.writeStringField("docPath", logEntry.getDocPath());
   jg.writeStringField("docType", logEntry.getDocType());
   jg.writeStringField("docUUID", logEntry.getDocUUID());
   jg.writeStringField("eventId", logEntry.getEventId());
   jg.writeStringField("repositoryId", logEntry.getRepositoryId());
   jg.writeStringField(
       "eventDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getEventDate())));
   jg.writeNumberField("id", logEntry.getId());
   jg.writeStringField(
       "logDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getLogDate())));
   writeExtendedInfos(jg, logEntry);
 }