ws-scout-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ks...@apache.org
Subject svn commit: r592154 - in /webservices/scout/trunk/scout/src: main/java/org/apache/ws/scout/util/EnumerationHelper.java main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java
Date Mon, 05 Nov 2007 21:16:43 GMT
Author: kstam
Date: Mon Nov  5 13:16:40 2007
New Revision: 592154

URL: http://svn.apache.org/viewvc?rev=592154&view=rev
Log:
SCOUT-53, adding code to create associations.

Modified:
    webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/EnumerationHelper.java
    webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
    webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java

Modified: webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/EnumerationHelper.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/EnumerationHelper.java?rev=592154&r1=592153&r2=592154&view=diff
==============================================================================
--- webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/EnumerationHelper.java
(original)
+++ webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/EnumerationHelper.java
Mon Nov  5 13:16:40 2007
@@ -16,78 +16,124 @@
  */
 package org.apache.ws.scout.util;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.StringTokenizer;
 
 import javax.xml.registry.JAXRException;
 import javax.xml.registry.infomodel.ClassificationScheme;
 import javax.xml.registry.infomodel.Concept;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
 import org.apache.ws.scout.registry.infomodel.ConceptImpl;
 import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
+import org.apache.ws.scout.registry.infomodel.KeyImpl;
 
 /**
  * Helper class that deals with predefined enumerations
  *
  * @author Anil Saldhana  <anil@apache.org>
+ * @author Kurt Stam <kstam@apache.org>
+ * 
  */
 public class EnumerationHelper
 {
+    private static Log log = LogFactory.getLog(EnumerationHelper.class);
+    
+    private final static String OBJECT_TYPE                   = "ObjectType";
+    private final static String ASSOCIATION_TYPE              = "AssociationType";
+    private final static String URL_TYPE                      = "URLType";
+    private final static String PHONE_TYPE                    = "PhoneType";
+    private final static String POSTAL_ADDRESS_ATTRIBUTES_STR = "PostalAddressAttributes";
+    private final static String[] TYPES = {OBJECT_TYPE, ASSOCIATION_TYPE, URL_TYPE, PHONE_TYPE,
POSTAL_ADDRESS_ATTRIBUTES_STR};
+    
+    private final static String[] OBJECT_TYPES = {
+         "ExternalLink","Package","ExternalId","Association","Classification","Concept",
+         "AuditableEvent","User","Organization","CPA","CPP","Service","ServiceBinding","Process","WSDL",
+         "ExtrinsicObj","Organization","User"};
+    private final static String[] ASSOCIATION_TYPES = {
+         "RelatedTo","ExternallyLinks","Contains","Extends","Implements",
+         "InstanceOf","Supersedes","Uses","HasMember","EquivalentTo","HasChild","HasParent","Replaces",
+         "ResponsibleFor","SubmitterOf"};
+    private final static String[] URL_TYPES = {
+         "HTTP","HTTPS","SMTP","FAX","PHONE","OTHER"};
+    private final static String[] PHONE_TYPES = {
+         "Office","Home","Mobile","Beeper","FAX"};
+    private final static String[] POSTAL_ADDRESS_ATTRIBUTES = {
+         "StreetNumber","Street","City","State","PostalCode","Country"};
+    
+    private final static ArrayList<String> TYPES_LIST                     = new ArrayList<String>(Arrays.asList(TYPES));
+    private final static ArrayList<String> OBJECT_TYPES_LIST              = new ArrayList<String>(Arrays.asList(OBJECT_TYPES));
+    private final static ArrayList<String> ASSOCIATION_TYPES_LIST         = new ArrayList<String>(Arrays.asList(ASSOCIATION_TYPES));
+    private final static ArrayList<String> URL_TYPES_LIST                 = new ArrayList<String>(Arrays.asList(URL_TYPES));
+    private final static ArrayList<String> PHONE_TYPES_LIST               = new ArrayList<String>(Arrays.asList(PHONE_TYPES));
+    private final static ArrayList<String> POSTAL_ADDRESS_ATTRIBUTES_LIST = new ArrayList<String>(Arrays.asList(POSTAL_ADDRESS_ATTRIBUTES));
+
+    private static Map<String,ArrayList<String>> typesMap = new HashMap<String,ArrayList<String>>();
+    static {
+        typesMap.put(OBJECT_TYPE                  ,OBJECT_TYPES_LIST);
+        typesMap.put(ASSOCIATION_TYPE             ,ASSOCIATION_TYPES_LIST);
+        typesMap.put(URL_TYPE                     , URL_TYPES_LIST);
+        typesMap.put(PHONE_TYPE                   , PHONE_TYPES_LIST);
+        typesMap.put(POSTAL_ADDRESS_ATTRIBUTES_STR, POSTAL_ADDRESS_ATTRIBUTES_LIST);
+    }
+    
     public static Concept getConceptByPath( String path)
     throws IllegalArgumentException, JAXRException
     {
         //Lets tokenize the path
         StringTokenizer tokenizer = new StringTokenizer(path,"/");
-        //Deal with the first token
-        String firstToken = "";
+        String firstToken = null;
+        String secondToken = null;
+        
         if(tokenizer.hasMoreTokens())
         {
            firstToken = tokenizer.nextToken();
-           if(!checkFirstToken( firstToken))
-               throw new IllegalArgumentException("Wrong Path");;
+           if (tokenizer.hasMoreTokens()) {
+               secondToken = tokenizer.nextToken();
+               if (tokenizer.hasMoreTokens()) {
+                   log.warn("Looking for 2 tokens. " + tokenizer.nextToken() + " will be
ignored");
+               }
+           } else {
+               throw new IllegalArgumentException("Expected two token separated with a forward
slash (/)");
+           }
+        } else {
+            throw new IllegalArgumentException("Expected two token separated with a forward
slash (/)");
         }
-
-        String secondToken = tokenizer.nextToken();
-        //TODO:Check whether the second token is also valid
         return createConcept(firstToken, secondToken) ;
-
-    }
-
-
-    private static boolean checkFirstToken(String token)
-    throws IllegalArgumentException
-    {
-        if(token == null )
-            throw new IllegalArgumentException();
-        if(token.equalsIgnoreCase("AssociationType"))  return true;
-        if(token.equalsIgnoreCase("URLType"))  return true;
-        if(token.equalsIgnoreCase("PhoneType"))  return true;
-        if(token.equalsIgnoreCase("PostalAddressAttributes"))  return true;
-        if(token.equalsIgnoreCase("ObjectType"))  return true;
-        return false;
     }
 
     /**
-     *
+     * 
      * @param firstToken
      * @param secondToken
-     * @return
+     * @return Concept
      * @throws JAXRException
      */
     private static  Concept createConcept(String firstToken, String secondToken)
-            throws JAXRException
+            throws JAXRException, IllegalArgumentException
     {
-        /**
-         * This is a hack!!!  Need to figure out how to do this!
-         */
+        if (!TYPES_LIST.contains(firstToken)) throw new IllegalArgumentException("Exspected
the path to " +
+                "start with one of " + TYPES);
+        
+        //get the predefined classificationscheme
         ClassificationScheme cs = new ClassificationSchemeImpl(null);
         cs.setName(new InternationalStringImpl(firstToken));
+        cs.setKey(new KeyImpl(firstToken));
 
+        ArrayList<String> conceptStrings = typesMap.get(firstToken);
+        if (!conceptStrings.contains(secondToken)) throw new IllegalArgumentException("Exspected
the path to " +
+                "end with one of " + conceptStrings.toArray());
+                
         Concept concept = new ConceptImpl(null);
         concept.setName(new InternationalStringImpl(secondToken.toLowerCase()));
         concept.setValue(secondToken);
+        concept.setKey(new KeyImpl(firstToken + "/" + secondToken));
         ((ConceptImpl)concept).setScheme(((ClassificationSchemeImpl)cs));
         return concept;
-
     }
 }

Modified: webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java?rev=592154&r1=592153&r2=592154&view=diff
==============================================================================
--- webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
(original)
+++ webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
Mon Nov  5 13:16:40 2007
@@ -269,7 +269,7 @@
 				// TODO: This setting to "" should not be needed at all.
 				// However, a bug in jUDDI needs it to be there. See:
 				// http://issues.apache.org/jira/browse/JUDDI-78
-				kr.setTModelKey("");
+				//kr.setTModelKey("");
 			} else {
                 kr.setTModelKey(key.getId());
 			}

Modified: webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java?rev=592154&r1=592153&r2=592154&view=diff
==============================================================================
--- webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java
(original)
+++ webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR030AssociationsTest.java
Mon Nov  5 13:16:40 2007
@@ -17,6 +17,7 @@
 package org.apache.ws.scout.registry.qa;
 
 import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -61,7 +62,7 @@
 
 	private BusinessQueryManager bqm = null;
 
-	String associationType = "/AssociationType/RelatedTo";
+	String associationType = "AssociationType/RelatedTo";
 	private static String tempSrcOrgName = "Apache Source Org -- APACHE SCOUT TEST";
 	private static String tempTgtOrgName = "Apache Target Org -- APACHE SCOUT TEST";
 
@@ -173,10 +174,12 @@
 
 		if (associations == null) {
 			System.out.println("\n-- Matched 0 orgs");
+            fail("Expected 1 association");
 
 		} else {
 			System.out.println("\n-- Matched " + associations.size()
 					+ " associations --\n");
+            assertEquals(1,associations.size());
 
 			// then step through them
 			for (Iterator conceptIter = associations.iterator(); conceptIter
@@ -206,6 +209,7 @@
 		keys.add(key);
 		BulkResponse response = blm.deleteAssociations(keys);
 
+        assertEquals(BulkResponse.STATUS_SUCCESS, response.getStatus());
 		Collection exceptions = response.getExceptions();
 		if (exceptions == null) {
 			Collection retKeys = response.getCollection();



---------------------------------------------------------------------
To unsubscribe, e-mail: scout-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: scout-dev-help@ws.apache.org


Mime
View raw message