/**
   * Convert an old {@link ActivityEvent} to the new {@link Event}.
   *
   * @param e the activity event to transform
   * @return the equivalent event
   */
  private Event convertActivityToEvent(ActivityEvent e) {
    Event result = this.eventFactory.createRawEvent();
    result.setApplication(e.getApplication());
    result.setBody(e.getBody());
    result.setDate(e.getDate());
    result.setDocument(
        new DocumentReference(this.resolver.resolve(e.getPage(), EntityType.DOCUMENT)));
    result.setId(e.getEventId());
    result.setDocumentTitle(e.getParam1());
    if (StringUtils.isNotEmpty(e.getParam2())) {
      if (StringUtils.endsWith(e.getType(), "Attachment")) {
        result.setRelatedEntity(
            this.explicitResolver.resolve(
                e.getParam2(), EntityType.ATTACHMENT, result.getDocument()));
      } else if (StringUtils.endsWith(e.getType(), "Comment")
          || StringUtils.endsWith(e.getType(), "Annotation")) {
        result.setRelatedEntity(
            this.explicitResolver.resolve(e.getParam2(), EntityType.OBJECT, result.getDocument()));
      }
    }
    result.setImportance(Event.Importance.MEDIUM);
    if (e.getPriority() > 0) {
      int priority = e.getPriority() / 10 - 1;
      if (priority >= 0 && priority < Event.Importance.values().length) {
        result.setImportance(Event.Importance.values()[priority]);
      }
    }

    result.setGroupId(e.getRequestId());
    result.setStream(e.getStream());
    result.setTitle(e.getTitle());
    result.setType(e.getType());
    if (StringUtils.isNotBlank(e.getUrl())) {
      try {
        result.setUrl(new URL(e.getUrl()));
      } catch (MalformedURLException ex) {
        // Should not happen
      }
    }
    result.setUser(new DocumentReference(this.resolver.resolve(e.getUser(), EntityType.DOCUMENT)));
    result.setDocumentVersion(e.getVersion());

    result.setParameters(e.getParameters());
    return result;
  }
  /**
   * Converts a new {@link Event} to the old {@link ActivityEvent}.
   *
   * @param e the event to transform
   * @return the equivalent activity event
   */
  private ActivityEvent convertEventToActivity(Event e) {
    ActivityEvent result = new ActivityEventImpl();
    result.setApplication(e.getApplication());
    result.setBody(e.getBody());
    result.setDate(e.getDate());
    result.setEventId(e.getId());
    result.setPage(this.serializer.serialize(e.getDocument()));
    if (e.getDocumentTitle() != null) {
      result.setParam1(e.getDocumentTitle());
    }
    if (e.getRelatedEntity() != null) {
      result.setParam2(this.serializer.serialize(e.getRelatedEntity()));
    }
    result.setPriority((e.getImportance().ordinal() + 1) * 10);

    result.setRequestId(e.getGroupId());
    result.setSpace(this.localSerializer.serialize(e.getSpace()));
    result.setStream(e.getStream());
    result.setTitle(e.getTitle());
    result.setType(e.getType());
    if (e.getUrl() != null) {
      result.setUrl(e.getUrl().toString());
    }
    result.setUser(this.serializer.serialize(e.getUser()));
    result.setVersion(e.getDocumentVersion());
    result.setWiki(this.serializer.serialize(e.getWiki()));

    result.setParameters(e.getParameters());

    return result;
  }