44import io .zentity .model .ValidationException ;
55import io .zentity .resolution .Job ;
66import io .zentity .resolution .input .Input ;
7+ import org .elasticsearch .action .get .GetResponse ;
78import org .elasticsearch .client .node .NodeClient ;
89import org .elasticsearch .common .inject .Inject ;
910import org .elasticsearch .common .settings .Settings ;
@@ -55,10 +56,15 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
5556
5657 // Parse and validate the job input.
5758 Input input ;
58- if (entityType == null || entityType .equals ("" ))
59+ if (entityType == null || entityType .equals ("" )) {
5960 input = new Input (body , entityType );
60- else
61- input = new Input (body , new Model (ModelsAction .getEntityModel (entityType , client ).getSourceAsString ()));
61+ } else {
62+ GetResponse getResponse = ModelsAction .getEntityModel (entityType , client );
63+ if (!getResponse .isExists ())
64+ throw new NotFoundException ("Entity type '" + entityType + "' not found." );
65+ String model = getResponse .getSourceAsString ();
66+ input = new Input (body , new Model (model ));
67+ }
6268 if (input .attributes ().isEmpty ())
6369 throw new ValidationException ("'attributes' is missing." );
6470 if (input .model () == null )
@@ -82,6 +88,8 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
8288
8389 } catch (ValidationException e ) {
8490 channel .sendResponse (new BytesRestResponse (channel , RestStatus .BAD_REQUEST , e ));
91+ } catch (NotFoundException e ) {
92+ channel .sendResponse (new BytesRestResponse (channel , RestStatus .NOT_FOUND , e ));
8593 }
8694 };
8795 }
0 commit comments