use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResource method createModelResponse.
private static ModelResponse createModelResponse(String id, Model model, boolean expand) {
ModelResponse response = new ModelResponse(id);
response.setMiningFunction(model.getMiningFunction());
response.setSummary(model.getSummary());
response.setProperties(model.getProperties());
if (expand) {
response.setSchema(model.getSchema());
}
return response;
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResource method doDeploy.
private Response doDeploy(String id, InputStream is) {
Model model;
try {
model = this.modelRegistry.load(is);
} catch (Exception e) {
logger.error("Failed to load PMML document", e);
throw new BadRequestException(e);
}
boolean success;
Model oldModel = this.modelRegistry.get(id);
if (oldModel != null) {
success = this.modelRegistry.replace(id, oldModel, model);
} else {
success = this.modelRegistry.put(id, model);
}
if (!success) {
throw new InternalServerErrorException("Concurrent modification");
}
ModelResponse entity = createModelResponse(id, model, true);
if (oldModel != null) {
return (Response.ok().entity(entity)).build();
} else {
UriBuilder uriBuilder = (this.uriInfo.getBaseUriBuilder()).path(ModelResource.class).path(id);
URI uri = uriBuilder.build();
return (Response.created(uri).entity(entity)).build();
}
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResource method queryBatch.
@GET
@Produces(MediaType.APPLICATION_JSON)
public BatchModelResponse queryBatch() {
BatchModelResponse batchResponse = new BatchModelResponse();
List<ModelResponse> responses = new ArrayList<>();
Collection<Map.Entry<String, Model>> entries = this.modelRegistry.entries();
for (Map.Entry<String, Model> entry : entries) {
ModelResponse response = createModelResponse(entry.getKey(), entry.getValue(), false);
responses.add(response);
}
Comparator<ModelResponse> comparator = new Comparator<ModelResponse>() {
@Override
public int compare(ModelResponse left, ModelResponse right) {
return (left.getId()).compareToIgnoreCase(right.getId());
}
};
Collections.sort(responses, comparator);
batchResponse.setResponses(responses);
return batchResponse;
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class Deployer method run.
@Override
public void run() throws Exception {
ModelResponse response = deploy();
String message = response.getMessage();
if (message != null) {
logger.warn("Deployment failed: {}", message);
return;
}
logger.info("Deployment succeeded: {}", response);
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class Deployer method deploy.
public ModelResponse deploy() throws Exception {
Operation<ModelResponse> operation = new Operation<ModelResponse>() {
@Override
public ModelResponse perform(WebTarget target) throws IOException {
try (PushbackInputStream is = new PushbackInputStream(new FileInputStream(getFile()), 16)) {
String encoding = getContentEncoding(is);
Variant variant = new Variant(MediaType.APPLICATION_XML_TYPE, (Locale) null, encoding);
Invocation invocation = target.request(MediaType.APPLICATION_JSON).buildPut(Entity.entity(is, variant));
Response response = invocation.invoke();
return response.readEntity(ModelResponse.class);
}
}
};
return execute(operation);
}
Aggregations