[jboss-svn-commits] JBoss PortletSwap SVN: r184 - in server/trunk/portletswap2: src and 43 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 9 10:28:17 EST 2008
Author: thomas.heute at jboss.com
Date: 2008-01-09 10:28:17 -0500 (Wed, 09 Jan 2008)
New Revision: 184
Added:
server/trunk/portletswap2/.classpath
server/trunk/portletswap2/.project
server/trunk/portletswap2/pom.xml
server/trunk/portletswap2/src/
server/trunk/portletswap2/src/main/
server/trunk/portletswap2/src/main/java/
server/trunk/portletswap2/src/main/java/jboss-beans.xml
server/trunk/portletswap2/src/main/java/log4j.properties
server/trunk/portletswap2/src/main/java/org/
server/trunk/portletswap2/src/main/java/org/jboss/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Artifact.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/ArtifactType.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Category.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/DirectoryService.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Module.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Ordering.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/RepositoryService.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Type.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/FileArtifact.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/ReferencedArtifact.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/AbstractArtifactImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/FileArtifactImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/LicenseImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/AbstractCategory.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/jcr/CategoryImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/memory/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/memory/CategoryImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/memory/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/Filter.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/TypeFilter.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRService.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/Author.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/CompatibilityList.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/License.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/AbstractModule.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/jcr/ModuleImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/memory/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/memory/ModuleImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteCategoryException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteModuleException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/PublishModuleException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveCategoryException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveModuleException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreArtifactException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreCategoryException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreLicenseException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreModuleException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/UnpublishModuleException.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/jcr/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/memory/
server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
server/trunk/portletswap2/src/main/resources/
server/trunk/portletswap2/src/main/resources/customNodes.cnd
server/trunk/portletswap2/src/test/
server/trunk/portletswap2/src/test/java/
server/trunk/portletswap2/src/test/java/org/
server/trunk/portletswap2/src/test/java/org/jboss/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/jcr/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/memory/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceTestCase.java
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/jcr/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/jcr/JCRServiceTestCase.java
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/jcr/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/memory/
server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
server/trunk/portletswap2/src/test/resources/
server/trunk/portletswap2/src/test/resources/settings.xml
Log:
Initial import.
Added: server/trunk/portletswap2/.classpath
===================================================================
--- server/trunk/portletswap2/.classpath (rev 0)
+++ server/trunk/portletswap2/.classpath 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/module-common"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: server/trunk/portletswap2/.project
===================================================================
--- server/trunk/portletswap2/.project (rev 0)
+++ server/trunk/portletswap2/.project 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>portletswap2</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: server/trunk/portletswap2/pom.xml
===================================================================
--- server/trunk/portletswap2/pom.xml (rev 0)
+++ server/trunk/portletswap2/pom.xml 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+ <groupId>org.jboss.portletswap</groupId>
+ <artifactId>portletswap-server</artifactId>
+ <version>0.0.1</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.0.0.Beta9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.portal.common</groupId>
+ <artifactId>jboss-portal-modules-common</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <!-- this is a java 1.5 project -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
Added: server/trunk/portletswap2/src/main/java/jboss-beans.xml
===================================================================
--- server/trunk/portletswap2/src/main/java/jboss-beans.xml (rev 0)
+++ server/trunk/portletswap2/src/main/java/jboss-beans.xml 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- JCR IMPLEMENTATION -->
+
+ <bean name="JCRService" class="org.jboss.portletswap.jcr.JCRServiceImpl">
+ <property name="settingsLocation">src/test/resources/settings.xml</property>
+ <property name="rootPath">/tmp/jcr</property>
+ </bean>
+
+ <bean name="RepositoryService"
+ class="org.jboss.portletswap.repository.impl.jcr.RepositoryServiceImpl">
+ <property name="jcrService">
+ <inject bean="JCRService"/>
+ </property>
+ </bean>
+
+ <bean name="DirectoryService"
+ class="org.jboss.portletswap.directory.impl.jcr.DirectoryServiceImpl">
+ </bean>
+
+ <!-- MEMORY IMPLEMENTATION
+
+ <bean name="RepositoryService"
+ class="org.jboss.portletswap.repository.impl.memory.RepositoryServiceImpl">
+ </bean>
+
+ <bean name="DirectoryService"
+ class="org.jboss.portletswap.directory.impl.memory.DirectoryServiceImpl">
+ <property name="storage">
+ <inject bean="RepositoryService" property="modules"/>
+ </property>
+ </bean>
+
+ -->
+
+</deployment>
\ No newline at end of file
Added: server/trunk/portletswap2/src/main/java/log4j.properties
===================================================================
--- server/trunk/portletswap2/src/main/java/log4j.properties (rev 0)
+++ server/trunk/portletswap2/src/main/java/log4j.properties 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,5 @@
+log4j.rootLogger=ERROR, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
\ No newline at end of file
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Artifact.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Artifact.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Artifact.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.metadata.CompatibilityList;
+import org.jboss.portletswap.metadata.License;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface Artifact
+{
+
+ public Object getId();
+
+ public String getName();
+
+ public ArtifactType getArtifactType();
+
+ public Type getType();
+
+ public LocalizedString getDescription();
+
+ public void setDescription(LocalizedString description);
+
+ public LocalizedString getDisplayName();
+
+ public void setDisplayName(LocalizedString displayName);
+
+ public CompatibilityList getCompatibilityList();
+
+ public void setCompatibilityList(CompatibilityList compatibilityList);
+
+ public License getLicense();
+
+ public void setLicense(License license);
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/ArtifactType.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/ArtifactType.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/ArtifactType.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public enum ArtifactType {
+
+ FILE_ARTIFACT_TYPE
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Category.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Category.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Category.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+import java.util.List;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface Category
+{
+
+ public static final String ROOT_CATEGORY_NAME = "org.jboss.portletswap.RootCategoryNode";
+
+ public Category getParent();
+
+ public void addChild(Category category);
+
+ public List<Category> getChildren();
+
+ public Object getId();
+
+ public String getName();
+
+ public LocalizedString getDisplayName();
+
+ public void setDisplayName(LocalizedString displayName);
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/DirectoryService.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/DirectoryService.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/DirectoryService.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,65 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+import java.util.List;
+
+import org.jboss.portletswap.filter.Filter;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface DirectoryService
+{
+
+ /**
+ * Get all the latest versions of all modules
+ * @return the latest versions of all modules
+ */
+ public List<Module> getModules(boolean published);
+
+ /**
+ * Get all the latest versions of all modules
+ * @return the latest versions of all modules
+ */
+ public List<Module> getModules(boolean published, Ordering ordering);
+
+ public List<Module> getModules(boolean published, Type type);
+
+ public List<Module> getModules(boolean published, Type type, Ordering ordering);
+
+ public List<Module> getModules(boolean published, Category category);
+
+ public List<Module> getModules(boolean published, Category category, Ordering ordering);
+
+ public List<Module> getModules(boolean published, Filter filter);
+
+ public List<Module> getModules(boolean published, Filter filter, Ordering ordering);
+
+ public List<Module> getModules(boolean published, List<Filter> filters);
+
+ public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering);
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Module.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Module.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Module.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+import java.util.List;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.Version;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.metadata.Author;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface Module
+{
+
+ public void setId(Object id);
+
+ public Object getId();
+
+ public String getName();
+
+ public Type getType();
+
+ public Version getVersion();
+
+ public LocalizedString getDescription();
+
+ public List<Author> getAuthors();
+
+ public void setDescription(LocalizedString localizedString);
+
+ public List<Artifact> getArtifacts();
+
+ public void addCategory(Category category);
+
+ public List<Category> getCategories();
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Ordering.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Ordering.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Ordering.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public enum Ordering {
+
+ NAME_ASC, NAME_DESC, NO_SPECIAL_ORDER
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/RepositoryService.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/RepositoryService.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/RepositoryService.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,82 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+import org.jboss.portletswap.metadata.License;
+import org.jboss.portletswap.repository.DeleteCategoryException;
+import org.jboss.portletswap.repository.DeleteModuleException;
+import org.jboss.portletswap.repository.PublishModuleException;
+import org.jboss.portletswap.repository.RetrieveCategoryException;
+import org.jboss.portletswap.repository.RetrieveModuleException;
+import org.jboss.portletswap.repository.StoreArtifactException;
+import org.jboss.portletswap.repository.StoreCategoryException;
+import org.jboss.portletswap.repository.StoreLicenseException;
+import org.jboss.portletswap.repository.StoreModuleException;
+import org.jboss.portletswap.repository.UnpublishModuleException;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface RepositoryService
+{
+ /**
+ * Retrieves a module by its id
+ *
+ * @param id of the module to retrieve
+ * @return The module, null if such a module could not be found
+ */
+ public Module getModule(Object id) throws RetrieveModuleException;
+
+ /**
+ * Store a new module or version of a module
+ *
+ * @param module to store
+ * @return the module
+ * @throws StoreModuleException if the module could not be stored
+ */
+ public Module storeModule(Module module) throws StoreModuleException;
+
+ /**
+ * Delete a module
+ *
+ * @param name of the module to delete
+ * @throws DeleteModuleException if the deletion could not happen
+ */
+ public void deleteModule(Module module) throws DeleteModuleException;
+
+ public Module publishModule(Module module) throws PublishModuleException;
+
+ public void unpublishModule(Module module) throws UnpublishModuleException;
+
+ public Category storeCategory(Category category) throws StoreCategoryException;
+
+ public Category getCategory(Object id) throws RetrieveCategoryException;
+
+ public void deleteCategory(Category category) throws DeleteCategoryException;
+
+ public Artifact storeArtifact(Module module, Artifact artifact) throws StoreArtifactException;
+
+ public License storeLicense(License license) throws StoreLicenseException;
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Type.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Type.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/Type.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public enum Type {
+
+ JSR168PORTLET, JSR286PORTLET, THEME, MIXED, OTHER
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/FileArtifact.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/FileArtifact.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/FileArtifact.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.artifact;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.jboss.portletswap.Artifact;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface FileArtifact extends Artifact
+{
+ public InputStream getInputStream();
+
+ public File getFile();
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/ReferencedArtifact.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/ReferencedArtifact.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/ReferencedArtifact.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.artifact;
+
+import java.net.URL;
+
+import org.jboss.portletswap.Artifact;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface ReferencedArtifact extends Artifact
+{
+ public URL getUrl();
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/AbstractArtifactImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/AbstractArtifactImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/AbstractArtifactImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,136 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.artifact.impl;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.ArtifactType;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.metadata.CompatibilityList;
+import org.jboss.portletswap.metadata.License;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class AbstractArtifactImpl implements Artifact
+{
+ private Object id;
+
+ private String name;
+
+ private ArtifactType artifactType;
+
+ private Type type;
+
+ private LocalizedString description;
+
+ private LocalizedString displayName;
+
+ private CompatibilityList compatibilityList;
+
+ private License license;
+
+ public ArtifactType getArtifactType()
+ {
+ return artifactType;
+ }
+
+ public void setArtifactType(ArtifactType artifactType)
+ {
+ this.artifactType = artifactType;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public void setType(Type type)
+ {
+ this.type = type;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(LocalizedString description)
+ {
+ this.description = description;
+ }
+
+ public LocalizedString getDisplayName()
+ {
+ return displayName;
+ }
+
+ public void setDisplayName(LocalizedString displayName)
+ {
+ this.displayName = displayName;
+ }
+
+ public CompatibilityList getCompatibilityList()
+ {
+ return compatibilityList;
+ }
+
+ public void setCompatibilityList(CompatibilityList compatibilityList)
+ {
+ this.compatibilityList = compatibilityList;
+ }
+
+ public License getLicense()
+ {
+ return license;
+ }
+
+ public void setLicense(License license)
+ {
+ this.license = license;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public void setId(Object id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/FileArtifactImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/FileArtifactImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/FileArtifactImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,120 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.artifact.impl.jcr;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.ArtifactType;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.artifact.FileArtifact;
+import org.jboss.portletswap.artifact.impl.AbstractArtifactImpl;
+import org.jboss.portletswap.jcr.JCRService;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class FileArtifactImpl extends AbstractArtifactImpl implements FileArtifact
+{
+
+ private InputStream inputStream;
+
+ private File file;
+
+ public FileArtifactImpl(Type type, File file, InputStream inputStream)
+ {
+ setType(type);
+ this.inputStream = inputStream;
+ this.file = file;
+ }
+
+ public FileArtifactImpl(JCRService jcrService, Node node) throws RepositoryException
+ {
+ setName(node.getName());
+ setId(node.getUUID());
+
+ Property typeProperty = node.getProperty("ps:type");
+ setType(Type.valueOf(typeProperty.getString()));
+
+ // Description
+ NodeIterator it = node.getNodes("ps:description");
+ Map<Locale, String> values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
+ String value = tmpNode.getProperty("ps:value").getString();
+ values.put(locale, value);
+ }
+ setDescription(new LocalizedString(values, Locale.ENGLISH));
+
+ // DisplayName
+ it = node.getNodes("ps:displayName");
+ values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
+ String value = tmpNode.getProperty("ps:value").getString();
+ values.put(locale, value);
+ }
+ setDisplayName(new LocalizedString(values, Locale.ENGLISH));
+
+ // Compatibility List
+ // TODO
+
+ // License
+ Property property = node.getProperty("ps:license");
+ Node licenseNode = node.getSession().getNodeByUUID(property.getString());
+ setLicense(new LicenseImpl(jcrService, licenseNode));
+
+ this.inputStream = node.getProperty("ps:file").getStream();
+ }
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ public ArtifactType getArtifactType()
+ {
+ return ArtifactType.FILE_ARTIFACT_TYPE;
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/LicenseImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/LicenseImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/artifact/impl/jcr/LicenseImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,78 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.artifact.impl.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.metadata.License;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class LicenseImpl implements License
+{
+ private String id;
+
+ private String name;
+
+ private String text;
+
+ public LicenseImpl(String name, String text)
+ {
+ this.name = name;
+ this.text = text;
+ }
+
+ public LicenseImpl(JCRService jcrService, Node licenseNode) throws RepositoryException
+ {
+ id = licenseNode.getUUID();
+ name = licenseNode.getProperty("ps:name").getString();
+ text = licenseNode.getProperty("ps:text").getString();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/AbstractCategory.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/AbstractCategory.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/AbstractCategory.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.category.impl;
+
+import java.util.List;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.Category;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class AbstractCategory implements Category
+{
+
+ private Object id;
+
+ private LocalizedString displayName;
+
+ private String name;
+
+ public abstract Category getParent();
+
+ public abstract void addChild(Category category);
+
+ public abstract List<Category> getChildren();
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public void setId(Object id)
+ {
+ if (this.id == null)
+ {
+ this.id = id;
+ }
+ else
+ {
+ throw new IllegalStateException("Not allowed to change the id");
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ if (this.name == null)
+ {
+ this.name = name;
+ }
+ else
+ {
+ throw new IllegalStateException("Not allowed to change the name");
+ }
+ }
+
+ public LocalizedString getDisplayName()
+ {
+ return displayName;
+ }
+
+ public void setDisplayName(LocalizedString displayName)
+ {
+ this.displayName = displayName;
+ }
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/jcr/CategoryImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/jcr/CategoryImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/jcr/CategoryImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.category.impl.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.category.impl.AbstractCategory;
+import org.jboss.portletswap.jcr.JCRService;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CategoryImpl extends AbstractCategory
+{
+
+ private JCRService jcrService;
+
+ private Node node;
+
+ public CategoryImpl(JCRService jcrService, Node node)
+ {
+ this.jcrService = jcrService;
+ this.node = node;
+ try
+ {
+ this.setId(node.getUUID());
+ this.setName(node.getName());
+ }
+ catch (UnsupportedRepositoryOperationException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
+ catch (RepositoryException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void addChild(Category category)
+ {
+
+ }
+
+ @Override
+ public List<Category> getChildren()
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ NodeIterator it = node.getNodes();
+ List<Category> list = new ArrayList<Category>();
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (node.isNodeType("ps:category"))
+ {
+ list.add(new CategoryImpl(jcrService, node));
+ }
+ }
+ return list;
+ }
+ catch (RepositoryException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ return null;
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ @Override
+ public Category getParent()
+ {
+ Session session = null;
+
+ if (getName().equals(ROOT_CATEGORY_NAME))
+ {
+ return null;
+ }
+
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ Node parent = node.getParent();
+ return new CategoryImpl(jcrService, parent);
+ }
+ catch (RepositoryException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ return null;
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/memory/CategoryImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/memory/CategoryImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/category/impl/memory/CategoryImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.category.impl.memory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.category.impl.AbstractCategory;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CategoryImpl extends AbstractCategory
+{
+ public static final String ROOT_CATEGORY_NAME = "org.jboss.portletswap.RootCategoryNode";
+
+ private Category parent;
+
+ private LocalizedString displayName;
+
+ private List<Category> children;
+
+ public CategoryImpl(String name, Category parent)
+ {
+ setParent(parent);
+ setName(name);
+ if (parent != null)
+ {
+ parent.addChild(this);
+ }
+ children = new ArrayList<Category>();
+ }
+
+ public Category getParent()
+ {
+ return parent;
+ }
+
+ private void setParent(Category parent)
+ {
+ this.parent = parent;
+ }
+
+ public void addChild(Category category)
+ {
+ children.add(category);
+ }
+
+ public LocalizedString getDisplayName()
+ {
+ if (displayName != null)
+ {
+ return displayName;
+ }
+ else
+ {
+ return new LocalizedString((String)getId());
+ }
+ }
+
+ public List<Category> getChildren()
+ {
+ return children;
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,251 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.directory.impl.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.DirectoryService;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.Ordering;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.filter.Filter;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.module.impl.jcr.ModuleImpl;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DirectoryServiceImpl implements DirectoryService
+{
+
+
+ private JCRService jcrService;
+
+ public JCRService getJcrService()
+ {
+ return jcrService;
+ }
+
+ public void setJcrService(JCRService jcrService)
+ {
+ this.jcrService = jcrService;
+ }
+ public List<Module> getModules(boolean published)
+ {
+ String workspace = JCRService.MODULE_WORKSPACE_NAME;
+ if (published)
+ {
+ workspace = JCRService.PUBLISHED_MODULE_WORKSPACE_NAME;
+ }
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(workspace);
+ NodeIterator it = session.getRootNode().getNodes();
+ List<Module> result = new ArrayList<Module>();
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (node.isNodeType("ps:module"))
+ {
+ result.add(new ModuleImpl(jcrService, node));
+ }
+ }
+ return result;
+ }
+ catch (ItemNotFoundException e)
+ {
+ return null;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Ordering ordering)
+ {
+ String workspace = JCRService.MODULE_WORKSPACE_NAME;
+ if (published)
+ {
+ workspace = JCRService.PUBLISHED_MODULE_WORKSPACE_NAME;
+ }
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(workspace);
+ QueryManager queryManager = session.getWorkspace().getQueryManager();
+ Query query = queryManager.createQuery("SELECT * from ps:module " + orderby(ordering), Query.SQL);
+ QueryResult queryResult = query.execute();
+
+ NodeIterator it = queryResult.getNodes();
+ List<Module> result = new ArrayList<Module>();
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (node.isNodeType("ps:module"))
+ {
+ result.add(new ModuleImpl(jcrService, node));
+ }
+ }
+ return result;
+ }
+ catch (ItemNotFoundException e)
+ {
+ return null;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ return null;
+ }
+
+ private String orderby(Ordering ordering)
+ {
+ if (Ordering.NAME_ASC.equals(ordering.name()))
+ {
+ return "ORDER BY ps:name";
+ }
+ else if (Ordering.NAME_DESC.equals(ordering.name()))
+ {
+ return " ORDER BY ps:name DESC";
+ }
+ else if (Ordering.NO_SPECIAL_ORDER.equals(ordering.name()))
+ {
+ return "";
+ }
+ return "";
+ }
+
+ public List<Module> getModules(boolean published, Type type)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Type type, Ordering ordering)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Category category)
+ {
+ String workspace = JCRService.MODULE_WORKSPACE_NAME;
+ if (published)
+ {
+ workspace = JCRService.PUBLISHED_MODULE_WORKSPACE_NAME;
+ }
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(workspace);
+ QueryManager queryManager = session.getWorkspace().getQueryManager();
+ Query query = queryManager.createQuery("SELECT * from ps:module where ps:categoryRef = '" + category.getId() + "'", Query.SQL);
+ QueryResult queryResult = query.execute();
+
+ NodeIterator it = queryResult.getNodes();
+ List<Module> result = new ArrayList<Module>();
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (node.isNodeType("ps:module"))
+ {
+ result.add(new ModuleImpl(jcrService, node));
+ }
+ }
+ return result;
+ }
+ catch (ItemNotFoundException e)
+ {
+ return null;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Category category, Ordering ordering)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Filter filter)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, Filter filter, Ordering ordering)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, List<Filter> filters)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+ public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering)
+ {
+ // FIXME getModules
+ return null;
+ }
+
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,166 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.directory.impl.memory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.DirectoryService;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.Ordering;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.filter.CategoryFilter;
+import org.jboss.portletswap.filter.Filter;
+import org.jboss.portletswap.filter.TypeFilter;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DirectoryServiceImpl implements DirectoryService
+{
+ private Map<Object, Module> modules;
+
+ public void setStorage(Map<Object, Module> modules)
+ {
+ this.modules = modules;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Module> getModules(boolean published)
+ {
+ return getModules(published, Collections.EMPTY_LIST);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Module> getModules(boolean published, Ordering ordering)
+ {
+ return getModules(published, Collections.EMPTY_LIST, ordering);
+ }
+
+ public List<Module> getModules(boolean published, Type type)
+ {
+ return getModules(published, type, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public List<Module> getModules(boolean published, Type type, Ordering ordering)
+ {
+ return getModules(published, new TypeFilter(type), ordering);
+ }
+
+ public List<Module> getModules(boolean published, Category category)
+ {
+ return getModules(published, category, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public List<Module> getModules(boolean published, Category category, Ordering ordering)
+ {
+ List<Filter> filters = new ArrayList<Filter>();
+ filters.add(new CategoryFilter(category));
+ return getModules(published, filters);
+ }
+
+ public List<Module> getModules(boolean published, Filter filter)
+ {
+ return getModules(published, filter, Ordering.NO_SPECIAL_ORDER);
+ }
+
+
+ public List<Module> getModules(boolean published, Filter filter, Ordering ordering)
+ {
+ List<Filter> list = new ArrayList<Filter>();
+ list.add(filter);
+ return getModules(published, list, ordering);
+ }
+
+ public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering)
+ {
+ Set<Module> result = null;
+ Comparator<Module> comparator = getComparator(ordering);
+ if (comparator != null)
+ {
+ result = new TreeSet<Module>(comparator);
+ }
+ else
+ {
+ result = new HashSet<Module>();
+ }
+ for(Module module: modules.values())
+ {
+ boolean accept = true;
+ for (Filter filter:filters)
+ {
+ if (!filter.accept(module))
+ {
+ accept = false;
+ }
+ }
+ if (accept)
+ {
+ result.add(module);
+ }
+ }
+ return Tools.toList(result.iterator());
+ }
+
+ public List<Module> getModules(boolean published, List<Filter> filters)
+ {
+ return getModules(published, filters, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ private Comparator<Module> getComparator(Ordering ordering)
+ {
+ if (ordering.equals(Ordering.NAME_ASC))
+ {
+ return new Comparator<Module>() {
+
+ public int compare(Module o1, Module o2)
+ {
+ return o1.getName().compareTo(o2.getName());
+ }
+ };
+ }
+ if (ordering.equals(Ordering.NAME_DESC))
+ {
+ return new Comparator<Module>() {
+
+ public int compare(Module o1, Module o2)
+ {
+ return o2.getName().compareTo(o1.getName());
+ }
+ };
+ }
+
+ return null;
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter;
+
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CategoryFilter implements Filter
+{
+
+ private Category category;
+
+ public CategoryFilter(Category category)
+ {
+ this.category = category;
+ }
+
+ public boolean accept(Module module)
+ {
+ /** TODO: do it recursively */
+ if (module.getCategories().contains(category))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/Filter.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/Filter.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/Filter.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter;
+
+import org.jboss.portletswap.Module;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface Filter
+{
+
+ public boolean accept(Module module);
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/TypeFilter.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/TypeFilter.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/filter/TypeFilter.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter;
+
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.Type;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class TypeFilter implements Filter
+{
+
+ private Type type;
+
+ public TypeFilter(Type type)
+ {
+ this.type = type;
+ }
+
+ public boolean accept(Module module)
+ {
+ if (module.getType().equals(type))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRService.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRService.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRService.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.jcr;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface JCRService
+{
+ public static String MODULE_WORKSPACE_NAME = "moduleWorkspace";
+
+ public static String PUBLISHED_MODULE_WORKSPACE_NAME = "publishedModuleWorkspace";
+
+ public Session openSession(String workspaceName) throws RepositoryException;
+
+ public void stop();
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,233 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.jcr;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.Calendar;
+import java.util.List;
+
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Workspace;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.core.nodetype.compact.ParseException;
+import org.apache.jackrabbit.value.DateValue;
+import org.jboss.portletswap.Category;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRServiceImpl implements JCRService
+{
+
+ private String settingsLocation;
+
+ private String rootPath;
+
+ private Repository repository;
+
+ public JCRServiceImpl()
+ {
+ }
+
+ public void setSettingsLocation(String settingsLocation)
+ {
+ this.settingsLocation = settingsLocation;
+ }
+
+ public void setRootPath(String rootPath)
+ {
+ this.rootPath= rootPath;
+ }
+
+ public void init()
+ {
+ Session session = null;
+ Credentials credentials = null;
+ try
+ {
+ Repository repository = getRepository();
+ credentials = new SimpleCredentials("userId", "".toCharArray());
+ session = repository.login(credentials);
+ WorkspaceImpl workspaceImpl = (WorkspaceImpl) session.getWorkspace();
+
+ if (workspaceImpl.getAccessibleWorkspaceNames().length == 1)
+ {
+ workspaceImpl.getNamespaceRegistry().registerNamespace("ps", "http://www.portletswap.com");
+
+ workspaceImpl.createWorkspace(MODULE_WORKSPACE_NAME);
+ registerCustomNodeTypes(MODULE_WORKSPACE_NAME, new File("src/main/resources/customNodes.cnd"));
+
+ workspaceImpl.createWorkspace(PUBLISHED_MODULE_WORKSPACE_NAME);
+// registerCustomNodeTypes(PUBLISHED_MODULE_WORKSPACE_NAME, new File("src/main/resources/customNodes.cnd"));
+ }
+ session.save();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+
+ try
+ {
+ session = repository.login(credentials, MODULE_WORKSPACE_NAME);
+ createRootCategoryNode(session.getRootNode());
+ session.save();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+
+ try
+ {
+ session = repository.login(credentials, PUBLISHED_MODULE_WORKSPACE_NAME);
+ createRootCategoryNode(session.getRootNode());
+ session.save();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+}
+
+ public void stop()
+ {
+ ((RepositoryImpl)repository).shutdown();
+ }
+
+ public Session openSession(String workspaceName) throws RepositoryException
+ {
+ Repository repository = getRepository();
+ Credentials credentials = new SimpleCredentials("userId", "".toCharArray());
+ return repository.login(credentials, workspaceName);
+ }
+
+ private Repository getRepository() throws RepositoryException
+ {
+ if (repository == null)
+ {
+ RepositoryConfig cfg = RepositoryConfig.create(settingsLocation, rootPath);
+ repository = RepositoryImpl.create(cfg);
+ }
+ return repository;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void registerCustomNodeTypes(String workspaceName, File cndFile) throws Exception
+ {
+ Session session = openSession(workspaceName);
+ Workspace ws = session.getWorkspace();
+ // Read in the CND file
+ try
+ {
+ FileReader fileReader = new FileReader(cndFile);
+
+ // Create a CompactNodeTypeDefReader
+ CompactNodeTypeDefReader cndReader = new CompactNodeTypeDefReader(fileReader, cndFile.getName());
+
+ // Get the List of NodeTypeDef objects
+ List<NodeTypeDef> ntdList = cndReader.getNodeTypeDefs();
+
+ // Get the NodeTypeManager from the Workspace.
+ // Note that it must be cast from the generic JCR NodeTypeManager to the
+ // Jackrabbit-specific implementation.
+ NodeTypeManagerImpl ntmgr =(NodeTypeManagerImpl)ws.getNodeTypeManager();
+
+ // Acquire the NodeTypeRegistry
+ NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry();
+
+ // Loop through the prepared NodeTypeDefs
+ for (NodeTypeDef nodeTypeDef: ntdList) {
+
+ // ...and register it
+ ntreg.registerNodeType(nodeTypeDef);
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new Exception("File " + cndFile.getAbsolutePath() + " could not be found");
+ }
+ catch (ParseException e)
+ {
+
+ throw new Exception("File " + cndFile.getAbsolutePath() + " could not be parsed correctly." + e.getMessage());
+ }
+ catch (InvalidNodeTypeDefException e)
+ {
+ throw e;
+ }
+ catch (RepositoryException e)
+ {
+ throw e;
+ }
+ finally
+ {
+ session.logout();
+ }
+
+ }
+
+ private void createRootCategoryNode(Node rootNode)
+ {
+ try
+ {
+ Node node = rootNode.addNode(Category.ROOT_CATEGORY_NAME, "ps:category");
+ node.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+ }
+ catch (Exception e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/Author.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/Author.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/Author.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class Author
+{
+ private String username;
+
+ private String firstname;
+
+ private String lastname;
+
+ public Author(String username, String firstname, String lastname)
+ {
+ this.username = username;
+ this.firstname = firstname;
+ this.lastname = lastname;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ public String getFirstname()
+ {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname)
+ {
+ this.firstname = firstname;
+ }
+
+ public String getLastname()
+ {
+ return lastname;
+ }
+
+ public void setLastname(String lastname)
+ {
+ this.lastname = lastname;
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/CompatibilityList.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/CompatibilityList.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/CompatibilityList.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CompatibilityList
+{
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/License.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/License.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/metadata/License.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface License
+{
+ public String getName();
+
+ public String getText();
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/AbstractModule.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/AbstractModule.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/AbstractModule.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,173 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.module.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.Version;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.metadata.Author;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class AbstractModule implements Module
+{
+ private List<Artifact> artifacts;
+
+ private Object id;
+
+ private String name;
+
+ private Version version;
+
+ private LocalizedString description;
+
+ private List<Author> authors;
+
+ private List<Category> categories = new ArrayList<Category>();
+
+ public AbstractModule(String name, Version version)
+ {
+ this.version = version;
+ this.name = name;
+ this.artifacts = new ArrayList<Artifact>();
+ }
+
+ public AbstractModule(String name)
+ {
+ this.name = name;
+ this.artifacts = new ArrayList<Artifact>();
+ }
+
+ public AbstractModule()
+ {
+ this.artifacts = new ArrayList<Artifact>();
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public Version getVersion()
+ {
+ return version;
+ }
+
+ public Type getType()
+ {
+ Type type = null;
+ for (Artifact artifact: artifacts)
+ {
+ if (type == null)
+ {
+ type = artifact.getType();
+ }
+ else if (type != artifact.getType())
+ {
+ type = Type.MIXED;
+ }
+ }
+ return type;
+ }
+
+ public List<Artifact> getArtifacts()
+ {
+ return artifacts;
+ }
+
+ public void setId(Object id)
+ {
+ if (this.id == null)
+ {
+ this.id = id;
+ }
+ else
+ {
+ throw new IllegalStateException("Not allowed to change the id");
+ }
+ }
+
+ public void setName(String name)
+ {
+ if (this.name == null)
+ {
+ this.name = name;
+ }
+ else
+ {
+ throw new IllegalStateException("Not allowed to change the name");
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setVersion(Version version)
+ {
+ this.version = version;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(LocalizedString description)
+ {
+ this.description = description;
+ }
+
+ public List<Author> getAuthors()
+ {
+ return authors;
+ }
+
+ public void setAuthors(List<Author> authors)
+ {
+ this.authors = authors;
+ }
+
+ public List<Category> getCategories()
+ {
+ return categories;
+ }
+
+ public void setCategories(List<Category> categories)
+ {
+ this.categories = categories;
+ }
+
+ public abstract void addCategory(Category category);
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/jcr/ModuleImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/jcr/ModuleImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/jcr/ModuleImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,239 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.module.impl.jcr;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.value.ReferenceValue;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.Version;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.artifact.impl.jcr.FileArtifactImpl;
+import org.jboss.portletswap.category.impl.jcr.CategoryImpl;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.metadata.Author;
+import org.jboss.portletswap.module.impl.AbstractModule;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ModuleImpl extends AbstractModule
+{
+
+ private List<Artifact> artifacts;
+
+ private JCRService jcrService;
+
+ public ModuleImpl(JCRService jcrService, Node node) throws RepositoryException
+ {
+ this.jcrService = jcrService;
+
+ setName(node.getProperty("ps:name").getString());
+ setId(node.getUUID());
+
+ Node versionNode = node.getNode("ps:version");
+ Version version = new Version(versionNode.getProperty("ps:name").getString(),
+ (int)versionNode.getProperty("ps:major").getValue().getLong(),
+ (int)versionNode.getProperty("ps:minor").getValue().getLong(),
+ (int)versionNode.getProperty("ps:patch").getValue().getLong(),
+ new Version.Qualifier(
+ Version.Qualifier.Prefix.valueOf(versionNode.getProperty("ps:prefix").getValue().getString()),
+ Version.Qualifier.Suffix.valueOf(versionNode.getProperty("ps:suffix").getValue().getString())),
+ versionNode.getProperty("ps:codename").getValue().getString());
+ setVersion(version);
+
+ NodeIterator it = node.getNodes("ps:description");
+ Map<Locale, String> values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
+ String value = tmpNode.getProperty("ps:value").getString();
+ values.put(locale, value);
+ }
+ setDescription(new LocalizedString(values, Locale.ENGLISH));
+
+ it = node.getNodes("ps:author");
+ List<Author> authors = new ArrayList<Author>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Author author = new Author(tmpNode.getProperty("ps:username").getString(),
+ tmpNode.getProperty("ps:firstname").getString(),
+ tmpNode.getProperty("ps:lastname").getString());
+ authors.add(author);
+ }
+ setAuthors(authors);
+
+ }
+
+ public ModuleImpl(JCRService jcrService, String name, Version version)
+ {
+ this.jcrService = jcrService;
+ setName(name);
+ setVersion(version);
+ }
+
+ @Override
+ public Type getType()
+ {
+ Type type = null;
+ for (Artifact artifact: artifacts)
+ {
+ if (type == null)
+ {
+ type = artifact.getType();
+ }
+ else if (type != artifact.getType())
+ {
+ type = Type.MIXED;
+ }
+ }
+ return type;
+ }
+
+ @Override
+ public List<Artifact> getArtifacts()
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String) getId());
+
+ List<Artifact> result = new ArrayList<Artifact>();
+ NodeIterator it = node.getNodes();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ if (tmpNode.isNodeType("ps:fileArtifact"))
+ {
+ result.add(new FileArtifactImpl(jcrService, tmpNode));
+ }
+ }
+ return result;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ return null;
+ }
+
+ @Override
+ public void addCategory(Category category)
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String) getId());
+
+ List<Value> valuesList;
+ try
+ {
+ Property property = node.getProperty("ps:categoryRef");
+ valuesList = new ArrayList<Value>(Arrays.asList(property.getValues()));
+ }
+ catch (PathNotFoundException e)
+ {
+ valuesList = new ArrayList<Value>();
+ }
+
+ valuesList.add(new ReferenceValue(session.getNodeByUUID((String)category.getId())));
+ Value[] values = valuesList.toArray(new Value[valuesList.size()]);
+
+ node.setProperty("ps:categoryRef", values);
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ @Override
+ public List<Category> getCategories()
+ {
+ Session session = null;
+ List<Category> categories = new ArrayList<Category>();
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ Node node = session.getNodeByUUID((String) getId());
+ Property property;
+ try
+ {
+ property = node.getProperty("ps:categoryRef");
+ }
+ catch (PathNotFoundException e)
+ {
+ return categories;
+ }
+
+ Value[] values = property.getValues();
+ for (Value value: values)
+ {
+ Node tmpNode = node.getSession().getNodeByUUID(value.getString());
+ Category category = new CategoryImpl(jcrService, tmpNode);
+ categories.add(category);
+ }
+ return categories;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+}
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/memory/ModuleImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/memory/ModuleImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/module/impl/memory/ModuleImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,107 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.module.impl.memory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.portal.common.util.Version;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.metadata.Author;
+import org.jboss.portletswap.module.impl.AbstractModule;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ModuleImpl extends AbstractModule
+{
+
+ private List<Artifact> artifacts;
+
+ public ModuleImpl(String name, Version version)
+ {
+ super(name, version);
+ artifacts = new ArrayList<Artifact>();
+ }
+
+ public Type getType()
+ {
+ Type type = null;
+ for (Artifact artifact: artifacts)
+ {
+ if (type == null)
+ {
+ type = artifact.getType();
+ }
+ else if (type != artifact.getType())
+ {
+ type = Type.MIXED;
+ }
+ }
+ return type;
+ }
+
+ public void addArtifact(Artifact artifact)
+ {
+ artifacts.add(artifact);
+ }
+
+ public List<Artifact> getArtifacts()
+ {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<Artifact> artifacts)
+ {
+ this.artifacts = artifacts;
+ }
+
+ public void addCategory(Category category)
+ {
+ // FIXME addCategory
+
+ }
+
+ public List<Author> getAuthors()
+ {
+ // FIXME getAuthors
+ return null;
+ }
+
+ public List<Category> getCategories()
+ {
+ // FIXME getCategories
+ return null;
+ }
+
+ public List<String> getKeywords()
+ {
+ // FIXME getKeywords
+ return null;
+ }
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteCategoryException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteCategoryException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteCategoryException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DeleteCategoryException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 9182835548026829570L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteModuleException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteModuleException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/DeleteModuleException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DeleteModuleException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 7650377766868991970L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/PublishModuleException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/PublishModuleException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/PublishModuleException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class PublishModuleException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 7339595717707845495L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveCategoryException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveCategoryException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveCategoryException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RetrieveCategoryException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3012658907801824817L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveModuleException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveModuleException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/RetrieveModuleException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RetrieveModuleException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1073395550575404278L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreArtifactException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreArtifactException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreArtifactException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class StoreArtifactException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1464464883984783905L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreCategoryException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreCategoryException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreCategoryException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class StoreCategoryException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -494227373485090213L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreLicenseException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreLicenseException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreLicenseException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class StoreLicenseException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 589991665204716100L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreModuleException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreModuleException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/StoreModuleException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class StoreModuleException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -8053828450478606547L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/UnpublishModuleException.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/UnpublishModuleException.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/UnpublishModuleException.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class UnpublishModuleException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -6962744679265911299L;
+
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,510 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository.impl.jcr;
+
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.value.DateValue;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.Version;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.ArtifactType;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.RepositoryService;
+import org.jboss.portletswap.artifact.FileArtifact;
+import org.jboss.portletswap.artifact.impl.jcr.FileArtifactImpl;
+import org.jboss.portletswap.artifact.impl.jcr.LicenseImpl;
+import org.jboss.portletswap.category.impl.AbstractCategory;
+import org.jboss.portletswap.category.impl.jcr.CategoryImpl;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.metadata.Author;
+import org.jboss.portletswap.metadata.License;
+import org.jboss.portletswap.module.impl.jcr.ModuleImpl;
+import org.jboss.portletswap.repository.DeleteCategoryException;
+import org.jboss.portletswap.repository.DeleteModuleException;
+import org.jboss.portletswap.repository.PublishModuleException;
+import org.jboss.portletswap.repository.RetrieveCategoryException;
+import org.jboss.portletswap.repository.RetrieveModuleException;
+import org.jboss.portletswap.repository.StoreArtifactException;
+import org.jboss.portletswap.repository.StoreCategoryException;
+import org.jboss.portletswap.repository.StoreLicenseException;
+import org.jboss.portletswap.repository.StoreModuleException;
+import org.jboss.portletswap.repository.UnpublishModuleException;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RepositoryServiceImpl implements RepositoryService
+{
+
+ private JCRService jcrService;
+
+ private Category rootCategory;
+
+ public RepositoryServiceImpl()
+ {
+ }
+
+ public JCRService getJcrService()
+ {
+ return jcrService;
+ }
+
+ public void setJcrService(JCRService jcrService)
+ {
+ this.jcrService = jcrService;
+ }
+
+ public void deleteModule(Module module) throws DeleteModuleException
+ {
+ try
+ {
+ unpublishModule(module);
+ }
+ catch (UnpublishModuleException e)
+ {
+ // ignore
+ }
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String)module.getId());
+ if (node != null)
+ {
+ node.remove();
+ }
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new DeleteModuleException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public Module getModule(Object id) throws RetrieveModuleException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String)id);
+ if (node != null)
+ {
+ return new ModuleImpl(jcrService, node);
+ }
+ }
+ catch (ItemNotFoundException e)
+ {
+ return null;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new RetrieveModuleException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ return null;
+ }
+
+ public Module publishModule(Module module) throws PublishModuleException
+ {
+ Session sessionUnpublished = null;
+ Session sessionPublished = null;
+ try
+ {
+ sessionUnpublished = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ Node node = sessionUnpublished.getNodeByUUID((String) module.getId());
+
+ sessionPublished = jcrService.openSession(JCRService.PUBLISHED_MODULE_WORKSPACE_NAME);
+
+ // Publish categories
+ List<Category> categories = module.getCategories();
+ for (Category category: categories)
+ {
+ try
+ {
+ sessionPublished.getNodeByUUID((String) category.getId());
+ }
+ catch (ItemNotFoundException e)
+ {
+ Node categoryNode = sessionUnpublished.getNodeByUUID((String) category.getId());
+ sessionPublished.getWorkspace().clone(sessionUnpublished.getWorkspace().getName(), categoryNode.getPath(), categoryNode.getPath(), false);
+ }
+ }
+
+ sessionPublished.getWorkspace().clone(sessionUnpublished.getWorkspace().getName(), node.getPath(), node.getPath(), false);
+
+ sessionPublished.save();
+ return new ModuleImpl(jcrService, sessionPublished.getNodeByUUID((String) module.getId()));
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new PublishModuleException();
+ }
+ finally
+ {
+ sessionPublished.logout();
+ sessionUnpublished.logout();
+ }
+ }
+
+ public Category storeCategory(Category category) throws StoreCategoryException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node rootnode = session.getRootNode().addNode(Category.ROOT_CATEGORY_NAME, "ps:category");
+ rootnode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ Node parentNode = null;
+ if (category.getName() == AbstractCategory.ROOT_CATEGORY_NAME)
+ {
+ parentNode = session.getRootNode();
+ }
+ else
+ {
+ parentNode = session.getNodeByUUID((String) category.getParent().getId());
+ }
+
+ Node node = parentNode.addNode(category.getName(), "ps:category");
+ node.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ session.save();
+
+ return new CategoryImpl(jcrService, node);
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new StoreCategoryException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public Module storeModule(Module module) throws StoreModuleException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ // Store the module name
+ Node moduleNode = session.getRootNode().addNode("ps:module", "ps:module");
+
+ moduleNode.setProperty("ps:name", module.getName());
+
+ // Store the last modified date
+ moduleNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ // Store the version
+ Version version = module.getVersion();
+ Node versionNode = moduleNode.addNode("ps:version", "ps:version");
+ {
+ versionNode.setProperty("ps:name", version.getName());
+ versionNode.setProperty("ps:major", version.getMajor());
+ versionNode.setProperty("ps:minor", version.getMinor());
+ versionNode.setProperty("ps:patch", version.getPatch());
+ versionNode.setProperty("ps:prefix", version.getQualifier().getPrefix().getName());
+ versionNode.setProperty("ps:suffix", version.getQualifier().getSuffix().name());
+ versionNode.setProperty("ps:codename", version.getCodeName());
+ }
+
+ // Store the description
+ LocalizedString description = module.getDescription();
+ if (description != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = description.getValues();
+
+ Set<Locale> set = values.keySet();
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ Node descriptionNode = moduleNode.addNode("ps:description", "ps:description");
+ descriptionNode.setProperty("jcr:language", locale.toString());
+ descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
+ }
+ }
+ }
+
+ // Store the authors
+ List<Author> authors = module.getAuthors();
+ if (authors != null)
+ {
+ for (Author author: authors)
+ {
+ Node authorNode = moduleNode.addNode("ps:author", "ps:author");
+ authorNode.setProperty("ps:username", author.getUsername());
+ authorNode.setProperty("ps:firstname", author.getFirstname());
+ authorNode.setProperty("ps:lastname", author.getLastname());
+ }
+ }
+
+ session.save();
+
+ module.setId(moduleNode.getUUID());
+
+ return module;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new StoreModuleException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public void unpublishModule(Module module) throws UnpublishModuleException
+ {
+ Session sessionPublished = null;
+ try
+ {
+ sessionPublished = jcrService.openSession(JCRService.PUBLISHED_MODULE_WORKSPACE_NAME);
+ Node node = sessionPublished.getNodeByUUID((String) module.getId());
+
+ node.remove();
+
+ sessionPublished.save();
+ }
+ catch (RepositoryException e)
+ {
+ throw new UnpublishModuleException();
+ }
+ finally
+ {
+ sessionPublished.logout();
+ }
+ }
+
+ public Category getCategory(Object id) throws RetrieveCategoryException
+ {
+ try
+ {
+ Session session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String)id);
+ if (node != null)
+ {
+ return new CategoryImpl(jcrService, node);
+ }
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new RetrieveCategoryException();
+ }
+ return null;
+ }
+
+ public Category getRootCategory() throws RetrieveCategoryException
+ {
+ if (rootCategory == null)
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node rootNode = session.getRootNode();
+ rootCategory = new CategoryImpl(jcrService, rootNode.getNode(Category.ROOT_CATEGORY_NAME));
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new RetrieveCategoryException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+ return rootCategory;
+ }
+
+ public void deleteCategory(Category category) throws DeleteCategoryException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ Node node = session.getNodeByUUID((String)category.getId());
+ if (node != null)
+ {
+ node.remove();
+ }
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new DeleteCategoryException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public Artifact storeArtifact(Module module, Artifact artifact) throws StoreArtifactException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ Node node = session.getNodeByUUID((String) module.getId());
+
+ Node artifactNode = null;
+ if (artifact.getArtifactType().equals(ArtifactType.FILE_ARTIFACT_TYPE))
+ {
+ artifactNode = node.addNode(artifact.getName(), "ps:fileArtifact");
+ artifactNode.setProperty("ps:file", ((FileArtifact)artifact).getInputStream());
+ artifactNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+ artifactNode.setProperty("ps:license", ((LicenseImpl)artifact.getLicense()).getId());
+ artifactNode.setProperty("ps:type", artifact.getType().name());
+
+ // Store the description
+ LocalizedString description = module.getDescription();
+ if (description != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = description.getValues();
+
+ Set<Locale> set = values.keySet();
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ Node descriptionNode = artifactNode.addNode("ps:description", "ps:description");
+ descriptionNode.setProperty("jcr:language", locale.toString());
+ descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
+ }
+ }
+ }
+
+ // Store the displayName
+ LocalizedString displayName = artifact.getDisplayName();
+ if (description != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = displayName.getValues();
+
+ Set<Locale> set = values.keySet();
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ Node displayNameNode = artifactNode.addNode("ps:displayName", "ps:displayName");
+ displayNameNode.setProperty("jcr:language", locale.toString());
+ displayNameNode.setProperty("ps:value", (values.get(locale)).getString());
+ }
+ }
+ }
+
+
+ session.save();
+ ((FileArtifactImpl)artifact).setId(artifactNode.getUUID());
+ return artifact;
+ }
+ return null;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new StoreArtifactException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public License storeLicense(License license) throws StoreLicenseException
+ {
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+
+ // Store the license name
+ Node licenseNode = session.getRootNode().addNode("ps:license", "ps:license");
+
+ // Store the license text
+ licenseNode.setProperty("ps:name", license.getName());
+ licenseNode.setProperty("ps:text", license.getText());
+
+ session.save();
+
+ ((LicenseImpl)license).setId(licenseNode.getUUID());
+
+ return license;
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ throw new StoreLicenseException();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+}
+
Added: server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
===================================================================
--- server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java (rev 0)
+++ server/trunk/portletswap2/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,133 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository.impl.memory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.RepositoryService;
+import org.jboss.portletswap.category.impl.memory.CategoryImpl;
+import org.jboss.portletswap.jcr.JCRServiceImpl;
+import org.jboss.portletswap.metadata.License;
+import org.jboss.portletswap.module.impl.AbstractModule;
+import org.jboss.portletswap.repository.DeleteCategoryException;
+import org.jboss.portletswap.repository.DeleteModuleException;
+import org.jboss.portletswap.repository.PublishModuleException;
+import org.jboss.portletswap.repository.StoreLicenseException;
+import org.jboss.portletswap.repository.StoreModuleException;
+import org.jboss.portletswap.repository.UnpublishModuleException;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RepositoryServiceImpl implements RepositoryService
+{
+
+ public static final Category ROOT_CATEGORY = new CategoryImpl(Category.ROOT_CATEGORY_NAME, null);
+
+ private JCRServiceImpl jcrService;
+
+ private Map<Object, Module> modules = new HashMap<Object, Module>();
+
+ private List<Module> published = new java.util.ArrayList<Module>();
+
+ public void deleteModule(Module module) throws DeleteModuleException
+ {
+ modules.remove(module.getId());
+ }
+
+ public Map<Object, Module> getModules()
+ {
+ return modules;
+ }
+
+ public Module getModule(Object id)
+ {
+ return modules.get(id);
+ }
+
+ public Module storeModule(Module module) throws StoreModuleException
+ {
+ ((AbstractModule)module).setId(module.getName() + module.getVersion());
+ modules.put(module.getId(), module);
+ return module;
+ }
+
+ public Category storeCategory(Category category)
+ {
+ // FIXME getCategory
+ return null;
+ }
+
+ public Module publishModule(Module module) throws PublishModuleException
+ {
+ published.add(module);
+ return module;
+ }
+
+ public void unpublishModule(Module module) throws UnpublishModuleException
+ {
+ published.remove(module);
+ }
+
+ public JCRServiceImpl getJcrService()
+ {
+ return jcrService;
+ }
+
+ public void setJcrService(JCRServiceImpl jcrService)
+ {
+ this.jcrService = jcrService;
+ }
+
+ public Category getCategory(Object id)
+ {
+ // FIXME getCategory
+ return null;
+ }
+
+ public void deleteCategory(Category category) throws DeleteCategoryException
+ {
+ // FIXME deleteCategory
+
+ }
+
+ public Artifact storeArtifact(Module module, Artifact artifact)
+ {
+ return null;
+ }
+
+ public License storeLicense(License license) throws StoreLicenseException
+ {
+ // FIXME storeLicense
+ return null;
+ }
+
+
+}
+
Added: server/trunk/portletswap2/src/main/resources/customNodes.cnd
===================================================================
--- server/trunk/portletswap2/src/main/resources/customNodes.cnd (rev 0)
+++ server/trunk/portletswap2/src/main/resources/customNodes.cnd 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,54 @@
+/** Categories node types */
+<mix = 'http://www.jcp.org/jcr/mix/1.0'>
+<nt = 'http://www.jcp.org/jcr/nt/1.0'>
+<jcr = 'http://www.jcp.org/jcr/1.0'>
+<ps = 'http://www.portletswap.com'>
+
+[ps:category] > nt:folder, mix:referenceable
+ - jcr:lastModified (date) mandatory ignore
+ + ps:description
+ + * (ps:category)
+
+[ps:localizedString] > nt:base
+ - jcr:language (string) mandatory
+ - ps:value
+
+[ps:description] > ps:localizedString
+
+[ps:displayName] > ps:localizedString
+
+[ps:license] > nt:base, mix:referenceable
+ - ps:text
+ - ps:name
+
+[ps:author] > nt:base
+ - ps:username
+ - ps:firstname
+ - ps:lastname
+ + ps:description
+ + ps:displayName
+
+[ps:fileArtifact] > nt:base, mix:referenceable
+ - jcr:lastModified (date) mandatory ignore
+ - ps:file (binary)
+ - ps:type (string) mandatory
+ - ps:license (reference) mandatory
+
+[ps:module] > nt:base, mix:referenceable
+ - jcr:lastModified (date) mandatory ignore
+ - ps:categoryRef (reference) multiple copy
+ - ps:name (string)
+ + ps:author
+ + ps:description
+ + ps:version mandatory
+ + * (ps:fileArtifact)
+
+[ps:version] > nt:base
+ - ps:name
+ - ps:major mandatory
+ - ps:minor mandatory
+ - ps:patch mandatory
+ - ps:prefix mandatory
+ - ps:suffix
+ - ps:codename
+
\ No newline at end of file
Added: server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java
===================================================================
--- server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java (rev 0)
+++ server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,189 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.directory.impl.jcr;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.common.util.Version;
+import org.jboss.portal.common.util.Version.Qualifier;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.jcr.JCRServiceImpl;
+import org.jboss.portletswap.module.impl.jcr.ModuleImpl;
+import org.jboss.portletswap.repository.PublishModuleException;
+import org.jboss.portletswap.repository.RetrieveCategoryException;
+import org.jboss.portletswap.repository.StoreCategoryException;
+import org.jboss.portletswap.repository.StoreModuleException;
+import org.jboss.portletswap.repository.impl.jcr.RepositoryServiceImpl;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DirectoryServiceTestCase extends TestCase
+{
+
+ private JCRServiceImpl jcrService;
+
+ private RepositoryServiceImpl repositoryService;
+
+ private DirectoryServiceImpl directoryService;
+
+ private Module module;
+
+ private Category category;
+
+ public void setUp()
+ {
+ jcrService = new JCRServiceImpl();
+ jcrService.setSettingsLocation("src/test/resources/settings.xml");
+ jcrService.setRootPath("/tmp/jcr");
+ jcrService.init();
+
+ directoryService = new DirectoryServiceImpl();
+ directoryService.setJcrService(jcrService);
+
+ repositoryService = new RepositoryServiceImpl();
+ repositoryService.setJcrService(jcrService);
+
+
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ module = new ModuleImpl(jcrService, "Foo", version);
+
+
+ try
+ {
+ category = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Foo", repositoryService.getRootCategory());
+ category = repositoryService.storeCategory(category);
+ }
+ catch (RetrieveCategoryException e)
+ {
+ e.printStackTrace();
+ }
+ catch (StoreCategoryException e)
+ {
+ e.printStackTrace();
+ }
+
+ assertNull(module.getId());
+ try
+ {
+ module = repositoryService.storeModule(module);
+ module.addCategory(category);
+ }
+ catch (StoreModuleException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void tearDown()
+ {
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ NodeIterator it = session.getRootNode().getNodes();
+
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (!node.getName().equals("jcr:system"))
+ {
+ node.remove();
+ }
+ }
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+
+ try
+ {
+ session = jcrService.openSession(JCRService.PUBLISHED_MODULE_WORKSPACE_NAME);
+ NodeIterator it = session.getRootNode().getNodes();
+
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (!node.getName().equals("jcr:system"))
+ {
+ node.remove();
+ }
+ }
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ jcrService.stop();
+ }
+
+
+ public void testGetModules() throws PublishModuleException
+ {
+ List<Module> modules = directoryService.getModules(false);
+ assertEquals(1, modules.size());
+ modules = directoryService.getModules(true);
+ assertEquals(0, modules.size());
+ repositoryService.publishModule(module);
+ modules = directoryService.getModules(true);
+ assertEquals(1, modules.size());
+ }
+
+ public void testGetModulesForOneCategory() throws PublishModuleException, StoreModuleException
+ {
+ Module module2 = new ModuleImpl(jcrService, "Bar", module.getVersion());
+ repositoryService.storeModule(module2);
+ List<Module> modules = directoryService.getModules(false);
+ assertEquals(2, modules.size());
+ modules = directoryService.getModules(false, category);
+ assertEquals(1, modules.size());
+ module2.addCategory(category);
+ modules = directoryService.getModules(false, category);
+ assertEquals(2, modules.size());
+ modules = directoryService.getModules(true, category);
+ assertEquals(0, modules.size());
+ }
+}
+
Added: server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceTestCase.java
===================================================================
--- server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceTestCase.java (rev 0)
+++ server/trunk/portletswap2/src/test/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceTestCase.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.directory.impl.memory;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.common.util.Version;
+import org.jboss.portal.common.util.Version.Qualifier;
+import org.jboss.portletswap.DirectoryService;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.module.impl.memory.ModuleImpl;
+import org.jboss.portletswap.repository.StoreModuleException;
+import org.jboss.portletswap.repository.impl.memory.RepositoryServiceImpl;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DirectoryServiceTestCase extends TestCase
+{
+
+ public void testRegister() throws StoreModuleException
+ {
+ RepositoryServiceImpl repositoryService = new RepositoryServiceImpl();
+
+ Version version1 = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module1 = new ModuleImpl("Foo", version1);
+ repositoryService.storeModule(module1);
+
+ Version version2 = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.CR), "");
+ Module module2 = new ModuleImpl("Foo", version2);
+ repositoryService.storeModule(module2);
+
+ DirectoryService directoryService = new DirectoryServiceImpl();
+ ((DirectoryServiceImpl)directoryService).setStorage(repositoryService.getModules());
+
+ List<Module> modules = directoryService.getModules(false);
+ assertEquals(2, modules.size());
+
+ Version version3 = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.BETA), "");
+ Module module3 = new ModuleImpl("Foo", version3);
+ repositoryService.storeModule(module3);
+
+ modules = directoryService.getModules(false);
+ assertEquals(3, modules.size());
+
+ }
+
+}
+
Added: server/trunk/portletswap2/src/test/java/org/jboss/portletswap/jcr/JCRServiceTestCase.java
===================================================================
--- server/trunk/portletswap2/src/test/java/org/jboss/portletswap/jcr/JCRServiceTestCase.java (rev 0)
+++ server/trunk/portletswap2/src/test/java/org/jboss/portletswap/jcr/JCRServiceTestCase.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.jcr;
+
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.value.DateValue;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRServiceTestCase extends TestCase
+{
+ public void testAddCustomNodes() throws Exception
+ {
+ JCRServiceImpl jcrService = new JCRServiceImpl();
+ jcrService.setSettingsLocation("src/test/resources/settings.xml");
+ jcrService.setRootPath("/tmp/jcr");
+ jcrService.init();
+
+ Session session = jcrService.openSession(JCRServiceImpl.MODULE_WORKSPACE_NAME);
+
+ Node node1 = session.getRootNode().addNode("Category1" , "ps:category");
+ node1.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ Node node2 = session.getRootNode().addNode("Category2" , "ps:category");
+ node2.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ Node node3 = session.getRootNode().addNode("Category3" , "ps:category");
+ node3.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ Node node1_1 = node1.addNode("Category11" , "ps:category");
+ node1_1.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ Node node1_2 = node1.addNode("Category12" , "ps:category");
+ node1_2.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ session.save();
+
+ dumpSession(session.getRootNode(), 0);
+
+ jcrService.stop();
+ }
+
+ private void dumpSession(Node node, int index) throws RepositoryException
+ {
+ NodeIterator it = node.getNodes();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ for (int i=0; i< index; i++)
+ {
+ System.out.print(" ");
+ }
+ System.out.println("* " + tmpNode.getName());
+ dumpSession(tmpNode, index+1);
+ }
+ }
+}
+
Added: server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
===================================================================
--- server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java (rev 0)
+++ server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,318 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository.impl.jcr;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.Version;
+import org.jboss.portal.common.util.Version.Qualifier;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Category;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.artifact.FileArtifact;
+import org.jboss.portletswap.artifact.impl.jcr.FileArtifactImpl;
+import org.jboss.portletswap.artifact.impl.jcr.LicenseImpl;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.jcr.JCRServiceImpl;
+import org.jboss.portletswap.metadata.License;
+import org.jboss.portletswap.module.impl.jcr.ModuleImpl;
+import org.jboss.portletswap.repository.RetrieveModuleException;
+import org.jboss.portletswap.repository.StoreModuleException;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RepositoryServiceTestCase extends TestCase
+{
+
+ private JCRServiceImpl jcrService;
+
+ private RepositoryServiceImpl repositoryService;
+
+ public void setUp()
+ {
+ jcrService = new JCRServiceImpl();
+ jcrService.setSettingsLocation("src/test/resources/settings.xml");
+ jcrService.setRootPath("/tmp/jcr");
+ jcrService.init();
+
+ repositoryService = new RepositoryServiceImpl();
+ repositoryService.setJcrService(jcrService);
+
+ }
+
+ public void tearDown()
+ {
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
+ NodeIterator it = session.getRootNode().getNodes();
+
+ while (it.hasNext())
+ {
+ Node node = it.nextNode();
+ if (!node.getName().equals("jcr:system"))
+ {
+ node.remove();
+ }
+ }
+ session.save();
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+
+ jcrService.stop();
+ }
+
+ public void testRegisterModule()
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Foo", version);
+ assertNull(module.getId());
+ try
+ {
+ module = repositoryService.storeModule(module);
+ }
+ catch (StoreModuleException e)
+ {
+ e.printStackTrace();
+ }
+ Object id = module.getId();
+ assertNotNull(id);
+ Module getModule = null;
+ try
+ {
+ getModule = repositoryService.getModule(id);
+ }
+ catch (RetrieveModuleException e)
+ {
+ e.printStackTrace();
+ }
+ assertNotNull(getModule);
+ assertEquals(id, getModule.getId());
+ assertEquals(version, module.getVersion());
+ }
+
+ public void testRegisterModuleWithDescription()
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Foo", version);
+ module.setDescription(new LocalizedString("Toto is bo"));
+ try
+ {
+ module = repositoryService.storeModule(module);
+ Module getModule = repositoryService.getModule(module.getId());
+ assertEquals("Toto is bo", getModule.getDescription().getDefaultString());
+ }
+ catch (StoreModuleException e)
+ {
+ e.printStackTrace();
+ }
+ catch (RetrieveModuleException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void testAddCategoryToModule() throws Exception
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Foo", version);
+ assertNull(module.getId());
+ try
+ {
+ module = repositoryService.storeModule(module);
+ }
+ catch (StoreModuleException e)
+ {
+ e.printStackTrace();
+ }
+
+ Category rootCategory = repositoryService.getRootCategory();
+
+ Category category1 = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Foo", rootCategory);
+ category1 = repositoryService.storeCategory(category1);
+
+ Category category2 = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Bar", rootCategory);
+ category2 = repositoryService.storeCategory(category2);
+
+ List<Category> categories = module.getCategories();
+ assertEquals(0, categories.size());
+
+ module.addCategory(category1);
+ categories = module.getCategories();
+ assertEquals(1, categories.size());
+
+ assertEquals(category1.getId(), categories.get(0).getId());
+
+ module.addCategory(category2);
+ categories = module.getCategories();
+ assertEquals(2, categories.size());
+
+ }
+
+ public void testRegisterCategory() throws Exception
+ {
+ Category rootCategory = repositoryService.getRootCategory();
+
+ Category category1 = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Foo", rootCategory);
+ category1 = repositoryService.storeCategory(category1);
+ Object id = category1.getId();
+ assertNotNull(id);
+
+ Category getCategory = repositoryService.getCategory(id);
+ assertNotNull(getCategory);
+ assertEquals(id, getCategory.getId());
+
+ }
+
+
+ public void testRegisterCategoryRecursive() throws Exception
+ {
+ Category rootCategory = repositoryService.getRootCategory();
+
+ Category category1 = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Bar", rootCategory);
+ category1 = repositoryService.storeCategory(category1);
+ Object id1 = category1.getId();
+ assertNotNull(id1);
+
+ Category category2 = new org.jboss.portletswap.category.impl.memory.CategoryImpl("Foo", category1);
+ category2 = repositoryService.storeCategory(category2);
+ Object id2 = category2.getId();
+ assertNotNull(id2);
+
+ Category getCategory1 = repositoryService.getCategory(id1);
+ assertNotNull(getCategory1);
+ assertEquals(id1, getCategory1.getId());
+
+ Category getCategory2 = repositoryService.getCategory(id2);
+ assertNotNull(getCategory2);
+ assertEquals(id2, getCategory2.getId());
+
+ assertEquals(rootCategory.getId(), getCategory1.getParent().getId());
+ assertEquals(getCategory1.getId(), getCategory2.getParent().getId());
+
+ }
+
+ public void testDeleteModule() throws Exception
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Test", version);
+ assertNull(module.getId());
+ module = repositoryService.storeModule(module);
+ Object id = module.getId();
+ assertNotNull(id);
+ Module getModule = repositoryService.getModule(id);
+ assertNotNull(getModule);
+ assertEquals(id, getModule.getId());
+
+ repositoryService.deleteModule(module);
+ getModule = repositoryService.getModule(id);
+ assertNull(getModule);
+ }
+
+ public void testPublishModule() throws Exception
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Test", version);
+ assertNull(module.getId());
+ module = repositoryService.storeModule(module);
+ Object id = module.getId();
+ assertNotNull(id);
+
+ repositoryService.publishModule(module);
+
+ Session session = null;
+ try
+ {
+ session = jcrService.openSession(JCRService.PUBLISHED_MODULE_WORKSPACE_NAME);
+ Node node = session.getNodeByUUID((String)id);
+ assertNotNull(node);
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ session.logout();
+ }
+ }
+
+ public void testAddArtifact() throws Exception
+ {
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl(jcrService, "Test", version);
+ assertNull(module.getId());
+ Module retModule = repositoryService.storeModule(module);
+
+ InputStream is = new FileInputStream("/tmp/test");
+ Artifact artifact = new FileArtifactImpl(Type.JSR168PORTLET, new File("/tmp/test"), is);
+ ((FileArtifactImpl)artifact).setName("Bozo");
+
+ License license = new LicenseImpl("LGPL", "blah");
+ license = repositoryService.storeLicense(license);
+
+ artifact.setLicense(license);
+ artifact = repositoryService.storeArtifact(retModule, artifact);
+
+ List<Artifact> artifacts = retModule.getArtifacts();
+ assertEquals(1, artifacts.size());
+
+ FileArtifact getArtifact = (FileArtifact)artifacts.get(0);
+ assertNotNull(getArtifact);
+ assertNotNull(getArtifact.getInputStream());
+
+// FileOutputStream fos = new FileOutputStream("/tmp/foobarou");
+//
+// byte[] buf = new byte[256];
+// int read = 0;
+// while ((read = getArtifact.getInputStream().read(buf)) > 0) {
+// fos.write(buf, 0, read);
+// }
+//
+
+ }
+}
+
Added: server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
===================================================================
--- server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java (rev 0)
+++ server/trunk/portletswap2/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository.impl.memory;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.common.util.Version;
+import org.jboss.portal.common.util.Version.Qualifier;
+import org.jboss.portletswap.Artifact;
+import org.jboss.portletswap.Module;
+import org.jboss.portletswap.RepositoryService;
+import org.jboss.portletswap.Type;
+import org.jboss.portletswap.artifact.impl.jcr.FileArtifactImpl;
+import org.jboss.portletswap.module.impl.memory.ModuleImpl;
+import org.jboss.portletswap.repository.StoreArtifactException;
+import org.jboss.portletswap.repository.StoreModuleException;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RepositoryServiceTestCase extends TestCase
+{
+ /*
+ public void testRegister() throws StoreModuleException
+ {
+ RepositoryService repositoryService = new RepositoryServiceImpl();
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new MemoryModuleImpl("Foo", version);
+ repositoryService.storeModule(module);
+
+ assertEquals(1, repositoryService.getModules("Foo").size());
+
+ assertNotNull(repositoryService.getModule("Foo", version));
+
+ Version version2 = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.BETA), "");
+ assertNull(repositoryService.getModule("Foo", version2));
+
+ Module module2 = new MemoryModuleImpl("Foo", version2);
+ repositoryService.storeModule(module2);
+
+ assertEquals(2, repositoryService.getModules("Foo").size());
+
+ assertNotNull(repositoryService.getModule("Foo", version2));
+ }
+ */
+
+ public void testAddArtifact() throws StoreModuleException, StoreArtifactException
+ {
+ RepositoryService repositoryService = new RepositoryServiceImpl();
+ Version version = new Version("", 1, 0, 0, new Qualifier(Qualifier.Prefix.ALPHA), "");
+ Module module = new ModuleImpl("Foo", version);
+ Artifact artifact = new FileArtifactImpl(Type.JSR168PORTLET, null, null);
+ module = repositoryService.storeModule(module);
+ repositoryService.storeArtifact(module, artifact);
+ }
+
+ /*
+ public void testAddCategory()
+ {
+ RepositoryService repositoryService = new RepositoryServiceImpl();
+ assertNull(repositoryService.findCategory("category1"));
+ assertNull(repositoryService.findCategory("category1_1"));
+ Category category1 = new CategoryImpl("category1", CategoryImpl.ROOT_CATEGORY);
+ assertNotNull(repositoryService.findCategory("category1"));
+ new CategoryImpl("category1_1", category1);
+ assertNotNull(repositoryService.findCategory("category1_1"));
+ }
+ */
+}
+
Added: server/trunk/portletswap2/src/test/resources/settings.xml
===================================================================
--- server/trunk/portletswap2/src/test/resources/settings.xml (rev 0)
+++ server/trunk/portletswap2/src/test/resources/settings.xml 2008-01-09 15:28:17 UTC (rev 184)
@@ -0,0 +1,40 @@
+<Repository>
+ <FileSystem
+ class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/repository" />
+ </FileSystem>
+ <Security appName="Jackrabbit">
+ <AccessManager
+ class="org.apache.jackrabbit.core.security.SimpleAccessManager" />
+ <LoginModule
+ class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+ <param name="anonymousId" value="anonymous" />
+ </LoginModule>
+ </Security>
+ <Workspaces rootPath="${rep.home}/workspaces"
+ defaultWorkspace="default" />
+ <Workspace name="${wsp.name}">
+ <FileSystem
+ class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${wsp.home}" />
+ </FileSystem>
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager" />
+ <SearchIndex
+ class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index" />
+ </SearchIndex>
+ </Workspace>
+ <Versioning rootPath="${rep.home}/version">
+ <FileSystem
+ class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/version" />
+ </FileSystem>
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager" />
+ </Versioning>
+ <SearchIndex
+ class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index" />
+ </SearchIndex>
+</Repository>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list