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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations