Skip to content

Commit

Permalink
JAMES-2813 DTO <-> domain object must be a bijection for jackson to work
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler authored and blackheaven committed Nov 12, 2019
1 parent 7464ff8 commit 7580bd4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ public List<Long> getUids() {
}

public static class ReprocessingContextInformationForErrorRecoveryIndexationTask extends ReprocessingContextInformation {
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForErrorRecoveryIndexationTask, ReprocessingContextInformationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) {

public static class DTO extends ReprocessingContextInformationDTO {

DTO(@JsonProperty("type") String type,
@JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount,
@JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount,
@JsonProperty("failures") List<ReindexingFailureDTO> failures,
@JsonProperty("timestamp") Instant timestamp) {
super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp);
}
}

public static final AdditionalInformationDTOModule<ReprocessingContextInformationForErrorRecoveryIndexationTask, DTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
return DTOModule.forDomainObject(ReprocessingContextInformationForErrorRecoveryIndexationTask.class)
.convertToDTO(ReprocessingContextInformationDTO.class)
.convertToDTO(DTO.class)
.toDomainObjectConverter(dto -> new ReprocessingContextInformationForErrorRecoveryIndexationTask(
dto.successfullyReprocessedMailCount,
dto.failedReprocessedMailCount,
deserializeFailures(mailboxIdFactory, dto.failures),
dto.getTimestamp()))
.toDTOConverter((details, type) -> new ReprocessingContextInformationDTO(
.toDTOConverter((details, type) -> new DTO(
type,
details.getSuccessfullyReprocessedMailCount(),
details.getFailedReprocessedMailCount(),
Expand All @@ -82,11 +94,23 @@ public static final AdditionalInformationDTOModule<ReprocessingContextInformatio
}

public static class ReprocessingContextInformationForFullReindexingTask extends ReprocessingContextInformation {
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForFullReindexingTask, ReprocessingContextInformationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) {

public static class DTO extends ReprocessingContextInformationDTO {

DTO(@JsonProperty("type") String type,
@JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount,
@JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount,
@JsonProperty("failures") List<ReindexingFailureDTO> failures,
@JsonProperty("timestamp") Instant timestamp) {
super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp);
}
}

public static final AdditionalInformationDTOModule<ReprocessingContextInformationForFullReindexingTask, DTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
return DTOModule.forDomainObject(ReprocessingContextInformationForFullReindexingTask.class)
.convertToDTO(ReprocessingContextInformationDTO.class)
.convertToDTO(DTO.class)
.toDomainObjectConverter(dto -> new ReprocessingContextInformationForFullReindexingTask(dto.successfullyReprocessedMailCount, dto.failedReprocessedMailCount, deserializeFailures(mailboxIdFactory, dto.failures), dto.getTimestamp()))
.toDTOConverter((details, type) -> new ReprocessingContextInformationDTO(
.toDTOConverter((details, type) -> new DTO(
type,
details.getSuccessfullyReprocessedMailCount(),
details.getFailedReprocessedMailCount(),
Expand Down Expand Up @@ -144,11 +168,11 @@ private static ImmutableList<Long> extractMessageUidsFromFailure(Map.Entry<Mailb
.collect(Guavate.toImmutableList());
}

private final String type;
private final int successfullyReprocessedMailCount;
private final int failedReprocessedMailCount;
private final List<ReindexingFailureDTO> failures;
private final Instant timestamp;
protected final String type;
protected final int successfullyReprocessedMailCount;
protected final int failedReprocessedMailCount;
protected final List<ReindexingFailureDTO> failures;
protected final Instant timestamp;


ReprocessingContextInformationDTO(@JsonProperty("type") String type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@

public class EventDeadLettersRedeliveryTaskAdditionalInformationDTO implements AdditionalInformationDTO {
public static class EventDeadLettersRedeliveryTaskAdditionalInformationForAll extends EventDeadLettersRedeliveryTaskAdditionalInformation {
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForAll, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =

public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
public DTO(@JsonProperty("type") String type,
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
@JsonProperty("group") Optional<String> group,
@JsonProperty("insertionId") Optional<String> insertionId,
@JsonProperty("timestamp") Instant timestamp) {
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
}
}

public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForAll, DTO> MODULE =
DTOModule
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForAll.class)
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
.convertToDTO(DTO.class)
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromAll)
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
domainObject.getSuccessfulRedeliveriesCount(),
domainObject.getFailedRedeliveriesCount(),
domainObject.getGroup(),
domainObject.getInsertionId(),
domainObject.timestamp()))
.typeName(EventDeadLettersRedeliverAllTask.TYPE.asString())
.withFactory(AdditionalInformationDTOModule::new);

Expand All @@ -30,12 +47,29 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForAll ex
}

public static class EventDeadLettersRedeliveryTaskAdditionalInformationForGroup extends EventDeadLettersRedeliveryTaskAdditionalInformation {
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForGroup, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =

public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
public DTO(@JsonProperty("type") String type,
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
@JsonProperty("group") Optional<String> group,
@JsonProperty("insertionId") Optional<String> insertionId,
@JsonProperty("timestamp") Instant timestamp) {
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
}
}

public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForGroup, DTO> MODULE =
DTOModule
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForGroup.class)
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
.convertToDTO(DTO.class)
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromGroup)
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
domainObject.getSuccessfulRedeliveriesCount(),
domainObject.getFailedRedeliveriesCount(),
domainObject.getGroup(),
domainObject.getInsertionId(),
domainObject.timestamp()))
.typeName(EventDeadLettersRedeliverGroupTask.TYPE.asString())
.withFactory(AdditionalInformationDTOModule::new);

Expand All @@ -46,12 +80,28 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForGroup
}

public static class EventDeadLettersRedeliveryTaskAdditionalInformationForOne extends EventDeadLettersRedeliveryTaskAdditionalInformation {
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForOne, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =
public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
public DTO(@JsonProperty("type") String type,
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
@JsonProperty("group") Optional<String> group,
@JsonProperty("insertionId") Optional<String> insertionId,
@JsonProperty("timestamp") Instant timestamp) {
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
}
}

public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForOne, DTO> MODULE =
DTOModule
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForOne.class)
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
.convertToDTO(DTO.class)
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromOne)
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
domainObject.getSuccessfulRedeliveriesCount(),
domainObject.getFailedRedeliveriesCount(),
domainObject.getGroup(),
domainObject.getInsertionId(),
domainObject.timestamp()))
.typeName(EventDeadLettersRedeliverOneTask.TYPE.asString())
.withFactory(AdditionalInformationDTOModule::new);

Expand All @@ -66,16 +116,6 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForOne ex
}
}

private static EventDeadLettersRedeliveryTaskAdditionalInformationDTO toDTO(EventDeadLettersRedeliveryTaskAdditionalInformation domainObject, String typeName) {
return new EventDeadLettersRedeliveryTaskAdditionalInformationDTO(
typeName,
domainObject.getSuccessfulRedeliveriesCount(),
domainObject.getFailedRedeliveriesCount(),
domainObject.getGroup(),
domainObject.getInsertionId(),
domainObject.timestamp());
}

private static EventDeadLettersRedeliveryTaskAdditionalInformationForAll fromAll(EventDeadLettersRedeliveryTaskAdditionalInformationDTO dto) {
return new EventDeadLettersRedeliveryTaskAdditionalInformationForAll(
dto.successfulRedeliveriesCount,
Expand Down

0 comments on commit 7580bd4

Please sign in to comment.