You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/12/03 08:15:27 UTC
[2/3] atlas git commit: ATLAS-2292: remove older version jackson
libraries from packaging
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/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 154f155..e3a5b1f 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
@@ -18,6 +18,8 @@
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;
@@ -43,6 +45,7 @@ import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.v1.model.instance.Id;
@@ -52,9 +55,6 @@ import org.apache.atlas.web.rest.EntityREST;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -68,9 +68,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -141,21 +141,20 @@ public class EntityResource {
String entities = Servlets.getRequestPayload(request);
//Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
- JSONArray jsonEntities = null;
+ ArrayNode jsonEntities = null;
try {
- jsonEntities = new JSONArray(entities);
- } catch (JSONException e) {
- final String finalEntities = entities;
- jsonEntities = new JSONArray() {{
- put(finalEntities);
- }};
+ jsonEntities = AtlasJson.parseToV1ArrayNode(entities);
+ } catch (IOException e) {
+ jsonEntities = AtlasJson.createV1ArrayNode();
+
+ jsonEntities.add(entities);
}
- String[] jsonStrings = new String[jsonEntities.length()];
+ String[] jsonStrings = new String[jsonEntities.size()];
- for (int i = 0; i < jsonEntities.length(); i++) {
- jsonStrings[i] = jsonEntities.getString(i);
+ for (int i = 0; i < jsonEntities.size(); i++) {
+ jsonStrings[i] = jsonEntities.get(i).asText();
}
if (LOG.isDebugEnabled()) {
@@ -173,7 +172,7 @@ public class EntityResource {
final CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
- JSONObject response = getResponse(result);
+ ObjectNode response = getResponse(result);
URI locationURI = getLocationURI(guids);
return Response.created(locationURI).entity(response).build();
@@ -216,27 +215,26 @@ public class EntityResource {
return locationURI;
}
- private JSONObject getResponse(EntityResult entityResult) throws AtlasBaseException, AtlasException, JSONException {
+ private ObjectNode getResponse(EntityResult entityResult) throws AtlasBaseException, AtlasException {
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
result.setEntityResult(entityResult);
return getResponse(result);
}
- private JSONObject getResponse(CreateUpdateEntitiesResult result) throws AtlasBaseException, AtlasException, JSONException {
- JSONObject response = new JSONObject();
+ private ObjectNode getResponse(CreateUpdateEntitiesResult result) throws AtlasBaseException, AtlasException {
+ ObjectNode response = AtlasJson.createV1ObjectNode();
EntityResult entityResult = result.getEntityResult();
GuidMapping mapping = result.getGuidMapping();
- response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+ response.putPOJO(AtlasClient.REQUEST_ID, Servlets.getRequestId());
if(entityResult != null) {
- response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES));
+ response.putPOJO(AtlasClient.ENTITIES, entityResult.getEntities());
String sampleEntityId = getSample(result.getEntityResult());
if (sampleEntityId != null) {
- String entityDefinition = getEntityJson(sampleEntityId);
- response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
+ response.putPOJO(AtlasClient.DEFINITION, getEntity(sampleEntityId));
}
}
if(mapping != null) {
- response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toV1Json(mapping)).get(AtlasClient.GUID_ASSIGNMENTS));
+ response.putPOJO(AtlasClient.GUID_ASSIGNMENTS, mapping);
}
return response;
}
@@ -261,12 +259,13 @@ public class EntityResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()");
}
- final String entities = Servlets.getRequestPayload(request);
- JSONArray jsonEntities = new JSONArray(entities);
- String[] jsonStrings = new String[jsonEntities.length()];
+ entityJson = Servlets.getRequestPayload(request);
+
+ ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
+ String[] jsonStrings = new String[jsonEntities.size()];
- for (int i = 0; i < jsonEntities.length(); i++) {
- jsonStrings[i] = jsonEntities.getString(i);
+ for (int i = 0; i < jsonEntities.size(); i++) {
+ jsonStrings[i] = jsonEntities.get(i).asText();
}
if (LOG.isDebugEnabled()) {
@@ -281,7 +280,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
- JSONObject response = getResponse(result);
+ ObjectNode response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
@@ -383,7 +382,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
- JSONObject response = getResponse(result);
+ ObjectNode response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to partially update entity {} {}:{}.{}", entityJson, entityType, attribute, value, e);
@@ -472,7 +471,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
- JSONObject response = getResponse(result);
+ ObjectNode response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
@@ -517,7 +516,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
- JSONObject response = getResponse(result);
+ ObjectNode response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e);
@@ -587,7 +586,7 @@ public class EntityResource {
LOG.debug("Deleted entity result: {}", entityResult);
}
- JSONObject response = getResponse(entityResult);
+ ObjectNode response = getResponse(entityResult);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
@@ -635,14 +634,13 @@ public class EntityResource {
guid = ParamChecker.notEmpty(guid, "guid cannot be null");
- String entityDefinition = getEntityJson(guid);
+ Referenceable entity = getEntity(guid);
- JSONObject response = new JSONObject();
- response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+ ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
Response.Status status = Response.Status.NOT_FOUND;
- if (entityDefinition != null) {
- response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
+ if (entity != null) {
+ response.putPOJO(AtlasClient.DEFINITION, entity);
status = Response.Status.OK;
} else {
response.put(AtlasClient.ERROR,
@@ -683,10 +681,10 @@ public class EntityResource {
List<String> entityGUIDS = entitiesStore.getEntityGUIDS(entityType);
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPENAME, entityType);
- response.put(AtlasClient.RESULTS, new JSONArray(entityGUIDS));
+ response.putPOJO(AtlasClient.RESULTS, entityGUIDS);
response.put(AtlasClient.COUNT, entityGUIDS.size());
return Response.ok(response).build();
@@ -769,20 +767,17 @@ public class EntityResource {
throw toWebApplicationException(e);
}
- String entityDefinition = null;
+ Referenceable entity = null;
if (entityInfo != null) {
- Referenceable instance = restAdapters.getReferenceable(entityInfo);
-
- entityDefinition = AtlasType.toV1Json(instance);
+ entity = restAdapters.getReferenceable(entityInfo);
}
- JSONObject response = new JSONObject();
- response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+ ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
Response.Status status = Response.Status.NOT_FOUND;
- if (entityDefinition != null) {
- response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
+ if (entity != null) {
+ response.putPOJO(AtlasClient.DEFINITION, entity);
status = Response.Status.OK;
} else {
response.put(AtlasClient.ERROR, Servlets.escapeJsonString(String.format("An entity with type={%s}, " +
@@ -840,9 +835,9 @@ public class EntityResource {
traitNames.add(classification.getTypeName());
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
- response.put(AtlasClient.RESULTS, new JSONArray(traitNames));
+ response.putPOJO(AtlasClient.RESULTS, traitNames);
response.put(AtlasClient.COUNT, traitNames.size());
return Response.ok(response).build();
@@ -891,16 +886,16 @@ public class EntityResource {
final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
- JSONArray traits = new JSONArray();
+ ArrayNode traits = AtlasJson.createV1ArrayNode();
for (AtlasClassification classification : classifications) {
Struct trait = restAdapters.getTrait(classification);
- traits.put(new JSONObject(AtlasType.toV1Json(trait)));
+ traits.addPOJO(trait);
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.RESULTS, traits);
- response.put(AtlasClient.COUNT, traits.length());
+ response.put(AtlasClient.COUNT, traits.size());
return Response.ok(response).build();
} catch (AtlasBaseException e) {
@@ -953,9 +948,9 @@ public class EntityResource {
Struct traitDefinition = restAdapters.getTrait(classification);
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
- response.put(AtlasClient.RESULTS, new JSONObject(AtlasType.toV1Json(traitDefinition)));
+ response.putPOJO(AtlasClient.RESULTS, traitDefinition);
return Response.ok(response).build();
@@ -1017,8 +1012,7 @@ public class EntityResource {
add(guid);
}});
- JSONObject response = new JSONObject();
- response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
+ ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.created(locationURI).entity(response).build();
} catch (AtlasBaseException e) {
@@ -1071,7 +1065,7 @@ public class EntityResource {
entitiesStore.deleteClassifications(guid, new ArrayList<String>() {{ add(traitName); }});
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(TRAIT_NAME, traitName);
@@ -1129,9 +1123,9 @@ public class EntityResource {
List<EntityAuditEvent> events = entityAuditRepository.listEvents(guid, startKey, count);
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
- response.put(AtlasClient.EVENTS, getJSONArray(events));
+ response.putPOJO(AtlasClient.EVENTS, events);
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
@@ -1151,14 +1145,6 @@ public class EntityResource {
}
}
- private <T> JSONArray getJSONArray(Collection<T> elements) throws JSONException {
- JSONArray jsonArray = new JSONArray();
- for(T element : elements) {
- jsonArray.put(new JSONObject(AtlasType.toV1Json(element)));
- }
- return jsonArray;
- }
-
private AtlasEntityType getEntityType(String typeName) throws AtlasBaseException {
AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName);
@@ -1184,11 +1170,10 @@ public class EntityResource {
return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
- private String getEntityJson(String guid) throws AtlasBaseException {
+ private Referenceable getEntity(String guid) throws AtlasBaseException {
AtlasEntityWithExtInfo entity = entitiesStore.getById(guid);
Referenceable referenceable = restAdapters.getReferenceable(entity);
- String entityJson = AtlasType.toV1Json(referenceable);
- return entityJson;
+ return referenceable;
}
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
index ff1751d..0ac4ad5 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
@@ -18,18 +18,18 @@
package org.apache.atlas.web.resources;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.query.QueryParams;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.configuration.Configuration;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -44,6 +44,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -150,7 +151,7 @@ public class MetadataDiscoveryResource {
QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByDSL(dslQuery, queryParams);
- JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
+ ObjectNode response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
@@ -222,17 +223,13 @@ public class MetadataDiscoveryResource {
gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
final List<Map<String, String>> results = new ArrayList<>(); // TODO-typeSystem-removal: discoveryService.searchByGremlin(gremlinQuery);
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.QUERY, gremlinQuery);
response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN);
- JSONArray list = new JSONArray();
- for (Map<String, String> result : results) {
- list.put(new JSONObject(result));
- }
- response.put(AtlasClient.RESULTS, list);
- response.put(AtlasClient.COUNT, list.length());
+ response.putPOJO(AtlasClient.RESULTS, results);
+ response.put(AtlasClient.COUNT, results.size());
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
@@ -281,9 +278,9 @@ public class MetadataDiscoveryResource {
query = ParamChecker.notEmpty(query, "query cannot be null or empty");
QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByFullText(query, queryParams);
- JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
+ ArrayNode rowsJsonArr = AtlasJson.parseToV1ArrayNode(jsonResultStr);
- JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
+ ObjectNode response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
LOG.error("Unable to get entity list for query {}", query, e);
@@ -308,10 +305,10 @@ public class MetadataDiscoveryResource {
protected int count = 0;
protected String query;
protected String queryType;
- protected JSONObject response;
+ protected ObjectNode response;
JsonResponseBuilder() {
- this.response = new JSONObject();
+ this.response = AtlasJson.createV1ObjectNode();
}
protected JsonResponseBuilder count(int count) {
@@ -329,7 +326,7 @@ public class MetadataDiscoveryResource {
return this;
}
- protected JSONObject build() throws JSONException {
+ protected ObjectNode build() {
Preconditions.checkNotNull(query, "Query cannot be null");
Preconditions.checkNotNull(queryType, "Query Type must be specified");
@@ -349,25 +346,24 @@ public class MetadataDiscoveryResource {
super();
}
- private JSONObject dslResults;
+ private ArrayNode dslResults;
- public DSLJSONResponseBuilder results(JSONObject dslResults) {
+ public DSLJSONResponseBuilder results(ArrayNode dslResults) {
this.dslResults = dslResults;
return this;
}
- public DSLJSONResponseBuilder results(String dslResults) throws JSONException {
- return results(new JSONObject(dslResults));
+ public DSLJSONResponseBuilder results(String dslResults) throws IOException {
+ return results(AtlasJson.parseToV1ArrayNode(dslResults));
}
@Override
- public JSONObject build() throws JSONException {
+ public ObjectNode build() {
Preconditions.checkNotNull(dslResults);
- JSONArray rowsJsonArr = dslResults.getJSONArray(AtlasClient.ROWS);
- count(rowsJsonArr.length());
+ count(dslResults.size());
queryType(QUERY_TYPE_DSL);
- JSONObject response = super.build();
- response.put(AtlasClient.RESULTS, rowsJsonArr);
+ ObjectNode response = super.build();
+ response.putPOJO(AtlasClient.RESULTS, dslResults);
response.put(AtlasClient.DATATYPE, dslResults.get(AtlasClient.DATATYPE));
return response;
}
@@ -376,15 +372,15 @@ public class MetadataDiscoveryResource {
private class FullTextJSonResponseBuilder extends JsonResponseBuilder {
- private JSONArray fullTextResults;
+ private ArrayNode fullTextResults;
- public FullTextJSonResponseBuilder results(JSONArray fullTextResults) {
+ public FullTextJSonResponseBuilder results(ArrayNode fullTextResults) {
this.fullTextResults = fullTextResults;
return this;
}
- public FullTextJSonResponseBuilder results(String dslResults) throws JSONException {
- return results(new JSONArray(dslResults));
+ public FullTextJSonResponseBuilder results(String dslResults) throws IOException {
+ return results(AtlasJson.parseToV1ArrayNode(dslResults));
}
public FullTextJSonResponseBuilder() {
@@ -392,12 +388,12 @@ public class MetadataDiscoveryResource {
}
@Override
- public JSONObject build() throws JSONException {
+ public ObjectNode build() {
Preconditions.checkNotNull(fullTextResults);
- count(fullTextResults.length());
+ count(fullTextResults.size());
queryType(QUERY_TYPE_FULLTEXT);
- JSONObject response = super.build();
+ ObjectNode response = super.build();
response.put(AtlasClient.RESULTS, fullTextResults);
return response;
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/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 9b2d7b2..a69b0e7 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,22 +18,21 @@
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;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.store.AtlasTypeDefStore;
-import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.repository.converters.TypeConverterUtil;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.rest.TypesREST;
import org.apache.atlas.web.util.Servlets;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -102,7 +101,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
}
- JSONArray typesResponse = new JSONArray();
+ ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try {
final String typeDefinition = Servlets.getRequestPayload(request);
@@ -116,13 +115,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
- final String name = typeNames.get(i);
- typesResponse.put(new JSONObject() {{
- put(AtlasClient.NAME, name);
- }});
+ ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
+
+ typesResponse.add(typeNode);
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.status(ClientResponse.Status.CREATED).entity(response).build();
@@ -170,7 +168,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
}
- JSONArray typesResponse = new JSONArray();
+ ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try {
final String typeDefinition = Servlets.getRequestPayload(request);
@@ -183,13 +181,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
- final String name = typeNames.get(i);
- typesResponse.put(new JSONObject() {{
- put(AtlasClient.NAME, name);
- }});
+ ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
+
+ typesResponse.add(typeNode);
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.ok().entity(response).build();
@@ -233,21 +230,20 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
try {
- TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
- String typeDefinition = AtlasType.toV1Json(typesDef);
+ TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
response.put(AtlasClient.TYPENAME, typeName);
- response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition));
+ response.putPOJO(AtlasClient.DEFINITION, typesDef);
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
- } catch (JSONException | IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
@@ -292,11 +288,11 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
}
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
try {
List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
- response.put(AtlasClient.RESULTS, new JSONArray(result));
+ response.putPOJO(AtlasClient.RESULTS, result);
response.put(AtlasClient.COUNT, result.size());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/main/java/org/apache/atlas/web/util/AtlasJsonProvider.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/util/AtlasJsonProvider.java b/webapp/src/main/java/org/apache/atlas/web/util/AtlasJsonProvider.java
new file mode 100644
index 0000000..efe0486
--- /dev/null
+++ b/webapp/src/main/java/org/apache/atlas/web/util/AtlasJsonProvider.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.atlas.web.util;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+
+
+@Provider
+@Produces(MediaType.APPLICATION_JSON)
+@Component
+public class AtlasJsonProvider extends JacksonJaxbJsonProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasJsonProvider.class);
+
+ private static final ObjectMapper mapper = new ObjectMapper()
+ .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
+
+ public AtlasJsonProvider() {
+ super(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
+
+ LOG.info("AtlasJsonProvider() instantiated");
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/main/java/org/apache/atlas/web/util/Servlets.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/util/Servlets.java b/webapp/src/main/java/org/apache/atlas/web/util/Servlets.java
index 638e428..ec340cf 100755
--- a/webapp/src/main/java/org/apache/atlas/web/util/Servlets.java
+++ b/webapp/src/main/java/org/apache/atlas/web/util/Servlets.java
@@ -18,11 +18,13 @@
package org.apache.atlas.web.util;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.LocalServletRequest;
import org.apache.atlas.exception.AtlasBaseException;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
@@ -30,8 +32,6 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -153,15 +153,10 @@ public final class Servlets {
}
public static Response getErrorResponse(String message, Response.Status status) {
- JSONObject errorJson = new JSONObject();
- Object errorEntity = escapeJsonString(message);
- try {
- errorJson.put(AtlasClient.ERROR, errorEntity);
- errorEntity = errorJson;
- } catch (JSONException jsonE) {
- LOG.warn("Could not construct error Json rensponse", jsonE);
- }
- return Response.status(status).entity(errorEntity).type(JSON_MEDIA_TYPE).build();
+ Object errorEntity = escapeJsonString(message);
+ ObjectNode errorJson = AtlasJson.createV1ObjectNode(AtlasClient.ERROR, errorEntity);
+
+ return Response.status(status).entity(errorJson).type(JSON_MEDIA_TYPE).build();
}
public static String getRequestPayload(HttpServletRequest request) throws IOException {
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
index 1b5e811..d9ef0a2 100644
--- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
+++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
@@ -18,14 +18,13 @@
package org.apache.atlas.examples;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.web.integration.BaseResourceIT;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -51,12 +50,12 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals(QuickStart.SALES_DB_DESCRIPTION, db.get("description"));
}
- private Referenceable getDB(String dbName) throws AtlasServiceException, JSONException {
+ private Referenceable getDB(String dbName) throws AtlasServiceException {
return atlasClientV1.getEntity(QuickStart.DATABASE_TYPE, "name", dbName);
}
@Test
- public void testTablesAreAdded() throws AtlasServiceException, JSONException {
+ public void testTablesAreAdded() throws AtlasServiceException {
Referenceable table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table);
@@ -71,11 +70,11 @@ public class QuickStartIT extends BaseResourceIT {
return atlasClientV1.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
}
- private void verifyTrait(Referenceable table) throws JSONException {
+ private void verifyTrait(Referenceable table) {
assertNotNull(table.getTrait(QuickStart.FACT_TRAIT));
}
- private void verifyColumnsAreAddedToTable(Referenceable table) throws JSONException {
+ private void verifyColumnsAreAddedToTable(Referenceable table) {
List<Referenceable> columns = (List<Referenceable>) table.get(QuickStart.COLUMNS_ATTRIBUTE);
assertEquals(4, columns.size());
Referenceable column = columns.get(0);
@@ -83,18 +82,18 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals("int", column.get("dataType"));
}
- private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException, JSONException {
+ private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException {
Referenceable db = getDB(QuickStart.SALES_DB);
assertEquals(db.getId(), table.get(QuickStart.DB_ATTRIBUTE));
}
- private void verifySimpleTableAttributes(Referenceable table) throws JSONException {
+ private void verifySimpleTableAttributes(Referenceable table) {
assertEquals(QuickStart.SALES_FACT_TABLE, table.get("name"));
assertEquals(QuickStart.SALES_FACT_TABLE_DESCRIPTION, table.get("description"));
}
@Test
- public void testProcessIsAdded() throws AtlasServiceException, JSONException {
+ public void testProcessIsAdded() throws AtlasServiceException {
Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
QuickStart.LOAD_SALES_DAILY_PROCESS);
@@ -118,29 +117,29 @@ public class QuickStartIT extends BaseResourceIT {
}
@Test
- public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
+ public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE);
- JSONObject inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
- JSONObject vertices = (JSONObject) ((JSONObject) inputGraph.get("values")).get("vertices");
- JSONObject edges = (JSONObject) ((JSONObject) inputGraph.get("values")).get("edges");
+ ObjectNode inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
+ ArrayNode vertices = (ArrayNode) inputGraph.get("values").get("vertices");
+ ArrayNode edges = (ArrayNode) inputGraph.get("values").get("edges");
assertTrue(vertices.has(salesFactTableId));
assertTrue(vertices.has(timeDimTableId));
assertTrue(vertices.has(salesFactDailyMVId));
assertTrue(edges.has(salesFactDailyMVId));
- JSONArray inputs = (JSONArray)edges.get((String) ((JSONArray) edges.get(salesFactDailyMVId)).get(0));
- String i1 = inputs.getString(0);
- String i2 = inputs.getString(1);
+ ArrayNode inputs = (ArrayNode)edges.get((edges.get(salesFactDailyMVId)).get(0).asText());
+ String i1 = inputs.get(0).asText();
+ String i2 = inputs.get(1).asText();
assertTrue(salesFactTableId.equals(i1) || salesFactTableId.equals(i2));
assertTrue(timeDimTableId.equals(i1) || timeDimTableId.equals(i2));
}
@Test
- public void testViewIsAdded() throws AtlasServiceException, JSONException {
+ public void testViewIsAdded() throws AtlasServiceException {
Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
index 80a01aa..02041ac 100644
--- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
+++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
@@ -27,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.web.integration.BaseResourceIT;
-import org.codehaus.jettison.json.JSONException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -57,7 +56,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertEquals("sales database", dbAttributes.get("description"));
}
- private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException {
+ private AtlasEntity getDB(String dbName) throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put("name", dbName);
AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity();
@@ -65,7 +64,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
- public void testTablesAreAdded() throws AtlasServiceException, JSONException {
+ public void testTablesAreAdded() throws AtlasServiceException {
AtlasEntity table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table);
@@ -97,7 +96,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertNotNull(traits.get(0).getTypeName());
}
- private void verifyColumnsAreAddedToTable(AtlasEntity table) throws JSONException {
+ private void verifyColumnsAreAddedToTable(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes();
List<Map> columns = (List<Map>) tableAttributes.get("columns");
assertEquals(4, columns.size());
@@ -108,21 +107,21 @@ public class QuickStartV2IT extends BaseResourceIT {
}
}
- private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException, JSONException {
+ private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException {
AtlasEntity db = getDB(QuickStartV2.SALES_DB);
Map<String, Object> tableAttributes = table.getAttributes();
Map dbFromTable = (Map) tableAttributes.get("db");
assertEquals(db.getGuid(), dbFromTable.get("guid"));
}
- private void verifySimpleTableAttributes(AtlasEntity table) throws JSONException {
+ private void verifySimpleTableAttributes(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes();
assertEquals(QuickStartV2.SALES_FACT_TABLE, tableAttributes.get("name"));
assertEquals("sales fact table", tableAttributes.get("description"));
}
@Test
- public void testProcessIsAdded() throws AtlasServiceException, JSONException {
+ public void testProcessIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.LOAD_SALES_DAILY_PROCESS);
AtlasEntity loadProcess = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity();
@@ -153,7 +152,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
- public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
+ public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE);
@@ -177,7 +176,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
- public void testViewIsAdded() throws AtlasServiceException, JSONException {
+ public void testViewIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.PRODUCT_DIM_VIEW);
AtlasEntity view = atlasClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity();
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
index 3dd3e1d..bf7e182 100644
--- a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
+++ b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
@@ -18,6 +18,7 @@
package org.apache.atlas.notification;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.v1.model.instance.Id;
@@ -27,7 +28,6 @@ import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUp
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest;
import org.apache.atlas.web.integration.BaseResourceIT;
-import org.codehaus.jettison.json.JSONArray;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -84,9 +84,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
+ ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
- return results.length() == 1;
+ return results.size() == 1;
}
});
}
@@ -106,9 +106,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
+ ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
- return results.length() == 1;
+ return results.size() == 1;
}
});
@@ -175,16 +175,16 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName));
+ ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName));
- return results.length() == 1;
+ return results.size() == 1;
}
});
//no entity with the old qualified name
- JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
+ ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
- assertEquals(results.length(), 0);
+ assertEquals(results.size(), 0);
}
@Test
@@ -237,9 +237,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
+ ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
- return results.length() == 1;
+ return results.size() == 1;
}
});
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
index 7d045f3..718844d 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
@@ -18,9 +18,9 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -37,13 +37,13 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test
public void testGetVersion() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
Assert.assertNotNull(response);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
- Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
- Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
- Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
+ Assert.assertEquals(response.get("Version").asText(), buildConfiguration.getString("build.version"));
+ Assert.assertEquals(response.get("Name").asText(), buildConfiguration.getString("project.name"));
+ Assert.assertEquals(response.get("Description").asText(), buildConfiguration.getString("project.description"));
}
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
index fe4d688..ede7848 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.base.Preconditions;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
@@ -50,7 +51,6 @@ import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -678,7 +678,7 @@ public abstract class BaseResourceIT {
};
}
- protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException {
+ protected ArrayNode searchByDSL(String dslQuery) throws AtlasServiceException {
return atlasClientV1.searchByDSL(dslQuery, 10, 0);
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
index c78bd58..2406f12 100644
--- a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id;
@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -64,14 +64,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testInputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
Assert.assertNotNull(response);
System.out.println("inputs graph = " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
+ JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
@@ -86,7 +86,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
public void testInputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
salesMonthlyTable).getId()._getId();
- JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
+ ObjectNode results = atlasClientV1.getInputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
@@ -113,14 +113,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testOutputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
Assert.assertNotNull(response);
System.out.println("outputs graph= " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
+ JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
@@ -134,7 +134,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testOutputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
- JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
+ ObjectNode results = atlasClientV1.getOutputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
@@ -159,23 +159,23 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testSchema() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
- JSONObject response = atlasClientV1.getSchemaForEntity(tableId);
+ ObjectNode response = atlasClientV1.getSchemaForEntity(tableId);
}
@Test
public void testSchemaForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
- JSONObject results = atlasClientV1.getSchemaForEntity(tableId);
+ ObjectNode results = atlasClientV1.getSchemaForEntity(tableId);
}
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
}
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
}
private void setupInstances() throws Exception {
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
index 9374719..d1a13b3 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
+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.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
@@ -35,8 +37,6 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -173,7 +173,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp");
- JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
+ ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -322,7 +322,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String description = "bar table - new desc";
addProperty(guid, "description", description);
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("description", description);
@@ -460,7 +460,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetInvalidEntityDefinition() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
Assert.assertNotNull(response);
@@ -493,7 +493,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", "blah");
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.ERROR));
}
@@ -506,12 +506,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", typeName);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertEquals(list.length(), 0);
+ final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
+ Assert.assertEquals(list.size(), 0);
}
private String addNewType() throws Exception {
@@ -827,8 +827,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
instance.set(attrName, attrValue);
Id guid = createInstance(instance);
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
- Referenceable getReferenceable = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), Referenceable.class);
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
+ Referenceable getReferenceable = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), Referenceable.class);
Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
@@ -1026,7 +1026,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
index 4be0002..693cb4b 100644
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasBaseClient;
import org.apache.atlas.AtlasClient;
@@ -26,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -67,7 +67,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+ ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("input lineage info = " + response
);
@@ -95,7 +95,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+ ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("output lineage info = " + response);
@@ -123,7 +123,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+ ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("both lineage info = " + response);
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
index 77a85f6..d1292fe 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.Lists;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.atlas.AtlasClient;
@@ -37,7 +38,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,13 +147,13 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
@Test
public void testEntityDeduping() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
+ ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
+ assertEquals(results.size(), 1);
final AtlasEntity hiveDBInstanceV2 = createHiveDB();
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
+ assertEquals(results.size(), 1);
//Test the same across references
final String tableName = randomString();
@@ -164,7 +164,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
assertNotNull(entity);
assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
+ assertEquals(results.size(), 1);
}
private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
index 789d412..9ca4a69 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
@@ -18,6 +18,9 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.JsonNode;
+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.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
@@ -28,8 +31,6 @@ import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -64,19 +65,19 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- assertEquals(response.getString("query"), dslQuery);
- assertEquals(response.getString("queryType"), "dsl");
+ assertEquals(response.get("query").asText(), dslQuery);
+ assertEquals(response.get("queryType").asText(), "dsl");
- JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
+ ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertNotNull(results);
- assertEquals(results.length(), 1);
+ assertEquals(results.size(), 1);
- int numRows = response.getInt(AtlasClient.COUNT);
+ int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1);
}
@@ -88,24 +89,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
assertNotNull(response);
//higher limit, all results returned
- JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
- assertEquals(results.length(), 1);
+ ArrayNode results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
+ assertEquals(results.size(), 1);
//default limit and offset -1, all results returned
results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
- assertEquals(results.length(), 1);
+ assertEquals(results.size(), 1);
//uses the limit parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
- assertEquals(results.length(), 1);
+ assertEquals(results.size(), 1);
//uses the offset parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
- assertEquals(results.length(), 0);
+ assertEquals(results.size(), 0);
//limit > 0
try {
@@ -146,13 +147,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
assertNotNull(response);
assertNotNull(response.get(AtlasClient.REQUEST_ID));
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "gremlin");
+ assertEquals(response.get("query").asText(), query);
+ assertEquals(response.get("queryType").asText(), "gremlin");
}
// Disabling DSL tests
@@ -162,13 +163,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "dsl");
+ assertEquals(response.get("query").asText(), query);
+ assertEquals(response.get("queryType").asText(), "dsl");
}
// Disabling DSL tests
@@ -177,32 +178,32 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "*";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "full-text");
+ assertEquals(response.get("query").asText(), query);
+ assertEquals(response.get("queryType").asText(), "full-text");
}
@Test(enabled = false, dependsOnMethods = "testSearchDSLLimits")
public void testSearchUsingFullText() throws Exception {
- JSONObject response = atlasClientV1.searchByFullText(dbName, 10, 0);
+ ObjectNode response = atlasClientV1.searchByFullText(dbName, 10, 0);
assertNotNull(response.get(AtlasClient.REQUEST_ID));
- assertEquals(response.getString("query"), dbName);
- assertEquals(response.getString("queryType"), "full-text");
+ assertEquals(response.get("query").asText(), dbName);
+ assertEquals(response.get("queryType").asText(), "full-text");
- JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1, "Results: " + results);
+ ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 1, "Results: " + results);
- JSONObject row = results.getJSONObject(0);
+ JsonNode row = results.get(0);
assertNotNull(row.get("guid"));
- assertEquals(row.getString("typeName"), DATABASE_TYPE);
+ assertEquals(row.get("typeName").asText(), DATABASE_TYPE);
assertNotNull(row.get("score"));
- int numRows = response.getInt(AtlasClient.COUNT);
+ int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1);
//API works without limit and offset
@@ -210,25 +211,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams);
- results = response.getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
+ results = (ArrayNode) response.get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 1);
//verify passed in limits and offsets are used
//higher limit and 0 offset returns all results
- results = atlasClientV1.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
+ results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 0).get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 1);
//offset is used
- results = atlasClientV1.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 0);
+ results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 1).get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 0);
//limit is used
- results = atlasClientV1.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
+ results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 0).get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 1);
//higher offset returns 0 results
- results = atlasClientV1.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 0);
+ results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 2).get(AtlasClient.RESULTS);
+ assertEquals(results.size(), 0);
}
private void createTypes() throws Exception {
http://git-wip-us.apache.org/repos/asf/atlas/blob/1f8e2146/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
index 39c2de0..7fa4fc8 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -81,13 +81,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System.out.println("typesAsJSON = " + typesAsJSON);
- JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
+ ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response);
- JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
- assertEquals(typesAdded.length(), 1);
- assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.getTypeName());
+ ArrayNode typesAdded = (ArrayNode) response.get(AtlasClient.TYPES);
+ assertEquals(typesAdded.size(), 1);
+ assertEquals(typesAdded.get(0).get(NAME).asText(), typeDefinition.getTypeName());
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
}
}
@@ -143,13 +143,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.getTypeName());
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName());
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName());
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- TypesDef typesDef = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), TypesDef.class);
+ TypesDef typesDef = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), TypesDef.class);
List<? extends HierarchicalTypeDefinition> hierarchicalTypeDefs = Collections.emptyList();
@@ -172,21 +172,21 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
}
@Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
+ ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list);
//Verify that primitive and core types are not returned
- String typesString = list.join(" ");
+ String typesString = list.toString();
Assert.assertFalse(typesString.contains(" \"__IdType\" "));
Assert.assertFalse(typesString.contains(" \"string\" "));
}
@@ -198,14 +198,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
+ ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list);
- Assert.assertTrue(list.length() >= traitsAdded.length);
+ Assert.assertTrue(list.size() >= traitsAdded.length);
}
@Test