JAMES-2588 Effectively remove JCR
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/876987c8 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/876987c8 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/876987c8 Branch: refs/heads/master Commit: 876987c805a9a51607f9f0136a105f26cd999dc1 Parents: 81d65f1 Author: Raphael Ouazana <[email protected]> Authored: Wed Nov 7 17:40:51 2018 +0100 Committer: Raphael Ouazana <[email protected]> Committed: Thu Nov 8 11:43:03 2018 +0100 ---------------------------------------------------------------------- mailbox/README.md | 7 - mailbox/jcr/pom.xml | 123 ---- .../mailbox/jcr/AbstractJCRScalingMapper.java | 175 ----- .../jcr/GlobalMailboxSessionJCRRepository.java | 56 -- .../org/apache/james/mailbox/jcr/JCRId.java | 77 -- .../james/mailbox/jcr/JCRImapConstants.java | 33 - .../mailbox/jcr/JCRMailboxIdDeserializer.java | 30 - .../james/mailbox/jcr/JCRMailboxManager.java | 88 --- .../jcr/JCRMailboxSessionMapperFactory.java | 105 --- .../james/mailbox/jcr/JCRMessageManager.java | 92 --- .../mailbox/jcr/JCRRepositoryAuthenticator.java | 58 -- .../mailbox/jcr/JCRSubscriptionManager.java | 39 - .../org/apache/james/mailbox/jcr/JCRUtils.java | 79 -- .../jcr/MailboxSessionJCRRepository.java | 114 --- .../apache/james/mailbox/jcr/Persistent.java | 50 -- .../mailbox/jcr/mail/JCRMailboxMapper.java | 250 ------- .../mailbox/jcr/mail/JCRMessageMapper.java | 688 ------------------ .../mailbox/jcr/mail/JCRModSeqProvider.java | 75 -- .../james/mailbox/jcr/mail/JCRUidProvider.java | 77 -- .../mailbox/jcr/mail/model/JCRMailbox.java | 304 -------- .../jcr/mail/model/JCRMailboxMessage.java | 720 ------------------- .../mailbox/jcr/mail/model/JCRProperty.java | 209 ------ .../mailbox/jcr/user/JCRSubscriptionMapper.java | 170 ----- .../mailbox/jcr/user/model/JCRSubscription.java | 169 ----- .../resources/META-INF/spring/mailbox-jcr.xml | 87 --- .../jcr/src/main/resources/jcr-repository.xml | 67 -- mailbox/jcr/src/main/resources/mailbox-jcr.cnd | 61 -- mailbox/jcr/src/reporting-site/site.xml | 29 - .../jcr/JCRMailboxIdDeserializerTest.java | 45 -- .../mailbox/jcr/JCRMailboxManagerProvider.java | 86 --- .../jcr/JCRMailboxManagerStressTest.java | 69 -- .../mailbox/jcr/JCRMailboxManagerTest.java | 70 -- .../mailbox/jcr/JCRSubscriptionManagerTest.java | 82 --- mailbox/jcr/src/test/resources/logback-test.xml | 18 - .../jcr/src/test/resources/test-repository.xml | 92 --- mailbox/pom.xml | 1 - mailbox/spring/pom.xml | 25 - .../META-INF/spring/spring-mailbox.xml | 4 - .../spring/src/main/resources/mailbox-jcr.cnd | 67 -- .../core/src/main/resources/test-repository.xml | 92 --- mpt/impl/imap-mailbox/jcr/LICENSE.txt | 176 ----- mpt/impl/imap-mailbox/jcr/NOTICE.txt | 11 - mpt/impl/imap-mailbox/jcr/pom.xml | 56 -- .../jcr/src/reporting-site/site.xml | 28 - .../mpt/imapmailbox/jcr/JcrMailboxTest.java | 26 - .../imapmailbox/jcr/JcrMailboxTestModule.java | 42 -- .../mpt/imapmailbox/jcr/host/JCRHostSystem.java | 191 ----- mpt/impl/imap-mailbox/pom.xml | 7 - pom.xml | 26 - server/Overview.md | 1 - server/app/pom.xml | 22 - server/app/src/main/app/var/README.txt | 2 +- server/app/src/main/app/var/store/README.txt | 7 +- server/app/src/main/licensing/app/licensing.xml | 10 - server/app/src/main/licensing/war/licensing.xml | 6 - server/app/src/main/resources/mailbox-jcr.cnd | 74 -- server/app/src/main/resources/mailbox.xml | 2 +- server/app/src/test/resources/mailbox.xml | 2 +- .../src/main/resources/mailbox.xml | 2 +- ...oxConfigurationBeanFactoryPostProcessor.java | 9 +- server/data/data-jcr/pom.xml | 126 ---- .../mailrepository/jcr/JCRMailRepository.java | 653 ----------------- .../james/user/jcr/JCRUsersRepository.java | 410 ----------- .../apache/james/user/jcr/model/JCRUser.java | 92 --- .../org/apache/james/mailbox/jcr/james.cnd | 28 - .../data/data-jcr/src/reporting-site/site.xml | 29 - .../james/user/jcr/JcrUserRepositoryTest.java | 77 -- .../src/test/resources/log4j.properties | 6 - .../src/test/resources/test-repository.xml | 92 --- .../features/src/main/resources/features.xml | 4 - server/pom.xml | 1 - src/site/site.xml | 1 - src/site/xdoc/mailbox/index.xml | 1 - src/site/xdoc/mailbox/mailbox-api.xml | 3 +- src/site/xdoc/mailbox/mailbox-jcr.xml | 54 -- src/site/xdoc/mailbox/mailbox-spring.xml | 1 - src/site/xdoc/mailbox/source-code.xml | 3 +- src/site/xdoc/server/config-mailbox.xml | 2 +- .../xdoc/server/config-mailrepositorystore.xml | 13 +- src/site/xdoc/server/config-system.xml | 10 +- src/site/xdoc/server/config.xml | 5 - src/site/xdoc/server/feature-persistence.xml | 4 +- src/site/xdoc/server/features.xml | 18 +- src/site/xdoc/server/monitor-folders.xml | 10 +- src/site/xdoc/server/packaging.xml | 2 +- src/site/xdoc/server/quick-start.xml | 3 +- 86 files changed, 17 insertions(+), 7014 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/README.md ---------------------------------------------------------------------- diff --git a/mailbox/README.md b/mailbox/README.md index 4ef2312..e76ce0a 100644 --- a/mailbox/README.md +++ b/mailbox/README.md @@ -13,7 +13,6 @@ Apache James Mailbox has the following project (Maven) structure: ~~~ |-- api -- Mailbox API -|-- jcr -- Mailbox implementation over Java Content Repository (JCR) |-- jpa -- Database Mailbox implementation using Java Persistence API |-- lucene -- Email indexing module with Apache Lucene |-- maildir -- Email storage using Maildir format http://en.wikipedia.org/wiki/Maildir @@ -36,12 +35,6 @@ Mailbox 'In memory' message store In module **memory**, does not persist emails. It just keeps them in memory. Fast, and good for testing. **Note:** Not to be used in production. -Mailbox JCR -=========== - -Uses Java Content Repository as a persistence layer. Uses Jackrabbit as a provider (http://jackrabbit.apache.org/), -but you could swap in any provider. Comes with all the nice features that Jackrabbit has. - Mailbox Maildir =============== http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/jcr/pom.xml b/mailbox/jcr/pom.xml deleted file mode 100644 index 3354985..0000000 --- a/mailbox/jcr/pom.xml +++ /dev/null @@ -1,123 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.james</groupId> - <artifactId>apache-james-mailbox</artifactId> - <version>3.2.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>apache-james-mailbox-jcr</artifactId> - <packaging>bundle</packaging> - <name>Apache James :: Mailbox :: JCR</name> - - <dependencies> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-api</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-api</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-store</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-store</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.sun.mail</groupId> - <artifactId>javax.mail</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-jcr-commons</artifactId> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>xml-apis</groupId> - <artifactId>xml-apis</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <reuseForks>true</reuseForks> - </configuration> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java deleted file mode 100644 index f8dedc3..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java +++ /dev/null @@ -1,175 +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.jcr; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.apache.jackrabbit.commons.JcrUtils; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.store.transaction.TransactionalMapper; - -/** - * Abstract base class for Mapper's which support scaling. This supports Level 1 Implementations of JCR. So no real transaction management is used. - * - * The Session.save() will get called on commit() method, session.refresh(false) on rollback, and session.refresh(true) on begin() - * - */ -public abstract class AbstractJCRScalingMapper extends TransactionalMapper implements JCRImapConstants { - public static final String MAILBOXES_PATH = "mailboxes"; - - private final MailboxSessionJCRRepository repository; - private final int scaling; - - private final MailboxSession mSession; - private static final char PAD = '_'; - - public AbstractJCRScalingMapper(MailboxSessionJCRRepository repository, MailboxSession mSession, int scaling) { - this.scaling = scaling; - - this.mSession = mSession; - this.repository = repository; - } - - /** - * Return the JCR Session - * - * @return session - */ - protected Session getSession() throws RepositoryException { - return repository.login(mSession); - } - - /** - * Begin is not supported by level 1 JCR implementations, however we refresh the session - */ - @Override - protected void begin() throws MailboxException { - try { - getSession().refresh(true); - } catch (RepositoryException e) { - // do nothin on refresh - } - // Do nothing - } - - /** - * Just call save on the underlying JCR Session, because level 1 JCR implementation does not offer Transactions - */ - @Override - protected void commit() throws MailboxException { - try { - if (getSession().hasPendingChanges()) { - getSession().save(); - } - } catch (RepositoryException e) { - throw new MailboxException("Unable to commit", e); - } - } - - /** - * Rollback is not supported by level 1 JCR implementations, so just do nothing - */ - @Override - protected void rollback() throws MailboxException { - try { - // just refresh session and discard all pending changes - getSession().refresh(false); - } catch (RepositoryException e) { - // just catch on rollback by now - } - } - - /** - * Logout from open JCR Session - */ - @Override - public void endRequest() { - repository.logout(mSession); - } - - /** - * Construct the user node path part, using the specified scaling factor. - * If the username is not long enough it will fill it with {@link #PAD} - * - * So if you use a scaling of 2 it will look like: - * - * foo: - * f/fo/foo - * - * fo: - * f/fo/fo - * - * f: - * f/f_/f - * - * @param username - * @return path - */ - protected String constructUserPathPart(String username) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < scaling; i++) { - if (username.length() > i) { - sb.append(username.substring(0,i + 1)); - } else { - sb.append(username); - int a = i - username.length(); - for (int b = 0; b < a; b++) { - sb.append(PAD); - } - } - sb.append(NODE_DELIMITER); - } - sb.append(username); - return sb.toString(); - - } - - /** - * Create the needed Node structure for the given username using the given Node as parent. - * - * The method will use {@link #constructUserPathPart(String)} for create the needed node path and split - * it when a NODE_DELIMITER was found - * - * @param parent - * @param username - * @return userNode - * @throws RepositoryException - */ - protected Node createUserPathStructure(Node parent, String username) - throws RepositoryException { - String userpath = constructUserPathPart(username); - - String[] userPathParts = userpath.split(NODE_DELIMITER); - for (int a = 0; a < userPathParts.length; a++) { - parent = JcrUtils.getOrAddNode(parent, userPathParts[a], - "nt:unstructured"); - - // thats the last user node so add the right mixin type - if (a + 1 == userPathParts.length) { - parent.addMixin("jamesMailbox:user"); - } - } - - return parent; - - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/GlobalMailboxSessionJCRRepository.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/GlobalMailboxSessionJCRRepository.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/GlobalMailboxSessionJCRRepository.java deleted file mode 100644 index 9f839ae..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/GlobalMailboxSessionJCRRepository.java +++ /dev/null @@ -1,56 +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.jcr; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.apache.james.mailbox.MailboxSession; - - -/** - * - * Manage JCR {@link Session}. It will use one user and password for all - * - */ -public class GlobalMailboxSessionJCRRepository extends MailboxSessionJCRRepository { - - private final String username; - private final char[] pass; - - public GlobalMailboxSessionJCRRepository(Repository repository, String workspace, String username, String password) { - super(repository, workspace); - this.username = username; - if (password == null) { - pass = null; - } else { - pass = password.toCharArray(); - } - } - - /** - * Login in the {@link Repository} with the global configured user and password - */ - @Override - public Session login(MailboxSession session) throws RepositoryException { - return login(session, username, pass); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRId.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRId.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRId.java deleted file mode 100644 index bfb0a92..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRId.java +++ /dev/null @@ -1,77 +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.jcr; - -import java.io.Serializable; - -import org.apache.james.mailbox.model.MailboxId; - -public class JCRId implements MailboxId, Serializable { - - public static JCRId of(String value) { - return new JCRId(value); - } - - private final String value; - - private JCRId(String value) { - this.value = value; - } - - @Override - public String serialize() { - return value; - } - - @Override - public String toString() { - return value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - JCRId other = (JCRId) obj; - if (value == null) { - if (other.value != null) { - return false; - } - } else if (!value.equals(other.value)) { - return false; - } - return true; - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRImapConstants.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRImapConstants.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRImapConstants.java deleted file mode 100644 index 80b8150..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRImapConstants.java +++ /dev/null @@ -1,33 +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.jcr; - -/** - * Constants for JCR - * - */ -public interface JCRImapConstants { - - - /** - * Delimiter for Nodes - */ - String NODE_DELIMITER = "/"; - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java deleted file mode 100644 index 290b674..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java +++ /dev/null @@ -1,30 +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.jcr; - -import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer; - -public class JCRMailboxIdDeserializer implements MailboxIdDeserializer { - - @Override - public JCRId deserialize(String serializedMailboxId) { - return JCRId.of(serializedMailboxId); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java deleted file mode 100644 index cf6a940..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java +++ /dev/null @@ -1,88 +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.jcr; - -import java.util.EnumSet; - -import org.apache.james.mailbox.MailboxPathLocker; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.jcr.mail.model.JCRMailbox; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.model.MessageId; -import org.apache.james.mailbox.store.Authenticator; -import org.apache.james.mailbox.store.Authorizator; -import org.apache.james.mailbox.store.StoreMailboxAnnotationManager; -import org.apache.james.mailbox.store.StoreMailboxManager; -import org.apache.james.mailbox.store.StoreMessageManager; -import org.apache.james.mailbox.store.StoreRightManager; -import org.apache.james.mailbox.store.event.DelegatingMailboxListener; -import org.apache.james.mailbox.store.event.MailboxEventDispatcher; -import org.apache.james.mailbox.store.mail.model.Mailbox; -import org.apache.james.mailbox.store.mail.model.impl.MessageParser; - -/** - * JCR implementation of a MailboxManager - * - * @Deprecated: See JAMES-2571 The JCR implementation is not enough maintained and thus will be removed from James in version 3.3.0. Please prefer using - * other MailboxManagers or contribute the JCR mailbox maintenance. - */ -@Deprecated -public class JCRMailboxManager extends StoreMailboxManager implements JCRImapConstants { - - public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, - Authenticator authenticator, - Authorizator authorizator, - MailboxPathLocker locker, - MessageParser messageParser, - MessageId.Factory messageIdFactory, - MailboxEventDispatcher mailboxEventDispatcher, - DelegatingMailboxListener delegatingMailboxListener, - StoreMailboxAnnotationManager annotationManager, - StoreRightManager storeRightManager) { - super(mapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory, - annotationManager, mailboxEventDispatcher, delegatingMailboxListener, storeRightManager); - } - - @Override - public EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities() { - return EnumSet.of(MailboxCapabilities.Namespace); - } - - @Override - protected StoreMessageManager createMessageManager(Mailbox mailboxEntity, MailboxSession session) { - return new JCRMessageManager(getMapperFactory(), - getMessageSearchIndex(), - getEventDispatcher(), - getLocker(), - (JCRMailbox) mailboxEntity, - getQuotaManager(), - getQuotaRootResolver(), - getMessageParser(), - getMessageIdFactory(), - getBatchSizes(), - getImmutableMailboxMessageFactory(), - getStoreRightManager()); - } - - @Override - protected Mailbox doCreateMailbox(MailboxPath path, MailboxSession session) { - return new JCRMailbox(path, randomUidValidity()); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java deleted file mode 100644 index 5b014d7..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java +++ /dev/null @@ -1,105 +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.jcr; - -import org.apache.commons.lang3.NotImplementedException; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.exception.SubscriptionException; -import org.apache.james.mailbox.jcr.mail.JCRMailboxMapper; -import org.apache.james.mailbox.jcr.mail.JCRMessageMapper; -import org.apache.james.mailbox.jcr.user.JCRSubscriptionMapper; -import org.apache.james.mailbox.store.MailboxSessionMapperFactory; -import org.apache.james.mailbox.store.mail.AnnotationMapper; -import org.apache.james.mailbox.store.mail.MailboxMapper; -import org.apache.james.mailbox.store.mail.MessageIdMapper; -import org.apache.james.mailbox.store.mail.MessageMapper; -import org.apache.james.mailbox.store.mail.ModSeqProvider; -import org.apache.james.mailbox.store.mail.UidProvider; -import org.apache.james.mailbox.store.user.SubscriptionMapper; - -/** - * JCR implementation of a {@link MailboxSessionMapperFactory} - * - * @Deprecated: See JAMES-2571 The JCR implementation is not enough maintained and thus will be removed from James in version 3.3.0. Please prefer using - * other MailboxManagers or contribute the JCR mailbox maintenance. - */ -@Deprecated -public class JCRMailboxSessionMapperFactory extends MailboxSessionMapperFactory { - - private final MailboxSessionJCRRepository repository; - private static final int DEFAULT_SCALING = 2; - private final int scaling; - private final int messageScaling; - private final UidProvider uidProvider; - private final ModSeqProvider modSeqProvider; - - public JCRMailboxSessionMapperFactory(MailboxSessionJCRRepository repository, UidProvider uidProvider, ModSeqProvider modSeqProvider) { - this(repository, uidProvider, modSeqProvider, DEFAULT_SCALING, JCRMessageMapper.MESSAGE_SCALE_DAY); - } - - public JCRMailboxSessionMapperFactory(MailboxSessionJCRRepository repository, UidProvider uidProvider, ModSeqProvider modSeqProvider, int scaling, int messageScaling) { - this.repository = repository; - this.scaling = scaling; - this.messageScaling = messageScaling; - this.uidProvider = uidProvider; - this.modSeqProvider = modSeqProvider; - } - - @Override - public MailboxMapper createMailboxMapper(MailboxSession session) throws MailboxException { - return new JCRMailboxMapper(repository, session, scaling); - } - - @Override - public MessageMapper createMessageMapper(MailboxSession session) throws MailboxException { - return new JCRMessageMapper(repository, session, uidProvider, modSeqProvider, messageScaling); - } - - @Override - public MessageIdMapper createMessageIdMapper(MailboxSession session) throws MailboxException { - throw new NotImplementedException("Not implemented"); - } - - @Override - public SubscriptionMapper createSubscriptionMapper(MailboxSession session) throws SubscriptionException { - return new JCRSubscriptionMapper(repository, session, DEFAULT_SCALING); - } - - public MailboxSessionJCRRepository getRepository() { - return repository; - } - - @Override - public AnnotationMapper createAnnotationMapper(MailboxSession session) - throws MailboxException { - throw new NotImplementedException("Not implemented"); - } - - @Override - public UidProvider getUidProvider() { - return uidProvider; - } - - @Override - public ModSeqProvider getModSeqProvider() { - return modSeqProvider; - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java deleted file mode 100644 index 6a5f736..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java +++ /dev/null @@ -1,92 +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.jcr; - -import java.util.Date; -import java.util.List; - -import javax.mail.Flags; -import javax.mail.internet.SharedInputStream; - -import org.apache.james.mailbox.MailboxPathLocker; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.jcr.mail.model.JCRMailbox; -import org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage; -import org.apache.james.mailbox.model.MessageAttachment; -import org.apache.james.mailbox.model.MessageId; -import org.apache.james.mailbox.quota.QuotaManager; -import org.apache.james.mailbox.quota.QuotaRootResolver; -import org.apache.james.mailbox.store.BatchSizes; -import org.apache.james.mailbox.store.ImmutableMailboxMessage; -import org.apache.james.mailbox.store.MailboxSessionMapperFactory; -import org.apache.james.mailbox.store.StoreMessageManager; -import org.apache.james.mailbox.store.StoreRightManager; -import org.apache.james.mailbox.store.event.MailboxEventDispatcher; -import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.impl.MessageParser; -import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; -import org.apache.james.mailbox.store.search.MessageSearchIndex; - -/** - * JCR implementation of a {@link org.apache.james.mailbox.MessageManager} - * - * @Deprecated: See JAMES-2571 The JCR implementation is not enough maintained and thus will be removed from James in version 3.3.0. Please prefer using - * other MailboxManagers or contribute the JCR mailbox maintenance. - */ -@Deprecated -public class JCRMessageManager extends StoreMessageManager { - - public JCRMessageManager(MailboxSessionMapperFactory mapperFactory, - MessageSearchIndex index, - MailboxEventDispatcher dispatcher, - MailboxPathLocker locker, - JCRMailbox mailbox, - QuotaManager quotaManager, - QuotaRootResolver quotaRootResolver, - MessageParser messageParser, - MessageId.Factory messageIdFactory, - BatchSizes batchSizes, - ImmutableMailboxMessage.Factory immutableMailboxMessageFactory, - StoreRightManager storeRightManager) { - - super(JCRMailboxManager.DEFAULT_NO_MESSAGE_CAPABILITIES, mapperFactory, index, dispatcher, locker, mailbox, quotaManager, - quotaRootResolver, messageParser, messageIdFactory, batchSizes, immutableMailboxMessageFactory, storeRightManager); - } - - - @Override - protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, List<MessageAttachment> attachments) throws MailboxException { - JCRId mailboxId = (JCRId) getMailboxEntity().getMailboxId(); - return new JCRMailboxMessage(mailboxId, getMessageIdFactory().generate(), internalDate, - size, flags, content, bodyStartOctet, propertyBuilder); - } - - /** - * This implementation allow to store ANY user flag in a permanent manner - */ - @Override - protected Flags getPermanentFlags(MailboxSession session) { - Flags perm = super.getPermanentFlags(session); - perm.add(Flags.Flag.USER); - return perm; - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRRepositoryAuthenticator.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRRepositoryAuthenticator.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRRepositoryAuthenticator.java deleted file mode 100644 index 8784cd3..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRRepositoryAuthenticator.java +++ /dev/null @@ -1,58 +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.jcr; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; - -import org.apache.james.mailbox.store.Authenticator; - -/** - * {@link Authenticator} implementation which will try to log in the {@link Repository} and obtain a Session. If this fails it will handle the - * user/pass as invalid. If it success it will logout from the session again and handle the user/pass as valid. - * - * This implementation should be used if you want to handle the IMAP Users transparent to the JCR Users. The use of the implementation only makes - * real sense in conjunction with the direct {@link MailboxSessionJCRRepository} implementation (not a subclass). - * - */ -public class JCRRepositoryAuthenticator implements Authenticator { - - private final MailboxSessionJCRRepository repository; - - public JCRRepositoryAuthenticator(MailboxSessionJCRRepository repository) { - this.repository = repository; - } - - @Override - public boolean isAuthentic(String userid, CharSequence passwd) { - Repository repos = repository.getRepository(); - try { - // Try to log in the Repository with the user and password. If this success we can asume that the user/pass is valid. In - // all cases we need to logout again to not bind two JCR Session per thread later - Session session = repos.login(new SimpleCredentials(userid,passwd.toString().toCharArray()), repository.getWorkspace()); - session.logout(); - return true; - } catch (RepositoryException e) { - return false; - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRSubscriptionManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRSubscriptionManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRSubscriptionManager.java deleted file mode 100644 index bf4960d..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRSubscriptionManager.java +++ /dev/null @@ -1,39 +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.jcr; - -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.jcr.user.model.JCRSubscription; -import org.apache.james.mailbox.store.StoreSubscriptionManager; -import org.apache.james.mailbox.store.user.model.Subscription; - -/** - * JCR implementation of a SubscriptionManager - */ -public class JCRSubscriptionManager extends StoreSubscriptionManager implements JCRImapConstants { - - public JCRSubscriptionManager(JCRMailboxSessionMapperFactory mapperFactory) { - super(mapperFactory); - } - - @Override - protected Subscription createSubscription(MailboxSession session, String mailbox) { - return new JCRSubscription(session.getUser().getUserName(), mailbox); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRUtils.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRUtils.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRUtils.java deleted file mode 100644 index 192b548..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRUtils.java +++ /dev/null @@ -1,79 +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.jcr; - -import java.io.InputStream; -import java.io.InputStreamReader; - -import javax.jcr.Repository; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; - -import org.apache.jackrabbit.commons.cnd.CndImporter; - -/** - * Utilities used for JCR - * - */ -public class JCRUtils implements JCRImapConstants { - - /** - * Register the imap CND file in the workspace - * - * @param repository - * @param workspace - * @param username - * @param password - */ - public static void registerCnd(Repository repository, String workspace, String username, String password) { - try { - Session session; - if (username == null) { - session = repository.login(workspace); - } else { - char[] pass; - if (password == null) { - pass = new char[0]; - } else { - pass = password.toCharArray(); - } - session = repository.login(new SimpleCredentials(username, pass), workspace); - } - registerCnd(session); - session.logout(); - } catch (Exception e) { - throw new RuntimeException("Unable to register cnd file", e); - } - } - - /** - * Register the imap CND file - */ - public static void registerCnd(Session session) { - // Register the custom node types defined in the CND file - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - - try (InputStream is = contextClassLoader.getResourceAsStream("mailbox-jcr.cnd")) { - CndImporter.registerNodeTypes(new InputStreamReader(is), session); - } catch (Exception e) { - throw new RuntimeException("Unable to register cnd file", e); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/MailboxSessionJCRRepository.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/MailboxSessionJCRRepository.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/MailboxSessionJCRRepository.java deleted file mode 100644 index 05dcfc3..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/MailboxSessionJCRRepository.java +++ /dev/null @@ -1,114 +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.jcr; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; - -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.MailboxSession.User; - -/** - * Manage JCR {@link Session}. It use the username and the password of - * the logged in IMAP user to obtain a JCR {@link Session} from the {@link Repository} - * - */ -public class MailboxSessionJCRRepository { - private static final String JCR_SESSION = "JCR_SESSION"; - private final Repository repository; - private final String workspace; - - public MailboxSessionJCRRepository(Repository repository, String workspace) { - this.repository = repository; - this.workspace = workspace; - } - - /** - * If no {@link Session} exists for the {@link MailboxSession} one will get created. - * If one exists it just return the existing. - * - * @param session - * @return jcrSession - * @throws RepositoryException - */ - public Session login(MailboxSession session) throws RepositoryException { - User user = session.getUser(); - String username = user.getUserName(); - String password = user.getPassword(); - char[] pass = null; - if (password != null) { - pass = password.toCharArray(); - } - return login(session, username, pass); - } - - - - protected Session login(MailboxSession mSession, String username, - char[] pass) throws RepositoryException { - Session session = (Session) mSession.getAttributes().get(JCR_SESSION); - if (session == null) { - session = repository.login(new SimpleCredentials(username, pass), - workspace); - mSession.getAttributes().put(JCR_SESSION, session); - } - return session; - } - - /** - * Logout the JCR {@link Session} if one exists - * - * @param mSession - */ - public void logout(MailboxSession mSession) { - if (mSession == null) { - return; - } - - Session session = (Session) mSession.getAttributes().remove(JCR_SESSION); - - if (session != null) { - if (session.isLive()) { - session.logout(); - } - session = null; - } - } - - - /** - * Return the {@link Repository} - * - * @return repository - */ - public Repository getRepository() { - return repository; - } - - /** - * Return the workspace - * - * @return workspace - */ - public String getWorkspace() { - return workspace; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/Persistent.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/Persistent.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/Persistent.java deleted file mode 100644 index f687ff7..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/Persistent.java +++ /dev/null @@ -1,50 +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.jcr; - -import java.io.IOException; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; - - -public interface Persistent { - - /** - * Merge the object with the node - * - * @param node - */ - void merge(Node node) throws RepositoryException, IOException; - - /** - * Return underlying Node - * - * @return node - */ - Node getNode(); - - /** - * Return if the object is persistent - * - * @return <code>true</code> if object is persistent else <code>false</code> - */ - boolean isPersistent(); - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/876987c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java deleted file mode 100644 index 458b714..0000000 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java +++ /dev/null @@ -1,250 +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.jcr.mail; - -import java.util.ArrayList; -import java.util.List; - -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; - -import org.apache.jackrabbit.JcrConstants; -import org.apache.jackrabbit.commons.JcrUtils; -import org.apache.jackrabbit.util.ISO9075; -import org.apache.jackrabbit.util.Text; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.acl.ACLDiff; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.exception.MailboxNotFoundException; -import org.apache.james.mailbox.jcr.AbstractJCRScalingMapper; -import org.apache.james.mailbox.jcr.MailboxSessionJCRRepository; -import org.apache.james.mailbox.jcr.mail.model.JCRMailbox; -import org.apache.james.mailbox.model.MailboxACL; -import org.apache.james.mailbox.model.MailboxACL.Right; -import org.apache.james.mailbox.model.MailboxId; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.store.mail.MailboxMapper; -import org.apache.james.mailbox.store.mail.model.Mailbox; - -import com.google.common.collect.ImmutableList; - -/** - * JCR implementation of a MailboxMapper - * - * - */ -public class JCRMailboxMapper extends AbstractJCRScalingMapper implements MailboxMapper { - - @SuppressWarnings("deprecation") - private static final String XPATH_LANGUAGE = Query.XPATH; - - public JCRMailboxMapper(MailboxSessionJCRRepository repos, MailboxSession session, int scaling) { - super(repos, session, scaling); - } - - @Override - public void delete(Mailbox mailbox) throws MailboxException { - try { - Node node = getSession().getNodeByIdentifier(((JCRMailbox) mailbox).getMailboxId().serialize()); - - node.remove(); - - } catch (PathNotFoundException e) { - // mailbox does not exists.. - } catch (RepositoryException e) { - throw new MailboxException("Unable to delete mailbox " + mailbox, e); - } - } - - @Override - public Mailbox findMailboxByPath(MailboxPath path) throws MailboxException, MailboxNotFoundException { - try { - String name = Text.escapeIllegalXpathSearchChars(path.getName()); - String user = path.getUser(); - if (user == null) { - user = ""; - } - user = Text.escapeIllegalXpathSearchChars(user); - String namespace = Text.escapeIllegalXpathSearchChars(path.getNamespace()); - - QueryManager manager = getSession().getWorkspace().getQueryManager(); - - String queryString = "/jcr:root/" + MAILBOXES_PATH + "/" + ISO9075.encodePath(path.getNamespace()) + "//element(*,jamesMailbox:mailbox)[@" + JCRMailbox.NAME_PROPERTY + "='" + name + "' and @" + JCRMailbox.NAMESPACE_PROPERTY + "='" + namespace + "' and @" + JCRMailbox.USER_PROPERTY + "='" + user + "']"; - QueryResult result = manager.createQuery(queryString, XPATH_LANGUAGE).execute(); - NodeIterator it = result.getNodes(); - if (it.hasNext()) { - return new JCRMailbox(it.nextNode()); - } - throw new MailboxNotFoundException(path); - } catch (PathNotFoundException e) { - throw new MailboxNotFoundException(path); - } catch (RepositoryException e) { - throw new MailboxException("Unable to find mailbox " + path, e); - } - } - - @Override - public Mailbox findMailboxById(MailboxId id) throws MailboxException, MailboxNotFoundException { - try { - Node node = getSession().getNodeByIdentifier(id.serialize()); - return new JCRMailbox(node); - } catch (PathNotFoundException e) { - throw new MailboxNotFoundException(id); - } catch (RepositoryException e) { - throw new MailboxException("Unable to find mailbox " + id.serialize(), e); - } - } - - - @Override - public List<Mailbox> findMailboxWithPathLike(MailboxPath path) throws MailboxException { - List<Mailbox> mailboxList = new ArrayList<>(); - try { - String name = Text.escapeIllegalXpathSearchChars(path.getName()); - String user = path.getUser(); - if (user == null) { - user = ""; - } - user = Text.escapeIllegalXpathSearchChars(user); - String namespace = Text.escapeIllegalXpathSearchChars(path.getNamespace()); - - QueryManager manager = getSession().getWorkspace().getQueryManager(); - String queryString = "/jcr:root/" + MAILBOXES_PATH + "/" + ISO9075.encodePath(path.getNamespace()) + "//element(*,jamesMailbox:mailbox)[jcr:like(@" + JCRMailbox.NAME_PROPERTY + ",'%" + name + "%') and @" + JCRMailbox.NAMESPACE_PROPERTY + "='" + namespace + "' and @" + JCRMailbox.USER_PROPERTY + "='" + user + "']"; - QueryResult result = manager.createQuery(queryString, XPATH_LANGUAGE).execute(); - NodeIterator it = result.getNodes(); - while (it.hasNext()) { - mailboxList.add(new JCRMailbox(it.nextNode())); - } - } catch (PathNotFoundException e) { - // nothing todo - } catch (RepositoryException e) { - throw new MailboxException("Unable to find mailbox " + path, e); - } - return mailboxList; - } - - @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { - - try { - final JCRMailbox jcrMailbox = (JCRMailbox)mailbox; - Node node = null; - - if (jcrMailbox.isPersistent()) { - node = getSession().getNodeByIdentifier(jcrMailbox.getMailboxId().serialize()); - } - if (node == null) { - Node rootNode = getSession().getRootNode(); - Node mailboxNode; - if (rootNode.hasNode(MAILBOXES_PATH) == false) { - mailboxNode = rootNode.addNode(MAILBOXES_PATH); - mailboxNode.addMixin(JcrConstants.MIX_LOCKABLE); - getSession().save(); - } else { - mailboxNode = rootNode.getNode(MAILBOXES_PATH); - } - - node = JcrUtils.getOrAddNode(mailboxNode, Text.escapeIllegalJcrChars(jcrMailbox.getNamespace()), "nt:unstructured"); - if (jcrMailbox.getUser() != null) { - node = createUserPathStructure(node, Text.escapeIllegalJcrChars(jcrMailbox.getUser())); - } - node = JcrUtils.getOrAddNode(node, Text.escapeIllegalJcrChars(jcrMailbox.getName()), "nt:unstructured"); - node.addMixin("jamesMailbox:mailbox"); - - jcrMailbox.merge(node); - - } else { - jcrMailbox.merge(node); - } - return jcrMailbox.getMailboxId(); - - } catch (RepositoryException e) { - throw new MailboxException("Unable to save mailbox " + mailbox, e); - } - } - - @Override - public boolean hasChildren(Mailbox mailbox, char delimiter) - throws MailboxException, MailboxNotFoundException { - try { - String name = Text.escapeIllegalXpathSearchChars(mailbox.getName()); - String user = mailbox.getUser(); - if (user == null) { - user = ""; - } - user = Text.escapeIllegalXpathSearchChars(user); - String namespace = Text.escapeIllegalXpathSearchChars(mailbox.getNamespace()); - - QueryManager manager = getSession().getWorkspace() - .getQueryManager(); - String queryString = "/jcr:root/" + MAILBOXES_PATH + "/" + ISO9075.encodePath(mailbox.getNamespace()) - + "//element(*,jamesMailbox:mailbox)[jcr:like(@" - + JCRMailbox.NAME_PROPERTY + ",'" + name + delimiter + "%') and @" + JCRMailbox.NAMESPACE_PROPERTY + "='" + namespace + "' and @" + JCRMailbox.USER_PROPERTY + "='" + user + "']"; - QueryResult result = manager.createQuery(queryString, XPATH_LANGUAGE) - .execute(); - NodeIterator it = result.getNodes(); - return it.hasNext(); - } catch (RepositoryException e) { - throw new MailboxException("Unable to retrieve children for mailbox " + mailbox, e); - } - } - - @Override - public List<Mailbox> list() throws MailboxException { - try { - List<Mailbox> mList = new ArrayList<>(); - QueryManager manager = getSession().getWorkspace().getQueryManager(); - - String queryString = "/jcr:root/" + MAILBOXES_PATH + "//element(*,jamesMailbox:mailbox)"; - QueryResult result = manager.createQuery(queryString, XPATH_LANGUAGE).execute(); - NodeIterator it = result.getNodes(); - while (it.hasNext()) { - mList.add(new JCRMailbox(it.nextNode())); - } - return mList; - } catch (RepositoryException e) { - throw new MailboxException("Unable to retrieve the list of mailboxes", e); - } - } - - @Override - public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException { - MailboxACL oldACL = mailbox.getACL(); - MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand); - mailbox.setACL(newACL); - return ACLDiff.computeDiff(oldACL, newACL); - } - - @Override - public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException { - MailboxACL oldMailboxAcl = mailbox.getACL(); - mailbox.setACL(mailboxACL); - return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL); - } - - @Override - public List<Mailbox> findNonPersonalMailboxes(String userName, Right right) throws MailboxException { - return ImmutableList.of(); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
