Search in sources :

Example 81 with Header

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);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Status(javax.ws.rs.core.Response.Status) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) 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 82 with Header

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);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) JSONException(org.json.JSONException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) 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 83 with Header

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);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) JSONException(org.json.JSONException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) 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 84 with Header

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);
}
Also used : KieScannerResource(org.kie.server.api.model.KieScannerResource) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) 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 85 with Header

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);
}
Also used : Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ReleaseId(org.kie.server.api.model.ReleaseId) Path(javax.ws.rs.Path) 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)

Aggregations

Header (org.kie.server.remote.rest.common.Header)212 ApiOperation (io.swagger.annotations.ApiOperation)203 Produces (javax.ws.rs.Produces)203 ApiResponses (io.swagger.annotations.ApiResponses)197 Path (javax.ws.rs.Path)191 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)190 Variant (javax.ws.rs.core.Variant)184 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)175 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)168 GET (javax.ws.rs.GET)110 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)75 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)72 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)70 Consumes (javax.ws.rs.Consumes)54 PUT (javax.ws.rs.PUT)42 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)41 POST (javax.ws.rs.POST)35 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)31 ExecutionErrorNotFoundException (org.jbpm.services.api.admin.ExecutionErrorNotFoundException)31 DeploymentNotActiveException (org.jbpm.services.api.DeploymentNotActiveException)25