From 7d9294076b80f5e1915bd9d78d87c302abf03e94 Mon Sep 17 00:00:00 2001
From: Suma Shivaprasad <sshivaprasad@sshivaprasad-rMBP.local>
Date: Thu, 7 May 2015 14:05:06 +0530
Subject: [PATCH] Fixed all issues in ITs

---
 client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java                | 34 +++++++++++++++++++---------------
 webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java          | 27 ++++++++++-----------------
 webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java | 12 +++++++-----
 webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java  |  2 +-
 4 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java b/client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
index b2e8dbb..230a4e8 100755
--- a/client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
+++ b/client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
@@ -53,30 +53,34 @@ public class MetadataServiceClient {
     }
 
     private static final String BASE_URI = "api/metadata/";
+    private static final String URI_TYPES = "types";
+    private static final String URI_ENTITIES = "entities";
+    private static final String URI_TRAITS = "traits";
+    private static final String URI_SEARCH = "discovery/search";
 
     static enum API {
         //Type operations
-        CREATE_TYPE(BASE_URI + "types", HttpMethod.POST),
-        GET_TYPE(BASE_URI + "types", HttpMethod.GET),
-        LIST_TYPES(BASE_URI + "types", HttpMethod.GET),
-        LIST_TRAIT_TYPES(BASE_URI + "types?type=trait", HttpMethod.GET),
+        CREATE_TYPE(BASE_URI + URI_TYPES, HttpMethod.POST),
+        GET_TYPE(BASE_URI + URI_TYPES, HttpMethod.GET),
+        LIST_TYPES(BASE_URI + URI_TYPES, HttpMethod.GET),
+        LIST_TRAIT_TYPES(BASE_URI + URI_TYPES + "?type=trait", HttpMethod.GET),
 
         //Entity operations
-        CREATE_ENTITY(BASE_URI + "entities", HttpMethod.POST),
-        GET_ENTITY(BASE_URI + "entities", HttpMethod.GET),
-        UPDATE_ENTITY(BASE_URI + "entities", HttpMethod.PUT),
-        LIST_ENTITY(BASE_URI + "entities", HttpMethod.GET),
+        CREATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.POST),
+        GET_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
+        UPDATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.PUT),
+        LIST_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
 
         //Trait operations
-        ADD_TRAITS(BASE_URI + "traits", HttpMethod.POST),
-        DELETE_TRAITS(BASE_URI + "traits", HttpMethod.DELETE),
-        LIST_TRAITS(BASE_URI + "traits", HttpMethod.GET),
+        ADD_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.POST),
+        DELETE_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.DELETE),
+        LIST_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.GET),
 
         //Search operations
-        SEARCH(BASE_URI + "discovery/search", HttpMethod.GET),
-        SEARCH_DSL(BASE_URI + "discovery/search/dsl", HttpMethod.GET),
-        SEARCH_GREMLIN(BASE_URI + "discovery/search/gremlin", HttpMethod.GET),
-        SEARCH_FULL_TEXT(BASE_URI + "discovery/search/fulltext", HttpMethod.GET);
+        SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET),
+        SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET),
+        SEARCH_GREMLIN(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET),
+        SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET);
 
         private final String method;
         private final String path;
diff --git a/webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java
index 9310c0e..d4c968d 100755
--- a/webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java
+++ b/webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java
@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
 import org.apache.hadoop.metadata.MetadataException;
 import org.apache.hadoop.metadata.MetadataServiceClient;
 import org.apache.hadoop.metadata.services.MetadataService;
+import org.apache.hadoop.metadata.typesystem.types.DataTypes;
 import org.apache.hadoop.metadata.web.util.Servlets;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
@@ -55,9 +56,6 @@ public class TypesResource {
     private final MetadataService metadataService;
 
     static final String TYPE_ALL = "all";
-    static final String TYPE_TRAIT = "trait";
-    static final String TYPE_CLASS = "class";
-    static final String TYPE_STRUCT = "struct";
 
     @Inject
     public TypesResource(MetadataService metadataService) {
@@ -129,20 +127,11 @@ public class TypesResource {
                                   @DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
         try {
             List<String> result = null;
-            switch(type) {
-                case TYPE_ALL :
-                    result = metadataService.getTypeNamesList();
-                    break;
-                case TYPE_TRAIT :
-                    result = metadataService.getTraitNamesList();
-                    break;
-                case TYPE_STRUCT :
-                case TYPE_CLASS :
-                    //TODO for ÇLASS, STRUCT
-                default:
-                    LOG.error("Unsupported typeName while retrieving type list {}", type);
-                    throw new WebApplicationException(
-                        Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST));
+            if (TYPE_ALL.equals(type)) {
+                result = metadataService.getTypeNamesList();
+            } else {
+                DataTypes.TypeCategory typeCategory = DataTypes.TypeCategory.valueOf(type);
+                result = metadataService.getTypeNamesByCategory(typeCategory);
             }
 
             JSONObject response = new JSONObject();
@@ -151,6 +140,10 @@ public class TypesResource {
             response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
 
             return Response.ok(response).build();
+        } catch(IllegalArgumentException ie) {
+            LOG.error("Unsupported typeName while retrieving type list {}", type);
+            throw new WebApplicationException(
+                    Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST));
         } catch (Exception e) {
             LOG.error("Unable to get types list", e);
             throw new WebApplicationException(
diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
index da8e66a..f917be3 100755
--- a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
@@ -66,6 +66,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
     private static final String DATABASE_NAME = "foo";
     private static final String TABLE_TYPE = "hive_table_type";
     private static final String TABLE_NAME = "bar";
+    private static final String TRAITS = "traits";
+    private static final String TRAIT = "trait";
 
     private Referenceable tableInstance;
     private Id tableId;
@@ -270,7 +272,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         ClientResponse clientResponse = service
                 .path("api/metadata/entities")
                 .path(guid)
-                .path(EntityResource.TRAITS)
+                .path(TRAITS)
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
                 .method(HttpMethod.GET, ClientResponse.class);
@@ -304,7 +306,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         ClientResponse clientResponse = service
                 .path("api/metadata/entities")
                 .path(guid)
-                .path(EntityResource.TRAITS)
+                .path(TRAITS)
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
                 .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
@@ -334,7 +336,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         ClientResponse clientResponse = service
                 .path("api/metadata/entities")
                 .path("random")
-                .path(EntityResource.TRAITS)
+                .path(TRAITS)
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
                 .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
@@ -350,7 +352,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         ClientResponse clientResponse = service
                 .path("api/metadata/entities")
                 .path(guid)
-                .path(EntityResource.TRAIT)
+                .path(TRAIT)
                 .path(traitName)
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
@@ -373,7 +375,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         ClientResponse clientResponse = service
                 .path("api/metadata/entities")
                 .path("random")
-                .path(EntityResource.TRAIT)
+                .path(TRAIT)
                 .path(traitName)
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
index 38f679b..8d82568 100755
--- a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
                 .path("api/metadata/types");
 
         ClientResponse clientResponse = resource
-                .queryParam("type", TypesResource.TYPE_TRAIT)
+                .queryParam("type", DataTypes.TypeCategory.TRAIT.name())
                 .accept(MediaType.APPLICATION_JSON)
                 .type(MediaType.APPLICATION_JSON)
                 .method(HttpMethod.GET, ClientResponse.class);
--
libgit2 0.27.1