use of water.api.schemas99.AssemblyV99 in project h2o-3 by h2oai.
the class RequestServer method serveSchema.
private static NanoResponse serveSchema(Schema s, RequestType type) {
// Convert Schema to desired output flavor
String http_response_header = H2OError.httpStatusHeader(HttpResponseStatus.OK.getCode());
// If we're given an http response code use it.
if (s instanceof SpecifiesHttpResponseCode) {
http_response_header = H2OError.httpStatusHeader(((SpecifiesHttpResponseCode) s).httpStatus());
}
// If we've gotten an error always return the error as JSON
if (s instanceof SpecifiesHttpResponseCode && HttpResponseStatus.OK.getCode() != ((SpecifiesHttpResponseCode) s).httpStatus()) {
type = RequestType.json;
}
if (s instanceof H2OErrorV3) {
return new NanoResponse(http_response_header, MIME_JSON, s.toJsonString());
}
if (s instanceof StreamingSchema) {
StreamingSchema ss = (StreamingSchema) s;
NanoResponse r = new NanoStreamResponse(http_response_header, MIME_DEFAULT_BINARY, ss.getStreamWriter());
// Needed to make file name match class name
r.addHeader("Content-Disposition", "attachment; filename=\"" + ss.getFilename() + "\"");
return r;
}
// TODO: remove this entire switch
switch(type) {
// return JSON for html requests
case html:
case json:
return new NanoResponse(http_response_header, MIME_JSON, s.toJsonString());
case xml:
throw H2O.unimpl("Unknown type: " + type.toString());
case java:
if (s instanceof AssemblyV99) {
// TODO: fix the AssemblyV99 response handler so that it produces the appropriate StreamingSchema
Assembly ass = DKV.getGet(((AssemblyV99) s).assembly_id);
NanoResponse r = new NanoResponse(http_response_header, MIME_DEFAULT_BINARY, ass.toJava(((AssemblyV99) s).pojo_name));
r.addHeader("Content-Disposition", "attachment; filename=\"" + JCodeGen.toJavaId(((AssemblyV99) s).pojo_name) + ".java\"");
return r;
} else {
throw new H2OIllegalArgumentException("Cannot generate java for type: " + s.getClass().getSimpleName());
}
default:
throw H2O.unimpl("Unknown type to serveSchema(): " + type);
}
}
Aggregations