|
Author: sascharodekamp
Date: Thu Jun 7 09:01:01 2012 New Revision: 1347547 URL: http://svn.apache.org/viewvc?rev=1347547&view=rev Log: Add multi tenant support to JCR repository. Each tenant have now it's own repository. Also added a test case which checks that one tenant haven't access to the repository of another tenant. Added: ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/ ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/entitymodel.xml ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitBaseTests.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitDataTests.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitFilesTests.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitQueryTests.java Removed: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java Modified: ofbiz/branches/jackrabbit20120501/framework/entity/data/TenantDemoData.xml ofbiz/branches/jackrabbit20120501/framework/jcr/config/jcr-config.xml ofbiz/branches/jackrabbit20120501/framework/jcr/ofbiz-component.xml ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java ofbiz/branches/jackrabbit20120501/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java Modified: ofbiz/branches/jackrabbit20120501/framework/entity/data/TenantDemoData.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/entity/data/TenantDemoData.xml?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/entity/data/TenantDemoData.xml (original) +++ ofbiz/branches/jackrabbit20120501/framework/entity/data/TenantDemoData.xml Thu Jun 7 09:01:01 2012 @@ -33,4 +33,12 @@ under the License. <TenantDataSource tenantId="DEMO2" entityGroupName="org.ofbiz.olap" jdbcUri="jdbc:derby:ofbizolap_DEMO2;create=true" jdbcUsername="ofbiz" jdbcPassword="ofbiz"/> <!-- See comments on entity def: <TenantUserLogin tenantId="DEMO2" userLoginId="admin" fromDate="2001-05-13 00:00:00.000" thruDate="" isManager="N"/> --> + + <TenantJcrDataSource tenantId="DEMO1" jcrRepId="demo1" jcrMinRecordLength="0" jcrRepHighlighting="1" + jcrRepPath="runtime/data/jcr/demo1/" statusId="" createdDate="" createdByUserLogin="" + lastModifiedDate="" lastModifiedByUserLogin="" /> + + <TenantJcrDataSource tenantId="DEMO2" jcrRepId="demo2" jcrMinRecordLength="0" jcrRepHighlighting="1" + jcrRepPath="runtime/data/jcr/demo2/" statusId="" createdDate="" createdByUserLogin="" + lastModifiedDate="" lastModifiedByUserLogin="" /> </entity-engine-xml> Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/config/jcr-config.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/config/jcr-config.xml?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/config/jcr-config.xml (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/config/jcr-config.xml Thu Jun 7 09:01:01 2012 @@ -15,7 +15,7 @@ <!-- <jcr name="myCustom" class="com.mycompany.jcr.MyCustomJCR"/> --> <!-- jcr home directory --> - <home-dir path="runtime/data/jcr/" /> + <home-dir path="runtime/data/jcr/common/" /> <!-- config file for thr jcr implementation --> <config-file-path path="framework/jcr/config/jackrabbit.xml" /> Added: ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/entitymodel.xml?rev=1347547&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/entitymodel.xml (added) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/entitydef/entitymodel.xml Thu Jun 7 09:01:01 2012 @@ -0,0 +1,47 @@ +<?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. +--> + +<entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/entitymodel.xsd"> + + <title>Entity of an Open For Business JCR Component</title> + <description>None</description> + <version>1.0</version> + + <entity entity-name="TenantJcrDataSource" package-name="org.apache.ofbiz.jcr" title="JCR params"> + <field name="tenantId" type="id-ne" /> + + <field name="jcrRepId" type="id-ne" /> + <field name="jcrMinRecordLength" type="long-varchar" /> + <field name="jcrRepHighlighting" type="indicator" /> + <field name="jcrRepPath" type="long-varchar" not-null="true"/> + + <field name="statusId" type="id-ne" /> + <field name="createdDate" type="date-time" /> + <field name="createdByUserLogin" type="id-vlong-ne" /> + <field name="lastModifiedDate" type="date-time"></field> + <field name="lastModifiedByUserLogin" type="id-vlong-ne" /> + + <prim-key field="tenantId" /> + <relation type="one" fk-name="TNTDTSRC_TNT" rel-entity-name="Tenant"> + <key-map field-name="tenantId" /> + </relation> + </entity> +</entitymodel> Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/ofbiz-component.xml?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/ofbiz-component.xml (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/ofbiz-component.xml Thu Jun 7 09:01:01 2012 @@ -26,8 +26,9 @@ under the License. <classpath type="jar" location="build/lib/*"/> <classpath type="jar" location="lib/*"/> - <service-resource type="model" loader="main" location="servicedef/services.xml"/> - <test-suite loader="main" location="testdef/jcrtests.xml"/> + <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/> + <service-resource type="model" loader="main" location="servicedef/services.xml"/> + <test-suite loader="main" location="testdef/jcrtests.xml" /> </ofbiz-component> Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java Thu Jun 7 09:01:01 2012 @@ -13,6 +13,7 @@ import net.sf.json.JSONArray; import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl; import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.ContentReader; import org.ofbiz.jcr.access.ContentWriter; @@ -34,11 +35,12 @@ public class JackrabbitRepositoryAccesso * Create a repository Access object based on the userLogin. * * @param userLogin + * @throws RepositoryException */ - public JackrabbitRepositoryAccessor(GenericValue userLogin) { + public JackrabbitRepositoryAccessor(GenericValue userLogin, Delegator delegator) throws RepositoryException { this.userLogin = userLogin; // TODO pass the userLogin to the getSession() method and perform some - this.session = JCRFactoryUtil.getSession(); + this.session = JCRFactoryUtil.getSession(delegator); this.ocm = new ObjectContentManagerImpl(session, JCRFactoryImpl.getMapper()); } @@ -231,13 +233,4 @@ public class JackrabbitRepositoryAccesso return false; } } - - /** - * Returns the party ID which created the accessor. - * - * @return - */ - private String getPartyId() { - return this.userLogin.getString("partyId"); - } } Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java Thu Jun 7 09:01:01 2012 @@ -16,6 +16,7 @@ import javax.jcr.ValueFormatException; import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; @@ -55,9 +56,10 @@ public class JackrabbitArticleHelper ext /** * Setup my content Object + * @throws RepositoryException */ - public JackrabbitArticleHelper(GenericValue userLogin) { - super(new JackrabbitRepositoryAccessor(userLogin)); + public JackrabbitArticleHelper(GenericValue userLogin, Delegator delegator) throws RepositoryException { + super(new JackrabbitRepositoryAccessor(userLogin, delegator)); } /* Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java Thu Jun 7 09:01:01 2012 @@ -13,6 +13,7 @@ import org.apache.tika.Tika; import org.apache.tika.io.TikaInputStream; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; @@ -42,8 +43,8 @@ public class JackrabbitFileHelper extend private JackrabbitHierarchyNode hierarchy = null; - public JackrabbitFileHelper(GenericValue userLogin) { - super(new JackrabbitRepositoryAccessor(userLogin)); + public JackrabbitFileHelper(GenericValue userLogin, Delegator delegator) throws RepositoryException { + super(new JackrabbitRepositoryAccessor(userLogin, delegator)); } /* Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java Thu Jun 7 09:01:01 2012 @@ -34,10 +34,10 @@ import org.w3c.dom.Element; */ public class JCRContainer implements Container { - public static final String module = JCRContainer.class.getName(); - public static final String DEFAULT_JCR_CONFIG_PATH = "framework/jcr/config/jcr-config.xml"; + private static final String module = JCRContainer.class.getName(); + private static String configFilePath = null; private boolean removeRepositoryOnShutdown = false; Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java Thu Jun 7 09:01:01 2012 @@ -22,6 +22,7 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.ofbiz.entity.Delegator; import org.w3c.dom.Element; public interface JCRFactory { @@ -53,13 +54,7 @@ public interface JCRFactory { * @return * @throws RepositoryException */ - public Session createSession() throws RepositoryException; + public Session createSession(Delegator delegator) throws RepositoryException; - /** - * Should return an instance of the repository implementation. - * - * @return - */ public Repository getInstance(); - } Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java Thu Jun 7 09:01:01 2012 @@ -22,11 +22,12 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; import org.ofbiz.security.SecurityFactory; public class JCRFactoryUtil { - public static final String module = JCRFactoryUtil.class.getName(); + private static final String module = JCRFactoryUtil.class.getName(); private static JCRFactory jcrFactory; private static String jcrFactoryName; @@ -61,15 +62,8 @@ public class JCRFactoryUtil { return jcrFactory; } - public static Session getSession() { - Session session = null; - try { - session = getJCRFactory().createSession(); - } catch (RepositoryException e) { - Debug.logError(e, module); - } - - return session; + public static Session getSession(Delegator delegator) throws RepositoryException { + return getJCRFactory().createSession(delegator); } public static void setJcrFactoryClassName(String jcrFactoryClassName) { Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java Thu Jun 7 09:01:01 2012 @@ -12,7 +12,7 @@ import org.ofbiz.base.util.JNDIContextFa public class JCRJndi { - public static final String module = JCRJndi.class.getName(); + private static final String module = JCRJndi.class.getName(); public final static String ADDR_TYPE_FOR_REPOSITORY_HOME_DIR = "REPHOME"; public final String ADDR_TYPE_FOR_CONFIG_FILE_PATH = "CONFPATH"; @@ -37,8 +37,6 @@ public class JCRJndi { } bindRepository(jndiContext); - // Test JNDI bind - RepositoryLoader.getRepository(); } public void unbindRepository() { Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java Thu Jun 7 09:01:01 2012 @@ -3,6 +3,7 @@ package org.ofbiz.jcr.loader; import java.util.Map; import javax.jcr.Repository; +import javax.naming.InitialContext; import javax.naming.NamingException; import javolution.util.FastMap; @@ -71,7 +72,8 @@ public class RepositoryLoader { String jndiName = curElement.getAttribute("jndi-name"); if (UtilValidate.isNotEmpty(jndiName)) { try { - repos.put(name, (Repository) JNDIContextFactory.getInitialContext("default").lookup(jndiName)); + InitialContext initialContext = JNDIContextFactory.getInitialContext("default"); + repos.put(name, (Repository) initialContext.lookup(jndiName)); } catch (NamingException e) { Debug.logError(e, module); } catch (GenericConfigException e) { Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java Thu Jun 7 09:01:01 2012 @@ -23,7 +23,9 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.jcr.Credentials; import javax.jcr.Repository; @@ -48,21 +50,23 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.loader.JCRFactory; import org.ofbiz.jcr.loader.JCRJndi; import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; +import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitLocalizedContent; +import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitNews; +import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitUnstructured; import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFile; import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFolder; import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitHierarchyNode; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitLocalizedContent; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitNews; import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitResource; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitUnstructured; import org.w3c.dom.Element; public class JCRFactoryImpl implements JCRFactory { - public static final String module = JCRFactoryImpl.class.getName(); + private static final String module = JCRFactoryImpl.class.getName(); private static String CUSTOM_NODE_TYPES = "framework/jcr/config/custom-jackrabbit-nodetypes.xml"; @@ -71,13 +75,12 @@ public class JCRFactoryImpl implements J private static String CREDENTIALS_USERNAME = null; private static char[] CREDENTIALS_PASSWORD = null; - protected static Repository repository = null; - protected Session session = null; - - protected static Mapper mapper = null; + private static Mapper mapper = null; private JCRJndi jndi; + private Map<String, Repository> repositoryReferenceStore; + /* * (non-Javadoc) * @@ -95,6 +98,8 @@ public class JCRFactoryImpl implements J CREDENTIALS_PASSWORD = UtilXml.elementAttribute(childElement, "password", null).toCharArray(); jackrabbitConfigFile = UtilXml.childElementAttribute(configRootElement, "config-file-path", "path", "framework/jcr/config/jackrabbit.xml"); + + repositoryReferenceStore = new HashMap<String, Repository>(); } /* @@ -104,28 +109,16 @@ public class JCRFactoryImpl implements J */ @Override public void start() throws RepositoryException { - // Transient repositories closes automatically when the last session is - // closed - repository = new TransientRepository(jackrabbitConfigFile, homeDir); - createSession(); - - List<Class> classes = new ArrayList<Class>(); - // put this in an xml configuration file - // should the ocm classes be loaded in during the container startup? - classes.add(JackrabbitUnstructured.class); - classes.add(JackrabbitHierarchyNode.class); - classes.add(JackrabbitNews.class); - classes.add(JackrabbitFile.class); - classes.add(JackrabbitFolder.class); - classes.add(JackrabbitResource.class); - classes.add(JackrabbitLocalizedContent.class); - classes.add(JackrabbitArticle.class); - - mapper = new AnnotationMapperImpl(classes); - + createRepository(); + createObjectRepositoryMapper(); jndi.registerJcrToJndi(); } + @Override + public Repository getInstance() { + return repositoryReferenceStore.get("default"); + } + /* * (non-Javadoc) * @@ -133,10 +126,6 @@ public class JCRFactoryImpl implements J */ @Override public void stop(boolean removeRepositoryOnShutdown) throws RepositoryException { - if (session != null && session.isLive()) { - session.logout(); - } - if (removeRepositoryOnShutdown) { if (UtilValidate.isNotEmpty(homeDir)) { File homeDirFile = new File(homeDir); @@ -157,45 +146,49 @@ public class JCRFactoryImpl implements J * @see org.ofbiz.jcr.JCRFactory#createSession() */ @Override - public Session createSession() throws RepositoryException { - if (session == null || !session.isLive()) { - Credentials credentials = new SimpleCredentials(CREDENTIALS_USERNAME, CREDENTIALS_PASSWORD); - try { - session = repository.login(credentials); - // register NameSpaces - RepositoryUtil.setupSession(session); - try { - // register the cool new noteTypes - registerNodeTypes(session); - } catch (InvalidNodeTypeDefException e) { - Debug.logError(e, module); - } catch (IOException e) { - Debug.logError(e, module); - } + public Session createSession(Delegator delegator) throws RepositoryException { + String tenantId = delegator.getDelegatorTenantId(); - } catch (RepositoryException e) { - Debug.logError(e, "Could not login to the workspace"); - throw e; - } + // TODO create session pool + Repository repository = null; + if (UtilValidate.isNotEmpty(tenantId)) { + repository = getTenantRepositoryInstance(delegator); + } else { + repository = repositoryReferenceStore.get("default"); } - return session; - } - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.JCRFactory#getInstance() - */ - @Override - public Repository getInstance() { - return repository; + Credentials credentials = new SimpleCredentials(CREDENTIALS_USERNAME, CREDENTIALS_PASSWORD); + Session session = repository.login(credentials); + // register NameSpaces + RepositoryUtil.setupSession(session); + try { + // register the new noteTypes + registerNodeTypes(session); + } catch (InvalidNodeTypeDefException e) { + Debug.logError(e, module); + } catch (IOException e) { + Debug.logError(e, module); + } + + return session; } public static Mapper getMapper() { return mapper; } + private Repository getDefaultRepository() { + return repositoryReferenceStore.get("default"); + } + + private void createRepository() { + // Transient repositories closes automatically when the last session is + // closed + Repository repository = new TransientRepository(jackrabbitConfigFile, homeDir); + repositoryReferenceStore.put("default", repository); + } + /* * Register some new node types */ @@ -222,4 +215,47 @@ public class JCRFactoryImpl implements J } } + + private void createObjectRepositoryMapper() { + List<Class> classes = new ArrayList<Class>(); + // put this in an xml configuration file + // should the ocm classes be loaded in during the container startup? + classes.add(JackrabbitUnstructured.class); + classes.add(JackrabbitHierarchyNode.class); + classes.add(JackrabbitNews.class); + classes.add(JackrabbitFile.class); + classes.add(JackrabbitFolder.class); + classes.add(JackrabbitResource.class); + classes.add(JackrabbitLocalizedContent.class); + classes.add(JackrabbitArticle.class); + + mapper = new AnnotationMapperImpl(classes); + } + + private Repository getTenantRepositoryInstance(Delegator delegator) { + + String tenantId = delegator.getDelegatorTenantId(); + if (this.repositoryReferenceStore.containsKey(tenantId)) { + return repositoryReferenceStore.get(tenantId); + } + + GenericValue tenantJcrDataSource; + Repository tenantRepository = null; + try { + tenantJcrDataSource = delegator.findOne("TenantJcrDataSource", true, "tenantId", tenantId); + if (UtilValidate.isNotEmpty(tenantJcrDataSource)) { + String repositoryHome = tenantJcrDataSource.getString("jcrRepPath"); + tenantRepository = new TransientRepository(jackrabbitConfigFile, repositoryHome); + } else { + tenantRepository = new TransientRepository(jackrabbitConfigFile, homeDir + tenantId); + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + + repositoryReferenceStore.put(tenantId, tenantRepository); + + return tenantRepository; + } + } Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java Thu Jun 7 09:01:01 2012 @@ -9,11 +9,11 @@ import org.apache.jackrabbit.ocm.mapper. public class JackrabbitArticle extends JackrabbitLocalizedContent { @Field(id = true) - String title = null; + private String title = null; @Field - String content = null; + private String content = null; @Field - Calendar pubDate = null; + private Calendar pubDate = null; /** * Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java Thu Jun 7 09:01:01 2012 @@ -9,11 +9,11 @@ import org.apache.jackrabbit.ocm.mapper. public class JackrabbitNews extends JackrabbitLocalizedContent { @Field(id = true) - String title = null; + private String title = null; @Field(jcrType = "Date") - Calendar pubDate = null; + private Calendar pubDate = null; @Field - String content = null; + private String content = null; public JackrabbitNews() { super(); Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java Thu Jun 7 09:01:01 2012 @@ -11,7 +11,7 @@ import org.ofbiz.jcr.util.jackrabbit.Jac @Node(isAbstract = true, jcrMixinTypes = "mix:versionable") public abstract class JackrabbitUnstructured implements OfbizRepositoryMapping { - protected static String module = JackrabbitUnstructured.class.getName(); + private static String module = JackrabbitUnstructured.class.getName(); @Field(path = true) private String path; Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java Thu Jun 7 09:01:01 2012 @@ -29,7 +29,7 @@ public class JackrabbitServices { Long start = 0l; Long diff = 0l; - Session session = JCRFactoryUtil.getSession(); + Session session = JCRFactoryUtil.getSession(ctx.getDelegator()); VersionManager vm = session.getWorkspace().getVersionManager(); start = new Date().getTime(); for (int i = 0; i <= maxNodes; i++) { @@ -54,7 +54,7 @@ public class JackrabbitServices { diff = (new Date().getTime() - start); result.put("repositoryDirectAccessTime", diff.toString()); - JackrabbitRepositoryAccessor access = new JackrabbitRepositoryAccessor(userLogin); + JackrabbitRepositoryAccessor access = new JackrabbitRepositoryAccessor(userLogin, ctx.getDelegator()); start = new Date().getTime(); for (int i = 0; i <= maxNodes; i++) { try { Added: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitBaseTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitBaseTests.java?rev=1347547&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitBaseTests.java (added) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitBaseTests.java Thu Jun 7 09:01:01 2012 @@ -0,0 +1,118 @@ +/* +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.ofbiz.jcr.test; + +import java.util.Map; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import javolution.util.FastMap; + +import org.apache.jackrabbit.ocm.mapper.Mapper; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.jcr.access.JcrRepositoryAccessor; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; +import org.ofbiz.jcr.loader.JCRFactory; +import org.ofbiz.jcr.loader.JCRFactoryUtil; +import org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; +import org.ofbiz.service.ServiceUtil; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class JackrabbitBaseTests extends OFBizTestCase { + + private GenericValue userLogin = null; + + public JackrabbitBaseTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + + } + + @Override + protected void tearDown() throws Exception { + } + + public void testRepositoryConstructor() throws Exception { + JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin, delegator); + assertNotNull(repositoryAccess); + repositoryAccess.closeAccess(); + } + + public void testFactoryGetMapper() { + assertNotNull(JCRFactoryImpl.getMapper()); + assertTrue(JCRFactoryImpl.getMapper() instanceof Mapper); + } + + public void testFactoryUtilGetJcrFactory() { + JCRFactory factory = JCRFactoryUtil.getJCRFactory(); + assertNotNull(factory); + assertTrue((factory instanceof JCRFactoryImpl)); + } + + public void testUtilGetSession() throws RepositoryException { + Session session = JCRFactoryUtil.getSession(delegator); + assertNotNull(session); + assertTrue((session instanceof Session)); + session.logout(); + } + + public void testCreateAbsoluteAndNormalizedNodePath() { + String result = JackrabbitUtils.createAbsoluteNodePath("foo/baa"); + + assertEquals("/foo/baa", result); + } + + public void testCheckIfNodePathIsAbsoluteAndNormalized() { + assertFalse(JackrabbitUtils.checkIfNodePathIsAbsolute("foo/baa")); + assertFalse(JackrabbitUtils.checkIfNodePathIsAbsolute("foo/baa/")); + assertTrue(JackrabbitUtils.checkIfNodePathIsAbsolute("/foo/baa/")); + assertTrue(JackrabbitUtils.checkIfNodePathIsAbsolute("/foo/baa")); + } + + public void testListRepositoryNodes() throws Exception { + assertNotNull(JackrabbitUtils.getRepositoryNodes(userLogin, null, delegator)); + } + + public void testDefaultLanguage() { + assertEquals(UtilProperties.getPropertyValue("general", "locale.properties.fallback"), JackrabbitUtils.determindeTheDefaultLanguage()); + } + + public void testSpeedTestService() throws Exception { + Map<String, Object> context = FastMap.newInstance(); + context.put("maxNodes", new Integer(10)); + context.put("userLogin", dispatcher.getDelegator().findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"))); + + Map<String, Object> serviceResult = this.dispatcher.runSync("determineJackrabbitRepositorySpeed", context); + + if (ServiceUtil.isError(serviceResult)) { + fail(); + } else { + assertTrue(true); + } + + } +} \ No newline at end of file Added: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitDataTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitDataTests.java?rev=1347547&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitDataTests.java (added) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitDataTests.java Thu Jun 7 09:01:01 2012 @@ -0,0 +1,174 @@ +/* +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.ofbiz.jcr.test; + +import java.util.GregorianCalendar; + +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import net.sf.json.JSONArray; + +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.jcr.access.ContentWriter; +import org.ofbiz.jcr.access.JcrRepositoryAccessor; +import org.ofbiz.jcr.access.jackrabbit.ContentWriterJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; +import org.ofbiz.jcr.api.JcrDataHelper; +import org.ofbiz.jcr.api.jackrabbit.JackrabbitArticleHelper; +import org.ofbiz.jcr.loader.JCRFactoryUtil; +import org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl; +import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class JackrabbitDataTests extends OFBizTestCase { + + private GenericValue userLogin = null; + + public JackrabbitDataTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + + } + + @Override + protected void tearDown() throws Exception { + } + + public void testAccessorConstructor() throws RepositoryException { + JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin, delegator); + + assertNotNull(accessor); + assertEquals("/", accessor.getSession().getRootNode().getPath()); + + accessor.closeAccess(); + } + + public void testAccessorDataTree() throws RepositoryException { + JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin, delegator); + + JSONArray array = accessor.getJsonDataTree(); + // should be 0 because there are no entries in the repository yet + assertEquals(0, array.size()); + + accessor.closeAccess(); + } + + public void testAccessorNodeExist() throws RepositoryException { + JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin, delegator); + assertTrue(accessor.checkIfNodeExist("/")); + assertFalse(accessor.checkIfNodeExist("/test")); + + accessor.closeAccess(); + } + + public void testWriterConsturctor() throws RepositoryException { + + Session session = JCRFactoryUtil.getSession(delegator); + ObjectContentManager ocm = new ObjectContentManagerImpl(session, JCRFactoryImpl.getMapper()); + ContentWriter writer = new ContentWriterJackrabbit(ocm); + + assertNotNull(writer); + + ocm.logout(); + } + + public void testCrudArticleNode() throws Exception { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin, delegator); + helper.storeContentInRepository("news/article", "en", "News Of Today", "Hello World", new GregorianCalendar()); + + JackrabbitArticle content = helper.readContentFromRepository("news/article"); + assertEquals("Hello World", content.getContent()); + + content.setContent("New World!"); + + helper.updateContentInRepository(content); + + JackrabbitArticle updatedContent = helper.readContentFromRepository("news/article"); + assertEquals("New World!", updatedContent.getContent()); + + helper.removeContentObject("news"); + + helper.closeContentSession(); + } + + public void testVersionning() throws Exception { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin, delegator); + helper.storeContentInRepository("news/versionArticle", "en", "News Of Today", "Hello World", new GregorianCalendar()); + + JackrabbitArticle content = helper.readContentFromRepository("news/versionArticle"); + assertEquals("1.0", content.getVersion()); + + content.setTitle("New Title"); + helper.updateContentInRepository(content); + + content = helper.readContentFromRepository("news/versionArticle"); + assertEquals("1.1", content.getVersion()); + + helper.removeContentObject("news"); + + helper.closeContentSession(); + } + + public void testLanguageDetermination() throws Exception { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin, delegator); + + helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); + helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar()); + + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow/en", "").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage()); + + assertEquals("de", helper.readContentFromRepository("/superhero", "de").getLanguage()); + assertEquals("de", helper.readContentFromRepository("/superhero", "").getLanguage()); + assertEquals("de", helper.readContentFromRepository("/superhero", "fr").getLanguage()); + + helper.removeContentObject("/superhero"); + helper.removeContentObject("/news"); + helper.closeContentSession(); + } + + public void testLanguageDeterminationExpectedPathNotFoundException() throws Exception { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin, delegator); + helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); + + try { + helper.readContentFromRepository("/news/tomorrow/fr", "").getLanguage(); + // if no exception is thrown, the test should fail + fail("Expected a PathNotFoundException."); + } catch (PathNotFoundException pnf) { + // check if the right exception is thrown (in jUnit 4 this could be + // replaced by annotations) + assertTrue("A PathNotFoundException is catched as expected.", true); + } + + helper.removeContentObject("/news"); + helper.closeContentSession(); + } +} \ No newline at end of file Added: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitFilesTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitFilesTests.java?rev=1347547&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitFilesTests.java (added) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitFilesTests.java Thu Jun 7 09:01:01 2012 @@ -0,0 +1,79 @@ +/* +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.ofbiz.jcr.test; + +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class JackrabbitFilesTests extends OFBizTestCase { + + private GenericValue userLogin = null; + + public JackrabbitFilesTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + + } + + @Override + protected void tearDown() throws Exception { + } + + /* + public void testAccessorFileTree() throws RepositoryException { + JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); + + JSONArray array = accessor.getJsonFileTree(); + assertEquals(0, array.size()); // should be 0 because there are no + // entries in the repository yet + accessor.closeAccess(); + }*/ + + /* + * Test the File upload + */ /* + public void testCreateRepositoryFileNode() throws Exception { + File f = new File("stopofbiz.sh"); + File f2 = new File("README"); + assertTrue(f.exists() && f2.exists()); + + InputStream file = new FileInputStream(f); + + JcrFileHelper helper = new JackrabbitFileHelper(userLogin); + helper.storeContentInRepository(file, f.getName(), "/fileHome"); + + assertNotNull(helper.getRepositoryContent("/fileHome/" + f.getName())); + + // add a second file to the same folder + file = new FileInputStream(f2); + + helper.storeContentInRepository(file, f2.getName(), "/fileHome"); + assertNotNull(helper.getRepositoryContent("/fileHome/" + f2.getName())); + + // remove all files in folder + helper.removeContentObject("/fileHome"); + + helper.closeContentSession(); + }*/ +} \ No newline at end of file Added: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitQueryTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitQueryTests.java?rev=1347547&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitQueryTests.java (added) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitQueryTests.java Thu Jun 7 09:01:01 2012 @@ -0,0 +1,74 @@ +/* +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.ofbiz.jcr.test; + +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class JackrabbitQueryTests extends OFBizTestCase { + + private GenericValue userLogin = null; + + public JackrabbitQueryTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + + } + + @Override + protected void tearDown() throws Exception { + } + + /* + public void testAccessorQuery() throws RepositoryException { + JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); + QueryResult results = accessor.queryForRepositoryData("SELECT * FROM [rep:root]"); + + assertNotNull(results); + assertEquals(1, results.getNodes().getSize()); + + accessor.closeAccess(); + }*/ + + /* + public void testQuery() throws Exception { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); + + helper.storeContentInRepository("/query", "en", "query", "query test", new GregorianCalendar()); + + List<Map<String, String>> queryResult = helper.queryData("SELECT * FROM [nt:unstructured]"); + + assertEquals(3, queryResult.size()); // the list should contain 3 result + // sets + + assertEquals("/", queryResult.get(0).get("path")); + assertEquals("/query", queryResult.get(1).get("path")); + assertEquals("/query/en", queryResult.get(2).get("path")); + + helper.removeContentObject("query"); + + helper.closeContentSession(); + + }*/ +} \ No newline at end of file Modified: ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java Thu Jun 7 09:01:01 2012 @@ -13,13 +13,14 @@ import javolution.util.FastMap; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; import org.ofbiz.jcr.loader.JCRFactoryUtil; public class JackrabbitUtils { - public static final String module = JackrabbitUtils.class.getName(); + private static final String module = JackrabbitUtils.class.getName(); /** * A method to list all nodes in the repository. The result List contains @@ -29,16 +30,18 @@ public class JackrabbitUtils { * @return * @throws RepositoryException */ - public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException { + public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath, Delegator delegator) throws RepositoryException { List<Map<String, String>> returnList = null; - Session session = JCRFactoryUtil.getSession(); + Session session = JCRFactoryUtil.getSession(delegator); try { returnList = getRepositoryNodes(session, startNodePath); } catch (RepositoryException e) { throw new RepositoryException(e); } finally { - session.logout(); + if (session.isLive()) { + session.logout(); + } } return returnList; Modified: ofbiz/branches/jackrabbit20120501/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java?rev=1347547&r1=1347546&r2=1347547&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java (original) +++ ofbiz/branches/jackrabbit20120501/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java Thu Jun 7 09:01:01 2012 @@ -35,6 +35,7 @@ import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.JcrRepositoryAccessor; import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; @@ -61,7 +62,15 @@ public class JackrabbitEvents { */ public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + + JcrDataHelper articleHelper = null; + try { + articleHelper = new JackrabbitArticleHelper(userLogin, delegator); + } catch (RepositoryException e) { + Debug.logError(e, module); + return "error"; + } String contentPath = request.getParameter("path"); String language = request.getParameter("msgLocale"); @@ -94,8 +103,10 @@ public class JackrabbitEvents { */ public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + try { - List<Map<String, String>> listIt = JackrabbitUtils.getRepositoryNodes(userLogin, ""); + List<Map<String, String>> listIt = JackrabbitUtils.getRepositoryNodes(userLogin, "", delegator); request.setAttribute("listIt", listIt); } catch (RepositoryException e) { Debug.logError(e, module); @@ -114,6 +125,7 @@ public class JackrabbitEvents { */ public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); String contentPath = request.getParameter("path"); @@ -127,7 +139,14 @@ public class JackrabbitEvents { return "error"; } - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); + JcrDataHelper articleHelper; + try { + articleHelper = new JackrabbitArticleHelper(userLogin, delegator); + } catch (RepositoryException e) { + Debug.logError(e, module); + return "error"; + } + JackrabbitArticle ormArticle = null; try { if (UtilValidate.isEmpty(version)) { @@ -165,9 +184,16 @@ public class JackrabbitEvents { */ public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); String contentPath = request.getParameter("path"); - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); + JcrDataHelper articleHelper; + try { + articleHelper = new JackrabbitArticleHelper(userLogin, delegator); + } catch (RepositoryException e2) { + Debug.logError(e2, module); + return "error"; + } JackrabbitArticle ormArticle = null; try { @@ -208,10 +234,17 @@ public class JackrabbitEvents { */ public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); String contentPath = request.getParameter("path"); - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); + JcrDataHelper helper; + try { + helper = new JackrabbitArticleHelper(userLogin, delegator); + } catch (RepositoryException e) { + Debug.logError(e, module); + return "error"; + } helper.removeContentObject(contentPath); return "success"; @@ -225,6 +258,8 @@ public class JackrabbitEvents { */ public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); List<FileItem> list = null; Map<String, String> passedParams = FastMap.newInstance(); @@ -250,7 +285,13 @@ public class JackrabbitEvents { } } - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); + JcrFileHelper fileHelper; + try { + fileHelper = new JackrabbitFileHelper(userLogin, delegator); + } catch (RepositoryException e1) { + Debug.logError(e1, module); + return "error"; + } try { @@ -281,8 +322,16 @@ public class JackrabbitEvents { */ public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + + JcrRepositoryAccessor repositoryAccess; + try { + repositoryAccess = new JackrabbitRepositoryAccessor(userLogin, delegator); + } catch (RepositoryException e1) { + Debug.logError(e1, module); + return "error"; + } - JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); try { JSONArray fileTree = repositoryAccess.getJsonFileTree(); request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); @@ -307,8 +356,16 @@ public class JackrabbitEvents { */ public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + + JackrabbitRepositoryAccessor repositoryAccess = null; + try { + repositoryAccess = new JackrabbitRepositoryAccessor(userLogin, delegator); + } catch (RepositoryException e) { + Debug.logError(e, module); + return "error"; + } - JackrabbitRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); try { JSONArray fileTree = repositoryAccess.getJsonDataTree(); request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); @@ -369,6 +426,7 @@ public class JackrabbitEvents { public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); String contentPath = request.getParameter("path"); @@ -379,7 +437,14 @@ public class JackrabbitEvents { return "error"; } - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); + JcrFileHelper fileHelper; + try { + fileHelper = new JackrabbitFileHelper(userLogin, delegator); + } catch (RepositoryException e2) { + Debug.logError(e2, module); + return "error"; + } + JackrabbitHierarchyNode orm = null; try { orm = fileHelper.getRepositoryContent(contentPath); @@ -417,9 +482,18 @@ public class JackrabbitEvents { public static String getFileInformation(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + String contentPath = request.getParameter("path"); - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); + JcrFileHelper fileHelper; + try { + fileHelper = new JackrabbitFileHelper(userLogin, delegator); + } catch (RepositoryException e1) { + Debug.logError(e1, contentPath); + return "error"; + } + OfbizRepositoryMapping orm; try { orm = fileHelper.getRepositoryContent(contentPath); @@ -451,10 +525,17 @@ public class JackrabbitEvents { public static String queryRepositoryData(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); String searchQuery = request.getParameter("queryData"); - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); + JcrDataHelper helper; + try { + helper = new JackrabbitArticleHelper(userLogin, delegator); + } catch (RepositoryException e1) { + Debug.logError(e1, module); + return "error"; + } try { request.setAttribute("queryResult", helper.queryData(searchQuery)); |
| Free forum by Nabble | Edit this page |
