Repository: atlas
Updated Branches:
  refs/heads/master 9f0866c8a -> 8535e88cd


ATLAS-2351: fixed V1 REST APIs to retain the format for date type attributes as 
in earlier versions


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/8535e88c
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/8535e88c
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/8535e88c

Branch: refs/heads/master
Commit: 8535e88cd538c8b5ee2e7dbf803358654391d25d
Parents: 9f0866c
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Wed Jan 10 12:40:24 2018 -0800
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Wed Jan 10 17:00:34 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/atlas/AtlasBaseClient.java  |  8 +-
 .../java/org/apache/atlas/utils/AtlasJson.java  | 54 ++++++-----
 .../atlas/web/resources/AdminResource.java      | 18 ++--
 .../atlas/web/resources/EntityResource.java     | 99 +++++++++++---------
 .../atlas/web/resources/TypesResource.java      | 43 ++++-----
 5 files changed, 119 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/8535e88c/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java 
b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
index 05b6cc6..f2327df 100644
--- a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -348,9 +348,7 @@ public abstract class AtlasBaseClient {
 
             clientResponse = requestBuilder.method(api.getMethod(), 
ClientResponse.class, requestObject);
 
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("API {} returned status {}", resource.getURI(), 
clientResponse.getStatus());
-            }
+            LOG.info("HTTP Status  : {}", clientResponse.getStatus());
 
             if (clientResponse.getStatus() == 
api.getExpectedStatus().getStatusCode()) {
                 if (responseType == null) {
@@ -361,7 +359,7 @@ public abstract class AtlasBaseClient {
                         String stringEntity = 
clientResponse.getEntity(String.class);
                         try {
                             JsonNode jsonObject = 
AtlasJson.parseToV1JsonNode(stringEntity);
-                            LOG.debug("Response = {}", jsonObject);
+                            LOG.info("Response     : {}", jsonObject);
                             
LOG.info("------------------------------------------------------");
                             return (T) jsonObject;
                         } catch (IOException e) {
@@ -369,7 +367,7 @@ public abstract class AtlasBaseClient {
                         }
                     } else {
                         T entity = clientResponse.getEntity(responseType);
-                        LOG.debug("Response = {}", entity);
+                        LOG.info("Response     : {}", entity);
                         
LOG.info("------------------------------------------------------");
                         return entity;
                     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/8535e88c/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java 
b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
index 84234d9..d4db756 100644
--- a/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
+++ b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
@@ -97,14 +97,18 @@ public class AtlasJson {
     }
 
     public static <T> T fromJson(String jsonStr, Class<T> type) {
-        T ret;
-        try {
-            ret =  mapper.readValue(jsonStr, type);
-        }catch (IOException e){
-            LOG.error("AtlasType.fromJson()", e);
+        T ret = null;
 
-            ret = null;
+        if (jsonStr != null) {
+            try {
+                ret = mapper.readValue(jsonStr, type);
+            } catch (IOException e) {
+                LOG.error("AtlasType.fromJson()", e);
+
+                ret = null;
+            }
         }
+
         return ret;
     }
 
@@ -121,30 +125,38 @@ public class AtlasJson {
     }
 
     public static <T> T fromV1Json(String jsonStr, Class<T> type) {
-        T ret;
-        try {
-            ret =  mapperV1.readValue(jsonStr, type);
+        T ret = null;
 
-            if (ret instanceof Struct) {
-                ((Struct) ret).normalize();
-            }
-        }catch (IOException e){
-            LOG.error("AtlasType.fromV1Json()", e);
+        if (jsonStr != null) {
+            try {
+                ret = mapperV1.readValue(jsonStr, type);
 
-            ret = null;
+                if (ret instanceof Struct) {
+                    ((Struct) ret).normalize();
+                }
+            } catch (IOException e) {
+                LOG.error("AtlasType.fromV1Json()", e);
+
+                ret = null;
+            }
         }
+
         return ret;
     }
 
     public static <T> T fromV1Json(String jsonStr, TypeReference<T> type) {
-        T ret;
-        try {
-            ret =  mapperV1.readValue(jsonStr, type);
-        }catch (IOException e){
-            LOG.error("AtlasType.toV1Json()", e);
+        T ret = null;
 
-            ret = null;
+        if (jsonStr != null) {
+            try {
+                ret = mapperV1.readValue(jsonStr, type);
+            } catch (IOException e) {
+                LOG.error("AtlasType.toV1Json()", e);
+
+                ret = null;
+            }
         }
+
         return ret;
     }
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/8535e88c/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java 
b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
index c21dff4..914c5ed 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
@@ -18,7 +18,6 @@
 
 package org.apache.atlas.web.resources;
 
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.sun.jersey.multipart.FormDataParam;
 import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasClient;
@@ -75,7 +74,10 @@ import javax.ws.rs.core.Response;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -186,7 +188,7 @@ public class AdminResource {
             try {
                 PropertiesConfiguration configProperties = new 
PropertiesConfiguration("atlas-buildinfo.properties");
 
-                ObjectNode response = AtlasJson.createV1ObjectNode();
+                Map<String, Object> response = new HashMap<String, Object>();
                 response.put("Version", 
configProperties.getString("build.version", "UNKNOWN"));
                 response.put("Name", 
configProperties.getString("project.name", "apache-atlas"));
                 response.put("Description", 
configProperties.getString("project.description",
@@ -194,7 +196,7 @@ public class AdminResource {
 
                 // todo: add hadoop version?
                 // response.put("Hadoop", VersionInfo.getVersion() + "-r" + 
VersionInfo.getRevision());
-                version = Response.ok(response).build();
+                version = Response.ok(AtlasJson.toV1Json(response)).build();
             } catch (ConfigurationException e) {
                 throw new WebApplicationException(Servlets.getErrorResponse(e, 
Response.Status.INTERNAL_SERVER_ERROR));
             }
@@ -215,8 +217,8 @@ public class AdminResource {
             LOG.debug("==> AdminResource.getStatus()");
         }
 
-        ObjectNode responseData = 
AtlasJson.createV1ObjectNode(AtlasClient.STATUS, 
serviceState.getState().toString());
-        Response   response     = Response.ok(responseData).build();
+        Map<String, Object> responseData = 
Collections.singletonMap(AtlasClient.STATUS, 
serviceState.getState().toString());
+        Response            response     = 
Response.ok(AtlasJson.toV1Json(responseData)).build();
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== AdminResource.getStatus()");
@@ -253,7 +255,7 @@ public class AdminResource {
                     AtlasActionTypes.CREATE, userName, groups, 
httpServletRequest);
         }
 
-        ObjectNode responseData = AtlasJson.createV1ObjectNode();
+        Map<String, Object> responseData = new HashMap<>();
 
         responseData.put(isCSRF_ENABLED, 
AtlasCSRFPreventionFilter.isCSRF_ENABLED);
         responseData.put(BROWSER_USER_AGENT_PARAM, 
AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT);
@@ -263,9 +265,9 @@ public class AdminResource {
         responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
         responseData.put(editableEntityTypes, 
getEditableEntityTypes(atlasProperties));
         responseData.put("userName", userName);
-        responseData.put("groups", AtlasJson.createV1ArrayNode(groups));
+        responseData.put("groups", groups);
 
-        response = Response.ok(responseData).build();
+        response = Response.ok(AtlasJson.toV1Json(responseData)).build();
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== AdminResource.getUserProfile()");

http://git-wip-us.apache.org/repos/asf/atlas/blob/8535e88c/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java 
b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
index fb59e04..b062093 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
@@ -19,7 +19,6 @@
 package org.apache.atlas.web.resources;
 
 import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import org.apache.atlas.AtlasClient;
@@ -149,7 +148,7 @@ public class EntityResource {
                 jsonStrings = new String[jsonEntities.size()];
 
                 for (int i = 0; i < jsonEntities.size(); i++) {
-                    jsonStrings[i] = jsonEntities.get(i).textValue();
+                    jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i));
                 }
             } catch (IOException e) {
                 jsonStrings = new String[1];
@@ -172,8 +171,8 @@ public class EntityResource {
 
             final CreateUpdateEntitiesResult result = 
restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
 
-            ObjectNode response    = getResponse(result);
-            URI        locationURI = getLocationURI(guids);
+            String response    = getResponse(result);
+            URI    locationURI = getLocationURI(guids);
 
             return Response.created(locationURI).entity(response).build();
 
@@ -215,28 +214,32 @@ public class EntityResource {
         return locationURI;
     }
 
-    private ObjectNode getResponse(EntityResult entityResult) throws 
AtlasBaseException, AtlasException {
+    private String getResponse(EntityResult entityResult) throws 
AtlasBaseException, AtlasException {
         CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
         result.setEntityResult(entityResult);
         return getResponse(result);
 
     }
-    private ObjectNode getResponse(CreateUpdateEntitiesResult result) throws 
AtlasBaseException, AtlasException {
-        ObjectNode response = AtlasJson.createV1ObjectNode();
-        EntityResult entityResult = result.getEntityResult();
-        GuidMapping mapping = result.getGuidMapping();
-        response.putPOJO(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+    private String getResponse(CreateUpdateEntitiesResult result) throws 
AtlasBaseException, AtlasException {
+        Map<String, Object> response     = new HashMap<>();
+        EntityResult        entityResult = result.getEntityResult();
+        GuidMapping         mapping      = result.getGuidMapping();
+
+        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+
         if(entityResult != null) {
-            response.putPOJO(AtlasClient.ENTITIES, entityResult.getEntities());
+            response.put(AtlasClient.ENTITIES, entityResult.getEntities());
+
             String sampleEntityId = getSample(result.getEntityResult());
             if (sampleEntityId != null) {
-                response.putPOJO(AtlasClient.DEFINITION, 
getEntity(sampleEntityId));
+                response.put(AtlasClient.DEFINITION, 
getEntity(sampleEntityId));
             }
         }
+
         if(mapping != null) {
-            response.putPOJO(AtlasClient.GUID_ASSIGNMENTS, mapping);
+            response.put(AtlasClient.GUID_ASSIGNMENTS, mapping);
         }
-        return response;
+        return AtlasJson.toV1Json(response);
     }
 
     /**
@@ -284,7 +287,7 @@ public class EntityResource {
                 LOG.debug("Updated entities: {}", result.getEntityResult());
             }
 
-            ObjectNode response = getResponse(result);
+            String response = getResponse(result);
             return Response.ok(response).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to persist entity instance entityDef={}", 
entityJson, e);
@@ -386,7 +389,7 @@ public class EntityResource {
                 LOG.debug("Updated entities: {}", result.getEntityResult());
             }
 
-            ObjectNode response = getResponse(result);
+            String response = getResponse(result);
             return Response.ok(response).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to partially update entity {} {}:{}.{}", 
entityJson, entityType, attribute, value, e);
@@ -475,7 +478,7 @@ public class EntityResource {
                 LOG.debug("Updated entities: {}", result.getEntityResult());
             }
 
-            ObjectNode response = getResponse(result);
+            String response = getResponse(result);
             return Response.ok(response).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to update entity by GUID {} {} ", guid, 
entityJson, e);
@@ -520,7 +523,7 @@ public class EntityResource {
                 LOG.debug("Updated entities: {}", result.getEntityResult());
             }
 
-            ObjectNode response = getResponse(result);
+            String response = getResponse(result);
             return Response.ok(response).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to add property {} to entity id {} {} ", 
property, guid, value, e);
@@ -590,7 +593,7 @@ public class EntityResource {
                 LOG.debug("Deleted entity result: {}", entityResult);
             }
 
-            ObjectNode response = getResponse(entityResult);
+            String response = getResponse(entityResult);
             return Response.ok(response).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to delete entities {} {} {} {} ", guids, 
entityType, attribute, value, e);
@@ -640,18 +643,20 @@ public class EntityResource {
 
             Referenceable entity = getEntity(guid);
 
-            ObjectNode response = 
AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+            Map<String, Object> response = new HashMap<>();
+
+            response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
 
             Response.Status status = Response.Status.NOT_FOUND;
             if (entity != null) {
-                response.putPOJO(AtlasClient.DEFINITION, entity);
+                response.put(AtlasClient.DEFINITION, entity);
                 status = Response.Status.OK;
             } else {
                 response.put(AtlasClient.ERROR,
                         Servlets.escapeJsonString(String.format("An entity 
with GUID={%s} does not exist", guid)));
             }
 
-            return Response.status(status).entity(response).build();
+            return 
Response.status(status).entity(AtlasJson.toV1Json(response)).build();
         } catch (IllegalArgumentException e) {
             LOG.error("Bad GUID={} ", guid, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, 
Response.Status.BAD_REQUEST));
@@ -688,13 +693,13 @@ public class EntityResource {
 
             List<String> entityGUIDS = 
entitiesStore.getEntityGUIDS(entityType);
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
             response.put(AtlasClient.TYPENAME, entityType);
-            response.putPOJO(AtlasClient.RESULTS, entityGUIDS);
+            response.put(AtlasClient.RESULTS, entityGUIDS);
             response.put(AtlasClient.COUNT, entityGUIDS.size());
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (NullPointerException e) {
             LOG.error("Entity type cannot be null", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, 
Response.Status.BAD_REQUEST));
@@ -780,19 +785,20 @@ public class EntityResource {
                 entity = restAdapters.getReferenceable(entityInfo);
             }
 
-            ObjectNode response = 
AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+            Map<String, Object> response = new HashMap<>();
+
+            response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
 
             Response.Status status = Response.Status.NOT_FOUND;
             if (entity != null) {
-                response.putPOJO(AtlasClient.DEFINITION, entity);
+                response.put(AtlasClient.DEFINITION, entity);
                 status = Response.Status.OK;
             } else {
                 response.put(AtlasClient.ERROR, 
Servlets.escapeJsonString(String.format("An entity with type={%s}, " +
                         "qualifiedName={%s} does not exist", entityType, 
value)));
             }
 
-            return Response.status(status).entity(response).build();
-
+            return 
Response.status(status).entity(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to get instance definition for type={}, 
qualifiedName={}", entityType, value, e);
             throw toWebApplicationException(e);
@@ -842,12 +848,12 @@ public class EntityResource {
                 traitNames.add(classification.getTypeName());
             }
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
-            response.putPOJO(AtlasClient.RESULTS, traitNames);
+            response.put(AtlasClient.RESULTS, traitNames);
             response.put(AtlasClient.COUNT, traitNames.size());
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to get trait definition for entity {}", guid, e);
             throw toWebApplicationException(e);
@@ -893,18 +899,18 @@ public class EntityResource {
 
             final List<AtlasClassification> classifications = 
entitiesStore.getClassifications(guid);
 
-            ArrayNode traits = AtlasJson.createV1ArrayNode();
+            List<Struct> traits = new ArrayList<>(classifications.size());
             for (AtlasClassification classification : classifications) {
                 Struct trait = restAdapters.getTrait(classification);
-                traits.addPOJO(trait);
+                traits.add(trait);
             }
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
             response.put(AtlasClient.RESULTS, traits);
             response.put(AtlasClient.COUNT, traits.size());
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to get trait definition for entity {}", guid, e);
             throw toWebApplicationException(e);
@@ -955,11 +961,11 @@ public class EntityResource {
 
             Struct traitDefinition = restAdapters.getTrait(classification);
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
-            response.putPOJO(AtlasClient.RESULTS, traitDefinition);
+            response.put(AtlasClient.RESULTS, traitDefinition);
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
 
         } catch (AtlasBaseException e) {
             LOG.error("Unable to get trait definition for entity {} and trait 
{}", guid, traitName, e);
@@ -1019,9 +1025,10 @@ public class EntityResource {
                 add(guid);
             }});
 
-            ObjectNode response = 
AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+            Map<String, Object> response = new HashMap<>();
+            response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
 
-            return Response.created(locationURI).entity(response).build();
+            return 
Response.created(locationURI).entity(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to add trait for entity={} traitDef={}", guid, 
traitDefinition, e);
             throw toWebApplicationException(e);
@@ -1072,11 +1079,11 @@ public class EntityResource {
 
             entitiesStore.deleteClassifications(guid, new ArrayList<String>() 
{{ add(traitName); }});
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
             response.put(TRAIT_NAME, traitName);
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to delete trait name={} for entity={}", 
traitName, guid, e);
             throw toWebApplicationException(e);
@@ -1130,10 +1137,10 @@ public class EntityResource {
 
             List<EntityAuditEvent> events = 
entityAuditRepository.listEvents(guid, startKey, count);
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
-            response.putPOJO(AtlasClient.EVENTS, events);
-            return Response.ok(response).build();
+            response.put(AtlasClient.EVENTS, events);
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (IllegalArgumentException e) {
             LOG.error("Unable to get audit events for entity guid={} 
startKey={}", guid, startKey, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, 
Response.Status.BAD_REQUEST));

http://git-wip-us.apache.org/repos/asf/atlas/blob/8535e88c/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java 
b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
index a69b0e7..bcc57e0 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
@@ -18,8 +18,6 @@
 
 package org.apache.atlas.web.resources;
 
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.core.ResourceContext;
 import org.apache.atlas.AtlasClient;
@@ -52,7 +50,11 @@ import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * This class provides RESTful API for Types.
@@ -101,8 +103,6 @@ public class TypesResource {
             perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, 
"TypesResource.submit()");
         }
 
-        ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
-
         try {
             final String typeDefinition = Servlets.getRequestPayload(request);
 
@@ -113,17 +113,16 @@ public class TypesResource {
             AtlasTypesDef createTypesDef  = 
TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
             AtlasTypesDef createdTypesDef = 
typesREST.createAtlasTypeDefs(createTypesDef);
             List<String>  typeNames       = 
TypeConverterUtil.getTypeNames(createdTypesDef);
+            List<Map<String, Object>> typesResponse = new 
ArrayList<>(typeNames.size());
 
-            for (int i = 0; i < typeNames.size(); i++) {
-                ObjectNode typeNode = 
AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
-
-                typesResponse.add(typeNode);
+            for (String typeName : typeNames) {
+                typesResponse.add(Collections.singletonMap(AtlasClient.NAME, 
typeName));
             }
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
             response.put(AtlasClient.TYPES, typesResponse);
-            return 
Response.status(ClientResponse.Status.CREATED).entity(response).build();
+            return 
Response.status(ClientResponse.Status.CREATED).entity(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Type creation failed", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e));
@@ -168,7 +167,6 @@ public class TypesResource {
             perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, 
"TypesResource.update()");
         }
 
-        ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
         try {
             final String typeDefinition = Servlets.getRequestPayload(request);
 
@@ -179,17 +177,16 @@ public class TypesResource {
             AtlasTypesDef updateTypesDef  = 
TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
             AtlasTypesDef updatedTypesDef = 
typeDefStore.createUpdateTypesDef(updateTypesDef);
             List<String>  typeNames       = 
TypeConverterUtil.getTypeNames(updatedTypesDef);
+            List<Map<String, Object>> typesResponse = new 
ArrayList<>(typeNames.size());
 
-            for (int i = 0; i < typeNames.size(); i++) {
-                ObjectNode typeNode = 
AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
-
-                typesResponse.add(typeNode);
+            for (String typeName : typeNames) {
+                typesResponse.add(Collections.singletonMap(AtlasClient.NAME, 
typeName));
             }
 
-            ObjectNode response = AtlasJson.createV1ObjectNode();
+            Map<String, Object> response = new HashMap<>();
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
             response.put(AtlasClient.TYPES, typesResponse);
-            return Response.ok().entity(response).build();
+            return Response.ok().entity(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e));
@@ -230,16 +227,16 @@ public class TypesResource {
             perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, 
"TypesResource.getDefinition(" + typeName + ")");
         }
 
-        ObjectNode response = AtlasJson.createV1ObjectNode();
+        Map<String, Object> response = new HashMap<>();
 
         try {
             TypesDef typesDef = 
TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
 
             response.put(AtlasClient.TYPENAME, typeName);
-            response.putPOJO(AtlasClient.DEFINITION, typesDef);
+            response.put(AtlasClient.DEFINITION, typesDef);
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.error("Unable to get type definition for type {}", typeName, 
e);
             throw new WebApplicationException(Servlets.getErrorResponse(e));
@@ -288,15 +285,15 @@ public class TypesResource {
             perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, 
"TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + 
notsupertype + ")");
         }
 
-        ObjectNode response = AtlasJson.createV1ObjectNode();
+        Map<String, Object> response = new HashMap<>();
         try {
             List<String> result = 
TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
 
-            response.putPOJO(AtlasClient.RESULTS, result);
+            response.put(AtlasClient.RESULTS, result);
             response.put(AtlasClient.COUNT, result.size());
             response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
 
-            return Response.ok(response).build();
+            return Response.ok(AtlasJson.toV1Json(response)).build();
         } catch (AtlasBaseException e) {
             LOG.warn("TypesREST exception: {} {}", 
e.getClass().getSimpleName(), e.getMessage());
             throw new WebApplicationException(Servlets.getErrorResponse(e));

Reply via email to