use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class ProcessInstanceService method startInstance.
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response startInstance(ProcessInstanceCreateRequest processInstanceCreateRequest) {
if (log.isDebugEnabled()) {
log.debug("ProcessInstanceCreateRequest:" + processInstanceCreateRequest.getProcessDefinitionId());
log.debug(" processInstanceCreateRequest.getVariables().size():" + processInstanceCreateRequest.getVariables().size());
}
if (processInstanceCreateRequest.getProcessDefinitionId() == null && processInstanceCreateRequest.getProcessDefinitionKey() == null && processInstanceCreateRequest.getMessage() == null) {
throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey or message is required.");
}
int paramsSet = ((processInstanceCreateRequest.getProcessDefinitionId() != null) ? 1 : 0) + ((processInstanceCreateRequest.getProcessDefinitionKey() != null) ? 1 : 0) + ((processInstanceCreateRequest.getMessage() != null) ? 1 : 0);
if (paramsSet > 1) {
throw new ActivitiIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey or message should be set.");
}
if (processInstanceCreateRequest.isCustomTenantSet()) {
// Tenant-id can only be used with either key or message
if (processInstanceCreateRequest.getProcessDefinitionId() != null) {
throw new ActivitiIllegalArgumentException("TenantId can only be used with either processDefinitionKey or message.");
}
} else {
// if no tenantId, it must be from definitionId
if (processInstanceCreateRequest.getProcessDefinitionId() == null) {
throw new ActivitiIllegalArgumentException("TenantId should be specified to be used with either " + "processDefinitionKey or message.");
}
}
// Have to add the validation part here
if (!isValidUserToStartProcess(processInstanceCreateRequest)) {
throw new RestApiBasicAuthenticationException("User doesn't have the necessary permission to start the process");
}
if (processInstanceCreateRequest.getSkipInstanceCreation() || processInstanceCreateRequest.getSkipInstanceCreationIfExist()) {
ProcessInstanceQueryRequest processInstanceQueryRequest = processInstanceCreateRequest.cloneInstanceCreationRequest();
Map<String, String> allRequestParams = allRequestParams(uriInfo);
DataResponse dataResponse = getQueryResponse(processInstanceQueryRequest, allRequestParams, uriInfo);
if (log.isDebugEnabled()) {
log.debug("ProcessInstanceCreation check:" + dataResponse.getSize());
}
int dataResponseSize = dataResponse.getSize();
if (dataResponseSize > 0) {
if (processInstanceCreateRequest.getCorrelate()) {
if (dataResponseSize != 1) {
String responseMessage = "Correlation matching failed as there are more than one matching instance with " + "given variables state";
throw new NotFoundException(Response.ok().entity(responseMessage).status(Response.Status.NOT_FOUND).build());
}
if (processInstanceCreateRequest.getMessageName() == null) {
String responseMessage = "Correlation matching failed as messageName property is not specified";
throw new ActivitiIllegalArgumentException(responseMessage);
}
return performCorrelation(processInstanceCreateRequest);
} else {
dataResponse.setMessage("Instance information corresponding to the request");
return Response.ok().entity(dataResponse).build();
}
}
}
RestResponseFactory restResponseFactory = new RestResponseFactory();
Map<String, Object> startVariables = null;
if (processInstanceCreateRequest.getVariables() != null) {
startVariables = new HashMap<>();
for (RestVariable variable : processInstanceCreateRequest.getVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required.");
}
startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
// updated the additional variables
if (processInstanceCreateRequest.getAdditionalVariables() != null) {
if (startVariables == null) {
startVariables = new HashMap<>();
}
for (RestVariable variable : processInstanceCreateRequest.getAdditionalVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Additional Variable name is required.");
}
startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
IdentityService identityService = BPMNOSGIService.getIdentityService();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String userName = carbonContext.getUsername();
ProcessInstanceResponse processInstanceResponse;
// Actually start the instance based on key or id
try {
ProcessInstance instance;
identityService.setAuthenticatedUserId(userName);
if (processInstanceCreateRequest.getProcessDefinitionId() != null) {
instance = runtimeService.startProcessInstanceById(processInstanceCreateRequest.getProcessDefinitionId(), processInstanceCreateRequest.getBusinessKey(), startVariables);
} else if (processInstanceCreateRequest.getProcessDefinitionKey() != null) {
if (processInstanceCreateRequest.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByKeyAndTenantId(processInstanceCreateRequest.getProcessDefinitionKey(), processInstanceCreateRequest.getBusinessKey(), startVariables, processInstanceCreateRequest.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByKey(processInstanceCreateRequest.getProcessDefinitionKey(), processInstanceCreateRequest.getBusinessKey(), startVariables);
}
} else {
if (processInstanceCreateRequest.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByMessageAndTenantId(processInstanceCreateRequest.getMessage(), processInstanceCreateRequest.getBusinessKey(), startVariables, processInstanceCreateRequest.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByMessage(processInstanceCreateRequest.getMessage(), processInstanceCreateRequest.getBusinessKey(), startVariables);
}
}
HistoryService historyService = BPMNOSGIService.getHistoryService();
if (processInstanceCreateRequest.getReturnVariables()) {
Map<String, Object> runtimeVariableMap = null;
List<HistoricVariableInstance> historicVariableList = null;
if (instance.isEnded()) {
historicVariableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list();
} else {
runtimeVariableMap = runtimeService.getVariables(instance.getId());
}
processInstanceResponse = restResponseFactory.createProcessInstanceResponse(instance, true, runtimeVariableMap, historicVariableList, uriInfo.getBaseUri().toString());
} else {
processInstanceResponse = restResponseFactory.createProcessInstanceResponse(instance, uriInfo.getBaseUri().toString());
}
} catch (ActivitiObjectNotFoundException aonfe) {
throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
} finally {
identityService.setAuthenticatedUserId(null);
}
return Response.ok().status(Response.Status.CREATED).entity(processInstanceResponse).build();
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class ExecutionService method getProcessInstances.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstances() {
// Populate query based on request
ExecutionQueryRequest queryRequest = new ExecutionQueryRequest();
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
String id = uriInfo.getQueryParameters().getFirst("id");
if (id != null) {
queryRequest.setId(id);
}
String processInstanceId = uriInfo.getQueryParameters().getFirst("processInstanceId");
if (processInstanceId != null) {
queryRequest.setProcessInstanceId(processInstanceId);
}
String processInstanceBusinessKey = uriInfo.getQueryParameters().getFirst("processInstanceBusinessKey");
if (processInstanceBusinessKey != null) {
queryRequest.setProcessBusinessKey(processInstanceBusinessKey);
}
String processDefinitionKey = uriInfo.getQueryParameters().getFirst("processDefinitionKey");
if (processDefinitionKey != null) {
queryRequest.setProcessDefinitionKey(processDefinitionKey);
}
String processDefinitionId = uriInfo.getQueryParameters().getFirst("processDefinitionId");
if (processDefinitionId != null) {
queryRequest.setProcessDefinitionId(processDefinitionId);
}
String messageEventSubscriptionName = uriInfo.getQueryParameters().getFirst("messageEventSubscriptionName");
if (messageEventSubscriptionName != null) {
queryRequest.setMessageEventSubscriptionName(messageEventSubscriptionName);
}
String signalEventSubscriptionName = uriInfo.getQueryParameters().getFirst("signalEventSubscriptionName");
if (signalEventSubscriptionName != null) {
queryRequest.setSignalEventSubscriptionName(signalEventSubscriptionName);
}
String activityId = uriInfo.getQueryParameters().getFirst("activityId");
if (activityId != null) {
queryRequest.setActivityId(activityId);
}
String parentId = uriInfo.getQueryParameters().getFirst("parentId");
if (parentId != null) {
queryRequest.setParentId(parentId);
}
String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
if (tenantId != null) {
queryRequest.setTenantId(tenantId);
}
String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
if (tenantIdLike != null) {
queryRequest.setTenantIdLike(tenantIdLike);
}
String withoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
if (withoutTenantId != null) {
if (Boolean.valueOf(withoutTenantId)) {
queryRequest.setWithoutTenantId(Boolean.TRUE);
}
}
// add common parameters such as sort,order,start etc.
// allRequestParams = Utils.prepareCommonParameters(allRequestParams, uriInfo);
DataResponse dataResponse = getQueryResponse(queryRequest, allRequestParams, uriInfo);
return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class WorkflowTaskService method getTasks.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTasks() {
// Create a Task query request
TaskQueryRequest request = new TaskQueryRequest();
Map<String, String> requestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
requestParams.put(property, value);
}
}
// Populate filter-parameters
if (requestParams.containsKey("name")) {
request.setName(requestParams.get("name"));
}
if (requestParams.containsKey("nameLike")) {
request.setNameLike(requestParams.get("nameLike"));
}
if (requestParams.containsKey("description")) {
request.setDescription(requestParams.get("description"));
}
if (requestParams.containsKey("descriptionLike")) {
request.setDescriptionLike(requestParams.get("descriptionLike"));
}
if (requestParams.containsKey("priority")) {
request.setPriority(Integer.valueOf(requestParams.get("priority")));
}
if (requestParams.containsKey("minimumPriority")) {
request.setMinimumPriority(Integer.valueOf(requestParams.get("minimumPriority")));
}
if (requestParams.containsKey("maximumPriority")) {
request.setMaximumPriority(Integer.valueOf(requestParams.get("maximumPriority")));
}
if (requestParams.containsKey("assignee")) {
request.setAssignee(requestParams.get("assignee"));
}
if (requestParams.containsKey("owner")) {
request.setOwner(requestParams.get("owner"));
}
if (requestParams.containsKey("unassigned")) {
request.setUnassigned(Boolean.valueOf(requestParams.get("unassigned")));
}
if (requestParams.containsKey("delegationState")) {
request.setDelegationState(requestParams.get("delegationState"));
}
if (requestParams.containsKey("candidateUser")) {
request.setCandidateUser(requestParams.get("candidateUser"));
}
if (requestParams.containsKey("involvedUser")) {
request.setInvolvedUser(requestParams.get("involvedUser"));
}
if (requestParams.containsKey("candidateGroup")) {
request.setCandidateGroup(requestParams.get("candidateGroup"));
}
if (requestParams.containsKey("candidateGroups")) {
String[] candidateGroups = requestParams.get("candidateGroups").split(",");
List<String> groups = new ArrayList<String>(candidateGroups.length);
for (String candidateGroup : candidateGroups) {
groups.add(candidateGroup);
}
request.setCandidateGroupIn(groups);
}
if (requestParams.containsKey("processDefinitionKey")) {
request.setProcessDefinitionKey(requestParams.get("processDefinitionKey"));
}
if (requestParams.containsKey("processDefinitionKeyLike")) {
request.setProcessDefinitionKeyLike(requestParams.get("processDefinitionKeyLike"));
}
if (requestParams.containsKey("processDefinitionName")) {
request.setProcessDefinitionName(requestParams.get("processDefinitionName"));
}
if (requestParams.containsKey("processDefinitionNameLike")) {
request.setProcessDefinitionNameLike(requestParams.get("processDefinitionNameLike"));
}
if (requestParams.containsKey("processInstanceId")) {
request.setProcessInstanceId(requestParams.get("processInstanceId"));
}
if (requestParams.containsKey("processInstanceBusinessKey")) {
request.setProcessInstanceBusinessKey(requestParams.get("processInstanceBusinessKey"));
}
if (requestParams.containsKey("executionId")) {
request.setExecutionId(requestParams.get("executionId"));
}
if (requestParams.containsKey("createdOn")) {
request.setCreatedOn(RequestUtil.getDate(requestParams, "createdOn"));
}
if (requestParams.containsKey("createdBefore")) {
request.setCreatedBefore(RequestUtil.getDate(requestParams, "createdBefore"));
}
if (requestParams.containsKey("createdAfter")) {
request.setCreatedAfter(RequestUtil.getDate(requestParams, "createdAfter"));
}
if (requestParams.containsKey("excludeSubTasks")) {
request.setExcludeSubTasks(Boolean.valueOf(requestParams.get("excludeSubTasks")));
}
if (requestParams.containsKey("taskDefinitionKey")) {
request.setTaskDefinitionKey(requestParams.get("taskDefinitionKey"));
}
if (requestParams.containsKey("taskDefinitionKeyLike")) {
request.setTaskDefinitionKeyLike(requestParams.get("taskDefinitionKeyLike"));
}
if (requestParams.containsKey("dueDate")) {
request.setDueDate(RequestUtil.getDate(requestParams, "dueDate"));
}
if (requestParams.containsKey("dueBefore")) {
request.setDueBefore(RequestUtil.getDate(requestParams, "dueBefore"));
}
if (requestParams.containsKey("dueAfter")) {
request.setDueAfter(RequestUtil.getDate(requestParams, "dueAfter"));
}
if (requestParams.containsKey("active")) {
request.setActive(Boolean.valueOf(requestParams.get("active")));
}
if (requestParams.containsKey("includeTaskLocalVariables")) {
request.setIncludeTaskLocalVariables(Boolean.valueOf(requestParams.get("includeTaskLocalVariables")));
}
if (requestParams.containsKey("includeProcessVariables")) {
request.setIncludeProcessVariables(Boolean.valueOf(requestParams.get("includeProcessVariables")));
}
if (requestParams.containsKey("tenantId")) {
request.setTenantId(requestParams.get("tenantId"));
}
if (requestParams.containsKey("tenantIdLike")) {
request.setTenantIdLike(requestParams.get("tenantIdLike"));
}
if (requestParams.containsKey("withoutTenantId") && Boolean.valueOf(requestParams.get("withoutTenantId"))) {
request.setWithoutTenantId(Boolean.TRUE);
}
if (requestParams.containsKey("candidateOrAssigned")) {
request.setCandidateOrAssigned(requestParams.get("candidateOrAssigned"));
}
DataResponse dataResponse = getTasksFromQueryRequest(request, uriInfo, requestParams);
return Response.ok().entity(dataResponse).build();
// return getTasksFromQueryRequest(request, requestParams);
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class QueryExecutionService method queryProcessInstances.
@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response queryProcessInstances(ExecutionQueryRequest queryRequest, @Context UriInfo uriInfo) {
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
DataResponse dataResponse = getQueryResponse(queryRequest, allRequestParams, uriInfo);
return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class ProcessDefinitionService method getProcessDefinitions.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessDefinitions() {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
// Populate filter-parameters
if (allRequestParams.containsKey("category")) {
processDefinitionQuery.processDefinitionCategory(allRequestParams.get("category"));
}
if (allRequestParams.containsKey("categoryLike")) {
processDefinitionQuery.processDefinitionCategoryLike(allRequestParams.get("categoryLike"));
}
if (allRequestParams.containsKey("categoryNotEquals")) {
processDefinitionQuery.processDefinitionCategoryNotEquals(allRequestParams.get("categoryNotEquals"));
}
if (allRequestParams.containsKey("key")) {
processDefinitionQuery.processDefinitionKey(allRequestParams.get("key"));
}
if (allRequestParams.containsKey("keyLike")) {
processDefinitionQuery.processDefinitionKeyLike(allRequestParams.get("keyLike"));
}
if (allRequestParams.containsKey("name")) {
processDefinitionQuery.processDefinitionName(allRequestParams.get("name"));
}
if (allRequestParams.containsKey("nameLike")) {
processDefinitionQuery.processDefinitionNameLike(allRequestParams.get("nameLike"));
}
if (allRequestParams.containsKey("resourceName")) {
processDefinitionQuery.processDefinitionResourceName(allRequestParams.get("resourceName"));
}
if (allRequestParams.containsKey("resourceNameLike")) {
processDefinitionQuery.processDefinitionResourceNameLike(allRequestParams.get("resourceNameLike"));
}
if (allRequestParams.containsKey("version")) {
processDefinitionQuery.processDefinitionVersion(Integer.valueOf(allRequestParams.get("version")));
}
if (allRequestParams.containsKey("suspended")) {
Boolean suspended = Boolean.valueOf(allRequestParams.get("suspended"));
if (suspended != null) {
if (suspended) {
processDefinitionQuery.suspended();
} else {
processDefinitionQuery.active();
}
}
}
if (allRequestParams.containsKey("latest")) {
Boolean latest = Boolean.valueOf(allRequestParams.get("latest"));
if (latest != null && latest) {
processDefinitionQuery.latestVersion();
}
}
if (allRequestParams.containsKey("deploymentId")) {
processDefinitionQuery.deploymentId(allRequestParams.get("deploymentId"));
}
if (allRequestParams.containsKey("startableByUser")) {
processDefinitionQuery.startableByUser(allRequestParams.get("startableByUser"));
}
if (allRequestParams.containsKey("tenantId")) {
processDefinitionQuery.processDefinitionTenantId(allRequestParams.get("tenantId"));
}
if (allRequestParams.containsKey("tenantIdLike")) {
processDefinitionQuery.processDefinitionTenantIdLike(allRequestParams.get("tenantIdLike"));
}
DataResponse response = new ProcessDefinitionsPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, processDefinitionQuery, "name", properties);
return Response.ok().entity(response).build();
}
Aggregations