ottoka commented on code in PR #1004: URL: https://github.com/apache/james-project/pull/1004#discussion_r875924982
########## server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/ExpireInboxesAdditionalInformationDTO.java: ########## @@ -0,0 +1,109 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.webadmin.service; + +import java.time.Instant; + +import org.apache.james.json.DTOModule; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; +import org.apache.james.webadmin.service.ExpireInboxesService.RunningOptions; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ExpireInboxesAdditionalInformationDTO implements AdditionalInformationDTO { + + public static AdditionalInformationDTOModule<ExpireInboxesTask.AdditionalInformation, ExpireInboxesAdditionalInformationDTO> module() { + return DTOModule.forDomainObject(ExpireInboxesTask.AdditionalInformation.class) + .convertToDTO(ExpireInboxesAdditionalInformationDTO.class) + .toDomainObjectConverter(ExpireInboxesAdditionalInformationDTO::toDomainObject) + .toDTOConverter(ExpireInboxesAdditionalInformationDTO::toDto) + .typeName(ExpireInboxesTask.TASK_TYPE.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + private static ExpireInboxesTask.AdditionalInformation toDomainObject(ExpireInboxesAdditionalInformationDTO dto) { + return new ExpireInboxesTask.AdditionalInformation( + dto.getTimestamp(), + dto.getRunningOptions(), + dto.getInboxesExpired(), + dto.getInboxesFailed(), + dto.getInboxesProcessed()); + } + + private static ExpireInboxesAdditionalInformationDTO toDto(ExpireInboxesTask.AdditionalInformation details, String type) { + return new ExpireInboxesAdditionalInformationDTO( + details.timestamp(), + type, + details.getRunningOptions(), + details.getInboxesExpired(), + details.getInboxesFailed(), + details.getInboxesProcessed()); + } + + private final Instant timestamp; + private final String type; + private final RunningOptions runningOptions; + private final long inboxesExpired; + private final long inboxesFailed; + private final long inboxesProcessed; + + @JsonCreator + public ExpireInboxesAdditionalInformationDTO(@JsonProperty("timestamp") Instant timestamp, + @JsonProperty("type") String type, + @JsonProperty("runningOptions") RunningOptions runningOptions, + @JsonProperty("inboxesExpired") long inboxesExpired, + @JsonProperty("inboxesFailed") long inboxesFailed, + @JsonProperty("inboxesProcessed") long inboxesProcessed) { + this.timestamp = timestamp; + this.type = type; + this.runningOptions = runningOptions; + this.inboxesExpired = inboxesExpired; + this.inboxesFailed = inboxesFailed; + this.inboxesProcessed = inboxesProcessed; + } + + public RunningOptions getRunningOptions() { + return runningOptions; + } + + public long getInboxesExpired() { + return inboxesExpired; + } + + public long getInboxesFailed() { + return inboxesFailed; + } + + public long getInboxesProcessed() { + return inboxesProcessed; + } Review Comment: I added a metric for total messages deleted by the task. But I am not sure if the batch deletion is guaranteed to be atomic/transactional, i.e. if it fails on one message in the batch, could it still have deleted the messages listed before, or even all other messages? In that case, measuring failed deletions precisely is not really possible. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
