ATLAS-2292: remove older version jackson libraries from packaging
diff --git a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridgeTest.java b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridgeTest.java
index 819d734..ea669f3 100644
--- a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridgeTest.java
+++ b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridgeTest.java
@@ -31,7 +31,6 @@
import org.apache.hadoop.hive.ql.metadata.Partition;
import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hadoop.mapred.TextInputFormat;
-import org.codehaus.jettison.json.JSONException;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -113,7 +112,7 @@
}
private void returnExistingDatabase(String databaseName, AtlasClient atlasClient, String clusterName)
- throws AtlasServiceException, JSONException {
+ throws AtlasServiceException {
when(atlasClient.getEntity(
HiveDataTypes.HIVE_DB.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
HiveMetaStoreBridge.getDBQualifiedName(clusterName, databaseName))).thenReturn(
@@ -219,7 +218,7 @@
}
}
- private Referenceable getEntityReference(String typeName, String id) throws JSONException {
+ private Referenceable getEntityReference(String typeName, String id) {
return new Referenceable(id, typeName, null);
}
diff --git a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
index 517ee8e..5592b66 100755
--- a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
+++ b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.hive.hook;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Joiner;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.atlas.AtlasClient;
@@ -41,8 +43,6 @@
import org.apache.hadoop.hive.ql.plan.HiveOperation;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -381,8 +381,8 @@
//Check lineage which includes table1
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName);
- JSONObject response = atlasClient.getInputGraph(datasetName);
- JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices");
+ ObjectNode response = atlasClient.getInputGraph(datasetName);
+ JsonNode vertices = response.get("values").get("vertices");
assertTrue(vertices.has(viewId));
assertTrue(vertices.has(table1Id));
@@ -398,7 +398,7 @@
datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName);
response = atlasClient.getInputGraph(datasetName);
- vertices = response.getJSONObject("values").getJSONObject("vertices");
+ vertices = response.get("values").get("vertices");
assertTrue(vertices.has(viewId));
//This is through the alter view process
@@ -409,8 +409,8 @@
//Outputs dont exist
response = atlasClient.getOutputGraph(datasetName);
- vertices = response.getJSONObject("values").getJSONObject("vertices");
- Assert.assertEquals(vertices.length(), 0);
+ vertices = response.get("values").get("vertices");
+ Assert.assertEquals(vertices.size(), 0);
}
private String createTestDFSFile(String path) throws Exception {
@@ -938,7 +938,7 @@
}
- private String createTrait(String guid) throws AtlasServiceException, JSONException {
+ private String createTrait(String guid) throws AtlasServiceException {
//add trait
//valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters
String traitName = "PII_Trait" + random();
@@ -949,7 +949,7 @@
return traitName;
}
- private void assertTrait(String guid, String traitName) throws AtlasServiceException, JSONException {
+ private void assertTrait(String guid, String traitName) throws AtlasServiceException {
List<String> traits = atlasClient.listTraits(guid);
Assert.assertEquals(traits.get(0), traitName);
}
@@ -1166,20 +1166,20 @@
Assert.assertEquals(bProcessInputsAsString, bLineageInputs);
//Test lineage API response
- JSONObject response = atlasClient.getInputGraphForEntity(dest_a_guid);
- JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices");
- JSONObject dest_a_val = (JSONObject) vertices.get(dest_a_guid);
- JSONObject src_a_val = (JSONObject) vertices.get(a_guid);
- JSONObject src_b_val = (JSONObject) vertices.get(b_guid);
+ ObjectNode response = atlasClient.getInputGraphForEntity(dest_a_guid);
+ JsonNode vertices = response.get("values").get("vertices");
+ JsonNode dest_a_val = vertices.get(dest_a_guid);
+ JsonNode src_a_val = vertices.get(a_guid);
+ JsonNode src_b_val = vertices.get(b_guid);
Assert.assertNotNull(dest_a_val);
Assert.assertNotNull(src_a_val);
Assert.assertNotNull(src_b_val);
- JSONObject b_response = atlasClient.getInputGraphForEntity(dest_b_guid);
- JSONObject b_vertices = b_response.getJSONObject("values").getJSONObject("vertices");
- JSONObject b_val = (JSONObject) b_vertices.get(dest_b_guid);
- JSONObject src_tbl_val = (JSONObject) b_vertices.get(sourceTableGUID);
+ ObjectNode b_response = atlasClient.getInputGraphForEntity(dest_b_guid);
+ JsonNode b_vertices = b_response.get("values").get("vertices");
+ JsonNode b_val = b_vertices.get(dest_b_guid);
+ JsonNode src_tbl_val = b_vertices.get(sourceTableGUID);
Assert.assertNotNull(b_val);
Assert.assertNotNull(src_tbl_val);
}
@@ -1197,8 +1197,8 @@
//Check lineage
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName);
- JSONObject response = atlasClient.getInputGraph(datasetName);
- JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices");
+ ObjectNode response = atlasClient.getInputGraph(datasetName);
+ JsonNode vertices = response.get("values").get("vertices");
//Below should be assertTrue - Fix https://issues.apache.org/jira/browse/ATLAS-653
Assert.assertFalse(vertices.has(tableId));
}
@@ -1841,14 +1841,14 @@
String table2Id = assertTableIsRegistered(db2, table2);
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, db2, table2);
- JSONObject response = atlasClient.getInputGraph(datasetName);
- JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices");
+ ObjectNode response = atlasClient.getInputGraph(datasetName);
+ JsonNode vertices = response.get("values").get("vertices");
assertTrue(vertices.has(table1Id));
assertTrue(vertices.has(table2Id));
datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, table1);
response = atlasClient.getOutputGraph(datasetName);
- vertices = response.getJSONObject("values").getJSONObject("vertices");
+ vertices = response.get("values").get("vertices");
assertTrue(vertices.has(table1Id));
assertTrue(vertices.has(table2Id));
}
diff --git a/addons/sqoop-bridge/src/test/java/org/apache/atlas/sqoop/hook/SqoopHookIT.java b/addons/sqoop-bridge/src/test/java/org/apache/atlas/sqoop/hook/SqoopHookIT.java
index b1bd115..e366937 100644
--- a/addons/sqoop-bridge/src/test/java/org/apache/atlas/sqoop/hook/SqoopHookIT.java
+++ b/addons/sqoop-bridge/src/test/java/org/apache/atlas/sqoop/hook/SqoopHookIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.sqoop.hook;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.hive.bridge.HiveMetaStoreBridge;
@@ -26,8 +28,6 @@
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.sqoop.SqoopJobDataPublisher;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -110,15 +110,15 @@
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
- JSONArray results = atlasClient.search(query, 10, 0);
- return results.length() > 0;
+ ArrayNode results = atlasClient.search(query, 10, 0);
+ return results.size() > 0;
}
});
- JSONArray results = atlasClient.search(query, 10, 0);
- JSONObject row = results.getJSONObject(0).getJSONObject("t");
+ ArrayNode results = atlasClient.search(query, 10, 0);
+ JsonNode row = results.get(0).get("t");
- return row.getString("id");
+ return row.get("id").asText();
}
protected void waitFor(int timeout, Predicate predicate) throws Exception {
diff --git a/addons/storm-bridge/src/test/java/org/apache/atlas/storm/hook/StormAtlasHookIT.java b/addons/storm-bridge/src/test/java/org/apache/atlas/storm/hook/StormAtlasHookIT.java
index 5fef38d..5024638 100644
--- a/addons/storm-bridge/src/test/java/org/apache/atlas/storm/hook/StormAtlasHookIT.java
+++ b/addons/storm-bridge/src/test/java/org/apache/atlas/storm/hook/StormAtlasHookIT.java
@@ -18,6 +18,8 @@
package org.apache.atlas.storm.hook;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.hive.bridge.HiveMetaStoreBridge;
@@ -27,8 +29,6 @@
import org.apache.commons.configuration.Configuration;
import org.apache.storm.ILocalCluster;
import org.apache.storm.generated.StormTopology;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -89,9 +89,9 @@
String query = String.format("from %s where name = \"%s\"",
StormDataTypes.STORM_TOPOLOGY.getName(), TOPOLOGY_NAME);
- JSONArray results = atlasClient.search(query, 10, 0);
- JSONObject row = results.getJSONObject(0);
+ ArrayNode results = atlasClient.search(query, 10, 0);
+ JsonNode row = results.get(0);
- return row.has("$id$") ? row.getJSONObject("$id$").getString("id"): null;
+ return row.has("$id$") ? row.get("$id$").get("id").asText() : null;
}
}
diff --git a/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
index 436d66b..dcb67da 100644
--- a/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
+++ b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
@@ -18,6 +18,8 @@
package org.apache.atlas;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.model.legacy.EntityResult;
@@ -27,14 +29,12 @@
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation;
-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;
@@ -42,6 +42,7 @@
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import java.io.IOException;
import java.util.*;
/**
@@ -252,11 +253,11 @@
*/
public List<String> createType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Creating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson);
- List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
+ ObjectNode response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson);
+ List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, ObjectNode>() {
@Override
- String extractElement(JSONObject element) throws JSONException {
- return element.getString(AtlasClient.NAME);
+ String extractElement(ObjectNode element) {
+ return element.get(AtlasClient.NAME).asText();
}
});
LOG.debug("Create type definition returned results: {}", results);
@@ -309,11 +310,11 @@
*/
public List<String> updateType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Updating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson);
- List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
+ ObjectNode response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson);
+ List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, ObjectNode>() {
@Override
- String extractElement(JSONObject element) throws JSONException {
- return element.getString(AtlasClient.NAME);
+ String extractElement(ObjectNode element) {
+ return element.get(AtlasClient.NAME).asText();
}
});
LOG.debug("Update type definition returned results: {}", results);
@@ -336,7 +337,7 @@
* @throws AtlasServiceException
*/
public List<String> listTypes() throws AtlasServiceException {
- final JSONObject jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null);
+ final ObjectNode jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null);
return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>());
}
@@ -348,7 +349,7 @@
*/
public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException {
final API api = API_V1.LIST_TYPES;
- JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api.getNormalizedPath());
@@ -374,7 +375,7 @@
public List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
final String notSupertype) throws AtlasServiceException {
final API api = API_V1.LIST_TYPES;
- JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api);
@@ -388,13 +389,9 @@
}
public TypesDef getType(String typeName) throws AtlasServiceException {
- try {
- JSONObject response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
- String typeJson = response.getString(DEFINITION);
- return AtlasType.fromV1Json(typeJson, TypesDef.class);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
+ String typeJson = response.get(DEFINITION).asText();
+ return AtlasType.fromV1Json(typeJson, TypesDef.class);
}
/**
@@ -403,15 +400,15 @@
* @return json array of guids
* @throws AtlasServiceException
*/
- protected List<String> createEntity(JSONArray entities) throws AtlasServiceException {
+ protected List<String> createEntity(ArrayNode entities) throws AtlasServiceException {
LOG.debug("Creating entities: {}", entities);
- JSONObject response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString());
+ ObjectNode response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString());
List<String> results = extractEntityResult(response).getCreatedEntities();
LOG.debug("Create entities returned results: {}", results);
return results;
}
- protected EntityResult extractEntityResult(JSONObject response) throws AtlasServiceException {
+ protected EntityResult extractEntityResult(ObjectNode response) throws AtlasServiceException {
return EntityResult.fromString(response.toString());
}
@@ -422,7 +419,11 @@
* @throws AtlasServiceException
*/
public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException {
- return createEntity(new JSONArray(Arrays.asList(entitiesAsJson)));
+ try {
+ return createEntity(AtlasJson.parseToV1ArrayNode(Arrays.asList(entitiesAsJson)));
+ } catch (IOException excp) {
+ throw new AtlasServiceException(excp);
+ }
}
public List<String> createEntity(Referenceable... entities) throws AtlasServiceException {
@@ -430,14 +431,14 @@
}
public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException {
- JSONArray entityArray = getEntitiesArray(entities);
+ ArrayNode entityArray = getEntitiesArray(entities);
return createEntity(entityArray);
}
- private JSONArray getEntitiesArray(Collection<Referenceable> entities) {
- JSONArray entityArray = new JSONArray(entities.size());
+ private ArrayNode getEntitiesArray(Collection<Referenceable> entities) {
+ ArrayNode entityArray = AtlasJson.createV1ArrayNode();
for (Referenceable entity : entities) {
- entityArray.put(AtlasType.toV1Json(entity));
+ entityArray.add(AtlasType.toV1Json(entity));
}
return entityArray;
}
@@ -453,16 +454,16 @@
return updateEntities(Arrays.asList(entities));
}
- protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException {
+ protected EntityResult updateEntities(ArrayNode entities) throws AtlasServiceException {
LOG.debug("Updating entities: {}", entities);
- JSONObject response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString());
+ ObjectNode response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString());
EntityResult results = extractEntityResult(response);
LOG.debug("Update entities returned results: {}", results);
return results;
}
public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException {
- JSONArray entitiesArray = getEntitiesArray(entities);
+ ArrayNode entitiesArray = getEntitiesArray(entities);
return updateEntities(entitiesArray);
}
@@ -477,7 +478,7 @@
throws AtlasServiceException {
LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value);
final API api = API_V1.UPDATE_ENTITY_PARTIAL;
- JSONObject response = callAPIWithRetries(api, value, new ResourceCreator() {
+ ObjectNode response = callAPIWithRetries(api, value, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api, guid);
@@ -497,7 +498,7 @@
public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException {
String entityJson = AtlasType.toV1Json(entity);
LOG.debug("Updating entity id {} with {}", guid, entityJson);
- JSONObject response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid);
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid);
return extractEntityResult(response);
}
@@ -538,7 +539,7 @@
String entityJson = AtlasType.toV1Json(entity);
LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType,
uniqueAttributeName, uniqueAttributeValue, entityJson);
- JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
+ ObjectNode response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api, QUALIFIED_NAME);
@@ -553,12 +554,8 @@
return result;
}
- protected String getString(JSONObject jsonObject, String parameter) throws AtlasServiceException {
- try {
- return jsonObject.getString(parameter);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ protected String getString(ObjectNode jsonObject, String parameter) throws AtlasServiceException {
+ return jsonObject.get(parameter).asText();
}
/**
@@ -571,7 +568,7 @@
public EntityResult deleteEntities(final String... guids) throws AtlasServiceException {
LOG.debug("Deleting entities: {}", guids);
final API api = API_V1.DELETE_ENTITIES;
- JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api);
@@ -602,7 +599,7 @@
resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
- JSONObject jsonResponse = callAPIWithResource(api, resource);
+ ObjectNode jsonResponse = callAPIWithResource(api, resource);
EntityResult results = extractEntityResult(jsonResponse);
LOG.debug("Delete entities returned results: {}", results);
return results;
@@ -615,19 +612,15 @@
* @throws AtlasServiceException
*/
public Referenceable getEntity(String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
- try {
- String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
- return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
- } catch (JSONException e) {
- throw new AtlasServiceException(API_V1.GET_ENTITY, e);
- }
+ ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
+ String entityInstanceDefinition = jsonResponse.get(AtlasClient.DEFINITION).asText();
+ return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
}
- public static String toString(JSONArray jsonArray) throws JSONException {
+ public static String toString(ArrayNode jsonArray) {
ArrayList<String> resultsList = new ArrayList<>();
- for (int index = 0; index < jsonArray.length(); index++) {
- resultsList.add(jsonArray.getString(index));
+ for (int index = 0; index < jsonArray.size(); index++) {
+ resultsList.add(jsonArray.get(index).asText());
}
return StringUtils.join(resultsList, ",");
}
@@ -643,7 +636,7 @@
public Referenceable getEntity(final String entityType, final String attribute, final String value)
throws AtlasServiceException {
final API api = API_V1.GET_ENTITY;
- JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api);
@@ -653,12 +646,8 @@
return resource;
}
});
- try {
- String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
- return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
- } catch (JSONException e) {
- throw new AtlasServiceException(api, e);
- }
+ String entityInstanceDefinition = jsonResponse.get(AtlasClient.DEFINITION).asText();
+ return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
}
/**
@@ -668,7 +657,7 @@
* @throws AtlasServiceException
*/
public List<String> listEntities(final String entityType) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() {
+ ObjectNode jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(API_V1.LIST_ENTITIES);
@@ -686,7 +675,7 @@
* @throws AtlasServiceException
*/
public List<String> listTraits(final String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS);
+ ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS);
return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
}
@@ -697,10 +686,10 @@
* @throws AtlasServiceException
*/
public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
- List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>());
+ ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
+ List<ObjectNode> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<ObjectNode, ObjectNode>());
ArrayList<Struct> traitStructList = new ArrayList<>();
- for (JSONObject traitDef : traitDefList) {
+ for (ObjectNode traitDef : traitDefList) {
Struct traitStruct = AtlasType.fromV1Json(traitDef.toString(), Struct.class);
traitStructList.add(traitStruct);
}
@@ -715,34 +704,26 @@
* @throws AtlasServiceException
*/
public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
+ ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
- try {
- return AtlasType.fromV1Json(jsonResponse.getString(AtlasClient.RESULTS), Struct.class);
- } catch (JSONException e) {
- throw new AtlasServiceException(API_V1.GET_TRAIT_DEFINITION, e);
- }
+ return AtlasType.fromV1Json(jsonResponse.get(AtlasClient.RESULTS).asText(), Struct.class);
}
protected class ExtractOperation<T, U> {
- T extractElement(U element) throws JSONException {
+ T extractElement(U element) {
return (T) element;
}
}
- protected <T, U> List<T> extractResults(JSONObject jsonResponse, String key, ExtractOperation<T, U> extractInterafce)
+ protected <T, U> List<T> extractResults(ObjectNode jsonResponse, String key, ExtractOperation<T, U> extractInterafce)
throws AtlasServiceException {
- try {
- JSONArray results = jsonResponse.getJSONArray(key);
- ArrayList<T> resultsList = new ArrayList<>();
- for (int index = 0; index < results.length(); index++) {
- Object element = results.get(index);
- resultsList.add(extractInterafce.extractElement((U) element));
- }
- return resultsList;
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
+ ArrayNode results = (ArrayNode)jsonResponse.get(key);
+ ArrayList<T> resultsList = new ArrayList<>();
+ for (int index = 0; index < results.size(); index++) {
+ Object element = results.get(index);
+ resultsList.add(extractInterafce.extractElement((U) element));
}
+ return resultsList;
}
/**
@@ -773,10 +754,10 @@
}
resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
- JSONObject jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource);
- return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() {
+ ObjectNode jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource);
+ return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, ObjectNode>() {
@Override
- EntityAuditEvent extractElement(JSONObject element) throws JSONException {
+ EntityAuditEvent extractElement(ObjectNode element) {
return AtlasType.fromV1Json(element.toString(), EntityAuditEvent.class);
}
});
@@ -791,9 +772,9 @@
* @return Query results
* @throws AtlasServiceException
*/
- public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
+ public ArrayNode search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
final API api = API_V1.SEARCH;
- JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api);
@@ -803,12 +784,7 @@
return resource;
}
});
- try {
- return result.getJSONArray(RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
-
+ return (ArrayNode)result.get(RESULTS);
}
/**
@@ -819,10 +795,10 @@
* @return result json object
* @throws AtlasServiceException
*/
- public JSONArray searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
+ public ArrayNode searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
LOG.debug("DSL query: {}", query);
final API api = API_V1.SEARCH_DSL;
- JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
+ ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
WebResource resource = getResource(api);
@@ -832,11 +808,7 @@
return resource;
}
});
- try {
- return result.getJSONArray(RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ return (ArrayNode)result.get(RESULTS);
}
/**
@@ -847,7 +819,7 @@
* @return result json object
* @throws AtlasServiceException
*/
- public JSONObject searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
+ public ObjectNode searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
final API api = API_V1.SEARCH_FULL_TEXT;
return callAPIWithRetries(api, null, new ResourceCreator() {
@Override
@@ -861,60 +833,40 @@
});
}
- public JSONObject getInputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ public ObjectNode getInputGraph(String datasetName) throws AtlasServiceException {
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
+ return (ObjectNode)response.get(AtlasClient.RESULTS);
}
- public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ public ObjectNode getOutputGraph(String datasetName) throws AtlasServiceException {
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
+ return (ObjectNode)response.get(AtlasClient.RESULTS);
}
- public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ public ObjectNode getInputGraphForEntity(String entityId) throws AtlasServiceException {
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
+ return (ObjectNode)response.get(AtlasClient.RESULTS);
}
- public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ public ObjectNode getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
+ return (ObjectNode) response.get(AtlasClient.RESULTS);
}
- public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
+ public ObjectNode getSchemaForEntity(String datasetId) throws AtlasServiceException {
+ ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
+ return (ObjectNode) response.get(AtlasClient.RESULTS);
}
// Wrapper methods for compatibility
@VisibleForTesting
- public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
- return callAPIWithResource(api, resource, null, JSONObject.class);
+ public ObjectNode callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
+ return callAPIWithResource(api, resource, null, ObjectNode.class);
}
@VisibleForTesting
- public JSONObject callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException {
- return callAPIWithResource(apiV1, resource, null, JSONObject.class);
+ public ObjectNode callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException {
+ return callAPIWithResource(apiV1, resource, null, ObjectNode.class);
}
@VisibleForTesting
@@ -928,42 +880,42 @@
}
@VisibleForTesting
- public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
- return callAPI(api, JSONObject.class, requestObject, (String[]) null);
+ public ObjectNode callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
+ return callAPI(api, ObjectNode.class, requestObject, (String[]) null);
}
@VisibleForTesting
- public JSONObject callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException {
- return callAPI(apiV1, JSONObject.class, requestObject, (String[]) null);
+ public ObjectNode callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException {
+ return callAPI(apiV1, ObjectNode.class, requestObject, (String[]) null);
}
@VisibleForTesting
- public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException {
- return callAPI(api, JSONObject.class, requestObject, params);
+ public ObjectNode callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(api, ObjectNode.class, requestObject, params);
}
@VisibleForTesting
- public JSONObject callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException {
- return callAPI(apiV1, JSONObject.class, requestObject, params);
+ public ObjectNode callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(apiV1, ObjectNode.class, requestObject, params);
}
@VisibleForTesting
- public JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
- return callAPI(api, JSONObject.class, queryParams);
+ public ObjectNode callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
+ return callAPI(api, ObjectNode.class, queryParams);
}
@VisibleForTesting
- public JSONObject callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
- return callAPI(apiV1, JSONObject.class, queryParams);
+ public ObjectNode callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
+ return callAPI(apiV1, ObjectNode.class, queryParams);
}
@VisibleForTesting
- JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
+ ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
return super.callAPIWithRetries(api, requestObject, resourceCreator);
}
@VisibleForTesting
- JSONObject callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
+ ObjectNode callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
return super.callAPIWithRetries(apiV1, requestObject, resourceCreator);
}
}
diff --git a/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
index 5287af4..0bd66fe 100644
--- a/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
+++ b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
@@ -17,6 +17,8 @@
package org.apache.atlas;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
@@ -26,7 +28,6 @@
import org.apache.atlas.type.AtlasType;
import org.apache.commons.configuration.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONObject;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -96,9 +97,6 @@
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
- JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString());
- when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
- when(response.getLength()).thenReturn(jsonResponse.length());
String entityJson = AtlasType.toV1Json(new Referenceable("type"));
when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
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 aa1c773..4da66bb 100644
--- a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -17,6 +17,8 @@
*/
package org.apache.atlas;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
@@ -35,12 +37,11 @@
import org.apache.atlas.model.metrics.AtlasMetrics;
import org.apache.atlas.security.SecureClientUtils;
import org.apache.atlas.type.AtlasType;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -163,7 +164,7 @@
public boolean isServerReady() throws AtlasServiceException {
WebResource resource = getResource(API_VERSION.getNormalizedPath());
try {
- callAPIWithResource(API_VERSION, resource, null, JSONObject.class);
+ callAPIWithResource(API_VERSION, resource, null, ObjectNode.class);
return true;
} catch (ClientHandlerException che) {
return false;
@@ -186,12 +187,10 @@
public String getAdminStatus() throws AtlasServiceException {
String result = AtlasBaseClient.UNKNOWN_STATUS;
WebResource resource = getResource(service, API_STATUS.getNormalizedPath());
- JSONObject response = callAPIWithResource(API_STATUS, resource, null, JSONObject.class);
- try {
- result = response.getString("Status");
- } catch (JSONException e) {
- LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
- }
+ ObjectNode response = callAPIWithResource(API_STATUS, resource, null, ObjectNode.class);
+
+ result = response.get("Status").asText();
+
return result;
}
@@ -355,14 +354,14 @@
return null;
}
try {
- if (responseType.getRawClass().equals(JSONObject.class)) {
+ if (responseType.getRawClass().equals(ObjectNode.class)) {
String stringEntity = clientResponse.getEntity(String.class);
try {
- JSONObject jsonObject = new JSONObject(stringEntity);
+ JsonNode jsonObject = AtlasJson.parseToV1JsonNode(stringEntity);
LOG.debug("Response = {}", jsonObject);
LOG.info("------------------------------------------------------");
return (T) jsonObject;
- } catch (JSONException e) {
+ } catch (IOException e) {
throw new AtlasServiceException(api, e);
}
} else {
@@ -462,13 +461,13 @@
}
@VisibleForTesting
- JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator)
+ ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator)
throws AtlasServiceException {
for (int i = 0; i < getNumberOfRetries(); i++) {
WebResource resource = resourceCreator.createResource();
try {
LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1);
- return callAPIWithResource(api, resource, requestObject, JSONObject.class);
+ return callAPIWithResource(api, resource, requestObject, ObjectNode.class);
} catch (ClientHandlerException che) {
if (i == (getNumberOfRetries() - 1)) {
throw che;
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
index 33d0a21..6b4dd11 100755
--- a/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
@@ -19,10 +19,6 @@
package org.apache.atlas;
import com.sun.jersey.api.client.ClientResponse;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-
-import javax.ws.rs.WebApplicationException;
public class AtlasServiceException extends Exception {
private ClientResponse.Status status;
@@ -31,11 +27,6 @@
super("Metadata service API " + api.getMethod() + " : " + api.getNormalizedPath() + " failed", e);
}
- public AtlasServiceException(AtlasBaseClient.API api, WebApplicationException e) throws JSONException {
- this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
- ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
- }
-
private AtlasServiceException(AtlasBaseClient.API api, ClientResponse.Status status, String response) {
super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
+ " (" + status + ") Response Body (" + response + ")");
diff --git a/common/pom.xml b/common/pom.xml
index 08c6b6e..29ce58e 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -98,6 +98,10 @@
<scope>compile</scope>
<exclusions>
<exclusion>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ <exclusion>
<groupId>info.ganglia.gmetric4j</groupId>
<artifactId>gmetric4j</artifactId>
</exclusion>
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasType.java b/intg/src/main/java/org/apache/atlas/type/AtlasType.java
index d432496..47db2c0 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasType.java
@@ -18,30 +18,15 @@
package org.apache.atlas.type;
-import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
-import org.apache.atlas.model.notification.EntityNotification;
-import org.apache.atlas.model.notification.EntityNotification.EntityNotificationType;
-import org.apache.atlas.model.notification.HookNotification;
-import org.apache.atlas.model.notification.HookNotification.HookNotificationType;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
-import org.apache.atlas.v1.model.instance.Struct;
-import org.apache.atlas.v1.model.notification.EntityNotificationV1;
-import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest;
-import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityDeleteRequest;
-import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUpdateRequest;
-import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest;
-import org.apache.atlas.v1.model.notification.HookNotificationV1.TypeRequest;
+import org.apache.atlas.utils.AtlasJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
-import java.text.ParseException;
-import java.util.Date;
import java.util.List;
@@ -50,24 +35,7 @@
*/
public abstract class AtlasType {
- private static final Logger LOG = LoggerFactory.getLogger(AtlasStructType.class);
-
- private static final ObjectMapper mapper = new ObjectMapper()
- .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
-
- private static final ObjectMapper mapperV1 = new ObjectMapper()
- .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
-
- static {
- SimpleModule atlasSerDeModule = new SimpleModule("AtlasSerDe", new Version(1, 0, 0, null));
-
- atlasSerDeModule.addSerializer(Date.class, new DateSerializer());
- atlasSerDeModule.addDeserializer(Date.class, new DateDeserializer());
- atlasSerDeModule.addDeserializer(HookNotification.class, new HookNotificationDeserializer());
- atlasSerDeModule.addDeserializer(EntityNotification.class, new EntityNotificationDeserializer());
-
- mapperV1.registerModule(atlasSerDeModule);
- }
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasType.class);
private final String typeName;
@@ -135,155 +103,24 @@
return this;
}
- public static String toJson(Object obj) {
- String ret;
- try {
- ret = mapper.writeValueAsString(obj);
- }catch (IOException e){
- LOG.error("AtlasType.toJson()", e);
- ret = null;
- }
- return ret;
+ public static String toJson(Object obj) {
+ return AtlasJson.toJson(obj);
}
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);
-
- ret = null;
- }
- return ret;
+ return AtlasJson.fromJson(jsonStr, type);
}
public static String toV1Json(Object obj) {
- String ret;
- try {
- ret = mapperV1.writeValueAsString(obj);
- }catch (IOException e){
- LOG.error("AtlasType.toV1Json()", e);
-
- ret = null;
- }
- return ret;
+ return AtlasJson.toV1Json(obj);
}
public static <T> T fromV1Json(String jsonStr, Class<T> type) {
- T ret;
- try {
- ret = mapperV1.readValue(jsonStr, type);
-
- if (ret instanceof Struct) {
- ((Struct) ret).normalize();
- }
- }catch (IOException e){
- LOG.error("AtlasType.fromV1Json()", e);
-
- ret = null;
- }
- return ret;
+ return AtlasJson.fromV1Json(jsonStr, type);
}
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);
-
- ret = null;
- }
- return ret;
- }
-
- static class DateSerializer extends JsonSerializer<Date> {
- @Override
- public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
- if (value != null) {
- jgen.writeString(AtlasBaseTypeDef.DATE_FORMATTER.format(value));
- }
- }
- }
-
- static class DateDeserializer extends JsonDeserializer<Date> {
- @Override
- public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException {
- Date ret = null;
-
- String value = parser.readValueAs(String.class);
-
- if (value != null) {
- try {
- ret = AtlasBaseTypeDef.DATE_FORMATTER.parse(value);
- } catch (ParseException excp) {
- }
- }
-
- return ret;
- }
- }
-
- static class HookNotificationDeserializer extends JsonDeserializer<HookNotification> {
- @Override
- public HookNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
- HookNotification ret = null;
- ObjectCodec mapper = parser.getCodec();
- TreeNode root = mapper.readTree(parser);
- JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
- String strType = typeNode != null ? typeNode.asText() : null;
- HookNotificationType notificationType = strType != null ? HookNotificationType.valueOf(strType) : null;
-
- if (notificationType != null) {
- switch (notificationType) {
- case TYPE_CREATE:
- case TYPE_UPDATE:
- ret = mapper.treeToValue(root, TypeRequest.class);
- break;
-
- case ENTITY_CREATE:
- ret = mapper.treeToValue(root, EntityCreateRequest.class);
- break;
-
- case ENTITY_PARTIAL_UPDATE:
- ret = mapper.treeToValue(root, EntityPartialUpdateRequest.class);
- break;
-
- case ENTITY_FULL_UPDATE:
- ret = mapper.treeToValue(root, EntityUpdateRequest.class);
- break;
-
- case ENTITY_DELETE:
- ret = mapper.treeToValue(root, EntityDeleteRequest.class);
- break;
- }
- }
-
- return ret;
- }
- }
-
- static class EntityNotificationDeserializer extends JsonDeserializer<EntityNotification> {
- @Override
- public EntityNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
- EntityNotification ret = null;
- ObjectCodec mapper = parser.getCodec();
- TreeNode root = mapper.readTree(parser);
- JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
- String strType = typeNode != null ? typeNode.asText() : null;
- EntityNotificationType notificationType = strType != null ? EntityNotificationType.valueOf(strType) : EntityNotificationType.ENTITY_NOTIFICATION_V1;
-
- if (root != null) {
- switch (notificationType) {
- case ENTITY_NOTIFICATION_V1:
- ret = mapper.treeToValue(root, EntityNotificationV1.class);
- break;
- }
- }
-
- return ret;
- }
+ return AtlasJson.fromV1Json(jsonStr, type);
}
}
diff --git a/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
new file mode 100644
index 0000000..ec185d2
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
@@ -0,0 +1,273 @@
+/**
+ * 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.utils;
+
+
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.atlas.model.notification.EntityNotification;
+import org.apache.atlas.model.notification.EntityNotification.EntityNotificationType;
+import org.apache.atlas.model.notification.HookNotification;
+import org.apache.atlas.model.notification.HookNotification.HookNotificationType;
+import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.apache.atlas.v1.model.instance.Struct;
+import org.apache.atlas.v1.model.notification.EntityNotificationV1;
+import org.apache.atlas.v1.model.notification.HookNotificationV1.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+
+public class AtlasJson {
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasJson.class);
+
+ private static final ObjectMapper mapper = new ObjectMapper()
+ .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
+
+ private static final ObjectMapper mapperV1 = new ObjectMapper()
+ .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
+
+ static {
+ SimpleModule atlasSerDeModule = new SimpleModule("AtlasSerDe", new Version(1, 0, 0, null));
+
+ atlasSerDeModule.addSerializer(Date.class, new DateSerializer());
+ atlasSerDeModule.addDeserializer(Date.class, new DateDeserializer());
+ atlasSerDeModule.addDeserializer(HookNotification.class, new HookNotificationDeserializer());
+ atlasSerDeModule.addDeserializer(EntityNotification.class, new EntityNotificationDeserializer());
+
+ mapperV1.registerModule(atlasSerDeModule);
+ }
+
+ public static String toJson(Object obj) {
+ String ret;
+ try {
+ ret = mapper.writeValueAsString(obj);
+ }catch (IOException e){
+ LOG.error("AtlasJson.toJson()", e);
+
+ ret = null;
+ }
+ return ret;
+ }
+
+ 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);
+
+ ret = null;
+ }
+ return ret;
+ }
+
+ public static String toV1Json(Object obj) {
+ String ret;
+ try {
+ ret = mapperV1.writeValueAsString(obj);
+ }catch (IOException e){
+ LOG.error("AtlasType.toV1Json()", e);
+
+ ret = null;
+ }
+ return ret;
+ }
+
+ public static <T> T fromV1Json(String jsonStr, Class<T> type) {
+ T ret;
+ try {
+ ret = mapperV1.readValue(jsonStr, type);
+
+ 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);
+
+ ret = null;
+ }
+ return ret;
+ }
+
+
+ public static ObjectNode createV1ObjectNode() {
+ return mapperV1.createObjectNode();
+ }
+
+ public static ObjectNode createV1ObjectNode(String key, Object value) {
+ ObjectNode ret = mapperV1.createObjectNode();
+
+ ret.putPOJO(key, value);
+
+ return ret;
+ }
+
+ public static ArrayNode createV1ArrayNode() {
+ return mapperV1.createArrayNode();
+ }
+
+ public static ArrayNode createV1ArrayNode(Collection<?> array) {
+ ArrayNode ret = mapperV1.createArrayNode();
+
+ for (Object elem : array) {
+ ret.addPOJO(elem);
+ }
+
+ return ret;
+ }
+
+
+ public static JsonNode parseToV1JsonNode(String json) throws IOException {
+ JsonNode jsonNode = mapperV1.readTree(json);
+
+ return jsonNode;
+ }
+
+ public static ArrayNode parseToV1ArrayNode(String json) throws IOException {
+ JsonNode jsonNode = mapperV1.readTree(json);
+
+ if (jsonNode instanceof ArrayNode) {
+ return (ArrayNode)jsonNode;
+ }
+
+ throw new IOException("not an array");
+ }
+
+ public static ArrayNode parseToV1ArrayNode(Collection<String> jsonStrings) throws IOException {
+ ArrayNode ret = createV1ArrayNode();
+
+ for (String json : jsonStrings) {
+ JsonNode jsonNode = mapperV1.readTree(json);
+
+ ret.add(jsonNode);
+ }
+
+ return ret;
+ }
+
+ static class DateSerializer extends JsonSerializer<Date> {
+ @Override
+ public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ jgen.writeString(AtlasBaseTypeDef.DATE_FORMATTER.format(value));
+ }
+ }
+ }
+
+ static class DateDeserializer extends JsonDeserializer<Date> {
+ @Override
+ public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException {
+ Date ret = null;
+
+ String value = parser.readValueAs(String.class);
+
+ if (value != null) {
+ try {
+ ret = AtlasBaseTypeDef.DATE_FORMATTER.parse(value);
+ } catch (ParseException excp) {
+ }
+ }
+
+ return ret;
+ }
+ }
+
+ static class HookNotificationDeserializer extends JsonDeserializer<HookNotification> {
+ @Override
+ public HookNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
+ HookNotification ret = null;
+ ObjectCodec mapper = parser.getCodec();
+ TreeNode root = mapper.readTree(parser);
+ JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
+ String strType = typeNode != null ? typeNode.asText() : null;
+ HookNotificationType notificationType = strType != null ? HookNotificationType.valueOf(strType) : null;
+
+ if (notificationType != null) {
+ switch (notificationType) {
+ case TYPE_CREATE:
+ case TYPE_UPDATE:
+ ret = mapper.treeToValue(root, TypeRequest.class);
+ break;
+
+ case ENTITY_CREATE:
+ ret = mapper.treeToValue(root, EntityCreateRequest.class);
+ break;
+
+ case ENTITY_PARTIAL_UPDATE:
+ ret = mapper.treeToValue(root, EntityPartialUpdateRequest.class);
+ break;
+
+ case ENTITY_FULL_UPDATE:
+ ret = mapper.treeToValue(root, EntityUpdateRequest.class);
+ break;
+
+ case ENTITY_DELETE:
+ ret = mapper.treeToValue(root, EntityDeleteRequest.class);
+ break;
+ }
+ }
+
+ return ret;
+ }
+ }
+
+ static class EntityNotificationDeserializer extends JsonDeserializer<EntityNotification> {
+ @Override
+ public EntityNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
+ EntityNotification ret = null;
+ ObjectCodec mapper = parser.getCodec();
+ TreeNode root = mapper.readTree(parser);
+ JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
+ String strType = typeNode != null ? typeNode.asText() : null;
+ EntityNotificationType notificationType = strType != null ? EntityNotificationType.valueOf(strType) : EntityNotificationType.ENTITY_NOTIFICATION_V1;
+
+ if (root != null) {
+ switch (notificationType) {
+ case ENTITY_NOTIFICATION_V1:
+ ret = mapper.treeToValue(root, EntityNotificationV1.class);
+ break;
+ }
+ }
+
+ return ret;
+ }
+ }
+}
diff --git a/pom.xml b/pom.xml
index 49ab88a..e94f5dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1057,18 +1057,6 @@
<dependency>
<groupId>com.sun.jersey</groupId>
- <artifactId>jersey-json</artifactId>
- <version>${jersey.version}</version>
- <exclusions>
- <exclusion>
- <groupId>javax.xml.stream</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
@@ -1160,6 +1148,10 @@
</exclusion>
<exclusion>
<artifactId>*</artifactId>
+ <groupId>org.codehaus.jackson</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>*</artifactId>
<groupId>org.mortbay.jetty</groupId>
</exclusion>
<exclusion>
diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/LocalSolrTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/LocalSolrTest.java
index 1fbca80..f641a57 100644
--- a/repository/src/test/java/org/apache/atlas/repository/impexp/LocalSolrTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/impexp/LocalSolrTest.java
@@ -22,10 +22,10 @@
import org.apache.atlas.runner.LocalSolrRunner;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.configuration.Configuration;
-import org.junit.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import org.testng.Assert;
import javax.inject.Inject;
@@ -64,4 +64,4 @@
System.out.println("Stopping Local Solr...");
LocalSolrRunner.stop();
}
-}
\ No newline at end of file
+}
diff --git a/webapp/pom.xml b/webapp/pom.xml
index 3fdce11..475ed7d 100755
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -232,11 +232,6 @@
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-json</artifactId>
- </dependency>
-
- <dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
</dependency>
diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
index 0e2d32d..3449ece 100755
--- a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
+++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
@@ -18,6 +18,7 @@
package org.apache.atlas.examples;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.atlas.ApplicationProperties;
@@ -33,7 +34,6 @@
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration;
-import org.codehaus.jettison.json.JSONArray;
import java.util.Arrays;
import java.util.Collections;
@@ -478,9 +478,9 @@
private void search() throws AtlasBaseException {
try {
for (String dslQuery : getDSLQueries()) {
- JSONArray results = metadataServiceClient.search(dslQuery, 10, 0);
+ ArrayNode results = metadataServiceClient.search(dslQuery, 10, 0);
if (results != null) {
- System.out.println("query [" + dslQuery + "] returned [" + results.length() + "] rows");
+ System.out.println("query [" + dslQuery + "] returned [" + results.size() + "] rows");
} else {
System.out.println("query [" + dslQuery + "] failed, results:" + results);
}
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 de77c51..c21dff4 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,6 +18,7 @@
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;
@@ -39,6 +40,7 @@
import org.apache.atlas.services.MetricsService;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.util.SearchTracker;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter;
import org.apache.atlas.web.service.ServiceState;
import org.apache.atlas.web.util.Servlets;
@@ -46,8 +48,6 @@
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
@@ -186,7 +186,7 @@
try {
PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties");
- JSONObject response = new JSONObject();
+ ObjectNode response = AtlasJson.createV1ObjectNode();
response.put("Version", configProperties.getString("build.version", "UNKNOWN"));
response.put("Name", configProperties.getString("project.name", "apache-atlas"));
response.put("Description", configProperties.getString("project.description",
@@ -195,7 +195,7 @@
// todo: add hadoop version?
// response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision());
version = Response.ok(response).build();
- } catch (JSONException | ConfigurationException e) {
+ } catch (ConfigurationException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
@@ -215,15 +215,8 @@
LOG.debug("==> AdminResource.getStatus()");
}
- Response response;
-
- try {
- JSONObject responseData = new JSONObject();
- responseData.put(AtlasClient.STATUS, serviceState.getState().toString());
- response = Response.ok(responseData).build();
- } catch (JSONException e) {
- throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
- }
+ ObjectNode responseData = AtlasJson.createV1ObjectNode(AtlasClient.STATUS, serviceState.getState().toString());
+ Response response = Response.ok(responseData).build();
if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getStatus()");
@@ -241,42 +234,39 @@
}
Response response;
- try {
- boolean isEntityUpdateAccessAllowed = false;
- boolean isEntityCreateAccessAllowed = false;
- Authentication auth = SecurityContextHolder.getContext().getAuthentication();
- String userName = null;
- Set<String> groups = new HashSet<>();
- if (auth != null) {
- userName = auth.getName();
- Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
- for (GrantedAuthority c : authorities) {
- groups.add(c.getAuthority());
- }
- isEntityUpdateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
- AtlasActionTypes.UPDATE, userName, groups, httpServletRequest);
- isEntityCreateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
- AtlasActionTypes.CREATE, userName, groups, httpServletRequest);
+ boolean isEntityUpdateAccessAllowed = false;
+ boolean isEntityCreateAccessAllowed = false;
+ Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+ String userName = null;
+ Set<String> groups = new HashSet<>();
+ if (auth != null) {
+ userName = auth.getName();
+ Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
+ for (GrantedAuthority c : authorities) {
+ groups.add(c.getAuthority());
}
- JSONObject responseData = new JSONObject();
-
- responseData.put(isCSRF_ENABLED, AtlasCSRFPreventionFilter.isCSRF_ENABLED);
- responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT);
- responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT);
- responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT);
- responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed);
- responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
- responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties));
- responseData.put("userName", userName);
- responseData.put("groups", groups);
-
- response = Response.ok(responseData).build();
- } catch (JSONException e) {
- throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
+ isEntityUpdateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
+ AtlasActionTypes.UPDATE, userName, groups, httpServletRequest);
+ isEntityCreateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
+ AtlasActionTypes.CREATE, userName, groups, httpServletRequest);
}
+ ObjectNode responseData = AtlasJson.createV1ObjectNode();
+
+ responseData.put(isCSRF_ENABLED, AtlasCSRFPreventionFilter.isCSRF_ENABLED);
+ responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT);
+ responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT);
+ responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT);
+ responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed);
+ responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
+ responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties));
+ responseData.put("userName", userName);
+ responseData.put("groups", AtlasJson.createV1ArrayNode(groups));
+
+ response = Response.ok(responseData).build();
+
if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getUserProfile()");
}
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.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.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.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 @@
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 @@
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 @@
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 @@
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);
- for (int i = 0; i < jsonEntities.length(); i++) {
- jsonStrings[i] = jsonEntities.getString(i);
+ ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
+ String[] jsonStrings = new String[jsonEntities.size()];
+
+ for (int i = 0; i < jsonEntities.size(); i++) {
+ jsonStrings[i] = jsonEntities.get(i).asText();
}
if (LOG.isDebugEnabled()) {
@@ -281,7 +280,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
}
- 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 @@
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;
}
}
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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
@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;
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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());
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");
+ }
+}
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.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 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 {
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 @@
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 @@
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 @@
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 @@
}
@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);
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.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 @@
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 @@
}
@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 @@
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 @@
}
}
- 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 @@
}
@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 @@
}
@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();
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.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 @@
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 @@
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 @@
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 @@
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;
}
});
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 @@
@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"));
}
}
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.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 @@
};
}
- protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException {
+ protected ArrayNode searchByDSL(String dslQuery) throws AtlasServiceException {
return atlasClientV1.searchByDSL(dslQuery, 10, 0);
}
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.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 @@
@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 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 @@
@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 @@
@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 @@
@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 {
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.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 @@
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 @@
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 @@
@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 @@
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 @@
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 @@
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 @@
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()));
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.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 @@
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 @@
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 @@
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);
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.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 @@
@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 @@
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)
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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 {
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.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 @@
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 @@
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 @@
@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 @@
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
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
index c0bbf09..3c5d031 100644
--- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
@@ -18,9 +18,8 @@
package org.apache.atlas.web.resources;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.web.service.ServiceState;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
@@ -44,27 +43,27 @@
}
@Test
- public void testStatusOfActiveServerIsReturned() throws JSONException {
+ public void testStatusOfActiveServerIsReturned() {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE);
AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
Response response = adminResource.getStatus();
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
- JSONObject entity = (JSONObject) response.getEntity();
- assertEquals(entity.get("Status"), "ACTIVE");
+ ObjectNode entity = (ObjectNode) response.getEntity();
+ assertEquals(entity.get("Status").asText(), "ACTIVE");
}
@Test
- public void testResourceGetsValueFromServiceState() throws JSONException {
+ public void testResourceGetsValueFromServiceState() {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
Response response = adminResource.getStatus();
verify(serviceState).getState();
- JSONObject entity = (JSONObject) response.getEntity();
- assertEquals(entity.get("Status"), "PASSIVE");
+ ObjectNode entity = (ObjectNode) response.getEntity();
+ assertEquals(entity.get("Status").asText(), "PASSIVE");
}
}
\ No newline at end of file
diff --git a/webapp/src/test/java/org/apache/atlas/web/util/ServletsTest.java b/webapp/src/test/java/org/apache/atlas/web/util/ServletsTest.java
index e732dbf..4c07953 100644
--- a/webapp/src/test/java/org/apache/atlas/web/util/ServletsTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/util/ServletsTest.java
@@ -18,8 +18,8 @@
package org.apache.atlas.web.util;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
-import org.codehaus.jettison.json.JSONObject;
import org.testng.annotations.Test;
import javax.ws.rs.core.Response;
@@ -33,8 +33,8 @@
Response response =
Servlets.getErrorResponse(new NullPointerException(), Response.Status.INTERNAL_SERVER_ERROR);
assertNotNull(response);
- JSONObject responseEntity = (JSONObject) response.getEntity();
+ ObjectNode responseEntity = (ObjectNode) response.getEntity();
assertNotNull(responseEntity);
- assertNotNull(responseEntity.getString(AtlasClient.ERROR));
+ assertNotNull(responseEntity.get(AtlasClient.ERROR));
}
}