4
4
import io .zentity .model .ValidationException ;
5
5
import io .zentity .resolution .Job ;
6
6
import io .zentity .resolution .input .Input ;
7
+ import org .elasticsearch .action .get .GetResponse ;
7
8
import org .elasticsearch .client .node .NodeClient ;
8
9
import org .elasticsearch .common .inject .Inject ;
9
10
import org .elasticsearch .common .settings .Settings ;
@@ -55,10 +56,15 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
55
56
56
57
// Parse and validate the job input.
57
58
Input input ;
58
- if (entityType == null || entityType .equals ("" ))
59
+ if (entityType == null || entityType .equals ("" )) {
59
60
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
+ }
62
68
if (input .attributes ().isEmpty ())
63
69
throw new ValidationException ("'attributes' is missing." );
64
70
if (input .model () == null )
@@ -82,6 +88,8 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
82
88
83
89
} catch (ValidationException e ) {
84
90
channel .sendResponse (new BytesRestResponse (channel , RestStatus .BAD_REQUEST , e ));
91
+ } catch (NotFoundException e ) {
92
+ channel .sendResponse (new BytesRestResponse (channel , RestStatus .NOT_FOUND , e ));
85
93
}
86
94
};
87
95
}
0 commit comments