This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit ec1edc03651d53772f4966a437699155578b49b0 Author: Matthieu Baechler <[email protected]> AuthorDate: Wed Oct 23 14:31:39 2019 +0200 JAMES-2813 DTO <-> domain object must be a bijection for jackson to work Reference: https://github.com/FasterXML/jackson-databind/issues/2515 --- .../indexer/ReprocessingContextInformationDTO.java | 46 ++++++++++--- ...tersRedeliveryTaskAdditionalInformationDTO.java | 78 ++++++++++++++++------ 2 files changed, 94 insertions(+), 30 deletions(-) diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java index 3ee9c7f..9172e98 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java +++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java @@ -58,15 +58,27 @@ public class ReprocessingContextInformationDTO implements AdditionalInformationD } 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(), @@ -82,11 +94,23 @@ public class ReprocessingContextInformationDTO implements AdditionalInformationD } 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(), @@ -144,11 +168,11 @@ public class ReprocessingContextInformationDTO implements AdditionalInformationD .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, diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/EventDeadLettersRedeliveryTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/EventDeadLettersRedeliveryTaskAdditionalInformationDTO.java index 46dce06..552aa8b 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/EventDeadLettersRedeliveryTaskAdditionalInformationDTO.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/EventDeadLettersRedeliveryTaskAdditionalInformationDTO.java @@ -14,12 +14,29 @@ import com.github.fge.lambdas.Throwing; 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); @@ -30,12 +47,29 @@ public class EventDeadLettersRedeliveryTaskAdditionalInformationDTO implements A } 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); @@ -46,12 +80,28 @@ public class EventDeadLettersRedeliveryTaskAdditionalInformationDTO implements A } 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); @@ -66,16 +116,6 @@ public class EventDeadLettersRedeliveryTaskAdditionalInformationDTO implements A } } - 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, --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
