use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.
the class CommandResource method manageContainer.
@ApiOperation(value = "Executes one or more runtime commands")
@ApiResponses({ @ApiResponse(code = 200, message = "Successful execution", response = ServiceResponse.class), @ApiResponse(code = 500, message = "Unexpected error", response = ServiceResponse.class), @ApiResponse(code = 204, message = "Command execute successfully, but without response", response = ServiceResponse.class) })
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response manageContainer(@Context HttpHeaders headers, @ApiParam(value = "Container id where rules should be evaluated on", required = true) @PathParam(RestURI.CONTAINER_ID) String id, @ApiParam(value = "Commands to be executed on rule engine given as BatchExecutionCommand type", required = true) String cmdPayload) {
Variant v = getVariant(headers);
String contentType = getContentType(headers);
String classType = getClassType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
if (format == null) {
format = MarshallingFormat.valueOf(contentType);
}
logger.debug("Received request with content '{}'", cmdPayload);
Header conversationIdHeader = buildConversationIdHeader(id, registry, headers);
@SuppressWarnings("squid:S3740") ServiceResponse<?> result = delegate.callContainer(id, cmdPayload, format, classType);
Status status = result.getType() == FAILURE ? INTERNAL_SERVER_ERROR : OK;
try {
String response = marshallerHelper.marshal(id, format.getType(), result, ContainerLocatorProvider.get().getLocator());
logger.debug("Returning {} response with content '{}'", status, response);
return createResponse(response, v, status, conversationIdHeader);
} catch (IllegalArgumentException e) {
// in case marshalling failed return the call container response to keep backward compatibility
String response = marshallerHelper.marshal(format.getType(), result);
logger.debug("Returning {} response with content '{}'", status, response);
return createResponse(response, v, status, conversationIdHeader);
}
}
use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.
the class FormResource method getTaskRenderedForm.
@ApiOperation(value = "Returns the rendered form for a specified task instance.", response = String.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Task, form or Container Id not found") })
@GET
@Path(TASK_FORM_CONTENT_GET_URI)
@Produces({ MediaType.TEXT_HTML })
public Response getTaskRenderedForm(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that task instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of task instance that form should be fetched for", required = true, example = "123") @PathParam(TASK_INSTANCE_ID) Long taskId, @ApiParam(value = "optional renderer name that the form should be rendered with", required = false) @QueryParam("renderer") @DefaultValue("patternfly") String renderer) {
Variant variant = getVariant(headers);
Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
try {
String renderedForm = formRendererBase.getTaskRenderedForm(renderer, containerId, taskId);
if (renderedForm == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok().entity(renderedForm).build();
} catch (PermissionDeniedException e) {
return permissionDenied(MessageFormat.format(TASK_PERMISSION_ERROR, taskId), variant, conversationIdHeader);
} catch (TaskNotFoundException e) {
return notFound(MessageFormat.format(TASK_INSTANCE_NOT_FOUND, taskId), variant, conversationIdHeader);
} catch (DeploymentNotFoundException e) {
return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), variant, conversationIdHeader);
} catch (IllegalArgumentException | IllegalStateException e) {
return notFound(e.getMessage(), variant, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), variant, conversationIdHeader);
}
}
use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.
the class FormResource method getCaseRenderedForm.
@ApiOperation(value = "Returns the rendered form for a specified case definition.", response = String.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Case, form or Container Id not found") })
@GET
@Path(CASE_FORM_CONTENT_GET_URI)
@Produces({ MediaType.TEXT_HTML })
public Response getCaseRenderedForm(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that case definition belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of case definition that form should be fetched for", required = true, example = "orderhardware") @PathParam("caseDefId") String caseDefId, @ApiParam(value = "optional renderer name that the form should be rendered with", required = false) @QueryParam("renderer") @DefaultValue("patternfly") String renderer) {
Variant variant = getVariant(headers);
Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
try {
String renderedForm = formRendererBase.getCaseRenderedForm(renderer, containerId, caseDefId);
if (renderedForm == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok().entity(renderedForm).build();
} catch (DeploymentNotFoundException e) {
return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), variant, conversationIdHeader);
} catch (ProcessDefinitionNotFoundException e) {
return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, caseDefId, containerId), variant, conversationIdHeader);
} catch (IllegalArgumentException e) {
return notFound(e.getMessage(), variant, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), variant, conversationIdHeader);
}
}
use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.
the class KieServerRestImpl method updateScanner.
@ApiOperation(value = "Starts or stops a KIE scanner that controls polling for updated KIE container deployments, if applicable.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ServiceResponse.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = UPDATE_SCANNER_RESPONSE_JSON) })) })
@POST
@Path("containers/{" + CONTAINER_ID + "}/scanner")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateScanner(@Context HttpHeaders headers, @ApiParam(value = "Container id for scanner to be updated", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String id, @ApiParam(value = "Scanner information given as KieScannerResource type", required = true, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = UPDATE_SCANNER_JSON), @ExampleProperty(mediaType = XML, value = UPDATE_SCANNER_XML) })) String resourcePayload) {
ServiceResponse<?> forbidden = this.server.checkAccessability();
if (forbidden != null) {
return createCorrectVariant(forbidden, headers, Status.BAD_REQUEST);
}
String contentType = getContentType(headers);
KieScannerResource resource = marshallerHelper.unmarshal(resourcePayload, contentType, KieScannerResource.class);
Header conversationIdHeader = buildConversationIdHeader(id, server.getServerRegistry(), headers);
return createCorrectVariant(server.updateScanner(id, resource), headers, conversationIdHeader);
}
use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.
the class KieServerRestImpl method updateReleaseId.
@ApiOperation(value = "Updates release ID information (group ID, artifact ID, version) for a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ServiceResponse.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = UPDATE_RELEASE_RESPONSE_JSON) })) })
@POST
@Path("containers/{" + CONTAINER_ID + "}/release-id")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateReleaseId(@Context HttpHeaders headers, @ApiParam(value = "Container id that release id should be upgraded", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String id, @ApiParam(value = "Release Id to be upgraded to as ReleaseId type", required = true, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = UPDATE_RELEASE_ID_JSON), @ExampleProperty(mediaType = XML, value = UPDATE_RELEASE_ID_XML) })) String releaseIdPayload, @ApiParam(value = "Determines whether active processes are aborted (reset) before updating when the server runs in development mode") @QueryParam("resetBeforeUpdate") @DefaultValue("false") boolean resetBeforeUpdate) {
ServiceResponse<?> forbidden = this.server.checkAccessability();
if (forbidden != null) {
return createCorrectVariant(forbidden, headers, Status.BAD_REQUEST);
}
String contentType = getContentType(headers);
ReleaseId releaseId = marshallerHelper.unmarshal(releaseIdPayload, contentType, ReleaseId.class);
Header conversationIdHeader = buildConversationIdHeader(id, server.getServerRegistry(), headers);
return createCorrectVariant(server.updateContainerReleaseId(id, releaseId, resetBeforeUpdate), headers, conversationIdHeader);
}
Aggregations