Commit 1f8e2146 by Madhan Neethiraj

ATLAS-2292: remove older version jackson libraries from packaging

parent d1aa36c4
......@@ -31,7 +31,6 @@ import org.apache.hadoop.hive.ql.metadata.HiveException;
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 @@ public class HiveMetaStoreBridgeTest {
}
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 @@ public class HiveMetaStoreBridgeTest {
}
}
private Referenceable getEntityReference(String typeName, String id) throws JSONException {
private Referenceable getEntityReference(String typeName, String id) {
return new Referenceable(id, typeName, null);
}
......
......@@ -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.metadata.Table;
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 @@ public class HiveHookIT extends HiveITBase {
//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 @@ public class HiveHookIT extends HiveITBase {
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 @@ public class HiveHookIT extends HiveITBase {
//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 @@ public class HiveHookIT extends HiveITBase {
}
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 @@ public class HiveHookIT extends HiveITBase {
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 @@ public class HiveHookIT extends HiveITBase {
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 @@ public class HiveHookIT extends HiveITBase {
//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 @@ public class HiveHookIT extends HiveITBase {
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));
}
......
......@@ -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.sqoop.model.SqoopDataTypes;
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 @@ public class SqoopHookIT {
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 {
......
......@@ -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.atlas.utils.AuthenticationUtil;
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 @@ public class StormAtlasHookIT {
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;
}
}
......@@ -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.v1.model.instance.Referenceable;
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 @@ public class AtlasClientTest {
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);
......
......@@ -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.impexp.AtlasImportResult;
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 abstract class AtlasBaseClient {
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 abstract class AtlasBaseClient {
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 @@ public abstract class AtlasBaseClient {
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 @@ public abstract class AtlasBaseClient {
}
@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;
......
......@@ -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 @@ public class AtlasServiceException extends Exception {
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 + ")");
......
......@@ -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>
......
......@@ -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 @@ import java.util.List;
*/
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 @@ public abstract class AtlasType {
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);
}
}
/**
* 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;
}
}
}
......@@ -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>
......
......@@ -22,10 +22,10 @@ import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
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 @@ public class LocalSolrTest {
System.out.println("Stopping Local Solr...");
LocalSolrRunner.stop();
}
}
\ No newline at end of file
}
......@@ -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>
......
......@@ -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.type.AtlasType;
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 @@ public class QuickStart {
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);
}
......
......@@ -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.repository.impexp.ZipSource;
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.Configuration;
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 @@ public class AdminResource {
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 @@ public class AdminResource {
// 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 @@ public class AdminResource {
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 @@ public class AdminResource {
}
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()");
}
......
......@@ -18,18 +18,18 @@
package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.query.QueryParams;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
......@@ -44,6 +44,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -150,7 +151,7 @@ public class MetadataDiscoveryResource {
QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByDSL(dslQuery, queryParams);
JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
ObjectNode response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
......@@ -222,17 +223,13 @@ public class MetadataDiscoveryResource {
gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
final List<Map<String, String>> results = new ArrayList<>(); // TODO-typeSystem-removal: discoveryService.searchByGremlin(gremlinQuery);
JSONObject response = new JSONObject();
ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.QUERY, gremlinQuery);
response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN);
JSONArray list = new JSONArray();
for (Map<String, String> result : results) {
list.put(new JSONObject(result));
}
response.put(AtlasClient.RESULTS, list);
response.put(AtlasClient.COUNT, list.length());
response.putPOJO(AtlasClient.RESULTS, results);
response.put(AtlasClient.COUNT, results.size());
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
......@@ -281,9 +278,9 @@ public class MetadataDiscoveryResource {
query = ParamChecker.notEmpty(query, "query cannot be null or empty");
QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByFullText(query, queryParams);
JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
ArrayNode rowsJsonArr = AtlasJson.parseToV1ArrayNode(jsonResultStr);
JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
ObjectNode response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
return Response.ok(response).build();
} catch (IllegalArgumentException e) {
LOG.error("Unable to get entity list for query {}", query, e);
......@@ -308,10 +305,10 @@ public class MetadataDiscoveryResource {
protected int count = 0;
protected String query;
protected String queryType;
protected JSONObject response;
protected ObjectNode response;
JsonResponseBuilder() {
this.response = new JSONObject();
this.response = AtlasJson.createV1ObjectNode();
}
protected JsonResponseBuilder count(int count) {
......@@ -329,7 +326,7 @@ public class MetadataDiscoveryResource {
return this;
}
protected JSONObject build() throws JSONException {
protected ObjectNode build() {
Preconditions.checkNotNull(query, "Query cannot be null");
Preconditions.checkNotNull(queryType, "Query Type must be specified");
......@@ -349,25 +346,24 @@ public class MetadataDiscoveryResource {
super();
}
private JSONObject dslResults;
private ArrayNode dslResults;
public DSLJSONResponseBuilder results(JSONObject dslResults) {
public DSLJSONResponseBuilder results(ArrayNode dslResults) {
this.dslResults = dslResults;
return this;
}
public DSLJSONResponseBuilder results(String dslResults) throws JSONException {
return results(new JSONObject(dslResults));
public DSLJSONResponseBuilder results(String dslResults) throws IOException {
return results(AtlasJson.parseToV1ArrayNode(dslResults));
}
@Override
public JSONObject build() throws JSONException {
public ObjectNode build() {
Preconditions.checkNotNull(dslResults);
JSONArray rowsJsonArr = dslResults.getJSONArray(AtlasClient.ROWS);
count(rowsJsonArr.length());
count(dslResults.size());
queryType(QUERY_TYPE_DSL);
JSONObject response = super.build();
response.put(AtlasClient.RESULTS, rowsJsonArr);
ObjectNode response = super.build();
response.putPOJO(AtlasClient.RESULTS, dslResults);
response.put(AtlasClient.DATATYPE, dslResults.get(AtlasClient.DATATYPE));
return response;
}
......@@ -376,15 +372,15 @@ public class MetadataDiscoveryResource {
private class FullTextJSonResponseBuilder extends JsonResponseBuilder {
private JSONArray fullTextResults;
private ArrayNode fullTextResults;
public FullTextJSonResponseBuilder results(JSONArray fullTextResults) {
public FullTextJSonResponseBuilder results(ArrayNode fullTextResults) {
this.fullTextResults = fullTextResults;
return this;
}
public FullTextJSonResponseBuilder results(String dslResults) throws JSONException {
return results(new JSONArray(dslResults));
public FullTextJSonResponseBuilder results(String dslResults) throws IOException {
return results(AtlasJson.parseToV1ArrayNode(dslResults));
}
public FullTextJSonResponseBuilder() {
......@@ -392,12 +388,12 @@ public class MetadataDiscoveryResource {
}
@Override
public JSONObject build() throws JSONException {
public ObjectNode build() {
Preconditions.checkNotNull(fullTextResults);
count(fullTextResults.length());
count(fullTextResults.size());
queryType(QUERY_TYPE_FULLTEXT);
JSONObject response = super.build();
ObjectNode response = super.build();
response.put(AtlasClient.RESULTS, fullTextResults);
return response;
}
......
......@@ -18,22 +18,21 @@
package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.core.ResourceContext;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.repository.converters.TypeConverterUtil;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.rest.TypesREST;
import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
......@@ -102,7 +101,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
}
JSONArray typesResponse = new JSONArray();
ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try {
final String typeDefinition = Servlets.getRequestPayload(request);
......@@ -116,13 +115,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
final String name = typeNames.get(i);
typesResponse.put(new JSONObject() {{
put(AtlasClient.NAME, name);
}});
ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
typesResponse.add(typeNode);
}
JSONObject response = new JSONObject();
ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.status(ClientResponse.Status.CREATED).entity(response).build();
......@@ -170,7 +168,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
}
JSONArray typesResponse = new JSONArray();
ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try {
final String typeDefinition = Servlets.getRequestPayload(request);
......@@ -183,13 +181,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
final String name = typeNames.get(i);
typesResponse.put(new JSONObject() {{
put(AtlasClient.NAME, name);
}});
ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
typesResponse.add(typeNode);
}
JSONObject response = new JSONObject();
ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.ok().entity(response).build();
......@@ -233,21 +230,20 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
}
JSONObject response = new JSONObject();
ObjectNode response = AtlasJson.createV1ObjectNode();
try {
TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
String typeDefinition = AtlasType.toV1Json(typesDef);
TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
response.put(AtlasClient.TYPENAME, typeName);
response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition));
response.putPOJO(AtlasClient.DEFINITION, typesDef);
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (JSONException | IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
......@@ -292,11 +288,11 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
}
JSONObject response = new JSONObject();
ObjectNode response = AtlasJson.createV1ObjectNode();
try {
List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
response.put(AtlasClient.RESULTS, new JSONArray(result));
response.putPOJO(AtlasClient.RESULTS, result);
response.put(AtlasClient.COUNT, result.size());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
......
/**
* 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");
}
}
......@@ -18,11 +18,13 @@
package org.apache.atlas.web.util;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.LocalServletRequest;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
......@@ -30,8 +32,6 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -153,15 +153,10 @@ public final class Servlets {
}
public static Response getErrorResponse(String message, Response.Status status) {
JSONObject errorJson = new JSONObject();
Object errorEntity = escapeJsonString(message);
try {
errorJson.put(AtlasClient.ERROR, errorEntity);
errorEntity = errorJson;
} catch (JSONException jsonE) {
LOG.warn("Could not construct error Json rensponse", jsonE);
}
return Response.status(status).entity(errorEntity).type(JSON_MEDIA_TYPE).build();
Object errorEntity = escapeJsonString(message);
ObjectNode errorJson = AtlasJson.createV1ObjectNode(AtlasClient.ERROR, errorEntity);
return Response.status(status).entity(errorJson).type(JSON_MEDIA_TYPE).build();
}
public static String getRequestPayload(HttpServletRequest request) throws IOException {
......
......@@ -18,14 +18,13 @@
package org.apache.atlas.examples;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -51,12 +50,12 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals(QuickStart.SALES_DB_DESCRIPTION, db.get("description"));
}
private Referenceable getDB(String dbName) throws AtlasServiceException, JSONException {
private Referenceable getDB(String dbName) throws AtlasServiceException {
return atlasClientV1.getEntity(QuickStart.DATABASE_TYPE, "name", dbName);
}
@Test
public void testTablesAreAdded() throws AtlasServiceException, JSONException {
public void testTablesAreAdded() throws AtlasServiceException {
Referenceable table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table);
......@@ -71,11 +70,11 @@ public class QuickStartIT extends BaseResourceIT {
return atlasClientV1.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
}
private void verifyTrait(Referenceable table) throws JSONException {
private void verifyTrait(Referenceable table) {
assertNotNull(table.getTrait(QuickStart.FACT_TRAIT));
}
private void verifyColumnsAreAddedToTable(Referenceable table) throws JSONException {
private void verifyColumnsAreAddedToTable(Referenceable table) {
List<Referenceable> columns = (List<Referenceable>) table.get(QuickStart.COLUMNS_ATTRIBUTE);
assertEquals(4, columns.size());
Referenceable column = columns.get(0);
......@@ -83,18 +82,18 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals("int", column.get("dataType"));
}
private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException, JSONException {
private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException {
Referenceable db = getDB(QuickStart.SALES_DB);
assertEquals(db.getId(), table.get(QuickStart.DB_ATTRIBUTE));
}
private void verifySimpleTableAttributes(Referenceable table) throws JSONException {
private void verifySimpleTableAttributes(Referenceable table) {
assertEquals(QuickStart.SALES_FACT_TABLE, table.get("name"));
assertEquals(QuickStart.SALES_FACT_TABLE_DESCRIPTION, table.get("description"));
}
@Test
public void testProcessIsAdded() throws AtlasServiceException, JSONException {
public void testProcessIsAdded() throws AtlasServiceException {
Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
QuickStart.LOAD_SALES_DAILY_PROCESS);
......@@ -118,29 +117,29 @@ public class QuickStartIT extends BaseResourceIT {
}
@Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject vertices = (JSONObject) ((JSONObject) inputGraph.get("values")).get("vertices");
JSONObject edges = (JSONObject) ((JSONObject) inputGraph.get("values")).get("edges");
ObjectNode inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
ArrayNode vertices = (ArrayNode) inputGraph.get("values").get("vertices");
ArrayNode edges = (ArrayNode) inputGraph.get("values").get("edges");
assertTrue(vertices.has(salesFactTableId));
assertTrue(vertices.has(timeDimTableId));
assertTrue(vertices.has(salesFactDailyMVId));
assertTrue(edges.has(salesFactDailyMVId));
JSONArray inputs = (JSONArray)edges.get((String) ((JSONArray) edges.get(salesFactDailyMVId)).get(0));
String i1 = inputs.getString(0);
String i2 = inputs.getString(1);
ArrayNode inputs = (ArrayNode)edges.get((edges.get(salesFactDailyMVId)).get(0).asText());
String i1 = inputs.get(0).asText();
String i2 = inputs.get(1).asText();
assertTrue(salesFactTableId.equals(i1) || salesFactTableId.equals(i2));
assertTrue(timeDimTableId.equals(i1) || timeDimTableId.equals(i2));
}
@Test
public void testViewIsAdded() throws AtlasServiceException, JSONException {
public void testViewIsAdded() throws AtlasServiceException {
Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);
......
......@@ -27,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -57,7 +56,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertEquals("sales database", dbAttributes.get("description"));
}
private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException {
private AtlasEntity getDB(String dbName) throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put("name", dbName);
AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity();
......@@ -65,7 +64,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
public void testTablesAreAdded() throws AtlasServiceException, JSONException {
public void testTablesAreAdded() throws AtlasServiceException {
AtlasEntity table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table);
......@@ -97,7 +96,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertNotNull(traits.get(0).getTypeName());
}
private void verifyColumnsAreAddedToTable(AtlasEntity table) throws JSONException {
private void verifyColumnsAreAddedToTable(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes();
List<Map> columns = (List<Map>) tableAttributes.get("columns");
assertEquals(4, columns.size());
......@@ -108,21 +107,21 @@ public class QuickStartV2IT extends BaseResourceIT {
}
}
private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException, JSONException {
private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException {
AtlasEntity db = getDB(QuickStartV2.SALES_DB);
Map<String, Object> tableAttributes = table.getAttributes();
Map dbFromTable = (Map) tableAttributes.get("db");
assertEquals(db.getGuid(), dbFromTable.get("guid"));
}
private void verifySimpleTableAttributes(AtlasEntity table) throws JSONException {
private void verifySimpleTableAttributes(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes();
assertEquals(QuickStartV2.SALES_FACT_TABLE, tableAttributes.get("name"));
assertEquals("sales fact table", tableAttributes.get("description"));
}
@Test
public void testProcessIsAdded() throws AtlasServiceException, JSONException {
public void testProcessIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.LOAD_SALES_DAILY_PROCESS);
AtlasEntity loadProcess = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity();
......@@ -153,7 +152,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE);
......@@ -177,7 +176,7 @@ public class QuickStartV2IT extends BaseResourceIT {
}
@Test
public void testViewIsAdded() throws AtlasServiceException, JSONException {
public void testViewIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.PRODUCT_DIM_VIEW);
AtlasEntity view = atlasClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity();
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.notification;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.v1.model.instance.Id;
......@@ -27,7 +28,6 @@ import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUp
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest;
import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -84,9 +84,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
return results.length() == 1;
return results.size() == 1;
}
});
}
......@@ -106,9 +106,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
return results.length() == 1;
return results.size() == 1;
}
});
......@@ -175,16 +175,16 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName));
ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName));
return results.length() == 1;
return results.size() == 1;
}
});
//no entity with the old qualified name
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
assertEquals(results.length(), 0);
assertEquals(results.size(), 0);
}
@Test
......@@ -237,9 +237,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
return results.length() == 1;
return results.size() == 1;
}
});
......
......@@ -18,9 +18,9 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -37,13 +37,13 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test
public void testGetVersion() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
Assert.assertNotNull(response);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
Assert.assertEquals(response.get("Version").asText(), buildConfiguration.getString("build.version"));
Assert.assertEquals(response.get("Name").asText(), buildConfiguration.getString("project.name"));
Assert.assertEquals(response.get("Description").asText(), buildConfiguration.getString("project.description"));
}
}
......@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.base.Preconditions;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
......@@ -50,7 +51,6 @@ import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
......@@ -678,7 +678,7 @@ public abstract class BaseResourceIT {
};
}
protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException {
protected ArrayNode searchByDSL(String dslQuery) throws AtlasServiceException {
return atlasClientV1.searchByDSL(dslQuery, 10, 0);
}
......
......@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id;
......@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -64,14 +64,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testInputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
Assert.assertNotNull(response);
System.out.println("inputs graph = " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
......@@ -86,7 +86,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
public void testInputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
salesMonthlyTable).getId()._getId();
JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
ObjectNode results = atlasClientV1.getInputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
......@@ -113,14 +113,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testOutputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
Assert.assertNotNull(response);
System.out.println("outputs graph= " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
......@@ -134,7 +134,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testOutputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
ObjectNode results = atlasClientV1.getOutputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
......@@ -159,23 +159,23 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testSchema() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject response = atlasClientV1.getSchemaForEntity(tableId);
ObjectNode response = atlasClientV1.getSchemaForEntity(tableId);
}
@Test
public void testSchemaForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = atlasClientV1.getSchemaForEntity(tableId);
ObjectNode results = atlasClientV1.getSchemaForEntity(tableId);
}
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
}
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
}
private void setupInstances() throws Exception {
......
......@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
......@@ -35,8 +37,6 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -173,7 +173,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp");
JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
......@@ -322,7 +322,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String description = "bar table - new desc";
addProperty(guid, "description", description);
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("description", description);
......@@ -460,7 +460,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetInvalidEntityDefinition() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
Assert.assertNotNull(response);
......@@ -493,7 +493,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", "blah");
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.ERROR));
}
......@@ -506,12 +506,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", typeName);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
Assert.assertEquals(list.length(), 0);
final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertEquals(list.size(), 0);
}
private String addNewType() throws Exception {
......@@ -827,8 +827,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
instance.set(attrName, attrValue);
Id guid = createInstance(instance);
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
Referenceable getReferenceable = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), Referenceable.class);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
Referenceable getReferenceable = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), Referenceable.class);
Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
......@@ -1026,7 +1026,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasBaseClient;
import org.apache.atlas.AtlasClient;
......@@ -26,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -67,7 +67,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("input lineage info = " + response
);
......@@ -95,7 +95,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("output lineage info = " + response);
......@@ -123,7 +123,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response);
System.out.println("both lineage info = " + response);
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.Lists;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.atlas.AtlasClient;
......@@ -37,7 +38,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -147,13 +147,13 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
@Test
public void testEntityDeduping() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.size(), 1);
final AtlasEntity hiveDBInstanceV2 = createHiveDB();
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
assertEquals(results.size(), 1);
//Test the same across references
final String tableName = randomString();
......@@ -164,7 +164,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
assertNotNull(entity);
assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
assertEquals(results.size(), 1);
}
private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
......
......@@ -18,6 +18,9 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
......@@ -28,8 +31,6 @@ import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -64,19 +65,19 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), dslQuery);
assertEquals(response.getString("queryType"), "dsl");
assertEquals(response.get("query").asText(), dslQuery);
assertEquals(response.get("queryType").asText(), "dsl");
JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertNotNull(results);
assertEquals(results.length(), 1);
assertEquals(results.size(), 1);
int numRows = response.getInt(AtlasClient.COUNT);
int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1);
}
......@@ -88,24 +89,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
assertNotNull(response);
//higher limit, all results returned
JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
assertEquals(results.length(), 1);
ArrayNode results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
assertEquals(results.size(), 1);
//default limit and offset -1, all results returned
results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
assertEquals(results.length(), 1);
assertEquals(results.size(), 1);
//uses the limit parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
assertEquals(results.length(), 1);
assertEquals(results.size(), 1);
//uses the offset parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
assertEquals(results.length(), 0);
assertEquals(results.size(), 0);
//limit > 0
try {
......@@ -146,13 +147,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
assertNotNull(response);
assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query);
assertEquals(response.getString("queryType"), "gremlin");
assertEquals(response.get("query").asText(), query);
assertEquals(response.get("queryType").asText(), "gremlin");
}
// Disabling DSL tests
......@@ -162,13 +163,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query);
assertEquals(response.getString("queryType"), "dsl");
assertEquals(response.get("query").asText(), query);
assertEquals(response.get("queryType").asText(), "dsl");
}
// Disabling DSL tests
......@@ -177,32 +178,32 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "*";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query);
assertEquals(response.getString("queryType"), "full-text");
assertEquals(response.get("query").asText(), query);
assertEquals(response.get("queryType").asText(), "full-text");
}
@Test(enabled = false, dependsOnMethods = "testSearchDSLLimits")
public void testSearchUsingFullText() throws Exception {
JSONObject response = atlasClientV1.searchByFullText(dbName, 10, 0);
ObjectNode response = atlasClientV1.searchByFullText(dbName, 10, 0);
assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), dbName);
assertEquals(response.getString("queryType"), "full-text");
assertEquals(response.get("query").asText(), dbName);
assertEquals(response.get("queryType").asText(), "full-text");
JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1, "Results: " + results);
ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertEquals(results.size(), 1, "Results: " + results);
JSONObject row = results.getJSONObject(0);
JsonNode row = results.get(0);
assertNotNull(row.get("guid"));
assertEquals(row.getString("typeName"), DATABASE_TYPE);
assertEquals(row.get("typeName").asText(), DATABASE_TYPE);
assertNotNull(row.get("score"));
int numRows = response.getInt(AtlasClient.COUNT);
int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1);
//API works without limit and offset
......@@ -210,25 +211,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams);
results = response.getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertEquals(results.size(), 1);
//verify passed in limits and offsets are used
//higher limit and 0 offset returns all results
results = atlasClientV1.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 0).get(AtlasClient.RESULTS);
assertEquals(results.size(), 1);
//offset is used
results = atlasClientV1.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 0);
results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 1).get(AtlasClient.RESULTS);
assertEquals(results.size(), 0);
//limit is used
results = atlasClientV1.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 0).get(AtlasClient.RESULTS);
assertEquals(results.size(), 1);
//higher offset returns 0 results
results = atlasClientV1.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 0);
results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 2).get(AtlasClient.RESULTS);
assertEquals(results.size(), 0);
}
private void createTypes() throws Exception {
......
......@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
......@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
......@@ -81,13 +81,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System.out.println("typesAsJSON = " + typesAsJSON);
JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response);
JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
assertEquals(typesAdded.length(), 1);
assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.getTypeName());
ArrayNode typesAdded = (ArrayNode) response.get(AtlasClient.TYPES);
assertEquals(typesAdded.size(), 1);
assertEquals(typesAdded.get(0).get(NAME).asText(), typeDefinition.getTypeName());
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
}
}
......@@ -143,13 +143,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.getTypeName());
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName());
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName());
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
TypesDef typesDef = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), TypesDef.class);
TypesDef typesDef = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), TypesDef.class);
List<? extends HierarchicalTypeDefinition> hierarchicalTypeDefs = Collections.emptyList();
......@@ -172,21 +172,21 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
}
@Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list);
//Verify that primitive and core types are not returned
String typesString = list.join(" ");
String typesString = list.toString();
Assert.assertFalse(typesString.contains(" \"__IdType\" "));
Assert.assertFalse(typesString.contains(" \"string\" "));
}
......@@ -198,14 +198,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list);
Assert.assertTrue(list.length() >= traitsAdded.length);
Assert.assertTrue(list.size() >= traitsAdded.length);
}
@Test
......
......@@ -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 @@ public class AdminResourceTest {
}
@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
......@@ -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 @@ public class ServletsTest {
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));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment