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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 21 10:58:35 EST 2008


Author: jervisliu
Date: 2008-11-21 10:58:35 -0500 (Fri, 21 Nov 2008)
New Revision: 24034

Added:
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/LifeCycle.java
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Phase.java
Modified:
   labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java
   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/AtomRulesRepositoryServer.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/expected_get_testPackage1.txt
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/update_testPackage1.txt
   labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java
Log:
AtomPub lifecycle 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-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/atom/AtomRulesRepository.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -27,6 +27,7 @@
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.ExtensibleElement;
 import org.apache.abdera.model.Feed;
@@ -44,85 +45,6 @@
 /**
  * AtomRulesRepository provides an AtomPub interface on top of RulesRepository. 
  * 
- * A HTTP GET request to URL http://host:portnumber/repository/packages
- * returns a list of packages in the repository in Atom feed format. An example looks like below:
- * 
- * <feed xml:base="http://localhost:9080/repository/packages">
- *   <title type="text">Packages</title>
- *   
- *   <entry xml:base="http://localhost:9080/repository/packages">
- *     <title type="text">defaultPackage</title>
- *     <link href="http://localhost:9080/repository/packages/defaultPackage"/>
- *   </entry>
- * 
- *   <entry xml:base="http://localhost:9080/repository/packages">
- *     <title type="text">testPackage1</title>
- *     <link href="http://localhost:9080/repository/packages/testPackage1"/>
- *   </entry>
- * </feed>
- *
- *
- * You can navigate from packages to a specific package using the URL link returned.
- * A HTTP GET request to URL http://host:portnumber/repository/packages/testPackage1 
- * returns testPackag1 in the repository in Atom entry format. An example looks like below:
- * 
- * <entry xml:base="http://localhost:9080/repository/packages/testPackage1">
- *   <title type="text">testPackage1</title>
- *   <id>5632cf6c-0ef5-4ccc-b7e5-293285c4ce19</id>
- *   <link href="http://localhost:9080/repository/packages/testPackage1"/>
- *   <summary type="text">desc1</summary>
- *   <updated>2008-10-17T08:12:42.046Z</updated>
- *   <content type="text">archived=false</content>
- * </entry>    
- * 
- * A HTTP POST request to URL http://host:portnumber/repository/packages with the data:
- * 
- * <entry xml:base="http://localhost:9080/repository/packages">
- *   <title type="text">testPackage1</title>
- * </entry>   
- * 
- * creates a package named testPackage1 in the repository
- *  
- *  
- * A HTTP PUT request to URL http://host:portnumber/repository/packages with the data:
- * 
- * <entry xml:base="http://localhost:9080/repository/packages">
- *   <title type="text">testPackage1</title>
- *   <summary type="text">desc2</summary>
- *   <content type="text">archived=false</content>
- * </entry>     
- * 
- * updates testPackage1 in the repository
-
- * A HTTP DELETE request to URL http://host:portnumber/repository/packages/testPackage1  
- * deletes the package testPackage1
- * 
- * 
- * A HTTP GET request to URL http://host:portnumber/repository/packages/testPackage1/assets
- * returns a list of assets under the testPackage1 in the repository in Atom feed format. 
- * An example looks like below:
- * 
- * <feed xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/packages/testPackage1/assets">
- *   <title type="text">Packages</title>
- *   
- *   <entry xml:base="http://localhost:9080/repository/packages/testPackage1/assets">
- *     <title type="text">testAsset1</title>
- *     <link href="http://localhost:9080/repository/packages/packageName/asset/testAsset1" />
- *   </entry>
- *   
- *   <entry xml:base="http://localhost:9080/repository/packages/testPackage1/assets">
- *     <title type="text">testAsset2</title>
- *     <link href="http://localhost:9080/repository/packages/packageName/asset/testAsset2" />
- *   </entry>
- * </feed>
- * 
- * NOTE: The mapping between Atom Entry element and Drools PackageItem is as below:
- * 
- * atom:title   - PackageItem.name
- * atom:id      - PackageItem.UUID
- * atom:updated - PackageItem.lastModified 
- * atom:summary - PackageItem.description
- * 
  * @author Jervis Lliu
  */
 
@@ -323,7 +245,7 @@
     @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());
+        System.out.println("----invoking addArtifactAsEntry with artifact name: " + e.getTitle());
 
         try {
         	String artifactName = e.getTitle();
@@ -332,6 +254,7 @@
         	Artifact artifact = new Artifact();
         	artifact.setName(artifactName);
         	artifact.setDescription(e.getSummary());
+        	artifact.setContent(e.getContent());
         	artifactManager.createArtifact(artifact);
             
             URI uri = 
@@ -382,7 +305,7 @@
     @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());
+        System.out.println("----invoking updatePackageAsEntry artifact name is: " + e.getTitle());
         try {      	
            	ArtifactManager artifactManager = new ArtifactManager(repository);
 
@@ -396,6 +319,68 @@
 				artifact.setContent(e.getContent());
 			}
            	artifact.setLastModified(Calendar.getInstance());
+           	
+           	Map<String, Object> metadata = new HashMap<String, Object>();
+            String NS = "http://overlord.jboss.org/drools/1.0";
+            QName METADATA = new QName(NS, "metadata");
+            QName PROPERTY = new QName(NS, "property");
+            QName LIFECYCLE = new QName(NS, "lifecycle");
+            
+            ExtensibleElement metadataExtension = e.getExtension(METADATA);
+            if(metadataExtension != null) {
+            	List<Element> a1 = metadataExtension.getExtensions();
+               	List<Element> a2 = metadataExtension.getElements();
+               	Element child = metadataExtension.getFirstChild();
+               	while(child != null) {
+                	QName name = child.getQName();
+                	if(name.equals(PROPERTY)) {
+                		List<Element> propertyValues = child.getElements();
+            			String key = child.getAttributeValue("name");
+                		if(propertyValues.size() == 1) {
+                			String value = propertyValues.get(0).getText();
+                			metadata.put(key, value);
+                		} else if (propertyValues.size() > 1) {
+                			String[] value = new String[propertyValues.size()];
+                			int i = 0;
+                			for(Element valueElement : propertyValues) {
+                    			value[i] = valueElement.getText();
+                    			i++;                    			          				
+                			}
+                			metadata.put(key, value); 
+                		}            		
+                	} else if (name.equals(LIFECYCLE)) {
+            			String lifeCycleName = child.getAttributeValue("name");
+            			String phase = child.getAttributeValue("phase");
+            			metadata.put(lifeCycleName, phase);     
+                	}
+                	child = child.getNextSibling();
+               	}
+              	
+/*                           	
+            for(Element child : metadataExtension.getExtensions()) {
+            	QName name = child.getQName();
+            	if(name.equals(PROPERTY)) {
+            		List<Element> propertyValues = child.getElements();
+        			String key = child.getAttributeValue("name");
+            		if(propertyValues.size() == 1) {
+            			String value = propertyValues.get(0).getText();
+            			metadata.put(key, value);
+            		} else if (propertyValues.size() > 1) {
+            			for(Element valueElement : propertyValues) {
+                			String value = valueElement.getText();
+                			metadata.put(key, value);           				
+            			}
+            		}            		
+            	} else if (name.equals(LIFECYCLE)) {
+        			String lifeCycleName = child.getAttributeValue("name");
+        			String phase = child.getAttributeValue("phase");
+        			metadata.put(lifeCycleName, phase);     
+            	}
+            }*/
+            }
+            
+            artifact.setMetadata(metadata);
+    		
         	artifactManager.updateArtifact(artifact);
   		
             URI uri = 
@@ -463,7 +448,7 @@
 
         try {
         	MetaData md = new MetaData();
-        	md.setMetaDataName(e.getTitle());
+        	md.setName(e.getTitle());
         	md.setMetaDataType(e.getContent());
         	md.setDescription(e.getSummary());
         	
@@ -624,7 +609,7 @@
     
     private static Entry createDetailedArtifactEntry(Artifact artifact, Map<String, MetaData>metadataTypes, UriInfo baseUri) {
     	String artifactName = artifact.getName();
-    	Map<String, List<String>> metadata = artifact.getMetadata();
+    	Map<String, Object> metadata = artifact.getMetadata();
     	
         Factory factory = Abdera.getNewFactory();
         
@@ -640,18 +625,15 @@
         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");
+        QName LIFECYCLE = new QName(NS, "lifecycle");
         
         for (String key : metadata.keySet()) {
         	String metadataType = null;
@@ -660,25 +642,31 @@
         	}
         	
         	if(ArtifactManager.METADATA_TYPE_STRING.equals(metadataType)) {
-            	List<String> value = metadata.get(key);
+            	String value = (String)metadata.get(key);
                 ExtensibleElement childExtension = extension.addExtension(PROPERTY);
                 childExtension.setAttributeValue("name", key);
-                childExtension.addSimpleExtension(VALUE, value.get(0));
+                childExtension.addSimpleExtension(VALUE, value);
                 //childExtension.setText(value.get(0));
 			} else if (ArtifactManager.METADATA_TYPE_MULTI_VALUE_STRING.equals(metadataType)) {
-				List<String> values = metadata.get(key);
+				String[] values = (String[])metadata.get(key);
 				ExtensibleElement childExtension = extension
 						.addExtension(PROPERTY);
 				childExtension.setAttributeValue("name", key);
 				for(String value : values) {
 	                childExtension.addSimpleExtension(VALUE, value);					
 				}
+			} else if (ArtifactManager.METADATA_TYPE_LIFE_CYCLE.equals(metadataType)) {
+				String value = (String)metadata.get(key);
+				ExtensibleElement childExtension = extension
+						.addExtension(LIFECYCLE);
+				childExtension.setAttributeValue("name", key);
+				childExtension.setAttributeValue("phase", value);
 			} else {
 				//Default to string
-            	List<String> value = metadata.get(key);
+				String value = metadata.get(key).toString();
                 ExtensibleElement childExtension = extension.addExtension(PROPERTY);
                 childExtension.setAttributeValue("name", key);
-                childExtension.setText(value.get(0));		
+                childExtension.setText(value);		
 			}
          }
          
@@ -702,11 +690,11 @@
         if (baseUri != null) {
             e.setBaseUri(baseUri.getAbsolutePath().toString());
         }
-        e.setTitle(md.getMetaDataName());
+        e.setTitle(md.geName());
         e.setSummary(md.getDescription());
         e.setContent(md.getMetaDataType());
         URI uri = 
-        	baseUri.getBaseUriBuilder().path("repository").path("metadatatypes").path(md.getMetaDataName()
+        	baseUri.getBaseUriBuilder().path("repository").path("metadatatypes").path(md.geName()
         		).build();
         e.addLink(uri.toString());
 

Modified: 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	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Artifact.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -2,23 +2,19 @@
 
 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;
+	private String name;
+	private String description;
+	private Map<String, Object> metadata;	
+	private String content;	
+	private boolean isBinary;
+	private InputStream binaryContent;
+	private Calendar lastModified;
+	private String srcLink;
 	
 	public String getName() {
 		return name;
@@ -55,10 +51,10 @@
 	public void setDescription(String description) {
 		this.description = description;
 	}
-	public Map<String, List<String>> getMetadata() {
+	public Map<String, Object> getMetadata() {
 		return metadata;
 	}
-	public void setMetadata(Map<String, List<String>> metadata) {
+	public void setMetadata(Map<String, Object> metadata) {
 		this.metadata = metadata;
 	}
 	public boolean isBinary() {
@@ -83,12 +79,12 @@
 
             returnString.append( "Meta data: " );
             
-            Map<String, List<String>> metadata = this.getMetadata();            
+            Map<String, Object> metadata = this.getMetadata();            
 
-	    	for (Iterator<Map.Entry<String, List<String>>> iterator = metadata.entrySet().iterator(); iterator.hasNext();) {
-	    		Map.Entry<String, List<String>> en = iterator.next();
+	    	for (Iterator<Map.Entry<String, Object>> iterator = metadata.entrySet().iterator(); iterator.hasNext();) {
+	    		Map.Entry<String, Object> en = iterator.next();
 				String key = en.getKey();
-				List<String> value = en.getValue();
+				Object value = en.getValue();
 				returnString.append(key + ": " + value + "\n" );
 			}
 

Modified: 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	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/ArtifactManager.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -7,14 +7,12 @@
 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;
 
@@ -28,30 +26,72 @@
     
     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 static final String METADATA_TYPE_LIFE_CYCLE = "metadata_type_life_cycle";
+   
     public ArtifactManager(RulesRepository repo) {
         this.repository = repo;
         
+        //below are meta data types we supported out-of-box
         MetaData md = new MetaData();
-        md.setMetaDataName("archived");
+        md.setName("archived");
         md.setMetaDataType(METADATA_TYPE_STRING);
         md.setDescription("is archived or not");        
         createMetadataType(md);
         
         md = new MetaData();
-        md.setMetaDataName("format");
+        md.setName("format");
         md.setMetaDataType(METADATA_TYPE_STRING);
-        createMetadataType(md);
+        createMetadataType(md);  
         
         md = new MetaData();
-        md.setMetaDataName("description");
-        md.setMetaDataType(METADATA_TYPE_STRING);
-        createMetadataType(md);        
+        md.setName("multi-value-property");
+        md.setMetaDataType(METADATA_TYPE_MULTI_VALUE_STRING);
+        createMetadataType(md);
         
         md = new MetaData();
-        md.setMetaDataName("multi-value-property");
-        md.setMetaDataType(METADATA_TYPE_MULTI_VALUE_STRING);
+        md.setName("DefaultLifeCycle");
+        md.setMetaDataType(METADATA_TYPE_LIFE_CYCLE);
         createMetadataType(md);
+        
+        //below is the default lifecycle we provide out-of-box
+		LifeCycle lc = new LifeCycle();
+		lc.setDescription("This is the default LifeCycle");
+		lc.setName("DefaultLifeCycle");
+
+		Phase phase = new Phase();
+		phase.setName("created");
+		phase.setDescription("The initial phase");
+		phase.setInitialPhase(true);
+		phase.setNextPhase("developed");
+		lc.addPhase(phase);
+
+		phase = new Phase();
+		phase.setName("developed");
+		phase.setDescription("Developed phase");
+		phase.setInitialPhase(false);
+		phase.setNextPhase("tested");
+		lc.addPhase(phase);
+		
+		phase = new Phase();
+		phase.setName("tested");
+		phase.setDescription("Tested phase");
+		phase.setInitialPhase(false);
+		phase.setNextPhase("production");
+		lc.addPhase(phase);
+		
+		phase = new Phase();
+		phase.setName("production");
+		phase.setDescription("Production phase");
+		phase.setInitialPhase(false);
+		phase.setNextPhase("retired");
+		lc.addPhase(phase);
+		
+		phase = new Phase();
+		phase.setName("retired");
+		phase.setDescription("Retired phase");
+		lc.addPhase(phase);
+
+		createLifeCycle(lc);
     }
 
     /**
@@ -61,7 +101,7 @@
      */
     public void createArtifact(Artifact artifact) {
     	try {
-    		//TODO: should allow creating an artifact if it exists already
+    		//TODO: should not 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");
@@ -80,21 +120,40 @@
             Calendar lastModified = Calendar.getInstance();
             artifactNode.setProperty(AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
             
-            Map<String, List<String>> metadata = artifact.getMetadata();
+            Map<String, Object> metadata = artifact.getMetadata();
+            Map<String, MetaData> metadataTypes = getMetadataTypes();
 
-            if (artifact.getMetadata() != null) {
-				for (Iterator<Map.Entry<String, List<String>>> iterator = metadata
+            if (metadata != null) {
+				for (Iterator<Map.Entry<String, Object>> iterator = metadata
 						.entrySet().iterator(); iterator.hasNext();) {
-					Map.Entry<String, List<String>> en = iterator.next();
+					Map.Entry<String, Object> 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));
+					Object value = en.getValue();
+					MetaData md =  metadataTypes.get(key);
+					if (md != null) {
+						if (METADATA_TYPE_STRING.equals(md.getMetaDataType())) {
+							if(!(value instanceof String)) {
+								throw new RulesRepositoryException("Incompatible types. Expect String for " + key);
+							}
+							String targetValue = (String)value;
+							artifactNode.setProperty(key, targetValue);
+
+						} else if (METADATA_TYPE_MULTI_VALUE_STRING.equals(md.getMetaDataType())) {
+							if(!(value instanceof String[])) {
+								throw new RulesRepositoryException("Incompatible types. Expect String[] for " + key);
+							}
+							String[] targetValue = (String[]) value;
+							artifactNode.setProperty(key, targetValue);
+						} else if (METADATA_TYPE_LIFE_CYCLE.equals(md.getMetaDataType())) {
+							if(!(value instanceof String)) {
+								throw new RulesRepositoryException("Incompatible types. Expect String for " + key);
+							}
+							String phaseName = (String)value;
+							artifactNode.setProperty(key, phaseName);
+						}
 					} else {
-						artifactNode.setProperty(key, targets.toArray(new String[targets.size()]));
+						// default to string for unknown meta data types
+						artifactNode.setProperty(key, value.toString());
 					}
 				}
 			}
@@ -144,21 +203,39 @@
             Calendar lastModified = Calendar.getInstance();
             artifactNode.setProperty(AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
             
-            Map<String, List<String>> metadata = artifact.getMetadata();
+            Map<String, Object> metadata = artifact.getMetadata();
+            Map<String, MetaData> metadataTypes = getMetadataTypes();
 
             if (metadata != null) {
-				for (Iterator<Map.Entry<String, List<String>>> iterator = metadata
+				for (Iterator<Map.Entry<String, Object>> iterator = metadata
 						.entrySet().iterator(); iterator.hasNext();) {
-					Map.Entry<String, List<String>> en = iterator.next();
+					Map.Entry<String, Object> 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));
+					Object value = en.getValue();
+					MetaData md =  metadataTypes.get(key);
+					if (md != null) {
+						if (METADATA_TYPE_STRING.equals(md.getMetaDataType())) {
+							if(!(value instanceof String)) {
+								throw new RulesRepositoryException("Incompatible types. Expect String for " + key);
+							}
+							String targetValue = (String)value;
+							artifactNode.setProperty(key, targetValue);
+						} else if (METADATA_TYPE_MULTI_VALUE_STRING.equals(md.getMetaDataType())) {
+							if(!(value instanceof String[])) {
+								throw new RulesRepositoryException("Incompatible types. Expect String[] for " + key);
+							}
+							String[] targetValue = (String[]) value;
+							artifactNode.setProperty(key, targetValue);
+						} else if (METADATA_TYPE_LIFE_CYCLE.equals(md.getMetaDataType())) {
+							if(!(value instanceof String)) {
+								throw new RulesRepositoryException("Incompatible types. Expect String for " + key);
+							}
+							String phaseName = (String)value;
+							artifactNode.setProperty(key, phaseName);
+						}
 					} else {
-						artifactNode.setProperty(key, targets.toArray(new String[targets.size()]));
+						// default to string for unknown meta data types
+						artifactNode.setProperty(key, value.toString());
 					}
 				}
 			}
@@ -180,10 +257,10 @@
 	    	this.repository.save();
     	} catch (RepositoryException e) {
             if ( e instanceof ItemExistsException ) {
-                throw new RulesRepositoryException( "An artifact of that name already exists in that package.",
-                                                    e );
+                throw new RulesRepositoryException("An artifact of that name already exists in that package.",
+                                                    e);
             } else {
-                throw new RulesRepositoryException( e );
+                throw new RulesRepositoryException(e);
             }
     	}
     }
@@ -195,10 +272,11 @@
 	    	}
 	    	
     		Artifact artifact = new Artifact();
-	    	Map<String, List<String>> metadata = new HashMap<String, List<String>>(10);
+	    	Map<String, Object> metadata = new HashMap<String, Object>(10);
 	    	
-	    	Node permsNode = getArtifactNode(artifactName).getNode("jcr:content");
-	    	PropertyIterator it = permsNode.getProperties();
+	    	Node node = getArtifactNode(artifactName).getNode("jcr:content");
+	    	PropertyIterator it = node.getProperties();
+	        Map<String, MetaData> metadataTypes = getMetadataTypes();
 
 	    	while (it.hasNext()) {
 	    		Property p = (Property) it.next();
@@ -206,46 +284,51 @@
 	    		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());
+	    			} else if (metadataTypes.get(name) != null) {
+						if (METADATA_TYPE_STRING.equals(metadataTypes.get(name).getMetaDataType())) {
+							metadata.put(name, p.getValue().getString());
+						} else if (METADATA_TYPE_MULTI_VALUE_STRING.equals(metadataTypes.get(name)
+										.getMetaDataType())) {
+							Value[] vs = p.getValues();
+							String[] values = new String[vs.length];
+							for (int i = 0; i < vs.length; i++) {
+								values[i] = vs[i].getString();
+							}
+							metadata.put(name, values);
+						} else if (METADATA_TYPE_LIFE_CYCLE.equals(metadataTypes.get(name)
+										.getMetaDataType())) {			
+							metadata.put(name, p.getValue().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);
-	    			}
+					} else {
+						// other properties are treated as meta data
+						if (p.getDefinition().isMultiple()) {
+							Value[] vs = p.getValues();
+							String[] values = new String[vs.length];
+							for (int i = 0; i < vs.length; i++) {
+								values[i] = vs[i].getString();
+							}
+							metadata.put(name, values);
+						} else {
+							metadata.put(name, p.getValue().getString());
+						}
+					}
 	    		}
 	    	}
 	    	artifact.setMetadata(metadata);
 	    	if(artifact.getName() == null) {
 	    		artifact.setName(artifactName);
-	    	}
+	    	}	    	
 	    	
-	    	
 	    	return artifact;
     	} catch (RepositoryException e) {
     		throw new RulesRepositoryException(e);
@@ -314,9 +397,9 @@
      */
     public void createMetadataType(MetaData metaData) {
     	try {
-	    	Node metadataTypeNode = getMetaDataTypeNode(metaData.getMetaDataName());
+	    	Node metadataTypeNode = getMetaDataTypeNode(metaData.geName());
 	    	metadataTypeNode.remove(); //remove this so we get a fresh set
-	    	metadataTypeNode = getMetaDataTypeNode(metaData.getMetaDataName()).addNode("jcr:content", "nt:unstructured");
+	    	metadataTypeNode = getMetaDataTypeNode(metaData.geName()).addNode("jcr:content", "nt:unstructured");
 	    	
 	    	metadataTypeNode.setProperty("metadata_type", metaData.getMetaDataType()); 	
 	    	
@@ -342,7 +425,7 @@
          	while (nodes.hasNext()) {
          		MetaData md = new MetaData();         		
         		Node node = nodes.nextNode();
-        		md.setMetaDataName(node.getName());
+        		md.setName(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);
@@ -366,6 +449,85 @@
  		}
     }
     
+    public void createLifeCycle(LifeCycle lifeCycle) {
+    	try {
+	    	Node lifeCycleNode = getLifeCycleNode(lifeCycle.getName());
+	    	lifeCycleNode.remove(); //remove this so we get a fresh set
+	    	lifeCycleNode = getLifeCycleNode(lifeCycle.getName());
+/*	    	Node lifeCycleContentNode = lifeCycleNode.addNode("jcr:content", "nt:unstructured");
+			// JCR wont create a property if its value is null
+			//REVISIT: Set Phase.description default to "" instead?
+			if (lifeCycle.getDescription() != null) {
+				lifeCycleContentNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+						lifeCycle.getDescription());
+			} else {
+				lifeCycleContentNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+						"");
+			}*/
+			
+	    	for (Phase phase : lifeCycle.getPhases()) {
+				Node phaseNode = lifeCycleNode.addNode(phase.getName(),
+						"nt:file");
+				phaseNode = phaseNode.addNode("jcr:content", "nt:unstructured");
+				// JCR wont create a property if its value is null
+				if (phase.getDescription() != null) {
+					phaseNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+							phase.getDescription());
+				} else {
+					phaseNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
+							"");
+				}
+				phaseNode.setProperty("isInitialPhase", phase.isInitialPhase());
+				if (phase.getNextPhase() != null) {
+					phaseNode.setProperty("nextPhase", phase.getNextPhase());		
+				} 				
+			}
+
+	    	this.repository.save();
+    	} catch (RepositoryException e) {
+			throw new RulesRepositoryException(e);
+		}   	
+    }
+    
+    public Map<String, LifeCycle>  getLifeCycles() {
+       	Map<String, LifeCycle> lifeCycleList = new HashMap<String, LifeCycle>();
+
+ 		try{
+    		Node root = this.repository.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME);
+        	NodeIterator lifeCycleNodes = getNode(root, "life_cycles", "nt:folder").getNodes();
+         	while (lifeCycleNodes.hasNext()) {
+         		LifeCycle lc = new LifeCycle();         		
+        		Node lifeCycleNode = lifeCycleNodes.nextNode();
+        		lc.setName(lifeCycleNode.getName());
+        		//lc.setDescription(lifeCycleNode.getNode("jcr:content").getProperty(AssetItem.DESCRIPTION_PROPERTY_NAME).getString());
+        		
+            	NodeIterator phaseNodes = lifeCycleNode.getNodes();      		
+             	while (phaseNodes.hasNext()) {
+            		Node phaseNode = phaseNodes.nextNode();
+            		if(phaseNode.getName().equals("jcr:content")) {
+            			continue;
+            		}
+            		
+             		Phase phase = new Phase();         		
+            		phase.setName(phaseNode.getName());
+            		phase.setDescription(phaseNode.getNode("jcr:content").getProperty(AssetItem.DESCRIPTION_PROPERTY_NAME).getString());
+               		phase.setInitialPhase(phaseNode.getNode("jcr:content").getProperty("isInitialPhase").getBoolean());
+               		if (phaseNode.getNode("jcr:content").hasProperty("nextPhase")) {
+						phase.setNextPhase(phaseNode.getNode("jcr:content")
+								.getProperty("nextPhase").getString());
+					}
+              		lc.addPhase(phase);
+            	}  	
+             	lifeCycleList.put(lc.getName(), lc);
+          	}
+
+ 		} catch (RepositoryException e) {
+ 			throw new RulesRepositoryException(e);
+ 		}
+ 		
+    	return lifeCycleList;	
+    }
+    
 	private Node getArtifactNode(String artifactName)
 			throws RepositoryException {
 		Node root = this.repository.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME);
@@ -388,9 +550,20 @@
 				esbJarName, "nt:file");
 		return node;
 	}	
+	
+	private Node getLifeCycleNode(String lifeCycleName)
+			throws RepositoryException {
+		Node root = this.repository.getSession().getRootNode().getNode(
+				RulesRepository.RULES_REPOSITORY_NAME);
+		Node node = getNode(getNode(root, "life_cycles", "nt:folder"),
+				lifeCycleName, "nt:folder");
+		return node;
+	}
+	
     /**
      * Gets or creates a node.
      */
+	//REVIST: do not do adding new node 
 	private Node getNode(Node node, String name, String nodeType) throws RepositoryException {
 		Node resultNode;
 		if (!node.hasNode(name)) {

Added: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/LifeCycle.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/LifeCycle.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/LifeCycle.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -0,0 +1,39 @@
+package org.drools.repository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LifeCycle {   
+	private String name;
+	private String description;
+	private List<Phase> phases = new ArrayList<Phase>();	
+	
+	public String getName() {
+		return name;
+	}	
+	
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public List<Phase> getPhases() {
+		return phases;
+	}
+
+	public void setPhases(List<Phase> phases) {
+		this.phases = phases;
+	}
+	
+	public void addPhase(Phase phase) {
+		phases.add(phase);
+	}
+	
+}

Modified: 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	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/MetaData.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -1,30 +1,21 @@
 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;
+	private String name;
+	private String metaDataType;
+	private String description;
+	
 	public String getDescription() {
 		return description;
 	}
 	public void setDescription(String description) {
 		this.description = description;
 	}
-	public String getMetaDataName() {
-		return metaDataName;
+	public String geName() {
+		return name;
 	}
-	public void setMetaDataName(String metaDataName) {
-		this.metaDataName = metaDataName;
+	public void setName(String name) {
+		this.name = name;
 	}
 	public String getMetaDataType() {
 		return metaDataType;

Added: labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Phase.java
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Phase.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-atom/src/main/java/org/drools/repository/Phase.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -0,0 +1,41 @@
+package org.drools.repository;
+
+public class Phase {   
+	private String name;
+	private String description;
+	private boolean isInitialPhase;
+	private String nextPhase;
+	
+	public boolean isInitialPhase() {
+		return isInitialPhase;
+	}
+
+	public void setInitialPhase(boolean isInitialPhase) {
+		this.isInitialPhase = isInitialPhase;
+	}
+
+	public String getNextPhase() {
+		return nextPhase;
+	}
+
+	public void setNextPhase(String nextPhase) {
+		this.nextPhase = nextPhase;
+	}
+
+	public String getName() {
+		return name;
+	}	
+	
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+	
+}

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-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/AtomRulesRepositoryServer.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -40,10 +40,12 @@
 
         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");}});
+		Map<String, Object> metadata = new HashMap<String, Object>() {{
+			put("archived", "true");
+			put("format", "drl");
+			put("multi-value-property", new String[]{"value1", "value2"});
+			put("DefaultLifeCycle", "production");
+
 		}};
 		artifact.setMetadata(metadata);
 		artifact.setName("testArtifact1");

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-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/ClientServerAtomRulesRepositoryTest.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -10,11 +10,14 @@
 import java.util.List;
 
 import javax.ws.rs.core.UriInfo;
+import javax.xml.namespace.QName;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
 import org.apache.abdera.model.Feed;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.DeleteMethod;
@@ -27,7 +30,9 @@
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+import org.drools.repository.ArtifactManager;
 import org.drools.repository.PackageItem;
+import org.drools.repository.Phase;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -257,6 +262,119 @@
     }  
     
     @Test
+    public void testAddAndUpdateArtifact() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/repository/artifacts"; 
+        
+    	
+        Factory factory = Abdera.getNewFactory();        
+        Entry entry = factory.getAbdera().newEntry();
+        entry.setTitle("testArtifact1");
+        entry.setContent("the content of testArtifact1 in String format");
+       
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestEntity(new StringRequestEntity(entry.toString(), "application/atom+xml", null));
+        HttpClient httpclient = new HttpClient();
+
+        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("testArtifact1", entry.getTitle());
+			assertEquals("the content of testArtifact1 in String format", entry.getContent());
+			assertEquals("TEXT", entry.getContentType().name());
+        } finally {
+            post.releaseConnection();
+        } 
+        
+    	//Update artifact testArtifact1
+        entry.setSummary("desc for testArtifact1");
+        String NS = "http://overlord.jboss.org/drools/1.0";
+        QName METADATA = new QName(NS, "metadata");
+        QName PROPERTY = new QName(NS, "property");
+        QName VALUE = new QName(NS, "value");
+        QName LIFECYCLE = new QName(NS, "lifecycle");
+        ExtensibleElement metadataExtension  = entry.getExtension(METADATA);
+        if(metadataExtension == null) {
+        	metadataExtension = entry.addExtension(METADATA);
+        }
+        ExtensibleElement childExtension = metadataExtension.addExtension(PROPERTY);
+
+        childExtension.setAttributeValue("name", "archived");
+        childExtension.addSimpleExtension(VALUE, "false");
+        
+		String[] values = new String[]{"value1", "value2"};
+		childExtension = metadataExtension.addExtension(PROPERTY);
+		childExtension.setAttributeValue("name", "multi-value-property");
+		for(String value : values) {
+            childExtension.addSimpleExtension(VALUE, value);					
+		}		
+        
+        childExtension = metadataExtension.addExtension(LIFECYCLE);
+		childExtension.setAttributeValue("name", "DefaultLifeCycle");
+		childExtension.setAttributeValue("phase", "created");
+		
+        String endpointAddress1 = "http://localhost:9080/repository/artifacts";
+        PutMethod put = new PutMethod(endpointAddress1);
+        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/testArtifact1";
+        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("testArtifact1", entry.getTitle());
+		assertEquals("the content of testArtifact1 in String format", entry.getContent());
+		assertEquals("TEXT", entry.getContentType().name());
+		assertEquals("desc for testArtifact1", entry.getSummary());
+
+        metadataExtension  = entry.getExtension(METADATA); 
+        ExtensibleElement lifeCycleExtension = metadataExtension.getExtension(LIFECYCLE);
+		assertEquals("DefaultLifeCycle", lifeCycleExtension.getAttributeValue("name"));       
+		assertEquals("created", lifeCycleExtension.getAttributeValue("phase")); 
+		
+        List<ExtensibleElement> propertyExtensions = metadataExtension.getExtensions(PROPERTY);
+		assertEquals(3, propertyExtensions.size());  		
+
+		int expectedExtensionFound = 0;
+		int totalPhasesFound = 0;
+		for (ExtensibleElement expectedExtension : propertyExtensions) {
+			totalPhasesFound++;
+			if (expectedExtension.getAttributeValue("name").equals("archived")) {
+				assertEquals("false", expectedExtension.getSimpleExtension(VALUE));
+				expectedExtensionFound++;
+			} else if (expectedExtension.getAttributeValue("name").equals("multi-value-property")) {
+				expectedExtensionFound++;
+			} 
+		}		
+
+		assertEquals(2, expectedExtensionFound);
+		assertEquals(3, totalPhasesFound);
+		//a Abdera bug?
+/*	       List<Element> propertyExtensions1 = metadataExtension.getExtensions();
+	       assertEquals(4, propertyExtensions1.size());  */
+    }  
+    
+    @Test
     public void testAddAndUpdateESBJar() throws Exception {
         String endpointAddress =
             "http://localhost:9080/repository/esbs"; 
@@ -287,6 +405,15 @@
         
     	//Update artifact Quickstart_helloworld.esb
         entry.setSummary("desc for esb");
+        String NS = "http://overlord.jboss.org/drools/1.0";
+        QName METADATA = new QName(NS, "metadata");
+        QName LIFECYCLE = new QName(NS, "lifecycle");
+        ExtensibleElement metadataExtension  = entry.getExtension(METADATA);
+
+        ExtensibleElement childExtension = metadataExtension.addExtension(LIFECYCLE);
+		childExtension.setAttributeValue("name", "DefaultLifeCycle");
+		childExtension.setAttributeValue("phase", "created");
+				
         String endpointAddress1 = "http://localhost:9080/repository/artifacts";
         PutMethod put = new PutMethod(endpointAddress1);
         System.out.println("***********" + entry.toString());
@@ -316,6 +443,11 @@
 		assertEquals("/repository/esbs/Quickstart_helloworld.esb", entry.getContentSrc().getPath());
 		assertEquals("MEDIA", entry.getContentType().name());
 		assertEquals("desc for esb", entry.getSummary());
+        metadataExtension  = entry.getExtension(METADATA); 
+        ExtensibleElement lifeCycleExtension = metadataExtension.getExtension(LIFECYCLE);
+		assertEquals("DefaultLifeCycle", lifeCycleExtension.getAttributeValue("name"));       
+		assertEquals("created", lifeCycleExtension.getAttributeValue("phase"));            
+        
 		
 		//Get back the binary content of ESB Jar
         String endpointAddress3 = "http://localhost:9080/repository/esbs/Quickstart_helloworld.esb";

Modified: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/expected_get_testPackage1.txt
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/expected_get_testPackage1.txt	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/expected_get_testPackage1.txt	2008-11-21 15:58:35 UTC (rev 24034)
@@ -1 +1 @@
-<entry xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/packages/testPackage1"><title type="text">testPackage1</title><summary type="text">desc1</summary><content type="text">archived=false</content></entry>
\ No newline at end of file
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/packages/testPackage1"><title type="text">testPackage1</title><summary type="text">desc1</summary><content type="text">the content of testPackage1</content></entry>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/update_testPackage1.txt
===================================================================
--- labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/update_testPackage1.txt	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/atom/resources/update_testPackage1.txt	2008-11-21 15:58:35 UTC (rev 24034)
@@ -1 +1 @@
-<entry xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/packages/testPackage1"><title type="text">testPackage1</title><summary type="text">desc2</summary><content type="text">archived=false</content></entry>
\ No newline at end of file
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:base="http://localhost:9080/repository/packages/testPackage1"><title type="text">testPackage1</title><summary type="text">desc2</summary><content type="text">the content of testPackage1</content></entry>
\ No newline at end of file

Modified: 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	2008-11-21 14:05:34 UTC (rev 24033)
+++ labs/jbossrules/trunk/drools-atom/src/test/java/org/drools/repository/ArtifactManagerTest.java	2008-11-21 15:58:35 UTC (rev 24034)
@@ -1,30 +1,30 @@
 package org.drools.repository;
 
-
 import java.io.File;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 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 {
+	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");}});
-		}};
-        	
+		Map<String, Object> metadata = new HashMap<String, Object>() {{
+			put("archived", "false");
+			put("format", "drl");
+			put("multi-value-property", new String[]{"value1","value2"});
+			put("DefaultLifeCycle", "created");
+
+		}};        	
 		
 		Artifact artifact = new Artifact();
 		artifact.setMetadata(metadata);
@@ -40,122 +40,138 @@
         assertFalse(artifactResult.isBinary());       
         assertNotNull(artifactResult.getLastModified());       
        
-        Map<String, List<String>> result = artifactResult.getMetadata();
-        //assertEquals(3, result.size());       
+        Map<String, Object> result = artifactResult.getMetadata();
+        // assertEquals(3, result.size());
 
-        List<String> archived = result.get("archived");
-        assertEquals("true", archived.get(0));       
+        String archived = (String)result.get("archived");
+        assertEquals("false", archived);       
         
-        List<String> format = result.get("format");
-        assertEquals("drl", format.get(0));    
+        String format = (String)result.get("format");
+        assertEquals("drl", format);    
         
-        List<String> multiValueProperty = result.get("multi-value-property");
-        assertEquals("value1", multiValueProperty.get(0));     
-        assertEquals("value2", multiValueProperty.get(1));   
+        String[] multiValueProperty = (String[])result.get("multi-value-property");
+        assertEquals("value1", multiValueProperty[0]);     
+        assertEquals("value2", multiValueProperty[1]);   
         
+        String lifeCycle = (String)result.get("DefaultLifeCycle");
+        assertEquals("created", lifeCycle);    
+        
         System.out.println(artifactResult.toString());
-    }    
+    }
 
-    public void testCreateArtifactWithBinaryContent() throws Exception {
-        RulesRepository repo = RepositorySessionUtil.getRepository();
-        ArtifactManager am = new ArtifactManager(repo);
-		
+	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.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);
         
-        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");}});
-		}};        	
-		
+		Map<String, Object> metadata = new HashMap<String, Object>() {{
+			put("archived", "false");
+			put("format", "drl");
+			put("multi-value-property",  new String[]{"value1","value2"});
+			put("DefaultLifeCycle", "created");
+
+		}};
+
 		Artifact artifact = new Artifact();
 		artifact.setMetadata(metadata);
 		artifact.setName("testArtifact1");
 		artifact.setDescription("desc1");
-		artifact.setContent("the string content of testArtifact1");		
-        am.createArtifact(artifact);
-                
+		artifact.setContent("the string content of testArtifact1");
+		am.createArtifact(artifact);
+
+		//Register a new metadata type named "new-multi-value-property".
+		MetaData md = new MetaData();
+        md.setName("new-multi-value-property");
+        md.setMetaDataType(ArtifactManager.METADATA_TYPE_MULTI_VALUE_STRING);
+        am.createMetadataType(md);
         
-        //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");}});
-		}};        	
-		
+		// update
+		Map<String, Object> newMetadata = new HashMap<String, Object>() {{
+			put("archived", "true");
+			put("format", "otherformat");
+			put("multi-value-property",  new String[]{"value3","value4"});
+			put("new-multi-value-property",  new String[]{"value1","value2"});
+			put("DefaultLifeCycle", "developed");
+			put("checkinComment", "move to developed phase");
+		}};
+
+
 		Artifact newArtifact = new Artifact();
-		//TODO: how to remove a meta-data?
+		// 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");}});
-		}};        	
+		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, Object> result = artifactResult.getMetadata();
+
+		String archived = (String)result.get("archived");
+		assertEquals("true",archived);
+
+		String format = (String)result.get("format");
+		assertEquals("otherformat", format);
+
+		String[] multiValueProperty = (String[])result.get("multi-value-property");
+		assertEquals("value3", multiValueProperty[0]);
+		assertEquals("value4", multiValueProperty[1]);
+
+		String[] newMultiValueProperty = (String[])result
+				.get("new-multi-value-property");
+		assertEquals("value1", newMultiValueProperty[0]);
+		assertEquals("value2", newMultiValueProperty[1]);
+
+		String lifeCycle = (String)result.get("DefaultLifeCycle");
+		assertEquals("developed", lifeCycle);
 		
+		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, Object> metadata = new HashMap<String, Object>() {{
+			put("archived", "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");}});
-		}};        	
-		
+		am.createArtifact(artifact);
+
+		// update the single value entry with multi valued entry
+		Map<String, Object> newMetadata = new HashMap<String, Object>() {{
+			put("archived", new String[]{"value1", "value2"});
+		}};
+
 		Artifact newArtifact = new Artifact();
 		newArtifact.setMetadata(newMetadata);
 		newArtifact.setName("testArtifact1");
@@ -165,89 +181,160 @@
 		} catch (RulesRepositoryException e) {
 
 		}
-    }
-    
-    public void testUpdateArtifactWithBinaryContent() throws Exception {
-        RulesRepository repo = RepositorySessionUtil.getRepository();
-        ArtifactManager am = new ArtifactManager(repo);
-		
+	}
+
+	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");}});
-		}};        	
-		
+		am.createArtifact(artifact);
+
+		// update
+		Map<String, Object> newMetadata = new HashMap<String, Object>() {{
+			put("serviceCategory", "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
+		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, Object> result = artifactResult.getMetadata();
+		String serviceCategory = (String)result.get("serviceCategory");
+		assertEquals("helloWorld", serviceCategory);
+
+		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);
-        
+		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());
-    }
+		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());
+	}
 
+	public void testCreateLifeCycle() throws Exception {
+		RulesRepository repo = RepositorySessionUtil.getRepository();
+		ArtifactManager am = new ArtifactManager(repo);
 
+		LifeCycle lc = new LifeCycle();
+		lc.setDescription("This is my LifeCycle");
+		lc.setName("MyLifeCycle");
+
+		Phase phase = new Phase();
+		phase.setName("phase1");
+		phase.setDescription("This is the initial phase");
+		phase.setInitialPhase(true);
+		phase.setNextPhase("phase2");
+		lc.addPhase(phase);
+
+		phase = new Phase();
+		phase.setName("phase2");
+		phase.setDescription("This is the phase2");
+		phase.setInitialPhase(false);
+		phase.setNextPhase("phase3");
+		lc.addPhase(phase);
+
+		phase = new Phase();
+		phase.setName("phase3");
+		phase.setInitialPhase(false);
+		lc.addPhase(phase);
+
+		am.createLifeCycle(lc);
+
+		Map<String, LifeCycle> expectedlifeCycles = am.getLifeCycles();
+		assertEquals(2, expectedlifeCycles.size());
+
+		List<Phase> phases = expectedlifeCycles.get("MyLifeCycle").getPhases();
+		assertEquals(3, phases.size());
+
+		int expectedPhasesFound = 0;
+		int totalPhasesFound = 0;
+		for (Phase expectedPhase : phases) {
+			totalPhasesFound++;
+			if (expectedPhase.getName().equals("phase1")) {
+				assertEquals("This is the initial phase", expectedPhase
+						.getDescription());
+				assertEquals(true, expectedPhase.isInitialPhase());
+				assertEquals("phase2", expectedPhase.getNextPhase());
+				expectedPhasesFound++;
+			} else if (expectedPhase.getName().equals("phase2")) {
+				assertEquals("This is the phase2", expectedPhase
+						.getDescription());
+				assertEquals(false, expectedPhase.isInitialPhase());
+				assertEquals("phase3", expectedPhase.getNextPhase());
+				expectedPhasesFound++;
+			} else if (expectedPhase.getName().equals("phase3")) {
+				assertEquals("", expectedPhase.getDescription());
+				assertEquals(false, expectedPhase.isInitialPhase());
+				assertEquals(null, expectedPhase.getNextPhase());
+				expectedPhasesFound++;
+			}
+		}
+
+		assertEquals(3, expectedPhasesFound);
+		assertEquals(3, totalPhasesFound);
+	}
 }




More information about the jboss-svn-commits mailing list