use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class SignalService method signalEventReceived.
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response signalEventReceived(SignalEventReceivedRequest signalRequest) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (signalRequest.getSignalName() == null) {
throw new ActivitiIllegalArgumentException("signalName is required");
}
Map<String, Object> signalVariables = null;
if (signalRequest.getVariables() != null) {
signalVariables = new HashMap<String, Object>();
for (RestVariable variable : signalRequest.getVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required.");
}
signalVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
if (signalRequest.isAsync()) {
if (signalVariables != null) {
throw new ActivitiIllegalArgumentException("Async signals cannot take variables as payload");
}
if (signalRequest.isCustomTenantSet()) {
runtimeService.signalEventReceivedAsyncWithTenantId(signalRequest.getSignalName(), signalRequest.getTenantId());
} else {
runtimeService.signalEventReceivedAsync(signalRequest.getSignalName());
}
return Response.ok().status(Response.Status.ACCEPTED).build();
} else {
if (signalRequest.isCustomTenantSet()) {
runtimeService.signalEventReceivedWithTenantId(signalRequest.getSignalName(), signalVariables, signalRequest.getTenantId());
} else {
runtimeService.signalEventReceived(signalRequest.getSignalName(), signalVariables);
}
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class WorkflowTaskService method completeTask.
protected void completeTask(Task task, TaskActionRequest actionRequest, TaskService taskService) {
if (actionRequest.getVariables() != null) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
RestResponseFactory restResponseFactory = new RestResponseFactory();
for (RestVariable var : actionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
taskService.complete(task.getId(), variablesToSet);
} else {
taskService.complete(task.getId());
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class WorkflowTaskService method getEvents.
@GET
@Path("/{taskId}/events")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getEvents(@PathParam("taskId") String taskId) {
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
TaskService taskService = BPMNOSGIService.getTaskService();
List<EventResponse> eventResponseList = new RestResponseFactory().createEventResponseList(taskService.getTaskEvents(task.getId()), uriInfo.getBaseUri().toString());
EventResponseCollection eventResponseCollection = new EventResponseCollection();
eventResponseCollection.setEventResponseList(eventResponseList);
return Response.ok().entity(eventResponseCollection).build();
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class WorkflowTaskService method getIdentityLink.
/* protected AttachmentResponse createBinaryAttachment(HttpServletRequest httpServletRequest, Task task, Response.ResponseBuilder responseBuilder) throws
IOException {
String name = uriInfo.getQueryParameters().getFirst("name");
String description = uriInfo.getQueryParameters().getFirst("description");
String type = uriInfo.getQueryParameters().getFirst("type");
byte[] byteArray = Utils.processMultiPartFile(httpServletRequest, "Attachment content");
if (byteArray == null) {
throw new ActivitiIllegalArgumentException("Empty attachment body was found in request body after " +
"decoding the request" +
".");
}
if (name == null) {
throw new ActivitiIllegalArgumentException("Attachment name is required.");
}
TaskService taskService = BPMNOSGIService.getTaskService();
try {
InputStream inputStream = new ByteArrayInputStream(byteArray);
Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name,
description, inputStream);
responseBuilder.status(Response.Status.CREATED);
return new RestResponseFactory().createAttachmentResponse(createdAttachment, uriInfo.getBaseUri().toString());
} catch (Exception e) {
throw new ActivitiException("Error creating attachment response", e);
}
}*/
protected IdentityLink getIdentityLink(String family, String identityId, String type, String taskId) {
boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
TaskService taskService = BPMNOSGIService.getTaskService();
// Perhaps it would be better to offer getting a single identitylink from the API
List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(taskId);
for (IdentityLink link : allLinks) {
boolean rightIdentity = false;
if (isUser) {
rightIdentity = identityId.equals(link.getUserId());
} else {
rightIdentity = identityId.equals(link.getGroupId());
}
if (rightIdentity && link.getType().equals(type)) {
return link;
}
}
throw new ActivitiObjectNotFoundException("Could not find the requested identity link.", IdentityLink.class);
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class WorkflowTaskService method getIdentityLink.
@GET
@Path("/{taskId}/identitylinks/{family}/{identityId}/{type}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLink(@PathParam("taskId") String taskId, @PathParam("family") String family, @PathParam("identityId") String identityId, @PathParam("type") String type, @Context HttpServletRequest httpServletRequest) {
Task task = getTaskFromRequest(taskId);
validateIdentityLinkArguments(family, identityId, type);
IdentityLink link = getIdentityLink(family, identityId, type, task.getId());
return Response.ok().entity(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString())).build();
}
Aggregations