Commit fdf97ae4 by Suma Shivaprasad

ATLAS-1200 Error Catalog enhancement (apoorvnaik via sumasai)

parent 5a4dd2e7
...@@ -34,5 +34,4 @@ public final class AtlasConstants { ...@@ -34,5 +34,4 @@ public final class AtlasConstants {
public static final String DEFAULT_ATLAS_REST_ADDRESS = "http://localhost:21000"; public static final String DEFAULT_ATLAS_REST_ADDRESS = "http://localhost:21000";
public static final int ATLAS_SHUTDOWN_HOOK_PRIORITY = 30; public static final int ATLAS_SHUTDOWN_HOOK_PRIORITY = 30;
public static final String DEFAULT_TYPE_VERSION = "1.0"; public static final String DEFAULT_TYPE_VERSION = "1.0";
} }
/**
* 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.MessageFormat;
import java.util.Arrays;
import javax.ws.rs.core.Response;
public enum AtlasErrorCode {
NO_SEARCH_RESULTS(204, "ATLAS2041E", "Given search filter did not yield any results"),
UNKNOWN_TYPE(400, "ATLAS4001E", "Unknown type {0} for {1}.{2}"),
TYPE_NAME_NOT_FOUND(404, "ATLAS4041E", "Given typename {0} was invalid"),
TYPE_GUID_NOT_FOUND(404, "ATLAS4042E", "Given type guid {0} was invalid"),
EMPTY_RESULTS(404, "ATLAS4044E", "No result found for {0}"),
TYPE_ALREADY_EXISTS(409, "ATLAS4091E", "Given type {0} already exists"),
TYPE_HAS_REFERENCES(409, "ATLAS4092E", "Given type {0} has references"),
TYPE_MATCH_FAILED(409, "ATLAS4093E", "Given type {0} doesn't match {1}"),
INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}");
private String errorCode;
private String errorMessage;
private Response.Status httpCode;
private static final Logger LOG = LoggerFactory.getLogger(AtlasErrorCode.class);
AtlasErrorCode(int httpCode, String errorCode, String errorMessage) {
this.httpCode = Response.Status.fromStatusCode(httpCode);
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
public String getFormattedErrorMessage(String... params) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== AtlasErrorCode.getMessage(%s)", Arrays.toString(params)));
}
MessageFormat mf = new MessageFormat(errorMessage);
String result = mf.format(params);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> AtlasErrorCode.getMessage(%s): %s", Arrays.toString(params), result));
}
return result;
}
public Response.Status getHttpCode() {
return httpCode;
}
public String getErrorCode() {
return errorCode;
}
}
...@@ -17,27 +17,47 @@ ...@@ -17,27 +17,47 @@
*/ */
package org.apache.atlas.exception; package org.apache.atlas.exception;
import org.apache.atlas.AtlasErrorCode;
import javax.ws.rs.core.Response;
/** /**
* Base Exception class for Atlas API. * Base Exception class for Atlas API.
*/ */
public class AtlasBaseException extends Exception { public class AtlasBaseException extends Exception {
private AtlasErrorCode atlasErrorCode;
public AtlasBaseException(AtlasErrorCode errorCode, String ... params) {
super(errorCode.getFormattedErrorMessage(params));
this.atlasErrorCode = errorCode;
}
public AtlasBaseException() { public AtlasBaseException() {
this(AtlasErrorCode.INTERNAL_ERROR);
} }
public AtlasBaseException(String message) { public AtlasBaseException(String message) {
super(message); super(message);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(String message, Throwable cause) { public AtlasBaseException(String message, Throwable cause) {
super(message, cause); super(message, cause);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(Throwable cause) { public AtlasBaseException(Throwable cause) {
super(cause); super(cause);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { public AtlasBaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
}
public AtlasErrorCode getAtlasErrorCode() {
return atlasErrorCode;
} }
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.apache.atlas.model.typedef; package org.apache.atlas.model.typedef;
import org.apache.commons.collections.CollectionUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize;
...@@ -89,4 +90,11 @@ public class AtlasTypesDef { ...@@ -89,4 +90,11 @@ public class AtlasTypesDef {
public void setEntityDefs(List<AtlasEntityDef> entityDefs) { public void setEntityDefs(List<AtlasEntityDef> entityDefs) {
this.entityDefs = entityDefs; this.entityDefs = entityDefs;
} }
public boolean isEmpty() {
return CollectionUtils.isEmpty(enumDefs) &&
CollectionUtils.isEmpty(structDefs) &&
CollectionUtils.isEmpty(classificationDefs) &&
CollectionUtils.isEmpty(entityDefs);
}
} }
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1200 Error Catalog enhancement (apoorvnaik via sumasai)
ATLAS-1207 Dataset exists query in lineage APIs takes longer (shwethags) ATLAS-1207 Dataset exists query in lineage APIs takes longer (shwethags)
ATLAS-1232 added preCreate(), preDelete() in typedef persistence, to enable edge creation for references in a later stage (mneethiraj) ATLAS-1232 added preCreate(), preDelete() in typedef persistence, to enable edge creation for references in a later stage (mneethiraj)
ATLAS-1183 UI: help link should point to atlas website (kevalbhatt via shwethags) ATLAS-1183 UI: help link should point to atlas website (kevalbhatt via shwethags)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.apache.atlas.repository.store.graph; package org.apache.atlas.repository.store.graph;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
...@@ -41,6 +42,7 @@ import org.slf4j.LoggerFactory; ...@@ -41,6 +42,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -102,9 +104,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -102,9 +104,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection<AtlasEnumDef> enumDefs = typeRegistry.getAllEnumDefs(); Collection<AtlasEnumDef> enumDefs = typeRegistry.getAllEnumDefs();
if (enumDefs != null) { ret = CollectionUtils.isNotEmpty(enumDefs) ?
ret = new ArrayList<>(enumDefs); new ArrayList<>(enumDefs) : Collections.<AtlasEnumDef>emptyList();
}
return ret; return ret;
} }
...@@ -113,7 +114,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -113,7 +114,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException { public AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException {
AtlasEnumDef ret = typeRegistry.getEnumDefByName(name); AtlasEnumDef ret = typeRegistry.getEnumDefByName(name);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
return ret; return ret;
} }
...@@ -121,7 +124,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -121,7 +124,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException { public AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException {
AtlasEnumDef ret = typeRegistry.getEnumDefByGuid(guid); AtlasEnumDef ret = typeRegistry.getEnumDefByGuid(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
return ret; return ret;
} }
...@@ -180,7 +185,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -180,7 +185,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException { public AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException {
return getEnumDefStore(typeRegistry).search(filter); AtlasEnumDefs search = getEnumDefStore(typeRegistry).search(filter);
if (search == null || search.getTotalCount() == 0) {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
return search;
} }
@Override @Override
...@@ -206,9 +215,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -206,9 +215,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection<AtlasStructDef> structDefs = typeRegistry.getAllStructDefs(); Collection<AtlasStructDef> structDefs = typeRegistry.getAllStructDefs();
if (structDefs != null) { ret = CollectionUtils.isNotEmpty(structDefs) ?
ret = new ArrayList<>(structDefs); new ArrayList<>(structDefs) : Collections.<AtlasStructDef>emptyList();
}
return ret; return ret;
} }
...@@ -217,7 +225,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -217,7 +225,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasStructDef getStructDefByName(String name) throws AtlasBaseException { public AtlasStructDef getStructDefByName(String name) throws AtlasBaseException {
AtlasStructDef ret = typeRegistry.getStructDefByName(name); AtlasStructDef ret = typeRegistry.getStructDefByName(name);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
return ret; return ret;
} }
...@@ -225,7 +235,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -225,7 +235,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException { public AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException {
AtlasStructDef ret = typeRegistry.getStructDefByGuid(guid); AtlasStructDef ret = typeRegistry.getStructDefByGuid(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
return ret; return ret;
} }
...@@ -284,7 +296,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -284,7 +296,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException { public AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException {
return getStructDefStore(typeRegistry).search(filter); AtlasStructDefs search = getStructDefStore(typeRegistry).search(filter);
if (search == null || search.getTotalCount() == 0) {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
return search;
} }
@Override @Override
...@@ -311,9 +327,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -311,9 +327,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection<AtlasClassificationDef> classificationDefs = typeRegistry.getAllClassificationDefs(); Collection<AtlasClassificationDef> classificationDefs = typeRegistry.getAllClassificationDefs();
if (classificationDefs != null) { ret = CollectionUtils.isNotEmpty(classificationDefs) ?
ret = new ArrayList<>(classificationDefs); new ArrayList<>(classificationDefs) : Collections.<AtlasClassificationDef>emptyList();
}
return ret; return ret;
} }
...@@ -323,6 +338,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -323,6 +338,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException { public AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException {
AtlasClassificationDef ret = typeRegistry.getClassificationDefByName(name); AtlasClassificationDef ret = typeRegistry.getClassificationDefByName(name);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
return ret; return ret;
} }
...@@ -330,7 +348,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -330,7 +348,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasClassificationDef getClassificationDefByGuid(String guid) throws AtlasBaseException { public AtlasClassificationDef getClassificationDefByGuid(String guid) throws AtlasBaseException {
AtlasClassificationDef ret = typeRegistry.getClassificationDefByGuid(guid); AtlasClassificationDef ret = typeRegistry.getClassificationDefByGuid(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
return ret; return ret;
} }
...@@ -391,7 +411,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -391,7 +411,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException { public AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException {
return getClassificationDefStore(typeRegistry).search(filter); AtlasClassificationDefs search = getClassificationDefStore(typeRegistry).search(filter);
if (search == null || search.getTotalCount() == 0) {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
return search;
} }
@Override @Override
...@@ -417,9 +441,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -417,9 +441,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs(); Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs();
if (entityDefs != null) { ret = CollectionUtils.isNotEmpty(entityDefs) ?
ret = new ArrayList<>(entityDefs); new ArrayList<>(entityDefs) : Collections.<AtlasEntityDef>emptyList();
}
return ret; return ret;
} }
...@@ -428,7 +451,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -428,7 +451,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException { public AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException {
AtlasEntityDef ret = typeRegistry.getEntityDefByName(name); AtlasEntityDef ret = typeRegistry.getEntityDefByName(name);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
return ret; return ret;
} }
...@@ -436,7 +461,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -436,7 +461,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction @GraphTransaction
public AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException { public AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException {
AtlasEntityDef ret = typeRegistry.getEntityDefByGuid(guid); AtlasEntityDef ret = typeRegistry.getEntityDefByGuid(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
return ret; return ret;
} }
...@@ -495,7 +522,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -495,7 +522,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException { public AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException {
return getEntityDefStore(typeRegistry).search(filter); AtlasEntityDefs search = getEntityDefStore(typeRegistry).search(filter);
if (search == null || search.getTotalCount() == 0) {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
return search;
} }
@Override @Override
...@@ -809,6 +840,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -809,6 +840,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
LOG.error("Failed to retrieve the EntityDefs", ex); LOG.error("Failed to retrieve the EntityDefs", ex);
} }
if (typesDef.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
return typesDef; return typesDef;
} }
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.repository.store.graph.v1; package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
...@@ -58,13 +59,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -58,13 +59,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType type = typeRegistry.getType(classificationDef.getName()); AtlasType type = typeRegistry.getType(classificationDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) { if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a classification type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
} }
AtlasVertex ret = typeDefStore.findTypeVertexByName(classificationDef.getName()); AtlasVertex ret = typeDefStore.findTypeVertexByName(classificationDef.getName());
if (ret != null) { if (ret != null) {
throw new AtlasBaseException(classificationDef.getName() + ": type already exists"); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, classificationDef.getName());
} }
ret = typeDefStore.createTypeVertex(classificationDef); ret = typeDefStore.createTypeVertex(classificationDef);
...@@ -132,7 +133,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -132,7 +133,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
...@@ -155,7 +156,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -155,7 +156,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
AtlasClassificationDef ret = toClassificationDef(vertex); AtlasClassificationDef ret = toClassificationDef(vertex);
...@@ -193,13 +194,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -193,13 +194,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType type = typeRegistry.getType(classificationDef.getName()); AtlasType type = typeRegistry.getType(classificationDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) { if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a struct type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex);
...@@ -223,13 +224,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -223,13 +224,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType type = typeRegistry.getTypeByGuid(guid); AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) { if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a struct type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex);
...@@ -253,7 +254,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -253,7 +254,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
...@@ -295,7 +296,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -295,7 +296,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
...@@ -346,6 +347,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -346,6 +347,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
} }
} }
if (CollectionUtils.isNotEmpty(classificationDefs)) {
CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter)); CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter));
AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs); AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs);
...@@ -353,8 +355,10 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple ...@@ -353,8 +355,10 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.search({}): {}", filter, ret); LOG.debug("<== AtlasClassificationDefStoreV1.search({}): {}", filter, ret);
} }
return ret; return ret;
} else {
throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS);
}
} }
private void updateVertexPreCreate(AtlasClassificationDef classificationDef, private void updateVertexPreCreate(AtlasClassificationDef classificationDef,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.apache.atlas.repository.store.graph.v1; package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
...@@ -57,13 +58,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -57,13 +58,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getType(entityDef.getName()); AtlasType type = typeRegistry.getType(entityDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) { if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
} }
AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName()); AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName());
if (ret != null) { if (ret != null) {
throw new AtlasBaseException(entityDef.getName() + ": type already exists"); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, entityDef.getName());
} }
ret = typeDefStore.createTypeVertex(entityDef); ret = typeDefStore.createTypeVertex(entityDef);
...@@ -131,7 +132,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -131,7 +132,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
...@@ -154,7 +155,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -154,7 +155,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
AtlasEntityDef ret = toEntityDef(vertex); AtlasEntityDef ret = toEntityDef(vertex);
...@@ -191,13 +192,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -191,13 +192,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getType(entityDef.getName()); AtlasType type = typeRegistry.getType(entityDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) { if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex);
...@@ -221,13 +222,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -221,13 +222,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getTypeByGuid(guid); AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) { if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex);
...@@ -251,7 +252,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -251,7 +252,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no entityDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
...@@ -293,7 +294,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -293,7 +294,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no entityDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.apache.atlas.repository.store.graph.v1; package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
...@@ -57,7 +58,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -57,7 +58,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByName(enumDef.getName()); AtlasVertex vertex = typeDefStore.findTypeVertexByName(enumDef.getName());
if (vertex != null) { if (vertex != null) {
throw new AtlasBaseException(enumDef.getName() + ": type already exists"); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, enumDef.getName());
} }
vertex = typeDefStore.createTypeVertex(enumDef); vertex = typeDefStore.createTypeVertex(enumDef);
...@@ -102,7 +103,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -102,7 +103,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
...@@ -125,7 +126,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -125,7 +126,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
AtlasEnumDef ret = toEnumDef(vertex); AtlasEnumDef ret = toEnumDef(vertex);
...@@ -162,7 +163,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -162,7 +163,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
toVertex(enumDef, vertex); toVertex(enumDef, vertex);
...@@ -185,7 +186,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -185,7 +186,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
toVertex(enumDef, vertex); toVertex(enumDef, vertex);
...@@ -208,7 +209,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -208,7 +209,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
typeDefStore.deleteTypeVertex(vertex); typeDefStore.deleteTypeVertex(vertex);
...@@ -227,7 +228,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla ...@@ -227,7 +228,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no enumdef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
typeDefStore.deleteTypeVertex(vertex); typeDefStore.deleteTypeVertex(vertex);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.apache.atlas.repository.store.graph.v1; package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef;
...@@ -70,13 +71,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -70,13 +71,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getType(structDef.getName()); AtlasType type = typeRegistry.getType(structDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) {
throw new AtlasBaseException(structDef.getName() + ": not a struct type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
} }
AtlasVertex ret = typeDefStore.findTypeVertexByName(structDef.getName()); AtlasVertex ret = typeDefStore.findTypeVertexByName(structDef.getName());
if (ret != null) { if (ret != null) {
throw new AtlasBaseException(structDef.getName() + ": type already exists"); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, structDef.getName());
} }
ret = typeDefStore.createTypeVertex(structDef); ret = typeDefStore.createTypeVertex(structDef);
...@@ -143,7 +144,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -143,7 +144,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no structDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, String.class); vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, String.class);
...@@ -166,7 +167,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -166,7 +167,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
AtlasStructDef ret = toStructDef(vertex); AtlasStructDef ret = toStructDef(vertex);
...@@ -203,13 +204,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -203,13 +204,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getType(structDef.getName()); AtlasType type = typeRegistry.getType(structDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) {
throw new AtlasBaseException(structDef.getName() + ": not a struct type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT); AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no structDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore); AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore);
...@@ -233,13 +234,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -233,13 +234,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType type = typeRegistry.getTypeByGuid(guid); AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) {
throw new AtlasBaseException(structDef.getName() + ": not a struct type"); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
} }
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
if (vertex == null) { if (vertex == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore); AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore);
...@@ -263,7 +264,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -263,7 +264,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT); AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no structDef exists with name " + name); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
...@@ -305,7 +306,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -305,7 +306,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
typeDefStore.deleteTypeVertexOutEdges(ret); typeDefStore.deleteTypeVertexOutEdges(ret);
...@@ -477,7 +478,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At ...@@ -477,7 +478,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName); AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);
if (referencedTypeVertex == null) { if (referencedTypeVertex == null) {
throw new AtlasBaseException(referencedTypeName + ": unknown datatype"); throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
} }
String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName()); String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());
......
...@@ -20,6 +20,8 @@ package org.apache.atlas.repository.store.graph.v1; ...@@ -20,6 +20,8 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.atlas.AtlasConstants;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
...@@ -232,7 +234,7 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -232,7 +234,7 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator(); Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
if (inEdges.hasNext()) { if (inEdges.hasNext()) {
throw new AtlasBaseException("has references"); throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES);
} }
Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT); Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT);
......
/**
* 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.errors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ThreadLocalRandom;
import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
* Exception mapper for Jersey.
* @param <E>
*/
@Provider
@Singleton
public class AllExceptionMapper implements ExceptionMapper<Exception> {
private static final Logger LOGGER = LoggerFactory.getLogger(AllExceptionMapper.class);
@Override
public Response toResponse(Exception exception) {
final long id = ThreadLocalRandom.current().nextLong();
// Log the response and use the error codes from the Exception
ExceptionMapperUtil.logException(id, exception);
return Response
.serverError()
.entity(ExceptionMapperUtil.formatErrorMessage(id, exception))
.build();
}
}
...@@ -18,38 +18,59 @@ ...@@ -18,38 +18,59 @@
package org.apache.atlas.web.errors; package org.apache.atlas.web.errors;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.type.AtlasType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.ws.rs.WebApplicationException; import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import javax.inject.Singleton;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import java.util.concurrent.ThreadLocalRandom; import javax.ws.rs.ext.Provider;
/** /**
* Exception mapper for Jersey. * Exception mapper for Jersey.
* @param <E> * @param <E>
*/ */
public class LoggingExceptionMapper<E extends Throwable> implements ExceptionMapper<E> { @Provider
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingExceptionMapper.class); @Singleton
public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseException> {
private static final Logger LOGGER = LoggerFactory.getLogger(AtlasBaseExceptionMapper.class);
@Override @Override
public Response toResponse(E exception) { public Response toResponse(AtlasBaseException exception) {
if (exception instanceof WebApplicationException) {
return ((WebApplicationException) exception).getResponse();
}
final long id = ThreadLocalRandom.current().nextLong(); final long id = ThreadLocalRandom.current().nextLong();
// Log the response and use the error codes from the Exception
logException(id, exception); logException(id, exception);
return Response.serverError().entity(formatErrorMessage(id, exception)).build(); return buildAtlasBaseExceptionResponse((AtlasBaseException) exception);
}
protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
Map<String, String> errorJsonMap = new LinkedHashMap<>();
AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
errorJsonMap.put("errorCode", errorCode.getErrorCode());
errorJsonMap.put("errorMessage", baseException.getMessage());
Response.ResponseBuilder responseBuilder = Response.status(errorCode.getHttpCode());
// No body for 204 (and maybe 304)
if (Response.Status.NO_CONTENT != errorCode.getHttpCode()) {
responseBuilder.entity(AtlasType.toJson(errorJsonMap));
}
return responseBuilder.build();
} }
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
protected String formatErrorMessage(long id, E exception) { protected String formatErrorMessage(long id, AtlasBaseException exception) {
return String.format("There was an error processing your request. It has been logged (ID %016x).", id); return String.format("There was an error processing your request. It has been logged (ID %016x).", id);
} }
protected void logException(long id, E exception) { protected void logException(long id, AtlasBaseException exception) {
LOGGER.error(formatLogMessage(id, exception), exception); LOGGER.error(formatLogMessage(id, exception), exception);
} }
...@@ -57,4 +78,5 @@ public class LoggingExceptionMapper<E extends Throwable> implements ExceptionMap ...@@ -57,4 +78,5 @@ public class LoggingExceptionMapper<E extends Throwable> implements ExceptionMap
protected String formatLogMessage(long id, Throwable exception) { protected String formatLogMessage(long id, Throwable exception) {
return String.format("Error handling a request: %016x", id); return String.format("Error handling a request: %016x", id);
} }
} }
/**
* 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.errors;
import org.apache.atlas.exception.AtlasBaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExceptionMapperUtil {
protected static final Logger LOGGER = LoggerFactory.getLogger(ExceptionMapperUtil.class);
@SuppressWarnings("UnusedParameters")
protected static String formatErrorMessage(long id, Exception exception) {
return String.format("There was an error processing your request. It has been logged (ID %016x).", id);
}
protected static void logException(long id, Exception exception) {
LOGGER.error(formatLogMessage(id, exception), exception);
}
@SuppressWarnings("UnusedParameters")
protected static String formatLogMessage(long id, Throwable exception) {
return String.format("Error handling a request: %016x", id);
}
}
...@@ -66,7 +66,6 @@ public class TypesREST { ...@@ -66,7 +66,6 @@ public class TypesREST {
@Inject @Inject
public TypesREST(AtlasTypeDefStore typeDefStore) { public TypesREST(AtlasTypeDefStore typeDefStore) {
LOG.info("new TypesREST");
this.typeDefStore = typeDefStore; this.typeDefStore = typeDefStore;
} }
...@@ -76,24 +75,17 @@ public class TypesREST { ...@@ -76,24 +75,17 @@ public class TypesREST {
@Path("/enumdef") @Path("/enumdef")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws Exception { public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException {
AtlasEnumDef ret = null; AtlasEnumDef ret = typeDefStore.createEnumDef(enumDef);
try {
ret = typeDefStore.createEnumDef(enumDef);
return ret; return ret;
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST));
}
} }
@GET @GET
@Path("/enumdef/name/{name}") @Path("/enumdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDef getEnumDefByName(@PathParam("name") String name) throws Exception { public AtlasEnumDef getEnumDefByName(@PathParam("name") String name) throws AtlasBaseException {
AtlasEnumDef ret = null; AtlasEnumDef ret = typeDefStore.getEnumDefByName(name);
ret = typeDefStore.getEnumDefByName(name);
return ret; return ret;
} }
...@@ -101,10 +93,8 @@ public class TypesREST { ...@@ -101,10 +93,8 @@ public class TypesREST {
@GET @GET
@Path("/enumdef/guid/{guid}") @Path("/enumdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDef getEnumDefByGuid(@PathParam("guid") String guid) throws Exception { public AtlasEnumDef getEnumDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
AtlasEnumDef ret = null; AtlasEnumDef ret = typeDefStore.getEnumDefByGuid(guid);
ret = typeDefStore.getEnumDefByGuid(guid);
return ret; return ret;
} }
...@@ -113,10 +103,8 @@ public class TypesREST { ...@@ -113,10 +103,8 @@ public class TypesREST {
@Path("/enumdef/name/{name}") @Path("/enumdef/name/{name}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDef updateEnumDefByName(@PathParam("name") String name, AtlasEnumDef enumDef) throws Exception { public AtlasEnumDef updateEnumDefByName(@PathParam("name") String name, AtlasEnumDef enumDef) throws AtlasBaseException {
AtlasEnumDef ret = null; AtlasEnumDef ret = typeDefStore.updateEnumDefByName(name, enumDef);
ret = typeDefStore.updateEnumDefByName(name, enumDef);
return ret; return ret;
} }
...@@ -125,10 +113,8 @@ public class TypesREST { ...@@ -125,10 +113,8 @@ public class TypesREST {
@Path("/enumdef/guid/{guid}") @Path("/enumdef/guid/{guid}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDef updateEnumDefByGuid(@PathParam("guid") String guid, AtlasEnumDef enumDef) throws Exception { public AtlasEnumDef updateEnumDefByGuid(@PathParam("guid") String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
AtlasEnumDef ret = null; AtlasEnumDef ret = typeDefStore.updateEnumDefByGuid(guid, enumDef);
ret = typeDefStore.updateEnumDefByGuid(guid, enumDef);
return ret; return ret;
} }
...@@ -136,21 +122,21 @@ public class TypesREST { ...@@ -136,21 +122,21 @@ public class TypesREST {
@DELETE @DELETE
@Path("/enumdef/name/{name}") @Path("/enumdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteEnumDefByName(@PathParam("name") String name) throws Exception { public void deleteEnumDefByName(@PathParam("name") String name) throws AtlasBaseException {
typeDefStore.deleteEnumDefByName(name); typeDefStore.deleteEnumDefByName(name);
} }
@DELETE @DELETE
@Path("/enumdef/guid/{guid}") @Path("/enumdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteEnumDefByGuid(@PathParam("guid") String guid) throws Exception { public void deleteEnumDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
typeDefStore.deleteEnumDefByGuid(guid); typeDefStore.deleteEnumDefByGuid(guid);
} }
@GET @GET
@Path("/enumdef") @Path("/enumdef")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEnumDefs searchEnumDefs() throws Exception { public AtlasEnumDefs searchEnumDefs() throws AtlasBaseException {
AtlasEnumDefs ret = null; AtlasEnumDefs ret = null;
SearchFilter filter = getSearchFilter(); SearchFilter filter = getSearchFilter();
...@@ -167,25 +153,17 @@ public class TypesREST { ...@@ -167,25 +153,17 @@ public class TypesREST {
@Path("/structdef") @Path("/structdef")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDef createStructDef(AtlasStructDef structDef) throws Exception { public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException {
AtlasStructDef ret = null; AtlasStructDef ret = typeDefStore.createStructDef(structDef);
try {
ret = typeDefStore.createStructDef(structDef);
return ret; return ret;
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST));
}
} }
@GET @GET
@Path("/structdef/name/{name}") @Path("/structdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDef getStructDefByName(@PathParam("name") String name) throws Exception { public AtlasStructDef getStructDefByName(@PathParam("name") String name) throws AtlasBaseException {
AtlasStructDef ret = null; AtlasStructDef ret = typeDefStore.getStructDefByName(name);
ret = typeDefStore.getStructDefByName(name);
return ret; return ret;
} }
...@@ -193,10 +171,8 @@ public class TypesREST { ...@@ -193,10 +171,8 @@ public class TypesREST {
@GET @GET
@Path("/structdef/guid/{guid}") @Path("/structdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDef getStructDefByGuid(@PathParam("guid") String guid) throws Exception { public AtlasStructDef getStructDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
AtlasStructDef ret = null; AtlasStructDef ret = typeDefStore.getStructDefByGuid(guid);
ret = typeDefStore.getStructDefByGuid(guid);
return ret; return ret;
} }
...@@ -205,10 +181,8 @@ public class TypesREST { ...@@ -205,10 +181,8 @@ public class TypesREST {
@Path("/structdef/name/{name}") @Path("/structdef/name/{name}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDef updateStructDefByName(@PathParam("name") String name, AtlasStructDef structDef) throws Exception { public AtlasStructDef updateStructDefByName(@PathParam("name") String name, AtlasStructDef structDef) throws AtlasBaseException {
AtlasStructDef ret = null; AtlasStructDef ret = typeDefStore.updateStructDefByName(name, structDef);
ret = typeDefStore.updateStructDefByName(name, structDef);
return ret; return ret;
} }
...@@ -217,10 +191,8 @@ public class TypesREST { ...@@ -217,10 +191,8 @@ public class TypesREST {
@Path("/structdef/guid/{guid}") @Path("/structdef/guid/{guid}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDef updateStructDefByGuid(@PathParam("guid") String guid, AtlasStructDef structDef) throws Exception { public AtlasStructDef updateStructDefByGuid(@PathParam("guid") String guid, AtlasStructDef structDef) throws AtlasBaseException {
AtlasStructDef ret = null; AtlasStructDef ret = typeDefStore.updateStructDefByGuid(guid, structDef);
ret = typeDefStore.updateStructDefByGuid(guid, structDef);
return ret; return ret;
} }
...@@ -228,25 +200,23 @@ public class TypesREST { ...@@ -228,25 +200,23 @@ public class TypesREST {
@DELETE @DELETE
@Path("/structdef/name/{name}") @Path("/structdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteStructDefByName(@PathParam("name") String name) throws Exception { public void deleteStructDefByName(@PathParam("name") String name) throws AtlasBaseException {
typeDefStore.deleteStructDefByName(name); typeDefStore.deleteStructDefByName(name);
} }
@DELETE @DELETE
@Path("/structdef/guid/{guid}") @Path("/structdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteStructDefByGuid(@PathParam("guid") String guid) throws Exception { public void deleteStructDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
typeDefStore.deleteStructDefByGuid(guid); typeDefStore.deleteStructDefByGuid(guid);
} }
@GET @GET
@Path("/structdef") @Path("/structdef")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasStructDefs searchStructDefs() throws Exception { public AtlasStructDefs searchStructDefs() throws AtlasBaseException {
AtlasStructDefs ret = null;
SearchFilter filter = getSearchFilter(); SearchFilter filter = getSearchFilter();
ret = typeDefStore.searchStructDefs(filter); AtlasStructDefs ret = typeDefStore.searchStructDefs(filter);
return ret; return ret;
} }
...@@ -257,24 +227,17 @@ public class TypesREST { ...@@ -257,24 +227,17 @@ public class TypesREST {
@Path("/classificationdef") @Path("/classificationdef")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws Exception { public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException {
AtlasClassificationDef ret = null; AtlasClassificationDef ret = typeDefStore.createClassificationDef(classificationDef);
try {
ret = typeDefStore.createClassificationDef(classificationDef);
return ret; return ret;
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST));
}
} }
@GET @GET
@Path("/classificationdef/name/{name}") @Path("/classificationdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDef getClassificationDefByName(@PathParam("name") String name) throws Exception { public AtlasClassificationDef getClassificationDefByName(@PathParam("name") String name) throws AtlasBaseException {
AtlasClassificationDef ret = null; AtlasClassificationDef ret = typeDefStore.getClassificationDefByName(name);
ret = typeDefStore.getClassificationDefByName(name);
return ret; return ret;
} }
...@@ -282,10 +245,8 @@ public class TypesREST { ...@@ -282,10 +245,8 @@ public class TypesREST {
@GET @GET
@Path("/classificationdef/guid/{guid}") @Path("/classificationdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDef getClassificationDefByGuid(@PathParam("guid") String guid) throws Exception { public AtlasClassificationDef getClassificationDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
AtlasClassificationDef ret = null; AtlasClassificationDef ret = typeDefStore.getClassificationDefByGuid(guid);
ret = typeDefStore.getClassificationDefByGuid(guid);
return ret; return ret;
} }
...@@ -294,10 +255,8 @@ public class TypesREST { ...@@ -294,10 +255,8 @@ public class TypesREST {
@Path("/classificationdef/name/{name}") @Path("/classificationdef/name/{name}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDef updateClassificationDefByName(@PathParam("name") String name, AtlasClassificationDef classificationDef) throws Exception { public AtlasClassificationDef updateClassificationDefByName(@PathParam("name") String name, AtlasClassificationDef classificationDef) throws AtlasBaseException {
AtlasClassificationDef ret = null; AtlasClassificationDef ret = typeDefStore.updateClassificationDefByName(name, classificationDef);
ret = typeDefStore.updateClassificationDefByName(name, classificationDef);
return ret; return ret;
} }
...@@ -306,10 +265,8 @@ public class TypesREST { ...@@ -306,10 +265,8 @@ public class TypesREST {
@Path("/classificationdef/guid/{guid}") @Path("/classificationdef/guid/{guid}")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDef updateClassificationDefByGuid(@PathParam("guid") String guid, AtlasClassificationDef classificationDef) throws Exception { public AtlasClassificationDef updateClassificationDefByGuid(@PathParam("guid") String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException {
AtlasClassificationDef ret = null; AtlasClassificationDef ret = typeDefStore.updateClassificationDefByGuid(guid, classificationDef);
ret = typeDefStore.updateClassificationDefByGuid(guid, classificationDef);
return ret; return ret;
} }
...@@ -317,14 +274,14 @@ public class TypesREST { ...@@ -317,14 +274,14 @@ public class TypesREST {
@DELETE @DELETE
@Path("/classificationdef/name/{name}") @Path("/classificationdef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteClassificationDefByName(@PathParam("name") String name) throws Exception { public void deleteClassificationDefByName(@PathParam("name") String name) throws AtlasBaseException {
typeDefStore.deleteClassificationDefByName(name); typeDefStore.deleteClassificationDefByName(name);
} }
@DELETE @DELETE
@Path("/classificationdef/guid/{guid}") @Path("/classificationdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteClassificationDefByGuid(@PathParam("guid") String guid) throws Exception { public void deleteClassificationDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
typeDefStore.deleteClassificationDefByGuid(guid); typeDefStore.deleteClassificationDefByGuid(guid);
} }
...@@ -332,11 +289,10 @@ public class TypesREST { ...@@ -332,11 +289,10 @@ public class TypesREST {
@Path("/classificationdef") @Path("/classificationdef")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassificationDefs searchClassificationDefs() throws Exception { public AtlasClassificationDefs searchClassificationDefs() throws AtlasBaseException {
AtlasClassificationDefs ret = null;
SearchFilter filter = getSearchFilter(); SearchFilter filter = getSearchFilter();
ret = typeDefStore.searchClassificationDefs(filter);
AtlasClassificationDefs ret = typeDefStore.searchClassificationDefs(filter);
return ret; return ret;
} }
...@@ -347,8 +303,8 @@ public class TypesREST { ...@@ -347,8 +303,8 @@ public class TypesREST {
@Path("/entitydef") @Path("/entitydef")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws Exception { public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException {
AtlasEntityDef ret = null; AtlasEntityDef ret = typeDefStore.createEntityDef(entityDef);
try { try {
ret = typeDefStore.createEntityDef(entityDef); ret = typeDefStore.createEntityDef(entityDef);
...@@ -361,10 +317,8 @@ public class TypesREST { ...@@ -361,10 +317,8 @@ public class TypesREST {
@GET @GET
@Path("/entitydef/name/{name}") @Path("/entitydef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByName(@PathParam("name") String name) throws Exception { public AtlasEntityDef getEntityDefByName(@PathParam("name") String name) throws AtlasBaseException {
AtlasEntityDef ret = null; AtlasEntityDef ret = typeDefStore.getEntityDefByName(name);
ret = typeDefStore.getEntityDefByName(name);
return ret; return ret;
} }
...@@ -372,10 +326,8 @@ public class TypesREST { ...@@ -372,10 +326,8 @@ public class TypesREST {
@GET @GET
@Path("/entitydef/guid/{guid}") @Path("/entitydef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByGuid(@PathParam("guid") String guid) throws Exception { public AtlasEntityDef getEntityDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
AtlasEntityDef ret = null; AtlasEntityDef ret = typeDefStore.getEntityDefByGuid(guid);
ret = typeDefStore.getEntityDefByGuid(guid);
return ret; return ret;
} }
...@@ -425,11 +377,9 @@ public class TypesREST { ...@@ -425,11 +377,9 @@ public class TypesREST {
@GET @GET
@Path("/entitydef") @Path("/entitydef")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDefs searchEntityDefs() throws Exception { public AtlasEntityDefs searchEntityDefs() throws AtlasBaseException {
AtlasEntityDefs ret = null;
SearchFilter filter = getSearchFilter(); SearchFilter filter = getSearchFilter();
ret = typeDefStore.searchEntityDefs(filter); AtlasEntityDefs ret = typeDefStore.searchEntityDefs(filter);
return ret; return ret;
} }
...@@ -447,16 +397,10 @@ public class TypesREST { ...@@ -447,16 +397,10 @@ public class TypesREST {
@GET @GET
@Path("/typedefs") @Path("/typedefs")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasTypesDef getAllTypeDefs() throws Exception { public AtlasTypesDef getAllTypeDefs() throws AtlasBaseException {
SearchFilter searchFilter = getSearchFilter(); SearchFilter searchFilter = getSearchFilter();
AtlasTypesDef typesDef = null; AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
try {
typesDef = typeDefStore.searchTypesDef(searchFilter);
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.NOT_FOUND));
}
return typesDef; return typesDef;
} }
...@@ -473,13 +417,9 @@ public class TypesREST { ...@@ -473,13 +417,9 @@ public class TypesREST {
@Path("/typedefs") @Path("/typedefs")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws Exception { public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasBaseException {
AtlasTypesDef ret = null; AtlasTypesDef ret = typeDefStore.createTypesDef(typesDef);
try {
ret = typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST));
}
return ret; return ret;
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<context-param> <context-param>
<param-name>guice.packages</param-name> <param-name>guice.packages</param-name>
<param-value> <param-value>
org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest,org.apache.atlas.web.errors
</param-value> </param-value>
</context-param> </context-param>
......
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