Skip to content
Permalink
Browse files
Throw NotFoundException if the requested entity_type does not exist w…
…hen submitting a resolution job. Fixes a vague NullPointerException.
  • Loading branch information
davemoore- committed May 17, 2018
1 parent 79a00e3 commit b5b6d88007537323e12d6ec6a50654bdee85f0d9
Showing 1 changed file with 11 additions and 3 deletions.
@@ -4,6 +4,7 @@
import io.zentity.model.ValidationException;
import io.zentity.resolution.Job;
import io.zentity.resolution.input.Input;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@@ -55,10 +56,15 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient

// Parse and validate the job input.
Input input;
if (entityType == null || entityType.equals(""))
if (entityType == null || entityType.equals("")) {
input = new Input(body, entityType);
else
input = new Input(body, new Model(ModelsAction.getEntityModel(entityType, client).getSourceAsString()));
} else {
GetResponse getResponse = ModelsAction.getEntityModel(entityType, client);
if (!getResponse.isExists())
throw new NotFoundException("Entity type '" + entityType + "' not found.");
String model = getResponse.getSourceAsString();
input = new Input(body, new Model(model));
}
if (input.attributes().isEmpty())
throw new ValidationException("'attributes' is missing.");
if (input.model() == null)
@@ -82,6 +88,8 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient

} catch (ValidationException e) {
channel.sendResponse(new BytesRestResponse(channel, RestStatus.BAD_REQUEST, e));
} catch (NotFoundException e) {
channel.sendResponse(new BytesRestResponse(channel, RestStatus.NOT_FOUND, e));
}
};
}

0 comments on commit b5b6d88

Please sign in to comment.