MAILBOX-365 Turn MailboxSession into POJO & delete SimpleMailboxSession
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a5982615 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a5982615 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a5982615 Branch: refs/heads/master Commit: a598261564104da0d0f0b30672a8983e8522681c Parents: 46e26b8 Author: Benoit Tellier <[email protected]> Authored: Sat Dec 15 16:25:56 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Tue Dec 18 14:48:10 2018 +0700 ---------------------------------------------------------------------- .../apache/james/mailbox/MailboxSession.java | 103 ++++++++++-- .../mailbox/store/SimpleMailboxSession.java | 157 ------------------- .../mailbox/store/StoreMailboxManager.java | 2 +- 3 files changed, 88 insertions(+), 174 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/a5982615/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java index 51dd6b3..0e1cc74 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java @@ -19,22 +19,25 @@ package org.apache.james.mailbox; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import org.apache.james.core.User; +import org.apache.james.mailbox.model.MailboxConstants; import com.google.common.base.MoreObjects; /** * Mailbox session. */ -public interface MailboxSession { +public class MailboxSession { - class SessionId { + public static class SessionId { public static SessionId of(long sessionId) { return new SessionId(sessionId); @@ -76,9 +79,9 @@ public interface MailboxSession { /** * Id which will be used for a System session */ - long SYSTEM_SESSION_ID = 0L; + public static long SYSTEM_SESSION_ID = 0L; - enum SessionType { + public enum SessionType { /** * Session was created via the System */ @@ -89,39 +92,83 @@ public interface MailboxSession { */ User } - + + private final Collection<String> sharedSpaces; + private final String otherUsersSpace; + private final String personalSpace; + private final SessionId sessionId; + private final String userName; + private boolean open = true; + private final List<Locale> localePreferences; + private final Map<Object, Object> attributes; + private final char pathSeparator; + private final SessionType type; + + public MailboxSession(SessionId sessionId, String userName, + List<Locale> localePreferences, char pathSeparator, SessionType type) { + this(sessionId, userName, localePreferences, new ArrayList<>(), null, pathSeparator, type); + } + + public MailboxSession(SessionId sessionId, String userName, + List<Locale> localePreferences, List<String> sharedSpaces, String otherUsersSpace, char pathSeparator, SessionType type) { + this.sessionId = sessionId; + this.userName = userName; + this.otherUsersSpace = otherUsersSpace; + this.sharedSpaces = sharedSpaces; + this.type = type; + if (otherUsersSpace == null && (sharedSpaces == null || sharedSpaces.isEmpty())) { + this.personalSpace = ""; + } else { + this.personalSpace = MailboxConstants.USER_NAMESPACE; + } + + this.localePreferences = localePreferences; + this.attributes = new HashMap<>(); + this.pathSeparator = pathSeparator; + } + /** * Return if the {@link MailboxSession} is of type {@link SessionType#User} or {@link SessionType#System} * * @return type */ - SessionType getType(); + public SessionType getType() { + return type; + } /** * Gets the session ID. * * @return session id */ - SessionId getSessionId(); + public SessionId getSessionId() { + return sessionId; + } /** * Is this session open? * * @return true if the session is open, false otherwise */ - boolean isOpen(); + public boolean isOpen() { + return open; + } /** * Closes this session. */ - void close(); + public void close() { + open = false; + } /** * Gets the user executing this session. * * @return not null */ - User getUser(); + public User getUser() { + return User.fromUsername(userName); + } /** * Gets acceptable localisation for this user in preference order.<br> @@ -130,7 +177,9 @@ public interface MailboxSession { * * @return not null, when empty the default local should be used */ - List<Locale> getLocalePreferences(); + public List<Locale> getLocalePreferences() { + return localePreferences; + } /** * Gets the <a href='http://www.isi.edu/in-notes/rfc2342.txt' rel='tag'>RFC @@ -141,7 +190,9 @@ public interface MailboxSession { * * @return Personal Namespace, not null */ - String getPersonalSpace(); + public String getPersonalSpace() { + return personalSpace; + } /** * Gets the <a href='http://www.isi.edu/in-notes/rfc2342.txt' rel='tag'>RFC @@ -152,7 +203,9 @@ public interface MailboxSession { * * @return Other Users Namespace or null when there is non available */ - String getOtherUsersSpace(); + public String getOtherUsersSpace() { + return otherUsersSpace; + } /** * Iterates the <a href='http://www.isi.edu/in-notes/rfc2342.txt' @@ -161,19 +214,37 @@ public interface MailboxSession { * * @return not null though possibly empty */ - Collection<String> getSharedSpaces(); + public Collection<String> getSharedSpaces() { + return sharedSpaces; + } /** * Return the stored attributes for this {@link MailboxSession}. * * @return attributes */ - Map<Object, Object> getAttributes(); + public Map<Object, Object> getAttributes() { + return attributes; + } /** * Return server side, folder path separator * * @return path separator */ - char getPathDelimiter(); + public char getPathDelimiter() { + return pathSeparator; + } + + /** + * Renders suitably for logging. + * + * @return a <code>String</code> representation of this object. + */ + public String toString() { + String TAB = " "; + + return "MailboxSession ( " + "sessionId = " + + this.sessionId + TAB + "open = " + this.open + TAB + " )"; + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/a5982615/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java deleted file mode 100644 index 2e3f159..0000000 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************** - * 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.store; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.apache.james.core.User; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.model.MailboxConstants; - -/** - * Describes a mailbox session. - */ -public class SimpleMailboxSession implements MailboxSession { - - private final Collection<String> sharedSpaces; - - private final String otherUsersSpace; - - private final String personalSpace; - - private final SessionId sessionId; - - private final String userName; - - private boolean open = true; - - private final List<Locale> localePreferences; - - private final Map<Object, Object> attributes; - - private final char pathSeparator; - - private final SessionType type; - - - public SimpleMailboxSession(SessionId sessionId, String userName, - List<Locale> localePreferences, char pathSeparator, SessionType type) { - this(sessionId, userName, localePreferences, new ArrayList<>(), null, pathSeparator, type); - } - - public SimpleMailboxSession(SessionId sessionId, String userName, - List<Locale> localePreferences, List<String> sharedSpaces, String otherUsersSpace, char pathSeparator, SessionType type) { - this.sessionId = sessionId; - this.userName = userName; - this.otherUsersSpace = otherUsersSpace; - this.sharedSpaces = sharedSpaces; - this.type = type; - if (otherUsersSpace == null && (sharedSpaces == null || sharedSpaces.isEmpty())) { - this.personalSpace = ""; - } else { - this.personalSpace = MailboxConstants.USER_NAMESPACE; - } - - this.localePreferences = localePreferences; - this.attributes = new HashMap<>(); - this.pathSeparator = pathSeparator; - } - - - @Override - public void close() { - open = false; - } - - @Override - public SessionId getSessionId() { - return sessionId; - } - - @Override - public boolean isOpen() { - return open; - } - - /** - * Renders suitably for logging. - * - * @return a <code>String</code> representation of this object. - */ - public String toString() { - final String TAB = " "; - - return "MailboxSession ( " + "sessionId = " - + this.sessionId + TAB + "open = " + this.open + TAB + " )"; - } - - /** - * Gets the user executing this session. - * @return not null - */ - @Override - public User getUser() { - return User.fromUsername(userName); - } - - @Override - public String getOtherUsersSpace() { - return otherUsersSpace; - } - - @Override - public String getPersonalSpace() { - return personalSpace; - } - - @Override - public Collection<String> getSharedSpaces() { - return sharedSpaces; - } - - @Override - public List<Locale> getLocalePreferences() { - return localePreferences; - } - - /** - * @see org.apache.james.mailbox.MailboxSession#getAttributes() - */ - @Override - public Map<Object, Object> getAttributes() { - return attributes; - } - - @Override - public char getPathDelimiter() { - return pathSeparator; - } - - @Override - public SessionType getType() { - return type; - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/a5982615/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index fba7edd..45b4fbc 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -357,7 +357,7 @@ public class StoreMailboxManager implements MailboxManager { */ protected MailboxSession createSession(String userName, SessionType type) { - return new SimpleMailboxSession(newSessionId(), userName, new ArrayList<>(), getDelimiter(), type); + return new MailboxSession(newSessionId(), userName, new ArrayList<>(), getDelimiter(), type); } private MailboxSession.SessionId newSessionId() { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
