You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/03/05 10:11:07 UTC
[GitHub] [james-project] LanKhuat opened a new pull request #324: WIP: MAILBOX-405 Task to create missing parent mailboxes
LanKhuat opened a new pull request #324:
URL: https://github.com/apache/james-project/pull/324
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #324:
URL: https://github.com/apache/james-project/pull/324#issuecomment-796456646
Merged
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r590029290
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -119,13 +138,45 @@ public CreateMissingParentsTask(MailboxManager mailboxManager) {
@Override
public Result run() {
Review comment:
No test to verify if the task does actually create missing parents mailboxes?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: WIP: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r588208105
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
Review comment:
We can use a static username here.
No we are outside of the mailbox project we should use `MailboxManager`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] LanKhuat commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
LanKhuat commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r590092236
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -119,13 +138,45 @@ public CreateMissingParentsTask(MailboxManager mailboxManager) {
@Override
public Result run() {
Review comment:
the fact that the "created" array has some mailboxIds in it is not convincing enough?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r589946115
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,207 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.ImmutableSet;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ private static final Username USERNAME = Username.of("createMissingParentsTask");
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), created, totalCreated, failures, totalFailure);
+ }
+
+ private final Instant timestamp;
+ private final Set<String> created;
+ private final long totalCreated;
+ private final Set<String> failures;
+ private final long totalFailure;
+
+ public AdditionalInformation(Instant timestamp, Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ this.created = created;
+ this.failures = failures;
+ this.totalCreated = totalCreated;
+ this.totalFailure = totalFailure;
+ this.timestamp = timestamp;
+ }
+
+ public Set<String> getCreated() {
+ return created;
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ public Set<String> getFailures() {
+ return failures;
+ }
+
+ public long getTotalFailure() {
+ return totalFailure;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final ConcurrentLinkedQueue<MailboxId> created;
+ private final AtomicLong totalCreated;
+ private final ConcurrentLinkedQueue<String> failures;
+ private final AtomicLong totalFailure;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ this.created = new ConcurrentLinkedQueue<>();
+ this.totalCreated = new AtomicLong(0L);
+ this.failures = new ConcurrentLinkedQueue<>();
+ this.totalFailure = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(USERNAME);
+ try {
+ List<MailboxPath> mailboxPaths = mailboxManager.list(session);
+
+ Set<MailboxPath> parentPaths = mailboxManager.list(session)
Review comment:
Why don't we reuse mailboxPaths here to save an expensive duplicated read to the DB?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael merged pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
Arsnael merged pull request #324:
URL: https://github.com/apache/james-project/pull/324
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #324:
URL: https://github.com/apache/james-project/pull/324#issuecomment-793661701
>I think we still need to document this task?
Correct.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] LanKhuat commented on pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
LanKhuat commented on pull request #324:
URL: https://github.com/apache/james-project/pull/324#issuecomment-793620503
I think we still need to document this task?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] LanKhuat commented on a change in pull request #324: WIP: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
LanKhuat commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r588201908
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
Review comment:
then shouldn't we have used mailboxDAO instead of mailboxManager?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r589945673
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,207 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.ImmutableSet;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ private static final Username USERNAME = Username.of("createMissingParentsTask");
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), created, totalCreated, failures, totalFailure);
+ }
+
+ private final Instant timestamp;
+ private final Set<String> created;
+ private final long totalCreated;
+ private final Set<String> failures;
+ private final long totalFailure;
+
+ public AdditionalInformation(Instant timestamp, Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ this.created = created;
+ this.failures = failures;
+ this.totalCreated = totalCreated;
+ this.totalFailure = totalFailure;
+ this.timestamp = timestamp;
+ }
+
+ public Set<String> getCreated() {
+ return created;
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ public Set<String> getFailures() {
+ return failures;
+ }
+
+ public long getTotalFailure() {
+ return totalFailure;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final ConcurrentLinkedQueue<MailboxId> created;
+ private final AtomicLong totalCreated;
+ private final ConcurrentLinkedQueue<String> failures;
+ private final AtomicLong totalFailure;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ this.created = new ConcurrentLinkedQueue<>();
+ this.totalCreated = new AtomicLong(0L);
+ this.failures = new ConcurrentLinkedQueue<>();
+ this.totalFailure = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(USERNAME);
+ try {
+ List<MailboxPath> mailboxPaths = mailboxManager.list(session);
+
+ Set<MailboxPath> parentPaths = mailboxManager.list(session)
+ .stream()
+ .filter(MailboxPath::hasParent)
+ .flatMap(this::getParents)
+ .collect(Collectors.toSet());
Review comment:
Guavate.toImmutableSet
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r589946352
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,207 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.ImmutableSet;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ private static final Username USERNAME = Username.of("createMissingParentsTask");
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), created, totalCreated, failures, totalFailure);
+ }
+
+ private final Instant timestamp;
+ private final Set<String> created;
+ private final long totalCreated;
+ private final Set<String> failures;
+ private final long totalFailure;
+
+ public AdditionalInformation(Instant timestamp, Set<String> created, long totalCreated, Set<String> failures, long totalFailure) {
+ this.created = created;
+ this.failures = failures;
+ this.totalCreated = totalCreated;
+ this.totalFailure = totalFailure;
+ this.timestamp = timestamp;
+ }
+
+ public Set<String> getCreated() {
+ return created;
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ public Set<String> getFailures() {
+ return failures;
+ }
+
+ public long getTotalFailure() {
+ return totalFailure;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final ConcurrentLinkedQueue<MailboxId> created;
+ private final AtomicLong totalCreated;
+ private final ConcurrentLinkedQueue<String> failures;
+ private final AtomicLong totalFailure;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ this.created = new ConcurrentLinkedQueue<>();
+ this.totalCreated = new AtomicLong(0L);
+ this.failures = new ConcurrentLinkedQueue<>();
+ this.totalFailure = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(USERNAME);
+ try {
+ List<MailboxPath> mailboxPaths = mailboxManager.list(session);
+
+ Set<MailboxPath> parentPaths = mailboxManager.list(session)
+ .stream()
+ .filter(MailboxPath::hasParent)
+ .flatMap(this::getParents)
+ .collect(Collectors.toSet());
+
+ return Flux.fromIterable(parentPaths)
+ .filter(Predicate.not(mailboxPaths::contains))
+ .flatMap(path -> createMailbox(path), DEFAULT_CONCURRENCY)
+ .reduce(Task::combine)
+ .switchIfEmpty(Mono.just(Result.COMPLETED))
+ .subscribeOn(Schedulers.elastic())
+ .block();
+ } catch (MailboxException e) {
+ LOGGER.error("Error fetching mailbox paths", e);
+ return Result.PARTIAL;
+ }
+ }
+
+ private Stream<MailboxPath> getParents(MailboxPath path) {
+ return path.getHierarchyLevels(DEFAULT_DELIMITER).stream().filter(p -> !p.equals(path));
Review comment:
This method need IMO to be in MailboxPath.... (and tested)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #324:
URL: https://github.com/apache/james-project/pull/324#issuecomment-810732339
After trying to find this task and seeing it was missing in the codebase, I realized this PR was not merged correctly.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] LanKhuat commented on a change in pull request #324: WIP: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
LanKhuat commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r588201908
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
Review comment:
then shouldn't we have to use mailboxDAO instead of mailboxManager?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r589944292
##########
File path: mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
##########
@@ -242,4 +244,7 @@ public String getFullName(char delimiter) {
return namespace + delimiter + name;
}
+ public boolean hasParent() {
+ return getHierarchyLevels(DEFAULT_DELIMITER).size() > 1;
Review comment:
1. You should retrieve the delimiter from the session, not use a static one. I suggest having a `char delimiter` parameter just like in getHierarchyLevels
2. No tests?
##########
File path: server/container/guice/protocols/webadmin-mailbox/src/main/java/org/apache/james/modules/server/CreateMissingParentsRoutesModule.java
##########
@@ -0,0 +1,42 @@
+/****************************************************************
+ * 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.server;
+
+import org.apache.james.webadmin.routes.MailboxesRoutes;
+import org.apache.james.webadmin.service.CreateMissingParentsRequestToTask;
+import org.apache.james.webadmin.service.ExportService;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
+
+public class CreateMissingParentsRoutesModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ install(new WebadminCreateMissingParentsTaskSerializationModule());
+
+ bind(ExportService.class).in(Scopes.SINGLETON);
Review comment:
Why do we care about the ExportService?
##########
File path: server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
##########
@@ -74,6 +75,7 @@
new DeletedMessageVaultRoutesModule(),
new DLPRoutesModule(),
new MailboxesExportRoutesModule(),
+ new CreateMissingParentsRoutesModule(),
Review comment:
I prefer to `install` this module within MailboxRoutesModule. It would be so easy to forget it otherwise....
##########
File path: server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
##########
@@ -398,6 +401,29 @@ void mailboxesExportTasksShouldBeExposed() throws Exception {
.body("type", is("MailboxesExportTask"));
}
+ @Test
+ void createMissParentsTasksShouldBeExposed() {
+ String taskId = with()
+ .queryParam("task", "createMissingParents")
+ .post("/mailboxes").prettyPeek()
Review comment:
Debug spotted
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #324: WIP: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #324:
URL: https://github.com/apache/james-project/pull/324#discussion_r588185307
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
+ private final AtomicLong totalCreated;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager, Username username) {
+ this.username = username;
+ this.mailboxManager = mailboxManager;
+ this.totalCreated = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(username);
Review comment:
Use a static username
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
Review comment:
I was thinking this task creates the missing parents for **all** mailboxes and is thus not bound to a user.
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
+ private final AtomicLong totalCreated;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager, Username username) {
+ this.username = username;
+ this.mailboxManager = mailboxManager;
+ this.totalCreated = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(username);
+
+ return Flux.fromIterable(Throwing.supplier(() -> mailboxManager.list(session)).sneakyThrow().get())
+ .filter(path -> path.getHierarchyLevels(DEFAULT_DELIMITER).size() > 1)
+ .map(path -> path.getHierarchyLevels(DEFAULT_DELIMITER).get(0))
+ .filterWhen(path -> mailboxNotExists(path, session))
+ .flatMap(path -> createMailbox(path, session), DEFAULT_CONCURRENCY)
+ .reduce(Task::combine)
+ .onErrorResume(e -> {
+ LOGGER.error("Error creating missing parent mailbox for user: {}", username.asString(), e);
+ return Mono.just(Task.Result.PARTIAL);
+ })
+ .subscribeOn(Schedulers.elastic())
+ .block();
+ }
+
+ private Mono<Boolean> mailboxNotExists(MailboxPath path, MailboxSession session) {
+ return Throwing.supplier(() -> Mono.from(mailboxManager.mailboxExists(path, session)).map(val -> !val)).sneakyThrow().get();
Review comment:
We do not have a negate function in FunctionalUtils?
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTaskAdditionalInformationDTO.java
##########
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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 com.fasterxml.jackson.annotation.JsonProperty;
+
+public class CreateMissingParentsTaskAdditionalInformationDTO implements AdditionalInformationDTO {
+
+ public static final AdditionalInformationDTOModule<CreateMissingParentsTask.AdditionalInformation, CreateMissingParentsTaskAdditionalInformationDTO> SERIALIZATION_MODULE =
+ DTOModule.forDomainObject(CreateMissingParentsTask.AdditionalInformation.class)
+ .convertToDTO(CreateMissingParentsTaskAdditionalInformationDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask.AdditionalInformation(
+ dto.timestamp,
+ Username.of(dto.username),
+ dto.totalCreated))
+ .toDTOConverter((details, type) -> new CreateMissingParentsTaskAdditionalInformationDTO(
+ type,
+ details.timestamp(),
+ details.getUsername(),
+ details.getTotalCreated()))
+ .typeName(CreateMissingParentsTask.TASK_TYPE.asString())
+ .withFactory(AdditionalInformationDTOModule::new);
+
+ private final String type;
+ private final String username;
Review comment:
Remove this field
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
+ private final AtomicLong totalCreated;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager, Username username) {
+ this.username = username;
+ this.mailboxManager = mailboxManager;
+ this.totalCreated = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(username);
+
+ return Flux.fromIterable(Throwing.supplier(() -> mailboxManager.list(session)).sneakyThrow().get())
+ .filter(path -> path.getHierarchyLevels(DEFAULT_DELIMITER).size() > 1)
Review comment:
Extract this to a hasParent method
##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/CreateMissingParentsTask.java
##########
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 static org.apache.james.mailbox.model.MailboxConstants.DEFAULT_DELIMITER;
+import static org.apache.james.util.ReactorUtils.DEFAULT_CONCURRENCY;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class CreateMissingParentsTask implements Task {
+ static final TaskType TASK_TYPE = TaskType.of("CreateMissingParentsTask");
+
+ public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+ private static AdditionalInformation from(Username username, long totalCreated) {
+ return new AdditionalInformation(Clock.systemUTC().instant(), username, totalCreated);
+ }
+
+ private final Username username;
+ private final Instant timestamp;
+ private final long totalCreated;
+
+ public AdditionalInformation(Instant timestamp, Username username, long totalCreated) {
+ this.username = username;
+ this.totalCreated = totalCreated;
+ this.timestamp = timestamp;
+ }
+
+ public String getUsername() {
+ return username.asString();
+ }
+
+ public long getTotalCreated() {
+ return totalCreated;
+ }
+
+ @Override
+ public Instant timestamp() {
+ return timestamp;
+ }
+ }
+
+ public static class CreateMissingParentsTaskDTO implements TaskDTO {
+ private final String type;
+ private final String username;
+
+ public CreateMissingParentsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("username") String username) {
+ this.type = type;
+ this.username = username;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+ public static TaskDTOModule<CreateMissingParentsTask, CreateMissingParentsTask.CreateMissingParentsTaskDTO> module(MailboxManager mailboxManager) {
+ return DTOModule
+ .forDomainObject(CreateMissingParentsTask.class)
+ .convertToDTO(CreateMissingParentsTask.CreateMissingParentsTaskDTO.class)
+ .toDomainObjectConverter(dto -> new CreateMissingParentsTask(mailboxManager, Username.of(dto.username)))
+ .toDTOConverter((task, type) -> new CreateMissingParentsTask.CreateMissingParentsTaskDTO(type, task.username.asString()))
+ .typeName(TASK_TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+ }
+
+ private final Username username;
+ private final AtomicLong totalCreated;
+ private final MailboxManager mailboxManager;
+
+ public CreateMissingParentsTask(MailboxManager mailboxManager, Username username) {
+ this.username = username;
+ this.mailboxManager = mailboxManager;
+ this.totalCreated = new AtomicLong(0L);
+ }
+
+ @Override
+ public Result run() {
+ MailboxSession session = mailboxManager.createSystemSession(username);
+
+ return Flux.fromIterable(Throwing.supplier(() -> mailboxManager.list(session)).sneakyThrow().get())
+ .filter(path -> path.getHierarchyLevels(DEFAULT_DELIMITER).size() > 1)
+ .map(path -> path.getHierarchyLevels(DEFAULT_DELIMITER).get(0))
+ .filterWhen(path -> mailboxNotExists(path, session))
Review comment:
Can't we reuse the list of mailboxes rather than perform backend reads here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael closed pull request #324: MAILBOX-405 Task to create missing parent mailboxes
Posted by GitBox <gi...@apache.org>.
Arsnael closed pull request #324:
URL: https://github.com/apache/james-project/pull/324
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org