chibenwa commented on a change in pull request #571:
URL: https://github.com/apache/james-project/pull/571#discussion_r682219606



##########
File path: 
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/ClearMailboxContentTaskAdditionalInformationDTO.java
##########
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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.core.Username;
+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.validation.MailboxName;
+
+public class ClearMailboxContentTaskAdditionalInformationDTO implements 
AdditionalInformationDTO {
+
+    public static final 
AdditionalInformationDTOModule<ClearMailboxContentTask.AdditionalInformation, 
ClearMailboxContentTaskAdditionalInformationDTO> SERIALIZATION_MODULE =
+        
DTOModule.forDomainObject(ClearMailboxContentTask.AdditionalInformation.class)
+            
.convertToDTO(ClearMailboxContentTaskAdditionalInformationDTO.class)
+            
.toDomainObjectConverter(ClearMailboxContentTaskAdditionalInformationDTO::toDomainObject)
+            
.toDTOConverter(ClearMailboxContentTaskAdditionalInformationDTO::toDto)
+            .typeName(ClearMailboxContentTask.TASK_TYPE.asString())
+            .withFactory(AdditionalInformationDTOModule::new);
+
+    private static ClearMailboxContentTask.AdditionalInformation 
toDomainObject(ClearMailboxContentTaskAdditionalInformationDTO dto) {
+        return new ClearMailboxContentTask.AdditionalInformation(
+            Username.of(dto.getUsername()),
+            new MailboxName(dto.getMailboxName()),
+            dto.getTimestamp(),
+            dto.getMessagesSuccessCount(),
+            dto.getMessagesFailCount());
+    }
+
+    private static ClearMailboxContentTaskAdditionalInformationDTO 
toDto(ClearMailboxContentTask.AdditionalInformation domain, String type) {
+        return new ClearMailboxContentTaskAdditionalInformationDTO(
+            type,
+            domain.getUsername().asString(),
+            domain.getMailboxName().asString(),
+            domain.getTimestamp(),
+            domain.getMessagesSuccessCount(),
+            domain.getMessagesFailCount());
+    }
+
+    private final String type;
+    private final String username;
+    private final String mailboxName;
+    private final Instant timestamp;
+    private final long messagesSuccessCount;
+    private final long messagesFailCount;
+
+    public ClearMailboxContentTaskAdditionalInformationDTO(String type, String 
username, String mailboxName, Instant timestamp, long messagesSuccessCount, 
long messagesFailCount) {

Review comment:
       Can you run this for the distributed server?
   
   I guess we not only need serialization but also deserialisation.
   
   

##########
File path: 
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
##########
@@ -99,6 +104,33 @@ public boolean testMailboxExists(Username username, 
MailboxName mailboxName) thr
             .block();
     }
 
+    public Mono<Result> clearMailboxContent(Username username, MailboxName 
mailboxName, ClearMailboxContentTask.Context context) throws 
UsersRepositoryException, MailboxException {
+        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(username);
+        MessageManager messageManager = 
mailboxManager.getMailbox(MailboxPath.forUser(username, 
mailboxName.asString()), mailboxSession);
+
+        return 
Flux.from(messageManager.listMessagesMetadata(MessageRange.all(), 
mailboxSession))
+            .map(metaData -> metaData.getComposedMessageId().getUid())
+            .map(messageUid -> deleteMessage(messageManager, messageUid, 
mailboxSession, context))

Review comment:
       deleteMessage is a disguised blocking call, I prefer to wrap it in a 
Mono.callable scheduled on the Elastic se=cheduler, inside a concatMap

##########
File path: 
server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/service/UserMailboxesServiceTest.java
##########
@@ -0,0 +1,54 @@
+/****************************************************************
+ * 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 org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class UserMailboxesServiceTest {

Review comment:
       Not sure testing the serives is strictly required as you might already 
have routes test covering this...




-- 
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]

Reply via email to