]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-725 - More refactoring of common client work.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 14 Jan 2010 01:52:24 +0000 (01:52 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 14 Jan 2010 01:52:24 +0000 (01:52 +0000)
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java
services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java
services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java

index 246917e43b732142472004a13b4fa67108fc7e5e..dd21227b5c500450428009cc41d880a3f1ddc4fc 100644 (file)
@@ -1,13 +1,18 @@
 package org.collectionspace.services.client;\r
 \r
+import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
 import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
 \r
 import org.collectionspace.services.OrganizationJAXBSchema;\r
+import org.collectionspace.services.client.test.ServiceRequestType;\r
 import org.collectionspace.services.organization.OrganizationsCommon;\r
 import org.collectionspace.services.organization.OrgauthoritiesCommon;\r
+import org.jboss.resteasy.client.ClientResponse;\r
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
 import org.slf4j.Logger;\r
@@ -71,4 +76,49 @@ public class OrgAuthorityClientUtils {
         return multipart;\r
     }\r
 \r
+    /**\r
+     * Returns an error message indicating that the status code returned by a\r
+     * specific call to a service does not fall within a set of valid status\r
+     * codes for that service.\r
+     *\r
+     * @param serviceRequestType  A type of service request (e.g. CREATE, DELETE).\r
+     *\r
+     * @param statusCode  The invalid status code that was returned in the response,\r
+     *                    from submitting that type of request to the service.\r
+     *\r
+     * @return An error message.\r
+     */\r
+    public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
+        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
+                requestType.validStatusCodesAsString();\r
+    }\r
+\r
+    public static String extractId(ClientResponse<Response> res) {\r
+        MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+        String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
+        if(logger.isDebugEnabled()){\r
+               logger.info("extractId:uri=" + uri);\r
+        }\r
+        String[] segments = uri.split("/");\r
+        String id = segments[segments.length - 1];\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("id=" + id);\r
+        }\r
+        return id;\r
+    }\r
+    \r
+    public static String createRefName(String displayName) {\r
+       return displayName.replaceAll("\\W", "");\r
+    }\r
+\r
+    public static String createOrgAuthRefName(String orgAuthorityName) {\r
+       return "urn:cspace:org.collectionspace.demo:orgauthority:name("\r
+                       +orgAuthorityName+")";\r
+    }\r
+\r
+    public static String createOrganizationRefName(\r
+                                               String orgAuthRefName, String orgName) {\r
+       return orgAuthRefName+":organization:name("+orgName+")";\r
+    }\r
+\r
 }\r
index 0d05865d87c36f8155715a3b900169131c17ee42..c7c6883bf129882e9630cedd8c5c78fe4276dbaf 100644 (file)
@@ -69,7 +69,7 @@ public class OrgAuthorityBaseImport {
        if(logger.isDebugEnabled()){
                logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\"");
        }
-       String baseOrgAuthRefName = createOrgAuthRefName(orgAuthorityName);
+       String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName);
        String fullOrgAuthRefName = baseOrgAuthRefName+"'"+orgAuthorityName+"'";
        MultipartOutput multipart = 
                OrgAuthorityClientUtils.createOrgAuthorityInstance(
@@ -81,7 +81,7 @@ public class OrgAuthorityBaseImport {
 
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
                throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName
-                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                               +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
        }
        if(statusCode != EXPECTED_STATUS_CODE) {
                throw new RuntimeException("Unexpected Status when creating enumeration: \""
@@ -90,7 +90,7 @@ public class OrgAuthorityBaseImport {
 
        // Store the ID returned from this create operation
        // for additional tests below.
-       String newOrgAuthorityId = extractId(res);
+       String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res);
        if(logger.isDebugEnabled()){
                logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:"
                                +newOrgAuthorityId );
@@ -108,7 +108,7 @@ public class OrgAuthorityBaseImport {
        // Type of service request being tested
        ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
        String shortName = orgInfo.get(OrganizationJAXBSchema.SHORT_NAME);
-       String refName = createOrganizationRefName(
+       String refName = OrgAuthorityClientUtils.createOrganizationRefName(
                                                orgAuthorityRefName, shortName)+"'"+shortName+"'";
 
        if(logger.isDebugEnabled()){
@@ -125,61 +125,20 @@ public class OrgAuthorityBaseImport {
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
                throw new RuntimeException("Could not create Item: \""+shortName
                                +"\" in orgAuthority: \"" + orgAuthorityRefName
-                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                               +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
        }
        if(statusCode != EXPECTED_STATUS_CODE) {
                throw new RuntimeException("Unexpected Status when creating Item: \""+shortName
                                +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);
        }
 
-       return extractId(res);
+       return OrgAuthorityClientUtils.extractId(res);
     }
 
     // ---------------------------------------------------------------
     // Utility methods used by methods above
     // ---------------------------------------------------------------
 
-    /**
-     * Returns an error message indicating that the status code returned by a
-     * specific call to a service does not fall within a set of valid status
-     * codes for that service.
-     *
-     * @param serviceRequestType  A type of service request (e.g. CREATE, DELETE).
-     *
-     * @param statusCode  The invalid status code that was returned in the response,
-     *                    from submitting that type of request to the service.
-     *
-     * @return An error message.
-     */
-    protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
-        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
-                requestType.validStatusCodesAsString();
-    }
-
-    protected String extractId(ClientResponse<Response> res) {
-        MultivaluedMap<String, Object> mvm = res.getMetadata();
-        String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);
-        if(logger.isDebugEnabled()){
-               logger.debug("extractId:uri=" + uri);
-        }
-        String[] segments = uri.split("/");
-        String id = segments[segments.length - 1];
-        if(logger.isDebugEnabled()){
-               logger.debug("id=" + id);
-        }
-        return id;
-    }
-    
-    protected String createOrgAuthRefName(String orgAuthorityName) {
-       return "urn:cspace:org.collectionspace.demo:orgauthority:name("
-                       +orgAuthorityName+")";
-    }
-
-    protected String createOrganizationRefName(
-                                               String orgAuthRefName, String orgName) {
-       return orgAuthRefName+":organization:name("+orgName+")";
-    }
-
        public static void main(String[] args) {
                
                BasicConfigurator.configure();
index f4b6db598c4b283ecb206bd717b00b5f2a52cf0e..91602d8c7922c297887c70eb855970653799b8d2 100644 (file)
@@ -102,7 +102,7 @@ public class Sample {
 \r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not create enumeration: \""+orgAuthName\r
-                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                               +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when creating enumeration: \""\r
@@ -111,7 +111,7 @@ public class Sample {
 \r
        // Store the ID returned from this create operation\r
        // for additional tests below.\r
-       String newOrgAuthId = extractId(res);\r
+       String newOrgAuthId = OrgAuthorityClientUtils.extractId(res);\r
         logger.info("Import: Created orgAuthority: \"" + orgAuthName +"\" ID:"\r
                                +newOrgAuthId );\r
         \r
@@ -146,7 +146,7 @@ public class Sample {
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not create Item: \""+shortName\r
                                +"\" in orgAuthority: \"" + orgAuthorityRefName\r
-                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                               +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when creating Item: \""+shortName\r
@@ -154,7 +154,7 @@ public class Sample {
                                "\", Status:"+ statusCode);\r
        }\r
 \r
-       return extractId(res);\r
+       return OrgAuthorityClientUtils.extractId(res);\r
     }\r
 \r
 \r
@@ -176,7 +176,7 @@ public class Sample {
         int statusCode = res.getStatus();\r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not read list of orgAuthorities: "\r
-                + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when reading " +\r
@@ -211,7 +211,7 @@ public class Sample {
             int statusCode = res.getStatus();\r
             if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                 throw new RuntimeException("Could not read orgAuthority"\r
-                    + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                    + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
             }\r
             if(statusCode != EXPECTED_STATUS_CODE) {\r
                 throw new RuntimeException("Unexpected Status when reading " +\r
@@ -243,7 +243,7 @@ public class Sample {
 \r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not read items in orgAuthority: "\r
-                + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when reading " +\r
@@ -279,7 +279,7 @@ public class Sample {
 \r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not delete orgAuthority: "\r
-                + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when deleting " +\r
@@ -305,7 +305,7 @@ public class Sample {
 \r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
                throw new RuntimeException("Could not delete orgAuthority item: "\r
-                + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+                + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
                throw new RuntimeException("Unexpected Status when deleting " +\r
@@ -394,41 +394,6 @@ public class Sample {
         return obj;\r
     }\r
 \r
-    /**\r
-     * Returns an error message indicating that the status code returned by a\r
-     * specific call to a service does not fall within a set of valid status\r
-     * codes for that service.\r
-     *\r
-     * @param serviceRequestType  A type of service request (e.g. CREATE, DELETE).\r
-     *\r
-     * @param statusCode  The invalid status code that was returned in the response,\r
-     *                    from submitting that type of request to the service.\r
-     *\r
-     * @return An error message.\r
-     */\r
-    protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
-        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
-                requestType.validStatusCodesAsString();\r
-    }\r
-\r
-    protected String extractId(ClientResponse<Response> res) {\r
-        MultivaluedMap<String, Object> mvm = res.getMetadata();\r
-        String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
-        if(logger.isDebugEnabled()){\r
-               logger.info("extractId:uri=" + uri);\r
-        }\r
-        String[] segments = uri.split("/");\r
-        String id = segments[segments.length - 1];\r
-        if(logger.isDebugEnabled()){\r
-               logger.debug("id=" + id);\r
-        }\r
-        return id;\r
-    }\r
-    \r
-    protected String createRefName(String displayName) {\r
-       return displayName.replaceAll("\\W", "");\r
-    }\r
-\r
        public static void main(String[] args) {\r
 \r
         // Configure logging.\r