vttranlina commented on code in PR #2408:
URL: https://github.com/apache/james-project/pull/2408#discussion_r1762339271


##########
server/container/guice/cassandra/src/main/java/org/apache/james/modules/MailboxFlagInconsistencyModule.java:
##########
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.modules;
+
+import org.apache.james.mailbox.cassandra.mail.CassandraDeletedMessageDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraMailboxRecentsDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraMessageIdDAO;
+import 
org.apache.james.mailbox.cassandra.mail.task.SolveMailboxFlagInconsistenciesService;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+
+public class MailboxFlagInconsistencyModule extends AbstractModule {
+
+    interface MailboxFlagInconsistencyInjectionsKey {
+        String SOLVE_MAILBOX_RECENT = "SolveMailboxRecentFlag";
+        String SOLVE_MAILBOX_DELETED = "SolveMailboxDeletedFlag";
+    }
+
+    @Provides
+    @Singleton
+    @Named(MailboxFlagInconsistencyInjectionsKey.SOLVE_MAILBOX_RECENT)
+    public SolveMailboxFlagInconsistenciesService 
provideSolveMailboxRecentInconsistenciesService(CassandraMessageIdDAO 
messageIdDAO,
+                                                                               
                   CassandraMailboxDAO mailboxDAO,
+                                                                               
                   CassandraMailboxRecentsDAO mailboxRecentDAO) {
+        return new SolveMailboxFlagInconsistenciesService(
+            new 
SolveMailboxFlagInconsistenciesService.SoleMailboxRecentFlagInconsistenciesStrategy(mailboxRecentDAO),
+            messageIdDAO, mailboxDAO);
+    }
+
+    @Provides
+    @Singleton
+    @Named(MailboxFlagInconsistencyInjectionsKey.SOLVE_MAILBOX_DELETED)
+    public SolveMailboxFlagInconsistenciesService 
solveMailboxDeletedInconsistenciesService(CassandraMessageIdDAO messageIdDAO,
+                                                                               
             CassandraMailboxDAO mailboxDAO,
+                                                                               
             CassandraDeletedMessageDAO deletedMessageDAO) {
+        return new SolveMailboxFlagInconsistenciesService(
+            new 
SolveMailboxFlagInconsistenciesService.SolveMailboxDeletedFlagInconsistenciesStrategy(deletedMessageDAO),
+            messageIdDAO, mailboxDAO);
+    }

Review Comment:
   updated



##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/SolveMailboxFlagInconsistenciesTaskDTO.java:
##########
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.mailbox.cassandra.mail.task;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.james.json.DTOModule;
+import 
org.apache.james.mailbox.cassandra.mail.task.SolveMailboxFlagInconsistencyTask.TargetFlag;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+
+public record SolveMailboxFlagInconsistenciesTaskDTO(@JsonProperty("type") 
String type,
+                                                     @JsonProperty("flagName") 
String flagName) implements TaskDTO {
+
+    public static final String TYPE = "solve-mailbox-flag-inconsistencies";
+    public static final TaskType TASK_TYPE = TaskType.of(TYPE);
+
+    public static TaskDTOModule<SolveMailboxFlagInconsistencyTask, 
SolveMailboxFlagInconsistenciesTaskDTO> module(
+        SolveMailboxFlagInconsistenciesService 
mailboxDeletedFlagResolveService,
+        SolveMailboxFlagInconsistenciesService 
mailboxRecentFlagResolveService) {
+        return DTOModule
+            .forDomainObject(SolveMailboxFlagInconsistencyTask.class)
+            .convertToDTO(SolveMailboxFlagInconsistenciesTaskDTO.class)
+            
.toDomainObjectConverter(getDomainObjectConverter(mailboxDeletedFlagResolveService,
 mailboxRecentFlagResolveService))
+            .toDTOConverter((task, type) -> new 
SolveMailboxFlagInconsistenciesTaskDTO(type, task.targetFlag()))
+            .typeName(TYPE)
+            .withFactory(TaskDTOModule::new);
+    }
+
+    private static 
DTOModule.DomainObjectConverter<SolveMailboxFlagInconsistencyTask, 
SolveMailboxFlagInconsistenciesTaskDTO> 
getDomainObjectConverter(SolveMailboxFlagInconsistenciesService 
mailboxDeletedFlagResolveService,
+                                                                               
                                                                        
SolveMailboxFlagInconsistenciesService mailboxRecentFlagResolveService) {
+        return dto -> {
+            
Preconditions.checkArgument(StringUtils.isNotEmpty(dto.flagName()), "flagName 
should not be empty");
+            return switch (TargetFlag.valueOf(dto.flagName())) {
+                case TargetFlag.DELETED ->
+                    new 
SolveMailboxFlagInconsistencyTask(mailboxDeletedFlagResolveService, 
TargetFlag.DELETED);
+                case TargetFlag.RECENT ->
+                    new 
SolveMailboxFlagInconsistencyTask(mailboxRecentFlagResolveService, 
TargetFlag.RECENT);
+            };

Review Comment:
   updated



-- 
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: notifications-unsubscr...@james.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to