Commit bb9c1e10 by Venkatesh Seetharam

BUG-37719 listing entities return's a 500

parent 9f28c422
...@@ -110,8 +110,6 @@ public class EntityResource { ...@@ -110,8 +110,6 @@ public class EntityResource {
@Path("{guid}") @Path("{guid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getEntityDefinition(@PathParam("guid") String guid) { public Response getEntityDefinition(@PathParam("guid") String guid) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
try { try {
LOG.debug("Fetching entity definition for guid={} ", guid); LOG.debug("Fetching entity definition for guid={} ", guid);
final String entityDefinition = metadataService.getEntityDefinition(guid); final String entityDefinition = metadataService.getEntityDefinition(guid);
...@@ -144,13 +142,14 @@ public class EntityResource { ...@@ -144,13 +142,14 @@ public class EntityResource {
/** /**
* Gets the list of entities for a given entity type. * Gets the list of entities for a given entity type.
* *
* @param entityType name of a type which is unique * @param entityType name of a type which is unique
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getEntityListByType(@QueryParam("type") String entityType) { public Response getEntityListByType(@QueryParam("type") String entityType) {
Preconditions.checkNotNull(entityType, "Entity type cannot be null");
try { try {
Preconditions.checkNotNull(entityType, "Entity type cannot be null");
LOG.debug("Fetching entity list for type={} ", entityType); LOG.debug("Fetching entity list for type={} ", entityType);
final List<String> entityList = metadataService.getEntityList(entityType); final List<String> entityList = metadataService.getEntityList(entityType);
...@@ -161,6 +160,10 @@ public class EntityResource { ...@@ -161,6 +160,10 @@ public class EntityResource {
response.put(MetadataServiceClient.COUNT, entityList.size()); response.put(MetadataServiceClient.COUNT, entityList.size());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (NullPointerException e) {
LOG.error("Entity type cannot be null", e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (MetadataException | IllegalArgumentException e) { } catch (MetadataException | IllegalArgumentException e) {
LOG.error("Unable to get entity list for type {}", entityType, e); LOG.error("Unable to get entity list for type {}", entityType, e);
throw new WebApplicationException( throw new WebApplicationException(
...@@ -213,8 +216,6 @@ public class EntityResource { ...@@ -213,8 +216,6 @@ public class EntityResource {
@Path("{guid}/traits") @Path("{guid}/traits")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getTraitNames(@PathParam("guid") String guid) { public Response getTraitNames(@PathParam("guid") String guid) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
try { try {
LOG.debug("Fetching trait names for entity={}", guid); LOG.debug("Fetching trait names for entity={}", guid);
final List<String> traitNames = metadataService.getTraitNames(guid); final List<String> traitNames = metadataService.getTraitNames(guid);
...@@ -248,8 +249,6 @@ public class EntityResource { ...@@ -248,8 +249,6 @@ public class EntityResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response addTrait(@Context HttpServletRequest request, public Response addTrait(@Context HttpServletRequest request,
@PathParam("guid") String guid) { @PathParam("guid") String guid) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
try { try {
final String traitDefinition = Servlets.getRequestPayload(request); final String traitDefinition = Servlets.getRequestPayload(request);
LOG.debug("Adding trait={} for entity={} ", traitDefinition, guid); LOG.debug("Adding trait={} for entity={} ", traitDefinition, guid);
...@@ -288,9 +287,6 @@ public class EntityResource { ...@@ -288,9 +287,6 @@ public class EntityResource {
public Response deleteTrait(@Context HttpServletRequest request, public Response deleteTrait(@Context HttpServletRequest request,
@PathParam("guid") String guid, @PathParam("guid") String guid,
@PathParam(TRAIT_NAME) String traitName) { @PathParam(TRAIT_NAME) String traitName) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
Preconditions.checkNotNull(traitName, "Trait name cannot be null");
LOG.debug("Deleting trait={} from entity={} ", traitName, guid); LOG.debug("Deleting trait={} from entity={} ", traitName, guid);
try { try {
metadataService.deleteTrait(guid, traitName); metadataService.deleteTrait(guid, traitName);
......
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