[jboss-svn-commits] JBL Code SVN: r23869 - in labs/jbossrules/trunk/drools-atom/src: main/java/org/drools/atom and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 13 22:38:32 EST 2008


Author: jervisliu
Date: 2008-11-13 22:38:31 -0500 (Thu, 13 Nov 2008)
New Revision: 23869

Added:
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Artifact.java
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/ArtifactManager.java
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/MetaData.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/Quickstart_helloworld.esb
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/add_metadata_servicecategory.txt
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/resources/
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/resources/Quickstart_helloworld.esb
Modified:
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/AtomRulesRepositoryServer.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java
Log:
More on atomPub support...

Modified: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java	2008-11-14 03:15:43 UTC (rev 23868)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -2,17 +2,22 @@
 package org.drools.atom;
 
 
+import java.io.InputStream;
 import java.net.URI;
+import java.util.Calendar;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
-import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
-import javax.ws.rs.ProduceMime;
+import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
@@ -25,11 +30,15 @@
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.ExtensibleElement;
 import org.apache.abdera.model.Feed;
+import org.drools.repository.Artifact;
+import org.drools.repository.ArtifactManager;
 import org.drools.repository.AssetItem;
+import org.drools.repository.MetaData;
 import org.drools.repository.PackageItem;
 import org.drools.repository.PackageIterator;
 import org.drools.repository.RulesRepository;
 import org.drools.repository.RulesRepositoryException;
+import org.drools.repository.security.PermissionManager;
 
 
 /**
@@ -133,7 +142,7 @@
     
     @GET
     @Path("/packages")
-    @ProduceMime({"application/atom+xml" })
+    @Produces({"application/atom+xml" })
     public Feed getPackagesAsFeed(@Context UriInfo uParam) {
         System.out.println("----invoking getPackagesAsFeed");
 
@@ -159,8 +168,87 @@
     }
     
     @GET
+    @Path("/packages/{packageName}")
+    @Produces({"application/atom+xml"})
+    public Entry getPackageAsEntry(@PathParam("packageName") String packageName, @Context UriInfo uParam) throws ResourceNotFoundFault {
+        System.out.println("----invoking getPackageAsEntry with packageName: " + packageName);
+        
+        try {
+            PackageItem packageItem = repository.loadPackage(packageName);
+            return createDetailedPackageItemEntry(packageItem, uParam);
+        } catch (RulesRepositoryException e) {
+        	ResourceNotFoundDetails details = new ResourceNotFoundDetails();
+            details.setName(packageName);
+            throw new ResourceNotFoundFault(details);       	
+        }
+    }
+                   
+    @POST
+    @Path("/packages")
+    @Consumes("application/atom+xml")
+    @Produces({"application/atom+xml"})
+    public Response addPackageAsEntry(Entry e, @Context UriInfo uParam) {
+        System.out.println("----invoking addPackageAsEntry with package name: " + e.getTitle());
+
+        try {
+        	String packageName = e.getTitle();
+
+        	PackageItem packageItem = repository.createPackage(packageName, "desc");
+            
+            URI uri = 
+            	uParam.getBaseUriBuilder().path("repository").path("packages").path(packageItem.getName()).build();
+            return Response.created(uri).entity(e).build();
+        } catch (RulesRepositoryException ex) {
+            return Response.serverError().build();
+        }
+    }   
+    
+    @PUT
+    @Path("/packages")
+    @Consumes("application/atom+xml")
+    @Produces({"application/atom+xml"})
+    public Response updatePackageAsEntry(Entry e, @Context UriInfo uParam) {
+        System.out.println("----invoking updatePackageAsEntry, package name is: " + e.getTitle());
+        try {      	
+        	PackageItem item = repository.loadPackage(e.getTitle());
+        	
+    		item.updateDescription(e.getSummary());
+    		//item.archiveItem(data.archived);
+    		//item.updateBinaryUpToDate(false);
+    		//this.ruleBaseCache.remove(data.uuid);
+    		item.checkin(e.getSummary());
+    		
+            URI uri = 
+            	uParam.getBaseUriBuilder().path("repository").path("packages").path(item.getName()).build();
+            return Response.ok(uri).entity(e).build();
+        } catch (RulesRepositoryException ex) {
+        	ex.printStackTrace();
+            return Response.serverError().build();
+        }
+    }
+        
+    @DELETE
+    @Path("/packages/{packageName}/")
+    public Response deletePackage(@PathParam("packageName") String packageName) {
+        System.out.println("----invoking deletePackage with packageName: " + packageName);
+        Response response;
+
+		try {
+			PackageItem item = repository.loadPackage(packageName);
+			item.remove();
+			repository.save();
+			
+			response = Response.ok().build();
+		} catch (RulesRepositoryException e) {
+			response = Response.notModified().build();
+		}
+
+        return response;
+    }
+    
+    @GET
     @Path("/packages/{packageName}/assets")
-    @ProduceMime({"application/atom+xml" })
+    @Produces({"application/atom+xml" })
     public Feed getAssetsAsFeed(@Context UriInfo uParam, @PathParam("packageName") String packageName) {
         System.out.println("----invoking getRulesAsFeed with packageName: " + packageName);
 
@@ -180,26 +268,10 @@
 
         return f;
     }
-    
+
     @GET
-    @Path("/packages/{packageName}")
-    @ProduceMime({"application/atom+xml"})
-    public Entry getPackageAsEntry(@PathParam("packageName") String packageName, @Context UriInfo uParam) throws ResourceNotFoundFault {
-        System.out.println("----invoking getPackageAsEntry with packageName: " + packageName);
-        
-        try {
-            PackageItem packageItem = repository.loadPackage(packageName);
-            return createDetailedPackageItemEntry(packageItem, uParam);
-        } catch (RulesRepositoryException e) {
-        	ResourceNotFoundDetails details = new ResourceNotFoundDetails();
-            details.setName(packageName);
-            throw new ResourceNotFoundFault(details);       	
-        }
-    }
-            
-    @GET
     @Path("/packages/{packageName}/assets/{assetName}")
-    @ProduceMime({"application/atom+xml"})
+    @Produces({"application/atom+xml"})
     public Entry getAssetAsEntry(@PathParam("packageName") String packageName, 
     		@Context UriInfo uParam,
     		@PathParam("assetName") String assetName) throws ResourceNotFoundFault {
@@ -225,63 +297,198 @@
         throw new ResourceNotFoundFault(details);       	
     }
     
+    @GET
+    @Path("/artifacts/{artifactName}")
+    @Produces({"application/atom+xml"})
+    public Entry getArtifactAsEntry(@PathParam("artifactName") String artifactName, 
+    		@Context UriInfo uParam) throws ResourceNotFoundFault {
+        System.out.println("----invoking getArtifactAsEntry with artifactName: " + artifactName);
+        
+        try {             
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+        	Artifact artifact = artifactManager.getArtifact(artifactName);
+        	Map<String, MetaData>metadataTypes = artifactManager.getMetadataTypes();
+ 
+            return createDetailedArtifactEntry(artifact, metadataTypes, uParam);
+        } catch (RulesRepositoryException e) {
+        	ResourceNotFoundDetails details = new ResourceNotFoundDetails();
+            details.setName(artifactName);
+            throw new ResourceNotFoundFault(details);       	
+        }
+     	
+    }
+    
     @POST
-    @Path("/packages")
-    @ConsumeMime("application/atom+xml")
-    @ProduceMime({"application/atom+xml"})
-    public Response addPackageAsEntry(Entry e, @Context UriInfo uParam) {
-        System.out.println("----invoking addPackageAsEntry with package name: " + e.getTitle());
+    @Path("/artifacts")
+    @Consumes("application/atom+xml")
+    @Produces({"application/atom+xml"})
+    public Response addArtifactAsEntry(Entry e, @Context UriInfo uParam) {
+        System.out.println("----invoking addArtifactAsEntry with package name: " + e.getTitle());
 
         try {
-        	String packageName = e.getTitle();
+        	String artifactName = e.getTitle();
 
-        	PackageItem packageItem = repository.createPackage(packageName, "desc");
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+        	Artifact artifact = new Artifact();
+        	artifact.setName(artifactName);
+        	artifact.setDescription(e.getSummary());
+        	artifactManager.createArtifact(artifact);
             
             URI uri = 
-            	uParam.getBaseUriBuilder().path("repository", "packages", 
-                                                packageItem.getName()).build();
+            	uParam.getBaseUriBuilder().path("repository").path("artifacts").path( 
+            			artifactName).build();
             return Response.created(uri).entity(e).build();
         } catch (RulesRepositoryException ex) {
             return Response.serverError().build();
         }
-    }    
+    }  
     
+    @POST
+    @Path("/esbs")
+    @Consumes("application/esb")
+    @Produces({"application/atom+xml"})
+    public Response addArtifactAsEntryMediaType(InputStream is, @Context UriInfo uParam) {
+        System.out.println("----invoking addArtifactAsEntryMediaType----");
+
+    	String name = null;
+    	List<String> slugHeaders = headers.getRequestHeader("Slug");
+    	if(slugHeaders != null) {
+    		name = slugHeaders.get(0);
+    	}
+    	
+    	if(name == null || name.equals("")) {
+    		return Response.serverError().build();
+    	}
+    	
+        try {
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+        	artifactManager.createEBSJar(name, is);
+
+         	Artifact artifact = artifactManager.getArtifact(name);
+         	
+         	Map<String, MetaData>metadataTypes = artifactManager.getMetadataTypes();
+
+            Entry e = createDetailedArtifactEntry(artifact, metadataTypes, uParam);
+            URI uri = uParam.getBaseUriBuilder().path("repository").path("artifacts").path(name).build();
+            return Response.created(uri).entity(e).build();
+        } catch (Exception ex) {
+        	ex.printStackTrace();
+            return Response.serverError().build();
+        }
+    } 
+    
     @PUT
-    @Path("/packages")
-    @ConsumeMime("application/atom+xml")
-    @ProduceMime({"application/atom+xml"})
-    public Response updatePackageAsEntry(Entry e, @Context UriInfo uParam) {
+    @Path("/artifacts")
+    @Consumes("application/atom+xml")
+    @Produces({"application/atom+xml"})
+    public Response updateArtifactAsEntry(Entry e, @Context UriInfo uParam) {
         System.out.println("----invoking updatePackageAsEntry, package name is: " + e.getTitle());
         try {      	
-        	PackageItem item = repository.loadPackage(e.getTitle());
-        	
-    		item.updateDescription(e.getSummary());
-    		//item.archiveItem(data.archived);
-    		//item.updateBinaryUpToDate(false);
-    		//this.ruleBaseCache.remove(data.uuid);
-    		item.checkin(e.getSummary());
-    		
+           	ArtifactManager artifactManager = new ArtifactManager(repository);
+
+           	Artifact artifact = artifactManager.getArtifact(e.getTitle());
+
+           	if (e.getSummary() != null) {
+				artifact.setDescription(e.getSummary());
+			}
+           	
+           	if (!(e.getContentType() == Content.Type.MEDIA) && e.getContent() != null) {
+				artifact.setContent(e.getContent());
+			}
+           	artifact.setLastModified(Calendar.getInstance());
+        	artifactManager.updateArtifact(artifact);
+  		
             URI uri = 
-            	uParam.getBaseUriBuilder().path("repository", "packages", 
-            			item.getName()).build();
-            return Response.ok(uri).entity(e).build();
+            	uParam.getBaseUriBuilder().path("repository").path("artifacts").path(e.getTitle()).build();
+            
+            Map<String, MetaData>metadataTypes = artifactManager.getMetadataTypes();
+        	Entry updatedEntry = createDetailedArtifactEntry(artifact, metadataTypes, uParam);
+
+            return Response.ok(uri).entity(updatedEntry).build();
         } catch (RulesRepositoryException ex) {
         	ex.printStackTrace();
             return Response.serverError().build();
         }
     }    
 
+    @GET
+    @Path("/esbs/{esbName}")
+    @Produces({"application/esb"})
+    public InputStream getArtifactAsEntryMediaType(@PathParam("esbName") String esbName, @Context UriInfo uParam) {
+        System.out.println("----invoking getArtifactAsEntryMediaType----");
+
+        try {
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+         	InputStream is = artifactManager.getEBSJar(esbName);
+
+            URI uri = uParam.getBaseUriBuilder().path("repository").path("esbs").path(esbName).build();
+            return is;
+        } catch (Exception ex) {
+        	ex.printStackTrace();
+        	return null;
+            //return Response.serverError().build();
+        }
+    }
+        
+    @GET
+    @Path("/metadatatypes")
+    @Produces({"application/atom+xml" })
+    public Feed getMetadataTypesAsFeed(@Context UriInfo uParam) {
+        System.out.println("----invoking getMetadataTypesAsFeed");
+
+        Factory factory = Abdera.getNewFactory();
+        Feed f = factory.newFeed();
+        f.setBaseUri(uParam.getAbsolutePath().toString());
+		
+        f.setTitle("Metadata types");
+        
+    	ArtifactManager artifactManager = new ArtifactManager(repository);
+    	Map<String, MetaData>metadataTypes = artifactManager.getMetadataTypes();
+    	
+        for (String key : metadataTypes.keySet()) {
+        	MetaData md = metadataTypes.get(key);
+           
+            f.addEntry(createMetadataTypeEntry(md, uParam));
+        }
+
+        return f;
+    }    
+    
+    @POST
+    @Path("/metadatatypes")
+    @Consumes("application/atom+xml")
+    @Produces({"application/atom+xml"})
+    public Response addMetaDataTypeAsEntry(Entry e, @Context UriInfo uParam) {
+        System.out.println("----invoking addMetaDataTypeAsEntry with metadata name: " + e.getTitle());
+
+        try {
+        	MetaData md = new MetaData();
+        	md.setMetaDataName(e.getTitle());
+        	md.setMetaDataType(e.getContent());
+        	md.setDescription(e.getSummary());
+        	
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+        	artifactManager.createMetadataType(md);
+            
+            URI uri = 
+            	uParam.getBaseUriBuilder().path("repository").path("metadatatypes").path(e.getTitle()).build();
+            return Response.created(uri).entity(e).build();
+        } catch (RulesRepositoryException ex) {
+            return Response.serverError().build();
+        }
+    }   
+    
     @DELETE
-    @Path("/packages/{packageName}/")
-    public Response deletePackage(@PathParam("packageName") String packageName) {
-        System.out.println("----invoking deletePackage with packageName: " + packageName);
+    @Path("/metadatatypes/{metadataname}/")
+    public Response deleteMetaDataType(@PathParam("metadataname") String metaDataName) {
+        System.out.println("----invoking deleteMetaDataType with metaDataName: " + metaDataName);
         Response response;
 
 		try {
-			PackageItem item = repository.loadPackage(packageName);
-			item.remove();
-			repository.save();
-			
+        	ArtifactManager artifactManager = new ArtifactManager(repository);
+        	
+        	artifactManager.deleteMetadataType(metaDataName);
+        	
 			response = Response.ok().build();
 		} catch (RulesRepositoryException e) {
 			response = Response.notModified().build();
@@ -289,7 +496,7 @@
 
         return response;
     }
-        
+    
     private static Entry createPackageItemEntry(PackageItem pkg, UriInfo baseUri) {
         Factory factory = Abdera.getNewFactory();
         
@@ -299,8 +506,7 @@
         }
         e.setTitle(pkg.getName());
         URI uri = 
-        	baseUri.getBaseUriBuilder().path("repository", "packages", 
-        			pkg.getName()).build();
+        	baseUri.getBaseUriBuilder().path("repository").path("packages").path(pkg.getName()).build();
         e.addLink(uri.toString());
 
         return e;
@@ -315,8 +521,7 @@
         }
         e.setTitle(asset.getName());
         URI uri = 
-        	baseUri.getBaseUriBuilder().path("repository", "packages", packageName, "assets",
-        			asset.getName()).build();
+        	baseUri.getBaseUriBuilder().path("repository").path("packages").path(packageName).path("assets").path(asset.getName()).build();
         e.addLink(uri.toString());
 
         return e;
@@ -334,8 +539,7 @@
         e.setSummary(pkg.getDescription());
         
         URI uri = 
-        	baseUri.getBaseUriBuilder().path("repository", "packages",  
-        			pkg.getName()).build();
+        	baseUri.getBaseUriBuilder().path("repository").path("packages").path(pkg.getName()).build();
         e.addLink(uri.toString());
         e.setUpdated(pkg.getLastModified().getTime());
         
@@ -354,8 +558,7 @@
         e.setSummary(asset.getDescription());
         
         URI uri = 
-        	baseUri.getBaseUriBuilder().path("repository", "packages",  
-        			asset.getName()).build();
+        	baseUri.getBaseUriBuilder().path("repository").path("packages").path(asset.getName()).build();
         e.addLink(uri.toString());
         e.setUpdated(asset.getLastModified().getTime());
         
@@ -419,6 +622,97 @@
         return e;
     }
     
+    private static Entry createDetailedArtifactEntry(Artifact artifact, Map<String, MetaData>metadataTypes, UriInfo baseUri) {
+    	String artifactName = artifact.getName();
+    	Map<String, List<String>> metadata = artifact.getMetadata();
+    	
+        Factory factory = Abdera.getNewFactory();
+        
+        Entry e = factory.getAbdera().newEntry();
+        if (baseUri != null) {
+            e.setBaseUri(baseUri.getAbsolutePath().toString());
+        }
+        e.setTitle(artifactName);
+        //e.setId(asset.getUUID());
+        e.setSummary(artifact.getDescription());
+        e.setUpdated(artifact.getLastModified().toString());
+        
+        URI uri = 
+        	baseUri.getBaseUriBuilder().path("repository").path("artifacts").path(artifactName).build();
+        e.addLink(uri.toString());
+        //e.setUpdated(asset.getLastModified().getTime());
+        
+        //meta data
+/*        StringProperty property = e.addExtension(MetaDataExtensionFactory.PROPERTY);
+        property.setValue("false");*/
+        String NS = "http://overlord.jboss.org/drools/1.0";
+        QName METADATA = new QName(NS, "metadata");
+        
+        ExtensibleElement extension = e.addExtension(METADATA);
+        //extension.declareNS(NS, "drools");
+        QName PROPERTY = new QName(NS, "property");
+        QName VALUE = new QName(NS, "value");
+        
+        for (String key : metadata.keySet()) {
+        	String metadataType = null;
+        	if(metadataTypes.get(key) != null) {
+        		metadataType = metadataTypes.get(key).getMetaDataType(); 
+        	}
+        	
+        	if(ArtifactManager.METADATA_TYPE_STRING.equals(metadataType)) {
+            	List<String> value = metadata.get(key);
+                ExtensibleElement childExtension = extension.addExtension(PROPERTY);
+                childExtension.setAttributeValue("name", key);
+                childExtension.addSimpleExtension(VALUE, value.get(0));
+                //childExtension.setText(value.get(0));
+			} else if (ArtifactManager.METADATA_TYPE_MULTI_VALUE_STRING.equals(metadataType)) {
+				List<String> values = metadata.get(key);
+				ExtensibleElement childExtension = extension
+						.addExtension(PROPERTY);
+				childExtension.setAttributeValue("name", key);
+				for(String value : values) {
+	                childExtension.addSimpleExtension(VALUE, value);					
+				}
+			} else {
+				//Default to string
+            	List<String> value = metadata.get(key);
+                ExtensibleElement childExtension = extension.addExtension(PROPERTY);
+                childExtension.setAttributeValue("name", key);
+                childExtension.setText(value.get(0));		
+			}
+         }
+         
+        if (!artifact.isBinary()) {
+			e.setContentElement(factory.newContent());
+			e.getContentElement().setContentType(Content.Type.TEXT);
+			e.getContentElement().setValue(artifact.getContent());
+		} else {
+			e.setContentElement(factory.newContent());
+			e.getContentElement().setContentType(Content.Type.MEDIA);
+			e.getContentElement().setSrc(artifact.getSrcLink());
+		}
+        
+        return e;
+    }
+      
+    private static Entry createMetadataTypeEntry(MetaData md, UriInfo baseUri) {
+        Factory factory = Abdera.getNewFactory();
+        
+        Entry e = factory.getAbdera().newEntry();
+        if (baseUri != null) {
+            e.setBaseUri(baseUri.getAbsolutePath().toString());
+        }
+        e.setTitle(md.getMetaDataName());
+        e.setSummary(md.getDescription());
+        e.setContent(md.getMetaDataType());
+        URI uri = 
+        	baseUri.getBaseUriBuilder().path("repository").path("metadatatypes").path(md.getMetaDataName()
+        		).build();
+        e.addLink(uri.toString());
+
+        return e;
+    }
+    
 	public RulesRepository getRulesRepository() {
 		return repository;
 	}

Added: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Artifact.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Artifact.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Artifact.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -0,0 +1,115 @@
+package org.drools.repository;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class Artifact {   
+	String name;
+	String description;
+	Map<String, List<String>> metadata;	
+	String content;	
+	boolean isBinary;
+	InputStream binaryContent;
+	Calendar lastModified;
+	String srcLink;
+	
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getContent() {
+		return content;
+	}
+    /**
+     * If this asset contains binary data, this is how you return it.
+     * Otherwise it will return null.
+     */
+    public InputStream getBinaryContentAttachment() {
+    	if(isBinary) {
+    		return binaryContent;
+    	}
+    	
+    	return null;
+    }
+
+	public void setContent(String content) {
+		this.content = content;
+		isBinary = false;
+	}
+	public void setBinaryContent(InputStream content) {
+		this.binaryContent = content;
+		isBinary = true;
+	}
+	public String getDescription() {
+		return description;
+	}
+	public void setDescription(String description) {
+		this.description = description;
+	}
+	public Map<String, List<String>> getMetadata() {
+		return metadata;
+	}
+	public void setMetadata(Map<String, List<String>> metadata) {
+		this.metadata = metadata;
+	}
+	public boolean isBinary() {
+		return isBinary;
+	}
+	public void setBinary(boolean isBinary) {
+		this.isBinary = isBinary;
+	}
+	
+    /**
+     * Nicely formats the information contained by the node that this object encapsulates
+     */
+    public String toString() {
+        try {
+            StringBuffer returnString = new StringBuffer();
+            returnString.append( "Content of artifact named '" + this.getName() + "':\n" );
+            returnString.append( "Content: " + this.getContent() + "\n" );
+            returnString.append( "------\n" );
+
+            returnString.append( "Description: " + this.getDescription() + "\n" );
+            returnString.append( "------\n" );
+
+            returnString.append( "Meta data: " );
+            
+            Map<String, List<String>> metadata = this.getMetadata();            
+
+	    	for (Iterator<Map.Entry<String, List<String>>> iterator = metadata.entrySet().iterator(); iterator.hasNext();) {
+	    		Map.Entry<String, List<String>> en = iterator.next();
+				String key = en.getKey();
+				List<String> value = en.getValue();
+				returnString.append(key + ": " + value + "\n" );
+			}
+
+            returnString.append( "--------------\n" );
+            return returnString.toString();
+        } catch ( Exception e ) {
+            throw new RulesRepositoryException( e );
+        }
+    }
+	public Calendar getLastModified() {
+		return lastModified;
+	}
+	public void setLastModified(Calendar lastModified) {
+		this.lastModified = lastModified;
+	}
+	public String getSrcLink() {
+		return srcLink;
+	}
+	public void setSrcLink(String srcLink) {
+		//has a srclink means this is a binary content
+		this.srcLink = srcLink;
+		isBinary = true;
+	}	
+}

Added: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/ArtifactManager.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/ArtifactManager.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/ArtifactManager.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -0,0 +1,410 @@
+package org.drools.repository;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.drools.repository.RulesRepository;
+import org.drools.repository.RulesRepositoryException;
+
+
+public class ArtifactManager {
+
+    private RulesRepository repository;
+    
+    public static final String METADATA_TYPE_STRING = "metadata_type_string";
+    public static final String METADATA_TYPE_MULTI_VALUE_STRING = "metadata_type_multi_value_string";
+    
+    public ArtifactManager(RulesRepository repo) {
+        this.repository = repo;
+        
+        MetaData md = new MetaData();
+        md.setMetaDataName("archived");
+        md.setMetaDataType(METADATA_TYPE_STRING);
+        md.setDescription("is archived or not");        
+        createMetadataType(md);
+        
+        md = new MetaData();
+        md.setMetaDataName("format");
+        md.setMetaDataType(METADATA_TYPE_STRING);
+        createMetadataType(md);
+        
+        md = new MetaData();
+        md.setMetaDataName("description");
+        md.setMetaDataType(METADATA_TYPE_STRING);
+        createMetadataType(md);        
+        
+        md = new MetaData();
+        md.setMetaDataName("multi-value-property");
+        md.setMetaDataType(METADATA_TYPE_MULTI_VALUE_STRING);
+        createMetadataType(md);
+    }
+
+    /**
+     * Create artifact
+     * @param Artifact
+     * @throws RepositoryException
+     */
+    public void createArtifact(Artifact artifact) {
+    	try {
+    		//TODO: should allow creating an artifact if it exists already
+	    	Node artifactNode = getArtifactNode(artifact.getName());
+	    	artifactNode.remove(); //remove this so we get a fresh set
+	    	artifactNode = getArtifactNode(artifact.getName()).addNode("jcr:content", "nt:unstructured");
+	    	
+	    	artifactNode.setProperty(AssetItem.TITLE_PROPERTY_NAME,
+	    			artifact.getName() ); 	
+
+	    	if (artifact.getDescription() != null) {
+				artifactNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+						artifact.getDescription());
+			}
+
+            artifactNode.setProperty(VersionableItem.CHECKIN_COMMENT,
+                                  "Initial");
+            
+            Calendar lastModified = Calendar.getInstance();
+            artifactNode.setProperty(AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
+            
+            Map<String, List<String>> metadata = artifact.getMetadata();
+
+            if (artifact.getMetadata() != null) {
+				for (Iterator<Map.Entry<String, List<String>>> iterator = metadata
+						.entrySet().iterator(); iterator.hasNext();) {
+					Map.Entry<String, List<String>> en = iterator.next();
+					String key = en.getKey();
+					List<String> targets = en.getValue();
+					if (targets == null) {
+						targets = new ArrayList<String>();
+					}
+					if(targets.size() == 1) {
+					    artifactNode.setProperty(key, targets.get(0));
+					} else {
+						artifactNode.setProperty(key, targets.toArray(new String[targets.size()]));
+					}
+				}
+			}
+
+	    	if (!artifact.isBinary() && artifact.getContent() != null) {
+				artifactNode.setProperty(AssetItem.CONTENT_PROPERTY_NAME,
+						artifact.getContent());
+			} else {
+				if(artifact.getSrcLink() != null) {
+					//If its a binary content, normally we will have a link to the actual source. We do not store 
+					//the binary content direclty on artifact node.
+					artifactNode.setProperty("drools:srcLink",
+							artifact.getSrcLink());					
+				} else {
+					//TODO
+				}
+			}
+	        
+	    	this.repository.save();
+    	} catch (RepositoryException e) {
+            if ( e instanceof ItemExistsException ) {
+                throw new RulesRepositoryException( "An artifact of that name already exists in that package.",
+                                                    e );
+            } else {
+                throw new RulesRepositoryException( e );
+            }
+    	}
+    }
+    
+    /**
+     * update artifact
+     * @param Artifact
+     * @throws RepositoryException
+     */
+    public void updateArtifact(Artifact artifact) {
+    	try {
+	    	if (!getArtifactNode(artifact.getName()).hasNode("jcr:content")) {
+	    		throw new RulesRepositoryException("Artifact " + artifact.getName() + " is not found");
+	    	}
+	    	Node artifactNode = getArtifactNode(artifact.getName()).getNode("jcr:content");
+	    	
+	    	if (artifact.getDescription() != null) {
+				artifactNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+						artifact.getDescription());
+			}
+
+            Calendar lastModified = Calendar.getInstance();
+            artifactNode.setProperty(AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
+            
+            Map<String, List<String>> metadata = artifact.getMetadata();
+
+            if (metadata != null) {
+				for (Iterator<Map.Entry<String, List<String>>> iterator = metadata
+						.entrySet().iterator(); iterator.hasNext();) {
+					Map.Entry<String, List<String>> en = iterator.next();
+					String key = en.getKey();
+					List<String> targets = en.getValue();
+					if (targets == null) {
+						targets = new ArrayList<String>();
+					}
+					if(targets.size() == 1) {
+					    artifactNode.setProperty(key, targets.get(0));
+					} else {
+						artifactNode.setProperty(key, targets.toArray(new String[targets.size()]));
+					}
+				}
+			}
+
+	    	if (!artifact.isBinary() && artifact.getContent() != null) {
+				artifactNode.setProperty(AssetItem.CONTENT_PROPERTY_NAME,
+						artifact.getContent());
+			} else {
+				if(artifact.getSrcLink() != null) {
+					//If its a binary content, normally we will have a link to the actual source. We do not store 
+					//the binary content direclty on artifact node.
+					artifactNode.setProperty("drools:srcLink",
+							artifact.getSrcLink());					
+				} else {
+					//TODO
+				}
+			}
+	        
+	    	this.repository.save();
+    	} catch (RepositoryException e) {
+            if ( e instanceof ItemExistsException ) {
+                throw new RulesRepositoryException( "An artifact of that name already exists in that package.",
+                                                    e );
+            } else {
+                throw new RulesRepositoryException( e );
+            }
+    	}
+    }
+    
+    public Artifact getArtifact(String artifactName) {
+    	try {   		
+	    	if (!getArtifactNode(artifactName).hasNode("jcr:content")) {
+	    		throw new RulesRepositoryException("Artifact " + artifactName + " is not found");
+	    	}
+	    	
+    		Artifact artifact = new Artifact();
+	    	Map<String, List<String>> metadata = new HashMap<String, List<String>>(10);
+	    	
+	    	Node permsNode = getArtifactNode(artifactName).getNode("jcr:content");
+	    	PropertyIterator it = permsNode.getProperties();
+
+	    	while (it.hasNext()) {
+	    		Property p = (Property) it.next();
+	    		String name = p.getName();
+	    		if (!name.startsWith("jcr")) {
+	    			if(AssetItem.TITLE_PROPERTY_NAME.equals(name)) {
+	    				artifact.setName(p.getValue().getString());
+	    				continue;
+	    			} else if(AssetItem.DESCRIPTION_PROPERTY_NAME.equals(name)) {
+	    				artifact.setDescription(p.getValue().getString());
+	    				continue;
+	    			} else if(AssetItem.CONTENT_PROPERTY_NAME.equals(name)) {
+	    				artifact.setContent(p.getValue().getString());
+	    				continue;
+	    			} else if(AssetItem.CONTENT_PROPERTY_BINARY_NAME.equals(name)) {
+	    				artifact.setBinaryContent(p.getValue().getStream());
+	    				continue;
+	    			} else if(AssetItem.LAST_MODIFIED_PROPERTY_NAME.equals(name)) {
+	    				artifact.setLastModified(p.getValue().getDate());
+	    				continue;
+	    			} else if("drools:srcLink".equals(name)) {
+	    				artifact.setSrcLink(p.getValue().getString());
+	    				continue;
+	    			} 
+
+	    			//other properties are treated as meta data
+	    			if (p.getDefinition().isMultiple()) {
+			    		Value[] vs = p.getValues();
+			    		List<String> perms = new ArrayList<String>();
+			    		for (int i = 0; i < vs.length; i++) {
+							perms.add(vs[i].getString());
+						}
+			    		metadata.put(name, perms);
+	    			} else {
+	    				Value v = p.getValue();
+	    				List<String> perms = new ArrayList<String>(1);
+	    				perms.add(v.getString());
+	    				metadata.put(name, perms);
+	    			}
+	    		}
+	    	}
+	    	artifact.setMetadata(metadata);
+	    	if(artifact.getName() == null) {
+	    		artifact.setName(artifactName);
+	    	}
+	    	
+	    	
+	    	return artifact;
+    	} catch (RepositoryException e) {
+    		throw new RulesRepositoryException(e);
+    	}   	
+    }
+    
+	//TODO: add meta-data. For example, if it is esb type, we need to extract jboss-esb.xml from the esb
+	//jar, figure out service category and service name etc as the meta-data.
+    //Create two nodes for an esb jar type. one under esbs, one under artifacts
+    public void createEBSJar(String esbJarName, InputStream data) {
+    	try {
+    		//REVISIT: should not allow create a new node if it exists already
+    		
+	    	Node artifactNode = getESBJarNode(esbJarName);
+	    	artifactNode.remove(); //remove this so we get a fresh set
+	    	artifactNode = getESBJarNode(esbJarName).addNode("jcr:content", "nt:unstructured");
+	    	
+	    	artifactNode.setProperty(AssetItem.CONTENT_PROPERTY_BINARY_NAME,
+                    data);            
+	    	
+			
+			Artifact newArtifact = new Artifact();
+			newArtifact.setName(esbJarName);
+			newArtifact.setSrcLink("/repository/esbs/" + esbJarName);
+	        createArtifact(newArtifact);
+		
+	    	this.repository.save();
+    	} catch (RepositoryException e) {
+			throw new RulesRepositoryException(e);
+		}    	
+    }
+    
+    public InputStream getEBSJar(String esbJarName) {
+    	try {
+ 	    	if (!getESBJarNode(esbJarName).hasNode("jcr:content")) {
+	    		throw new RulesRepositoryException("ESBJar " + esbJarName + " is not found");
+	    	}
+ 	    	
+	    	InputStream is = null;	    	
+	    	Node node = getESBJarNode(esbJarName).getNode("jcr:content");
+	    	PropertyIterator it = node.getProperties();
+	    	
+	    	while (it.hasNext()) {
+	    		Property p = (Property) it.next();
+	    		String name = p.getName();
+	    		if (!name.startsWith("jcr")) {
+	    			if(AssetItem.CONTENT_PROPERTY_BINARY_NAME.equals(name)) {
+	    				is = p.getValue().getStream();
+	    				break;
+	    			}
+	    		}
+	    	}
+	    	
+	    	return is;    				
+	     
+    	} catch (RepositoryException e) {
+			throw new RulesRepositoryException(e);
+		}    	
+    }
+ 
+    /**
+     * Create a metadata type
+     * @param metadataName
+     * @param type
+     * @throws RepositoryException
+     */
+    public void createMetadataType(MetaData metaData) {
+    	try {
+	    	Node metadataTypeNode = getMetaDataTypeNode(metaData.getMetaDataName());
+	    	metadataTypeNode.remove(); //remove this so we get a fresh set
+	    	metadataTypeNode = getMetaDataTypeNode(metaData.getMetaDataName()).addNode("jcr:content", "nt:unstructured");
+	    	
+	    	metadataTypeNode.setProperty("metadata_type", metaData.getMetaDataType()); 	
+	    	
+	    	//JCR wont create a property if its value is null
+	    	if(metaData.getDescription() != null) {
+	    	metadataTypeNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME, metaData.getDescription()); 
+	    	} else {
+		    	metadataTypeNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME, ""); 	    		
+	    	}
+        
+	    	this.repository.save();
+    	} catch (RepositoryException e) {
+			throw new RulesRepositoryException(e);
+		}
+	}
+    
+    public Map<String, MetaData> getMetadataTypes() {
+       	Map<String, MetaData> metaDataList = new HashMap<String, MetaData>();
+
+ 		try{
+    		Node root = this.repository.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME);
+        	NodeIterator nodes = getNode(root, "metadata_names", "nt:folder").getNodes();
+         	while (nodes.hasNext()) {
+         		MetaData md = new MetaData();         		
+        		Node node = nodes.nextNode();
+        		md.setMetaDataName(node.getName());
+        		md.setMetaDataType(node.getNode("jcr:content").getProperty("metadata_type").getString());
+        		md.setDescription(node.getNode("jcr:content").getProperty(AssetItem.DESCRIPTION_PROPERTY_NAME).getString());
+        		metaDataList.put(node.getName(), md);
+        	}
+
+ 		} catch (RepositoryException e) {
+ 			throw new RulesRepositoryException(e);
+ 		}
+ 		
+    	return metaDataList;
+    }
+    
+    
+    public void deleteMetadataType(String metaDataName) {
+ 		try{ 	 		
+ 	    	Node metadataTypeNode = getMetaDataTypeNode(metaDataName);
+ 	    	metadataTypeNode.remove();
+
+ 		} catch (RepositoryException e) {
+ 			throw new RulesRepositoryException(e);
+ 		}
+    }
+    
+	private Node getArtifactNode(String artifactName)
+			throws RepositoryException {
+		Node root = this.repository.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME);
+    	Node node = getNode(getNode(root, "artifacts", "nt:folder"), artifactName, "nt:file");
+		return node;
+	}
+
+	private Node getMetaDataTypeNode(String metadataType)
+			throws RepositoryException {
+		Node root = this.repository.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME);
+    	Node node = getNode(getNode(root, "metadata_names", "nt:folder"), metadataType, "nt:file");
+		return node;
+	}
+	
+	private Node getESBJarNode(String esbJarName)
+			throws RepositoryException {
+		Node root = this.repository.getSession().getRootNode().getNode(
+				RulesRepository.RULES_REPOSITORY_NAME);
+		Node node = getNode(getNode(root, "esbs", "nt:folder"),
+				esbJarName, "nt:file");
+		return node;
+	}	
+    /**
+     * Gets or creates a node.
+     */
+	private Node getNode(Node node, String name, String nodeType) throws RepositoryException {
+		Node resultNode;
+		if (!node.hasNode(name)) {
+			resultNode = node.addNode(name, nodeType);
+    	} else {
+    		resultNode = node.getNode(name);
+    	}
+		return resultNode;
+	}
+
+	private boolean isValideArtifactName(String artifactName) {
+		if("".equals(artifactName.trim()) || artifactName.trim().length() == 0) {
+			return false;
+		}
+		return true;
+	}
+}

Added: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/MetaData.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/MetaData.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/MetaData.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -0,0 +1,36 @@
+package org.drools.repository;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class MetaData {   
+	String metaDataName;
+	String metaDataType;
+	String description;
+	public String getDescription() {
+		return description;
+	}
+	public void setDescription(String description) {
+		this.description = description;
+	}
+	public String getMetaDataName() {
+		return metaDataName;
+	}
+	public void setMetaDataName(String metaDataName) {
+		this.metaDataName = metaDataName;
+	}
+	public String getMetaDataType() {
+		return metaDataType;
+	}
+	public void setMetaDataType(String metaDataType) {
+		this.metaDataType = metaDataType;
+	}
+	
+}

Modified: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/AtomRulesRepositoryServer.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/AtomRulesRepositoryServer.java	2008-11-14 03:15:43 UTC (rev 23868)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/AtomRulesRepositoryServer.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -2,13 +2,17 @@
 package org.drools.atom;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.provider.AtomEntryProvider;
 import org.apache.cxf.jaxrs.provider.AtomFeedProvider;
 import org.apache.cxf.testutil.common.AbstractTestServerBase;
+import org.drools.repository.Artifact;
+import org.drools.repository.ArtifactManager;
 import org.drools.repository.AssetItem;
 import org.drools.repository.PackageItem;
 import org.drools.repository.RepositorySessionUtil;
@@ -34,6 +38,19 @@
         AssetItem testAsset2 = pkg.addAsset( "testAsset2", "testAsset2Desc1", "/AtomRulesRepositoryTestCat", "drl");
         testAsset2.updateContent("a new test rule for testAsset2");
 
+        ArtifactManager artifactManager = new ArtifactManager(repo);
+        Artifact artifact = new Artifact();
+		Map<String, List<String>> metadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>() {{add("true");}});
+			put("format", new ArrayList<String>() {{add("drl");}});
+			put("multi-value-property", new ArrayList<String>() {{add("value1"); add("value2");}});
+		}};
+		artifact.setMetadata(metadata);
+		artifact.setName("testArtifact1");
+		artifact.setDescription("desc1");
+		artifact.setContent("the string content of testArtifact1");		
+		artifactManager.createArtifact(artifact);
+        
         repo.save();
 
         atomRepo.setRulesRepository(repo);

Modified: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java	2008-11-14 03:15:43 UTC (rev 23868)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -255,8 +255,192 @@
             put1.releaseConnection();
         }
     }  
+    
+    @Test
+    public void testAddAndUpdateESBJar() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/repository/esbs"; 
+        
+        PostMethod post = new PostMethod(endpointAddress);
+        File testESBJar = new File(getClass().getResource("resources/Quickstart_helloworld.esb").toURI());
+        post.setRequestEntity(
+             new FileRequestEntity(testESBJar, "application/esb"));
+        HttpClient httpclient = new HttpClient();
+        post.addRequestHeader("Slug", "Quickstart_helloworld.esb");
+        Entry entry = null;
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(201, result);
+            //String response = getStringFromInputStream(post.getResponseBodyAsStream());
+            //System.out.print(response);
+			Document<Entry> doc = abdera.getParser().parse(post.getResponseBodyAsStream());
+			entry = doc.getRoot();
 
+			assertEquals("Quickstart_helloworld.esb", entry.getTitle());
+			assertEquals("/repository/esbs/Quickstart_helloworld.esb", entry.getContentSrc().getPath());
+			assertEquals("MEDIA", entry.getContentType().name());
+
+        } finally {
+            post.releaseConnection();
+        } 
+        
+    	//Update artifact Quickstart_helloworld.esb
+        entry.setSummary("desc for esb");
+        String endpointAddress1 = "http://localhost:9080/repository/artifacts";
+        PutMethod put = new PutMethod(endpointAddress1);
+        System.out.println("***********" + entry.toString());
+        put.setRequestEntity(new StringRequestEntity(entry.toString(), "application/atom+xml", null));
+        HttpClient httpclient1 = new HttpClient();
+
+        try {
+            int result = httpclient1.executeMethod(put);
+            assertEquals(200, result);
+        } finally {
+            // Release current connection to the connection pool once you are
+            // done
+            put.releaseConnection();
+        }
+        
+        // Verify result
+        String endpointAddress2 = "http://localhost:9080/repository/artifacts/Quickstart_helloworld.esb";
+        URL url = new URL(endpointAddress2);
+        URLConnection connect = url.openConnection();
+        connect.addRequestProperty("Accept", "application/atom+xml");
+        InputStream in = connect.getInputStream();
+        assertNotNull(in);
+		Document<Entry> doc = abdera.getParser().parse(in);
+		entry = doc.getRoot();
+
+		assertEquals("Quickstart_helloworld.esb", entry.getTitle());
+		assertEquals("/repository/esbs/Quickstart_helloworld.esb", entry.getContentSrc().getPath());
+		assertEquals("MEDIA", entry.getContentType().name());
+		assertEquals("desc for esb", entry.getSummary());
+		
+		//Get back the binary content of ESB Jar
+        String endpointAddress3 = "http://localhost:9080/repository/esbs/Quickstart_helloworld.esb";
+        URL url3 = new URL(endpointAddress3);
+        URLConnection connect3 = url3.openConnection();
+        connect3.addRequestProperty("Accept", "application/esb");
+        InputStream in3 = connect3.getInputStream();
+        assertNotNull(in);
+		
+         // Roll back changes:
+/*        File input1 = new File(getClass().getResource("resources/expected_get_testPackage1.txt").toURI());
+        PutMethod put1 = new PutMethod(endpointAddress);
+        RequestEntity entity1 = new FileRequestEntity(input1, "application/atom+xml; charset=ISO-8859-1");
+        put1.setRequestEntity(entity1);
+        HttpClient httpclient1 = new HttpClient();
+
+        try {
+            int result = httpclient1.executeMethod(put1);
+            assertEquals(200, result);
+        } finally {
+            // Release current connection to the connection pool once you are
+            // done
+            put1.releaseConnection();
+        }*/
+    }      
     
+    @Test
+    public void testGetMetaDataTypes() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/repository/metadatatypes"; 
+        GetMethod get = new GetMethod(endpointAddress);
+        get.setRequestHeader("Content-Type", "*/*");
+        //get.setRequestHeader("Accept", type);
+        HttpClient httpClient = new HttpClient();
+        try {
+            httpClient.executeMethod(get);           
+            //String response = getStringFromInputStream(get.getResponseBodyAsStream());
+			Document<Feed> doc = abdera.getParser().parse(
+					get.getResponseBodyAsStream());
+			Feed feed = doc.getRoot();
+
+			assertEquals("http://localhost:9080/repository/metadatatypes", feed
+					.getBaseUri().toString());
+			assertEquals("Metadata types", feed.getTitle());
+			List<Entry> entries = feed.getEntries();
+			assertEquals(entries.size(), 4);	
+			
+        } finally {
+            get.releaseConnection();
+        }
+    }
+    
+    @Test
+    public void testAddAndDeleteMetaDataTypes() throws Exception {       
+        //Add a new metadata type called ServiceCategory
+        String endpointAddress =
+            "http://localhost:9080/repository/metadatatypes"; 
+        PostMethod post = new PostMethod(endpointAddress);
+        File newMetaData = new File(getClass().getResource("resources/add_metadata_servicecategory.txt").toURI());
+        post.setRequestEntity(
+             new FileRequestEntity(newMetaData, "application/atom+xml"));
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(201, result);
+        } finally {
+            post.releaseConnection();
+        }       
+                
+        // Verify result
+        endpointAddress =
+            "http://localhost:9080/repository/metadatatypes"; 
+        GetMethod get = new GetMethod(endpointAddress);
+        get.setRequestHeader("Content-Type", "*/*");
+        //get.setRequestHeader("Accept", type);
+        HttpClient httpClient = new HttpClient();
+        try {
+            httpClient.executeMethod(get);           
+            //String response = getStringFromInputStream(get.getResponseBodyAsStream());
+			Document<Feed> doc = abdera.getParser().parse(
+					get.getResponseBodyAsStream());
+			Feed feed = doc.getRoot();
+
+			assertEquals("http://localhost:9080/repository/metadatatypes", feed
+					.getBaseUri().toString());
+			assertEquals("Metadata types", feed.getTitle());
+			List<Entry> entries = feed.getEntries();
+			assertEquals(entries.size(), 5);	
+			
+        } finally {
+            get.releaseConnection();
+        }		
+        
+        //Delete
+        endpointAddress =
+            "http://localhost:9080/repository/metadatatypes/serviceCategory"; 
+        DeleteMethod delete = new DeleteMethod(endpointAddress);
+        delete.setRequestHeader("Content-Type", "*/*");
+        httpClient = new HttpClient();
+        try {
+        	httpClient.executeMethod(delete);           
+        } finally {
+        	delete.releaseConnection();
+        }    
+        
+        // Verify it has been deleted
+        endpointAddress =
+            "http://localhost:9080/repository/metadatatypes"; 
+        get = new GetMethod(endpointAddress);
+        get.setRequestHeader("Content-Type", "*/*");
+        httpClient = new HttpClient();
+        try {
+            httpClient.executeMethod(get);           
+            //String response = getStringFromInputStream(get.getResponseBodyAsStream());
+			Document<Feed> doc = abdera.getParser().parse(
+					get.getResponseBodyAsStream());
+			Feed feed = doc.getRoot();
+			List<Entry> entries = feed.getEntries();
+			assertEquals(entries.size(), 4);				
+        } finally {
+            get.releaseConnection();
+        }	
+    } 
+    
     private String getStringFromInputStream(InputStream in) throws Exception {        
         CachedOutputStream bos = new CachedOutputStream();
         IOUtils.copy(in, bos);

Added: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/Quickstart_helloworld.esb
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/Quickstart_helloworld.esb
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/add_metadata_servicecategory.txt
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/add_metadata_servicecategory.txt	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/add_metadata_servicecategory.txt	2008-11-14 03:38:31 UTC (rev 23869)
@@ -0,0 +1 @@
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/metadatatypes/serviceCategory"><title type="text">serviceCategory</title><summary type="text">ESB service category</summary><content type="text">metadata_type_string</content></entry>
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java	2008-11-14 03:38:31 UTC (rev 23869)
@@ -0,0 +1,253 @@
+package org.drools.repository;
+
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+
+import junit.framework.TestCase;
+
+public class ArtifactManagerTest extends TestCase {
+
+    public void testCreateArtifact() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+        
+		Map<String, List<String>> metadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>() {{add("true");}});
+			put("format", new ArrayList<String>() {{add("drl");}});
+			put("multi-value-property", new ArrayList<String>() {{add("value1"); add("value2");}});
+		}};
+        	
+		
+		Artifact artifact = new Artifact();
+		artifact.setMetadata(metadata);
+		artifact.setName("testArtifact1");
+		artifact.setDescription("desc1");
+		artifact.setContent("the string content of testArtifact1");		
+        am.createArtifact(artifact);
+        
+        Artifact artifactResult = am.getArtifact("testArtifact1");
+        assertEquals("testArtifact1", artifactResult.getName());       
+        assertEquals("desc1", artifactResult.getDescription());    
+        assertEquals("the string content of testArtifact1", artifactResult.getContent());       
+        assertFalse(artifactResult.isBinary());       
+        assertNotNull(artifactResult.getLastModified());       
+       
+        Map<String, List<String>> result = artifactResult.getMetadata();
+        //assertEquals(3, result.size());       
+
+        List<String> archived = result.get("archived");
+        assertEquals("true", archived.get(0));       
+        
+        List<String> format = result.get("format");
+        assertEquals("drl", format.get(0));    
+        
+        List<String> multiValueProperty = result.get("multi-value-property");
+        assertEquals("value1", multiValueProperty.get(0));     
+        assertEquals("value2", multiValueProperty.get(1));   
+        
+        System.out.println(artifactResult.toString());
+    }    
+
+    public void testCreateArtifactWithBinaryContent() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+		
+		Artifact artifact = new Artifact();
+		artifact.setName("testArtifact1");
+		artifact.setSrcLink("/esbs/HelloWorld.esb");		
+        am.createArtifact(artifact);
+        
+        Artifact artifactResult = am.getArtifact("testArtifact1");
+        assertEquals("testArtifact1", artifactResult.getName());       
+        assertNull(artifactResult.getDescription());    
+        assertNull(artifactResult.getContent());       
+        assertEquals("/esbs/HelloWorld.esb", artifactResult.getSrcLink());  
+        assertTrue(artifactResult.isBinary());     
+        assertNotNull(artifactResult.getLastModified());       
+       
+        System.out.println(artifactResult.toString());
+    }
+    
+    public void testUpdateArtifact() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+        
+		Map<String, List<String>> metadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>() {{add("true");}});
+			put("format", new ArrayList<String>() {{add("drl");}});
+			put("multi-value-property", new ArrayList<String>() {{add("value1"); add("value2");}});
+		}};        	
+		
+		Artifact artifact = new Artifact();
+		artifact.setMetadata(metadata);
+		artifact.setName("testArtifact1");
+		artifact.setDescription("desc1");
+		artifact.setContent("the string content of testArtifact1");		
+        am.createArtifact(artifact);
+                
+        
+        //update
+		Map<String, List<String>> newMetadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>() {{add("false");}});
+			put("format", new ArrayList<String>() {{add("otherformat");}});
+			put("multi-value-property", new ArrayList<String>() {{add("value3"); add("value4");}});
+			put("new-multi-value-property", new ArrayList<String>() {{add("value1"); add("value2");}});
+			put("checkinComment", new ArrayList<String>() {{add("initial");}});
+		}};        	
+		
+		Artifact newArtifact = new Artifact();
+		//TODO: how to remove a meta-data?
+		newArtifact.setMetadata(newMetadata);
+		newArtifact.setName("testArtifact1");
+		newArtifact.setDescription("desc2");
+		newArtifact.setContent("new content");		
+        am.updateArtifact(newArtifact);
+        
+        //verify 
+        Artifact artifactResult = am.getArtifact("testArtifact1");
+        assertEquals("testArtifact1", artifactResult.getName());       
+        assertEquals("desc2", artifactResult.getDescription());    
+        assertEquals("new content", artifactResult.getContent());       
+        assertNotNull(artifactResult.getLastModified());       
+       
+        Map<String, List<String>> result = artifactResult.getMetadata();
+ 
+        List<String> archived = result.get("archived");
+        assertEquals("false", archived.get(0));       
+        
+        List<String> format = result.get("format");
+        assertEquals("otherformat", format.get(0));    
+        
+        List<String> multiValueProperty = result.get("multi-value-property");
+        assertEquals("value3", multiValueProperty.get(0));     
+        assertEquals("value4", multiValueProperty.get(1));   
+        
+        List<String> newMultiValueProperty = result.get("new-multi-value-property");
+        assertEquals("value1", newMultiValueProperty.get(0));     
+        assertEquals("value2", newMultiValueProperty.get(1));
+        
+        System.out.println(artifactResult.toString());        
+    }
+    
+    public void testMultiValuedEntry() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+        
+        //add a single entry value first
+		Map<String, List<String>> metadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>(1) {{add("true");}});
+		}};        	
+		
+		Artifact artifact = new Artifact();
+		artifact.setMetadata(metadata);
+		artifact.setName("testArtifact1");
+        am.createArtifact(artifact);                
+        
+        //update the single value entry with multi valued entry
+		Map<String, List<String>> newMetadata = new HashMap<String, List<String>>() {{
+			put("archived", new ArrayList<String>() {{add("value1"); add("value2");}});
+		}};        	
+		
+		Artifact newArtifact = new Artifact();
+		newArtifact.setMetadata(newMetadata);
+		newArtifact.setName("testArtifact1");
+		try {
+			am.updateArtifact(newArtifact);
+			fail("did not catch expected exception");
+		} catch (RulesRepositoryException e) {
+
+		}
+    }
+    
+    public void testUpdateArtifactWithBinaryContent() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+		
+		Artifact artifact = new Artifact();
+		artifact.setName("testArtifact1");
+        am.createArtifact(artifact);                
+        
+        //update
+		Map<String, List<String>> newMetadata = new HashMap<String, List<String>>() {{
+			put("serviceCategory", new ArrayList<String>() {{add("helloWorld");}});
+		}};        	
+		
+		Artifact newArtifact = new Artifact();
+		newArtifact.setMetadata(newMetadata);
+		newArtifact.setName("testArtifact1");
+		newArtifact.setDescription("desc2");
+		newArtifact.setSrcLink("/esbs/HelloWorld.esb");
+        am.updateArtifact(newArtifact);
+        
+        //verify 
+        Artifact artifactResult = am.getArtifact("testArtifact1");
+        assertEquals("testArtifact1", artifactResult.getName());       
+        assertEquals("desc2", artifactResult.getDescription());    
+        assertNull(artifactResult.getContent());       
+        assertEquals("/esbs/HelloWorld.esb", artifactResult.getSrcLink());  
+        assertTrue(artifactResult.isBinary());  ;       
+        assertNotNull(artifactResult.getLastModified());       
+       
+        Map<String, List<String>> result = artifactResult.getMetadata(); 
+        List<String> serviceCategory = result.get("serviceCategory");
+        assertEquals("helloWorld", serviceCategory.get(0));       
+        
+        System.out.println(artifactResult.toString());        
+    }
+    
+    public void testCreateAndUpdateESBJar() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+        
+        //create
+        InputStream is = getClass().getResourceAsStream("resources/Quickstart_helloworld.esb");
+        am.createEBSJar("Quickstart_helloworld.esb", is);
+        
+        Artifact artifactResult = am.getArtifact("Quickstart_helloworld.esb");
+        assertEquals("Quickstart_helloworld.esb", artifactResult.getName());       
+        assertNull(artifactResult.getDescription());    
+        assertNull(artifactResult.getContent());       
+        assertEquals("/repository/esbs/Quickstart_helloworld.esb", artifactResult.getSrcLink());  
+        assertTrue(artifactResult.isBinary());  ;       
+        assertNotNull(artifactResult.getLastModified());       
+		
+        //update
+		Artifact artifact = new Artifact();
+		artifact.setName("Quickstart_helloworld.esb");
+		artifact.setDescription("desc1");
+        am.updateArtifact(artifact);        
+        
+        //verify
+        Artifact artifactResultNew = am.getArtifact("Quickstart_helloworld.esb");
+        assertEquals("Quickstart_helloworld.esb", artifactResultNew.getName());       
+        assertEquals("desc1", artifactResultNew.getDescription());       
+        assertNull(artifactResultNew.getContent());       
+        assertEquals("/repository/esbs/Quickstart_helloworld.esb", artifactResultNew.getSrcLink());  
+        assertTrue(artifactResultNew.isBinary());  ;       
+        assertNotNull(artifactResultNew.getLastModified());      
+     
+        
+        System.out.println(artifactResult.toString());
+    } 
+    
+    public void testGetMetadataTypes() throws Exception {
+        RulesRepository repo = RepositorySessionUtil.getRepository();
+        ArtifactManager am = new ArtifactManager(repo);
+        
+		Map<String, MetaData> metadataTypes = am.getMetadataTypes();
+        assertEquals(ArtifactManager.METADATA_TYPE_STRING, metadataTypes.get("archived").getMetaDataType());
+        assertEquals("is archived or not", metadataTypes.get("archived").getDescription());
+        assertEquals(ArtifactManager.METADATA_TYPE_STRING, metadataTypes.get("format").getMetaDataType());
+        assertEquals(ArtifactManager.METADATA_TYPE_MULTI_VALUE_STRING, metadataTypes.get("multi-value-property").getMetaDataType());
+    }
+
+
+}

Added: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/resources/Quickstart_helloworld.esb
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/resources/Quickstart_helloworld.esb
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream




More information about the jboss-svn-commits mailing list