Search in sources :

Example 26 with Variant

use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.

the class ScenarioSimulationResource method executeSimulation.

@ApiOperation(value = "Execute given test scenario against specified container", response = ServiceResponse.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container not found"), @ApiResponse(code = 400, message = "Malformed test scenario file") })
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response executeSimulation(@Context HttpHeaders headers, @ApiParam(value = "Container id", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "Test scenario file content to be executed", required = true) String rawContent) {
    KieContainer kieContainer = null;
    ScenarioSimulationModel model = null;
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, scenarioSimulationService.getKieServerRegistry(), headers);
    try {
        kieContainer = scenarioSimulationService.getKieContainerById(containerId);
    } catch (Exception e) {
        return createCorrectVariant(createFailedServiceResponse("Impossible to find container with id " + containerId, e), headers, Response.Status.NOT_FOUND, conversationIdHeader);
    }
    try {
        model = scenarioSimulationService.parseModel(rawContent);
    } catch (Exception e) {
        return createCorrectVariant(createFailedServiceResponse("Test scenario parsing error", e), headers, Response.Status.BAD_REQUEST, conversationIdHeader);
    }
    try {
        return createCorrectVariant(scenarioSimulationService.executeScenario(kieContainer, model), headers, Response.Status.OK, conversationIdHeader);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return internalServerError(e.getMessage(), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) KieContainer(org.kie.api.runtime.KieContainer) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with Variant

use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.

the class SolverResource method getSolver.

@ApiOperation(value = "Retrieves solver by its identifier from given container", response = SolverInstance.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container does not exist or failure in creating solver") })
@GET
@Path(RestURI.SOLVER_ID_URI)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSolver(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the solver resides", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the solver", required = true) @PathParam(SOLVER_ID) String solverId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, solverService.getKieServerRegistry(), headers);
    try {
        ServiceResponse<SolverInstance> result = solverService.getSolver(containerId, solverId);
        if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
            return createCorrectVariant(marshallerHelper, containerId, result.getResult(), headers, Response.Status.OK, conversationIdHeader);
        }
        return createCorrectVariant(marshallerHelper, containerId, result.getMsg(), headers, Response.Status.NOT_FOUND, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error retrieving solver state {}", e.getMessage(), e);
        return internalServerError(MessageFormat.format(Messages.UNEXPECTED_ERROR, e.getMessage()), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) SolverInstance(org.kie.server.api.model.instance.SolverInstance) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 28 with Variant

use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.

the class SolverResource method disposeSolver.

@ApiOperation(value = "Disposes given solver", response = Void.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container does not exist or failure in creating solver") })
@DELETE
@Path(RestURI.SOLVER_ID_URI)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response disposeSolver(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the solver resides", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the solver", required = true) @PathParam(SOLVER_ID) String solverId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, solverService.getKieServerRegistry(), headers);
    try {
        ServiceResponse<Void> result = solverService.disposeSolver(containerId, solverId);
        if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
            return createResponse("", v, Response.Status.OK, conversationIdHeader);
        }
        return createCorrectVariant(marshallerHelper, containerId, result.getMsg(), headers, Response.Status.BAD_REQUEST, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error disposing solver {} on container {}. Message: '{}'", solverId, containerId, e.getMessage(), e);
        return internalServerError(MessageFormat.format(Messages.UNEXPECTED_ERROR, e.getMessage()), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 29 with Variant

use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.

the class SolverResource method getSolverWithBestSolution.

@ApiOperation(value = "Retrieves best solution from solver within container", response = SolverInstance.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container does not exist or failure in creating solver") })
@GET
@Path(SOLVER_ID_URI + "/" + SOLVER_BEST_SOLUTION)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSolverWithBestSolution(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the solver resides", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the solver", required = true) @PathParam(SOLVER_ID) String solverId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, solverService.getKieServerRegistry(), headers);
    try {
        ServiceResponse<SolverInstance> result = solverService.getSolverWithBestSolution(containerId, solverId);
        if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
            return createCorrectVariant(marshallerHelper, containerId, result.getResult(), headers, Response.Status.OK, conversationIdHeader);
        }
        return createCorrectVariant(marshallerHelper, containerId, result.getMsg(), headers, Response.Status.NOT_FOUND, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(MessageFormat.format(Messages.UNEXPECTED_ERROR, e.getMessage()), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) SolverInstance(org.kie.server.api.model.instance.SolverInstance) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 30 with Variant

use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.

the class SolverResource method isEveryProblemFactChangeProcessed.

@ApiOperation(value = "Retrieves status if problem fact changes have been processed in given solver", response = Boolean.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container does not exist or failure in creating solver") })
@GET
@Path(RestURI.SOLVER_ID_URI + "/" + SOLVER_PROBLEM_FACTS_CHANGES_PROCESSED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response isEveryProblemFactChangeProcessed(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the solver resides", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the solver", required = true) @PathParam(SOLVER_ID) String solverId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, solverService.getKieServerRegistry(), headers);
    try {
        ServiceResponse<Boolean> result = solverService.isEveryProblemFactChangeProcessed(containerId, solverId);
        if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
            return createCorrectVariant(marshallerHelper, containerId, result.getResult(), headers, Response.Status.OK, conversationIdHeader);
        }
        return createCorrectVariant(marshallerHelper, containerId, result.getMsg(), headers, Response.Status.NOT_FOUND, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error querying problem facts processing state {}", e.getMessage(), e);
        return internalServerError(MessageFormat.format(Messages.UNEXPECTED_ERROR, e.getMessage()), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Variant (javax.ws.rs.core.Variant)269 Produces (javax.ws.rs.Produces)187 Header (org.kie.server.remote.rest.common.Header)183 ApiOperation (io.swagger.annotations.ApiOperation)180 Path (javax.ws.rs.Path)176 ApiResponses (io.swagger.annotations.ApiResponses)174 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)174 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)169 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)167 GET (javax.ws.rs.GET)102 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)74 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)71 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)69 Consumes (javax.ws.rs.Consumes)52 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)41 PUT (javax.ws.rs.PUT)39 Locale (java.util.Locale)33 POST (javax.ws.rs.POST)33 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)31 ExecutionErrorNotFoundException (org.jbpm.services.api.admin.ExecutionErrorNotFoundException)31