Author: thomas.heute(a)jboss.com
Date: 2008-01-28 03:33:42 -0500 (Mon, 28 Jan 2008)
New Revision: 223
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java
Log:
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -70,7 +70,7 @@
public void deleteCategory(Category category) throws RepositoryException,
NotFoundException;
- public Artifact storeArtifact(Module module, Artifact artifact) throws
RepositoryException, NotFoundException;
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException,
NotFoundException;
public Artifact getArtifact(Object id) throws RepositoryException, NotFoundException;
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -45,6 +45,8 @@
import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
import org.apache.jackrabbit.value.DateValue;
import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
import org.jboss.portletswap.model.impl.jcr.JCRModuleImpl;
/**
@@ -203,12 +205,14 @@
{
try
{
- Node node = rootNode.addNode(Category.ROOT_CATEGORY_NAME,
"ps:category");
+ Node node = rootNode.addNode(Category.ROOT_CATEGORY_NAME,
JCRCategoryImpl.NODE_TYPE);
node.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
- node.addNode("ps:categories" , "ps:categories");
+ node.addNode(JCRCategoryImpl.CATEGORIES_NODE ,
JCRCategoryImpl.CATEGORIES_NODE);
node = rootNode.addNode(JCRModuleImpl.ROOT_MODULE_NODENAME);
- }
+
+ node = rootNode.addNode(JCRLicenseImpl.ROOT_LICENSE_NODENAME);
+}
catch (Exception e)
{
// FIXME
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java
(rev 0)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * 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.model.impl.jcr;
+
+import java.util.HashMap;
+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 org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Type;
+import org.jboss.portletswap.model.Version;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class JCRArtifactImpl extends Artifact
+{
+
+ public static final String NODE_NAME = "ps:artifact";
+ public static final String ARTIFACT_TYPE_ATTRIBUTENAME = "ps:type";
+ public static final String DESCRIPTION_NODENAME = "ps:description";
+ public static final String DESCRIPTION_LANG_ATTRIBUTENAME = "ps:language";
+ public static final String DESCRIPTION_VALUE_ATTRIBUTENAME = "ps:value";
+ public static final String DISPLAYNAME_NODENAME = "ps:displayName";
+ public static final String DISPLAYNAME_LANG_ATTRIBUTENAME = "ps:language";
+ public static final String DISPLAYNAME_VALUE_ATTRIBUTENAME = "ps:value";
+ public static final String MODULE_ATTRIBUTENAME = "ps:module";
+
+ public static void fillCommonArtifactData(JCRService jcrService, Node node, Artifact
artifact) throws RepositoryException
+ {
+ artifact.setName(node.getName());
+ artifact.setId(node.getUUID());
+
+ Property typeProperty = node.getProperty(ARTIFACT_TYPE_ATTRIBUTENAME);
+ artifact.setType(Type.valueOf(typeProperty.getString()));
+
+ // Description
+ NodeIterator it = node.getNodes(DESCRIPTION_NODENAME);
+ Map<Locale, String> values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new
Locale(tmpNode.getProperty(DESCRIPTION_LANG_ATTRIBUTENAME).getString());
+ String value =
tmpNode.getProperty(DESCRIPTION_VALUE_ATTRIBUTENAME).getString();
+ values.put(locale, value);
+ }
+ artifact.setDescription(new LocalizedString(values, Locale.ENGLISH));
+
+ // DisplayName
+ it = node.getNodes(DISPLAYNAME_NODENAME);
+ values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new
Locale(tmpNode.getProperty(DISPLAYNAME_LANG_ATTRIBUTENAME).getString());
+ String value =
tmpNode.getProperty(DISPLAYNAME_VALUE_ATTRIBUTENAME).getString();
+ values.put(locale, value);
+ }
+ artifact.setDisplayName(new LocalizedString(values, Locale.ENGLISH));
+
+ // Compatibility List
+ // TODO
+
+ // License
+ try
+ {
+ Property property = node.getProperty(JCRLicenseImpl.NODE_TYPE);
+ Node licenseNode = node.getSession().getNodeByUUID(property.getString());
+ artifact.setLicense(new JCRLicenseImpl(licenseNode));
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore
+ }
+
+ // Module
+ try
+ {
+ Property property = node.getProperty(JCRModuleImpl.NODE_NAME);
+ Node moduleNode = node.getSession().getNodeByUUID(property.getString());
+ artifact.setModule(new JCRModuleImpl(jcrService, moduleNode));
+ }
+ catch (PathNotFoundException e)
+ {
+ throw new PathNotFoundException();
+ }
+
+ Node versionNode = node.getNode(JCRVersionImpl.NODE_NAME);
+ Version version = new JCRVersionImpl(versionNode);
+ artifact.setVersion(version);
+
+ }
+
+}
+
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java
(rev 0)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * 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.model.impl.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portletswap.model.Author;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRAuthorImpl extends Author
+{
+ public static final String NODE_TYPE = "ps:author";
+ public static final String NODE_NAME = "ps:author";
+ public static final String USERNAME_ATTRIBUTE = "ps:username";
+ public static final String FIRSTNAME_ATTRIBUTE = "ps:firstname";
+ public static final String LASTNAME_ATTRIBUTE = "ps:lastname";
+
+ public JCRAuthorImpl(Node node) throws RepositoryException
+ {
+ super(node.getProperty(JCRAuthorImpl.USERNAME_ATTRIBUTE).getString(),
+ node.getProperty(JCRAuthorImpl.FIRSTNAME_ATTRIBUTE).getString(),
+ node.getProperty(JCRAuthorImpl.LASTNAME_ATTRIBUTE).getString());
+ }
+
+
+}
+
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -41,7 +41,10 @@
*/
public class JCRCategoryImpl extends Category
{
+ public static final String NODE_TYPE = "ps:category";
+ public static final String CATEGORIES_NODE = "ps:categories";
+
private JCRService jcrService;
public JCRCategoryImpl(JCRService jcrService, Node node) throws RepositoryException
@@ -63,12 +66,6 @@
}
@Override
- public void addChild(Category category)
- {
-
- }
-
- @Override
public List<Category> getChildren()
{
Session session = null;
@@ -80,7 +77,7 @@
Node categoriesNode = null;
try
{
- categoriesNode = node.getNode("ps:categories");
+ categoriesNode = node.getNode(CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -22,23 +22,14 @@
******************************************************************************/
package org.jboss.portletswap.model.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.PathNotFoundException;
-import javax.jcr.Property;
import javax.jcr.RepositoryException;
-import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.model.FileArtifact;
-import org.jboss.portletswap.model.Type;
-import org.jboss.portletswap.jcr.JCRService;
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
@@ -46,59 +37,16 @@
*/
public class JCRFileArtifactImpl extends FileArtifact
{
-
+ public static final String NODE_TYPE = "ps:fileArtifact";
+ public static final String INPUT_STREAM_PROPERTYNAME = "ps:inputStream";
+
private InputStream inputStream;
-
- private File file;
public JCRFileArtifactImpl(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
- try
- {
- Property property = node.getProperty("ps:license");
- Node licenseNode = node.getSession().getNodeByUUID(property.getString());
- setLicense(new JCRLicenseImpl(jcrService, licenseNode));
- }
- catch (PathNotFoundException e)
- {
- // ignore
- }
-
- this.inputStream = node.getProperty("ps:file").getStream();
+ super();
+ JCRArtifactImpl.fillCommonArtifactData(jcrService, node, this);
+ this.inputStream = node.getProperty(INPUT_STREAM_PROPERTYNAME).getStream();
}
public InputStream getInputStream()
@@ -106,11 +54,6 @@
return inputStream;
}
- public File getFile()
- {
- return file;
- }
-
public ArtifactType getArtifactType()
{
return ArtifactType.FILE_ARTIFACT_TYPE;
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -25,7 +25,6 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
-import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.License;
/**
@@ -34,39 +33,15 @@
*/
public class JCRLicenseImpl extends License
{
- private String id;
-
- private String name;
-
- private String text;
+ public static final String ROOT_LICENSE_NODENAME =
"org.jboss.portletswap.root_license";
+ public static final String NODE_TYPE = "ps:license";
+ public static final String NODE_NAME = "ps:license";
+ public static final String TEXT_PROPERTY = "ps:text";
- public JCRLicenseImpl(JCRService jcrService, Node licenseNode) throws
RepositoryException
+ public JCRLicenseImpl(Node licenseNode) throws RepositoryException
{
- id = licenseNode.getUUID();
- name = licenseNode.getProperty("ps:name").getString();
- text = licenseNode.getProperty("ps:text").getString();
+ super(licenseNode.getName(), licenseNode.getProperty(TEXT_PROPERTY).getString());
+ setId(licenseNode.getUUID());
}
-
- public String getName()
- {
- return name;
- }
-
- public String getText()
- {
- return text;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setId(String id)
- {
- this.id = id;
-
- }
-
}
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -54,7 +54,12 @@
{
public static final String ROOT_MODULE_NODENAME =
"org.jboss.portletswap.root_module";
-
+ public static final String NODE_NAME = "ps:module";
+ public static final String DESCRIPTION_NODENAME = "ps:description";
+ public static final String ARTIFACTS_NODENAME = "ps:artifacts";
+ public static final String DESCRIPTION_LANG_ATTRIBUTENAME = "jcr:language";
+ public static final String DESCRIPTION_VALUE_ATTRIBUTENAME = "ps:value";
+
private List<Artifact> artifacts = new ArrayList<Artifact>();
private JCRService jcrService;
@@ -65,37 +70,24 @@
setName(node.getName());
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");
+
+ NodeIterator it = node.getNodes(DESCRIPTION_NODENAME);
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();
+ Locale locale = new
Locale(tmpNode.getProperty(DESCRIPTION_LANG_ATTRIBUTENAME).getString());
+ String value =
tmpNode.getProperty(DESCRIPTION_VALUE_ATTRIBUTENAME).getString();
values.put(locale, value);
}
setDescription(new LocalizedString(values, Locale.ENGLISH));
- it = node.getNodes("ps:author");
+ it = node.getNodes(JCRAuthorImpl.NODE_NAME);
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());
+ Author author = new JCRAuthorImpl(tmpNode);
authors.add(author);
}
setAuthors(authors);
@@ -142,7 +134,7 @@
Node artifactsNode = null;
try
{
- artifactsNode = node.getNode("ps:artifacts");
+ artifactsNode = node.getNode(ARTIFACTS_NODENAME);
}
catch (PathNotFoundException e)
{
@@ -181,7 +173,7 @@
List<Value> valuesList;
try
{
- Property property = node.getProperty("ps:categories");
+ Property property = node.getProperty(JCRCategoryImpl.CATEGORIES_NODE);
valuesList = new
ArrayList<Value>(Arrays.asList(property.getValues()));
}
catch (PathNotFoundException e)
@@ -192,7 +184,7 @@
valuesList.add(new
ReferenceValue(session.getNodeByUUID((String)category.getId())));
Value[] values = valuesList.toArray(new Value[valuesList.size()]);
- node.setProperty("ps:categories", values);
+ node.setProperty(JCRCategoryImpl.CATEGORIES_NODE, values);
session.save();
}
catch (RepositoryException e)
@@ -217,7 +209,7 @@
Property property;
try
{
- property = node.getProperty("ps:categories");
+ property = node.getProperty(JCRCategoryImpl.CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
@@ -243,9 +235,4 @@
session.logout();
}
}
-
- public void addArtifact(Artifact artifact)
- {
- // repositoryService.storeArtifact(this, artifact);
- }
}
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java
(rev 0)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * 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.model.impl.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portletswap.model.Version;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRVersionImpl extends Version
+{
+
+ public static final String NODE_NAME = "ps:version";
+ public static final String NODE_TYPE = "ps:version";
+ public static final String MAJOR_PROPERTYNAME = "ps:major";
+ public static final String MINOR_PROPERTYNAME = "ps:minor";
+ public static final String PATCH_PROPERTYNAME = "ps:patch";
+ public static final String PREFIX_PROPERTYNAME = "ps:prefix";
+ public static final String SUFFIX_PROPERTYNAME = "ps:suffix";
+
+ public JCRVersionImpl(Node node) throws RepositoryException
+ {
+ super((int)node.getProperty(MAJOR_PROPERTYNAME).getLong(),
+ (int)node.getProperty(MINOR_PROPERTYNAME).getLong(),
+ (int)node.getProperty(PATCH_PROPERTYNAME).getLong(),
+ new
Version.Qualifier(Version.Qualifier.Prefix.valueOf(node.getProperty(PREFIX_PROPERTYNAME).getString()),
+
Version.Qualifier.Suffix.valueOf(node.getProperty(SUFFIX_PROPERTYNAME).getString())));
+ }
+}
+
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java
(rev 0)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * 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.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.value.DateValue;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Author;
+import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.FileArtifact;
+import org.jboss.portletswap.model.License;
+import org.jboss.portletswap.model.Module;
+import org.jboss.portletswap.model.Version;
+import org.jboss.portletswap.model.impl.jcr.JCRArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRAuthorImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRFileArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRVersionImpl;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class NodeFactory
+{
+
+ public static Node createFileArtifactNode(Node parent, Artifact artifact) throws
RepositoryException
+ {
+ Node artifactNode = parent.addNode(JCRArtifactImpl.NODE_NAME,
JCRFileArtifactImpl.NODE_TYPE);
+ artifactNode.setProperty(JCRFileArtifactImpl.INPUT_STREAM_PROPERTYNAME,
((FileArtifact)artifact).getInputStream());
+ artifactNode.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
+ if (artifact.getLicense() != null)
+ {
+ artifactNode.setProperty(JCRLicenseImpl.NODE_NAME,
((License)artifact.getLicense()).getId());
+ }
+ artifactNode.setProperty(JCRArtifactImpl.ARTIFACT_TYPE_ATTRIBUTENAME,
artifact.getType().name());
+ artifactNode.setProperty(JCRArtifactImpl.MODULE_ATTRIBUTENAME,
(String)artifact.getModule().getId());
+
+ // Store the version
+ Version version = artifact.getVersion();
+ Node versionNode = artifactNode.addNode(JCRVersionImpl.NODE_NAME,
JCRVersionImpl.NODE_TYPE);
+ {
+ versionNode.setProperty(JCRVersionImpl.MAJOR_PROPERTYNAME, version.getMajor());
+ versionNode.setProperty(JCRVersionImpl.MINOR_PROPERTYNAME, version.getMinor());
+ versionNode.setProperty(JCRVersionImpl.PATCH_PROPERTYNAME, version.getPatch());
+ versionNode.setProperty(JCRVersionImpl.PREFIX_PROPERTYNAME,
version.getQualifier().getPrefix().getName());
+ versionNode.setProperty(JCRVersionImpl.SUFFIX_PROPERTYNAME,
version.getQualifier().getSuffix().name());
+ }
+
+ // Store the description
+ LocalizedString description = artifact.getModule().getDescription();
+ if (description != null)
+ {
+ createLocalizedStringNode(artifactNode, "ps:description",
description);
+ }
+
+ // Store the displayName
+ LocalizedString displayName = artifact.getDisplayName();
+ if (displayName != null)
+ {
+ createLocalizedStringNode(artifactNode, "ps:displayName",
displayName);
+ }
+
+ return artifactNode;
+ }
+
+ private static Node createLocalizedStringNode(Node parent, String nodeType,
LocalizedString lString) throws RepositoryException
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = lString.getValues();
+
+ Set<Locale> set = values.keySet();
+
+ Node descriptionNode = null;
+
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ descriptionNode = parent.addNode(nodeType, nodeType);
+ descriptionNode.setProperty("jcr:language", locale.toString());
+ descriptionNode.setProperty("ps:value",
(values.get(locale)).getString());
+ }
+ }
+ return descriptionNode;
+ }
+
+ public static Node createModuleNode(Node parent, Module module) throws
RepositoryException
+ {
+ Node moduleNode = parent.addNode(module.getName(), "ps:module");
+
+ // Store the last modified date
+ moduleNode.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
+
+ // 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(JCRAuthorImpl.NODE_NAME,
JCRAuthorImpl.NODE_TYPE);
+ authorNode.setProperty(JCRAuthorImpl.USERNAME_ATTRIBUTE,
author.getUsername());
+ authorNode.setProperty(JCRAuthorImpl.FIRSTNAME_ATTRIBUTE,
author.getFirstname());
+ authorNode.setProperty(JCRAuthorImpl.LASTNAME_ATTRIBUTE,
author.getLastname());
+ }
+ }
+ return moduleNode;
+ }
+
+ public static Node createLicenseNode(Node parent, License license) throws
RepositoryException
+ {
+ Node licenseNode = parent.addNode(license.getName(), JCRLicenseImpl.NODE_TYPE);
+ licenseNode.setProperty(JCRLicenseImpl.TEXT_PROPERTY, license.getText());
+ return licenseNode;
+ }
+
+ public static Node createCategoryNode(Node parent, Category category) throws
RepositoryException
+ {
+ Node node = parent.addNode(category.getName(), JCRCategoryImpl.NODE_TYPE);
+ node.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
+
+ // Store the displayName
+ LocalizedString displayName = category.getDisplayName();
+ if (displayName != null)
+ {
+ createLocalizedStringNode(node, "displayName", displayName);
+ }
+ return node;
+ }
+}
+
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -23,32 +23,24 @@
package org.jboss.portletswap.repository.impl.jcr;
import java.io.Serializable;
-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.PathNotFoundException;
import javax.jcr.Session;
-import org.apache.jackrabbit.value.DateValue;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.PortletswapException;
import org.jboss.portletswap.RepositoryService;
import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.Artifact;
-import org.jboss.portletswap.model.Author;
+import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.model.Category;
-import org.jboss.portletswap.model.FileArtifact;
import org.jboss.portletswap.model.License;
import org.jboss.portletswap.model.Module;
-import org.jboss.portletswap.model.Version;
import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRFileArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
import org.jboss.portletswap.model.impl.jcr.JCRModuleImpl;
import org.jboss.portletswap.repository.NotFoundException;
import org.jboss.portletswap.repository.RepositoryException;
@@ -203,37 +195,15 @@
Node categoriesNode = null;
try
{
- categoriesNode = parentNode.getNode("ps:categories");
+ categoriesNode = parentNode.getNode(JCRCategoryImpl.CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
- categoriesNode = parentNode.addNode("ps:categories",
"ps:categories");
+ categoriesNode = parentNode.addNode(JCRCategoryImpl.CATEGORIES_NODE,
JCRCategoryImpl.CATEGORIES_NODE);
}
- Node node = categoriesNode.addNode(category.getName(),
"ps:category");
- node.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
+ Node node = NodeFactory.createCategoryNode(categoriesNode, category);
- // Store the displayName
- LocalizedString displayName = category.getDisplayName();
- if (displayName != 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 = node.addNode("ps:displayName",
"ps:displayName");
- displayNameNode.setProperty("jcr:language",
locale.toString());
- displayNameNode.setProperty("ps:value",
(values.get(locale)).getString());
- }
- }
- }
-
-
session.save();
return new JCRCategoryImpl(jcrService, node);
@@ -256,44 +226,9 @@
session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
// Store the module name
- Node moduleNode =
session.getRootNode().getNode(JCRModuleImpl.ROOT_MODULE_NODENAME).addNode(module.getName(),
"ps:module");
-
- // Store the last modified date
- moduleNode.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
-
- // 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());
- }
- }
-
+ Node parentNode =
session.getRootNode().getNode(JCRModuleImpl.ROOT_MODULE_NODENAME);
+ Node moduleNode = NodeFactory.createModuleNode(parentNode, module);
+
session.save();
return new JCRModuleImpl(jcrService, moduleNode);
@@ -413,91 +348,29 @@
}
}
- public Artifact storeArtifact(Module module, Artifact artifact) throws
RepositoryException, NotFoundException
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException,
NotFoundException
{
Session session = null;
try
{
session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
- Node node = session.getNodeByUUID((String) module.getId());
+ Node node = session.getNodeByUUID((String) artifact.getModule().getId());
Node artifactsNode = null;
try
{
- artifactsNode = node.getNode("ps:artifacts");
+ artifactsNode = node.getNode(JCRModuleImpl.ARTIFACTS_NODENAME);
}
catch (PathNotFoundException e)
{
- artifactsNode = node.addNode("ps:artifacts",
"ps:artifacts");
+ artifactsNode = node.addNode(JCRModuleImpl.ARTIFACTS_NODENAME,
JCRModuleImpl.ARTIFACTS_NODENAME);
}
- Node artifactNode = null;
if (artifact.getArtifactType().equals(ArtifactType.FILE_ARTIFACT_TYPE))
{
- artifactNode = artifactsNode.addNode("ps:artifact",
"ps:fileArtifact");
- artifactNode.setProperty("ps:file",
((FileArtifact)artifact).getInputStream());
- artifactNode.setProperty("jcr:lastModified", new
DateValue(Calendar.getInstance()));
- if (artifact.getLicense() != null)
- {
- artifactNode.setProperty("ps:license",
((License)artifact.getLicense()).getId());
- }
- artifactNode.setProperty("ps:type", artifact.getType().name());
-
- // Store the version
- Version version = artifact.getVersion();
- Node versionNode = artifactNode.addNode("ps:version",
"ps:version");
- {
- 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());
- }
-
- // 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 (displayName != 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());
- }
- }
- }
-
-
+ Node artifactNode = NodeFactory.createFileArtifactNode(artifactsNode,
(Artifact)artifact);
session.save();
- ((FileArtifact)artifact).setId(artifactNode.getUUID());
- return artifact;
+ return new JCRFileArtifactImpl(jcrService, artifactNode);
}
return null;
}
@@ -550,18 +423,10 @@
{
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());
-
+ Node rootLicenseNode =
session.getRootNode().getNode(JCRLicenseImpl.ROOT_LICENSE_NODENAME);
+ Node licenseNode = NodeFactory.createLicenseNode(rootLicenseNode, license);
session.save();
-
- ((License)license).setId(licenseNode.getUUID());
-
- return license;
+ return new JCRLicenseImpl(licenseNode);
}
catch (javax.jcr.RepositoryException e)
{
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -111,7 +111,7 @@
}
- public Artifact storeArtifact(Module module, Artifact artifact) throws
RepositoryException, NotFoundException
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException,
NotFoundException
{
return null;
}
Modified: src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd
===================================================================
---
src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd 2008-01-28
08:33:42 UTC (rev 223)
@@ -34,13 +34,14 @@
+ ps:artifact multiple
[ps:artifact] > nt:base, mix:referenceable
+ - jcr:lastModified (date) mandatory ignore
+ - ps:module (reference) mandatory
+ - ps:license (reference)
+ - ps:type (string) mandatory
+ ps:version mandatory
[ps:fileArtifact] > ps:artifact
- - jcr:lastModified (date) mandatory ignore
- - ps:file (binary)
- - ps:type (string) mandatory
- - ps:license (reference)
+ - ps:inputStream (binary)
[ps:module] > nt:base, mix:referenceable
- jcr:lastModified (date) mandatory ignore
Modified:
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -318,22 +318,22 @@
{
Module module = new Module("Test");
assertNull(module.getId());
- Module retModule = repositoryService.storeModule(module);
+ module = repositoryService.storeModule(module);
Version version = new Version(1, 0, 0, new
Version.Qualifier(Version.Qualifier.Prefix.GA));
InputStream is = new FileInputStream("/tmp/test");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new
File("/tmp/test"), is);
- ((FileArtifact)artifact).setName("Bozo");
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new
File("/tmp/test"), is);
+ ((Artifact)artifact).setName("Bozo");
artifact.setVersion(version);
License license = new License("LGPL", "blah");
license = repositoryService.storeLicense(license);
artifact.setLicense(license);
- artifact = repositoryService.storeArtifact(retModule, artifact);
+ artifact = repositoryService.storeArtifact(artifact);
- List<Artifact> artifacts = retModule.getArtifacts();
+ List<Artifact> artifacts = module.getArtifacts();
assertEquals(1, artifacts.size());
FileArtifact getArtifact = (FileArtifact)artifacts.get(0);
Modified:
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
===================================================================
---
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -63,9 +63,9 @@
{
RepositoryService repositoryService = new RepositoryServiceImpl();
Module module = new Module("Foo");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, null, null);
module = repositoryService.storeModule(module);
- repositoryService.storeArtifact(module, artifact);
+ repositoryService.storeArtifact(artifact);
}
}
Modified:
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java
===================================================================
---
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -47,7 +47,27 @@
private CompatibilityList compatibilityList;
private License license;
+
+ private Module module;
+ protected Artifact()
+ {
+
+ }
+
+ protected Artifact(Module module)
+ {
+ this.module = module;
+ module.addArtifact(this);
+ }
+
+ public Artifact(Module module, Type type)
+ {
+ this.module = module;
+ module.addArtifact(this);
+ this.type = type;
+ }
+
public ArtifactType getArtifactType()
{
return artifactType;
@@ -138,6 +158,14 @@
this.version = version;
}
-
+ public Module getModule()
+ {
+ return module;
+ }
+
+ public void setModule(Module module)
+ {
+ this.module = module;
+ }
}
Modified:
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java
===================================================================
---
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -32,19 +32,22 @@
*/
public class FileArtifact extends Artifact
{
-
private InputStream inputStream;
private File file;
-
+
protected FileArtifact()
{
-
}
- public FileArtifact(Type type, File file, InputStream inputStream)
+ protected FileArtifact(Module module)
{
- setType(type);
+ super(module);
+ }
+
+ public FileArtifact(Type type, Module module, File file, InputStream inputStream)
+ {
+ super(module, type);
this.inputStream = inputStream;
this.file = file;
}
Modified:
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
===================================================================
---
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -82,7 +82,7 @@
category3.setDisplayName(new LocalizedString("foobar"));
Module module = new Module("Toto");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new
File("/tmp"), new ByteArrayInputStream(new byte[0]));
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new
File("/tmp"), new ByteArrayInputStream(new byte[0]));
module.addArtifact(artifact);
}
Modified: src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java
===================================================================
---
src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java 2008-01-25
14:07:01 UTC (rev 222)
+++
src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java 2008-01-28
08:33:42 UTC (rev 223)
@@ -206,8 +206,8 @@
try
{
Module module = repositoryService.getModule(moduleId);
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new File(filename), new
FileInputStream(filename));
- artifact = repositoryService.storeArtifact(module, artifact);
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new
File(filename), new FileInputStream(filename));
+ artifact = repositoryService.storeArtifact(artifact);
System.out.println("Successfully inserted artifact: " +
artifact.getId());
}
catch (PortletswapException e)
@@ -343,7 +343,7 @@
public void populate() throws RepositoryException
{
Module module1 = new Module("Module1");
- FileArtifact fileArtifact1_1 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact1_1 = new FileArtifact(Type.JSR168PORTLET, module1, null,
null);
fileArtifact1_1.setDisplayName(new LocalizedString("Artifact 1:1",
Locale.ENGLISH));
module1.addArtifact(fileArtifact1_1);
module1 = repositoryService.storeModule(module1);
@@ -355,10 +355,10 @@
module3 = repositoryService.storeModule(module3);
Module module4 = new Module("Module4");
- FileArtifact fileArtifact4_1 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact4_1 = new FileArtifact(Type.JSR168PORTLET, module4, null,
null);
fileArtifact4_1.setDisplayName(new LocalizedString("Artifact 4:1",
Locale.ENGLISH));
module4.addArtifact(fileArtifact4_1);
- FileArtifact fileArtifact4_2 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact4_2 = new FileArtifact(Type.JSR168PORTLET, module4, null,
null);
fileArtifact4_2.setDisplayName(new LocalizedString("Artifact 4:2",
Locale.ENGLISH));
module4.addArtifact(fileArtifact4_2);
module4 = repositoryService.storeModule(module4);