Search in sources :

Example 1 with AssociatedEntitiesDefinition

use of org.kie.server.api.model.definition.AssociatedEntitiesDefinition in project droolsjbpm-integration by kiegroup.

the class DefinitionResource method getAssociatedEntities.

@ApiOperation(value = "Retrieves actors and groups that are involved in given process and container")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process or Container Id not found"), @ApiResponse(code = 200, response = AssociatedEntitiesDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_ENTITIES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_DEF_ASSOCIATED_ENTITIES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAssociatedEntities(@Context HttpHeaders headers, @ApiParam(value = "container id where the process definition resides", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "process id that the involved actors and groups should be retrieved from", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        AssociatedEntitiesDefinition associatedEntitiesDefinition = definitionServiceBase.getAssociatedEntities(containerId, processId);
        return createCorrectVariant(associatedEntitiesDefinition, headers, Response.Status.OK, conversationIdHeader);
    } catch (IllegalStateException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), v, conversationIdHeader);
    } catch (Exception e) {
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) 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) AssociatedEntitiesDefinition(org.kie.server.api.model.definition.AssociatedEntitiesDefinition) 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 2 with AssociatedEntitiesDefinition

use of org.kie.server.api.model.definition.AssociatedEntitiesDefinition in project droolsjbpm-integration by kiegroup.

the class ProcessServicesClientImpl method getAssociatedEntityDefinitions.

@Override
public AssociatedEntitiesDefinition getAssociatedEntityDefinitions(String containerId, String processId) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_ID, processId);
        return makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_ASSOCIATED_ENTITIES_GET_URI, valuesMap), AssociatedEntitiesDefinition.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("DefinitionService", "getAssociatedEntities", new Object[] { containerId, processId })));
        ServiceResponse<AssociatedEntitiesDefinition> response = (ServiceResponse<AssociatedEntitiesDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) AssociatedEntitiesDefinition(org.kie.server.api.model.definition.AssociatedEntitiesDefinition)

Example 3 with AssociatedEntitiesDefinition

use of org.kie.server.api.model.definition.AssociatedEntitiesDefinition in project droolsjbpm-integration by kiegroup.

the class ProcessDefinitionIntegrationTest method testAssociatedEntitiesDefinition.

@Test
public void testAssociatedEntitiesDefinition() {
    AssociatedEntitiesDefinition result = processClient.getAssociatedEntityDefinitions(CONTAINER_ID, PROCESS_ID_EVALUATION);
    // assert associated entities - users and groups
    Map<String, String[]> entities = result.getAssociatedEntities();
    assertNotNull(entities);
    assertTrue(entities.containsKey("Evaluate items?"));
    String[] evaluateItemsEntities = entities.get("Evaluate items?");
    assertEquals(2, evaluateItemsEntities.length);
    assertEquals(USER_YODA, evaluateItemsEntities[0]);
    assertEquals("HR,PM", evaluateItemsEntities[1]);
}
Also used : AssociatedEntitiesDefinition(org.kie.server.api.model.definition.AssociatedEntitiesDefinition) Test(org.junit.Test)

Aggregations

AssociatedEntitiesDefinition (org.kie.server.api.model.definition.AssociatedEntitiesDefinition)3 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 Test (org.junit.Test)1 CommandScript (org.kie.server.api.commands.CommandScript)1 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)1 KieServerCommand (org.kie.server.api.model.KieServerCommand)1 ServiceResponse (org.kie.server.api.model.ServiceResponse)1 Header (org.kie.server.remote.rest.common.Header)1 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)1 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)1 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)1