Search in sources :

Example 1 with ModelResponse

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;
}
Also used : ModelResponse(org.openscoring.common.ModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse)

Example 2 with ModelResponse

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();
    }
}
Also used : ModelResponse(org.openscoring.common.ModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) IOException(java.io.IOException) EvaluationException(org.jpmml.evaluator.EvaluationException)

Example 3 with ModelResponse

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;
}
Also used : BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ArrayList(java.util.ArrayList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ModelResponse

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);
}
Also used : ModelResponse(org.openscoring.common.ModelResponse)

Example 5 with ModelResponse

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);
}
Also used : Variant(javax.ws.rs.core.Variant) Response(javax.ws.rs.core.Response) ModelResponse(org.openscoring.common.ModelResponse) Invocation(javax.ws.rs.client.Invocation) ModelResponse(org.openscoring.common.ModelResponse) PushbackInputStream(java.io.PushbackInputStream) WebTarget(javax.ws.rs.client.WebTarget) FileInputStream(java.io.FileInputStream)

Aggregations

ModelResponse (org.openscoring.common.ModelResponse)9 BatchModelResponse (org.openscoring.common.BatchModelResponse)7 Response (javax.ws.rs.core.Response)4 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)4 EvaluationResponse (org.openscoring.common.EvaluationResponse)4 SimpleResponse (org.openscoring.common.SimpleResponse)3 InputStream (java.io.InputStream)2 URI (java.net.URI)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PushbackInputStream (java.io.PushbackInputStream)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BadRequestException (javax.ws.rs.BadRequestException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Produces (javax.ws.rs.Produces)1