use of org.wso2.carbon.identity.application.common.model.Property in project carbon-business-process by wso2.
the class HistoricTaskInstanceService method getHistoricProcessInstances.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getHistoricProcessInstances() {
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
// Populate query based on request
HistoricTaskInstanceQueryRequest queryRequest = new HistoricTaskInstanceQueryRequest();
if (allRequestParams.get("taskId") != null) {
queryRequest.setTaskId(allRequestParams.get("taskId"));
}
if (allRequestParams.get("processInstanceId") != null) {
queryRequest.setProcessInstanceId(allRequestParams.get("processInstanceId"));
}
if (allRequestParams.get("processBusinessKey") != null) {
queryRequest.setProcessBusinessKey(allRequestParams.get("processBusinessKey"));
}
if (allRequestParams.get("processDefinitionKey") != null) {
queryRequest.setProcessDefinitionKey(allRequestParams.get("processDefinitionKey"));
}
if (allRequestParams.get("processDefinitionId") != null) {
queryRequest.setProcessDefinitionId(allRequestParams.get("processDefinitionId"));
}
if (allRequestParams.get("processDefinitionName") != null) {
queryRequest.setProcessDefinitionName(allRequestParams.get("processDefinitionName"));
}
if (allRequestParams.get("executionId") != null) {
queryRequest.setExecutionId(allRequestParams.get("executionId"));
}
if (allRequestParams.get("taskName") != null) {
queryRequest.setTaskName(allRequestParams.get("taskName"));
}
if (allRequestParams.get("taskNameLike") != null) {
queryRequest.setTaskNameLike(allRequestParams.get("taskNameLike"));
}
if (allRequestParams.get("taskDescription") != null) {
queryRequest.setTaskDescription(allRequestParams.get("taskDescription"));
}
if (allRequestParams.get("taskDescriptionLike") != null) {
queryRequest.setTaskDescriptionLike(allRequestParams.get("taskDescriptionLike"));
}
if (allRequestParams.get("taskDefinitionKey") != null) {
queryRequest.setTaskDefinitionKey(allRequestParams.get("taskDefinitionKey"));
}
if (allRequestParams.get("taskDeleteReason") != null) {
queryRequest.setTaskDeleteReason(allRequestParams.get("taskDeleteReason"));
}
if (allRequestParams.get("taskDeleteReasonLike") != null) {
queryRequest.setTaskDeleteReasonLike(allRequestParams.get("taskDeleteReasonLike"));
}
if (allRequestParams.get("taskAssignee") != null) {
queryRequest.setTaskAssignee(allRequestParams.get("taskAssignee"));
}
if (allRequestParams.get("taskAssigneeLike") != null) {
queryRequest.setTaskAssigneeLike(allRequestParams.get("taskAssigneeLike"));
}
if (allRequestParams.get("taskOwner") != null) {
queryRequest.setTaskOwner(allRequestParams.get("taskOwner"));
}
if (allRequestParams.get("taskOwnerLike") != null) {
queryRequest.setTaskOwnerLike(allRequestParams.get("taskOwnerLike"));
}
if (allRequestParams.get("taskInvolvedUser") != null) {
queryRequest.setTaskInvolvedUser(allRequestParams.get("taskInvolvedUser"));
}
if (allRequestParams.get("taskPriority") != null) {
queryRequest.setTaskPriority(Integer.valueOf(allRequestParams.get("taskPriority")));
}
if (allRequestParams.get("finished") != null) {
queryRequest.setFinished(Boolean.valueOf(allRequestParams.get("finished")));
}
if (allRequestParams.get("processFinished") != null) {
queryRequest.setProcessFinished(Boolean.valueOf(allRequestParams.get("processFinished")));
}
if (allRequestParams.get("parentTaskId") != null) {
queryRequest.setParentTaskId(allRequestParams.get("parentTaskId"));
}
if (allRequestParams.get("dueDate") != null) {
queryRequest.setDueDate(RequestUtil.getDate(allRequestParams, "dueDate"));
}
if (allRequestParams.get("dueDateAfter") != null) {
queryRequest.setDueDateAfter(RequestUtil.getDate(allRequestParams, "dueDateAfter"));
}
if (allRequestParams.get("dueDateBefore") != null) {
queryRequest.setDueDateBefore(RequestUtil.getDate(allRequestParams, "dueDateBefore"));
}
if (allRequestParams.get("taskCreatedOn") != null) {
queryRequest.setTaskCreatedOn(RequestUtil.getDate(allRequestParams, "taskCreatedOn"));
}
if (allRequestParams.get("taskCreatedBefore") != null) {
queryRequest.setTaskCreatedBefore(RequestUtil.getDate(allRequestParams, "taskCreatedBefore"));
}
if (allRequestParams.get("taskCreatedAfter") != null) {
queryRequest.setTaskCreatedAfter(RequestUtil.getDate(allRequestParams, "taskCreatedAfter"));
}
if (allRequestParams.get("taskCompletedOn") != null) {
queryRequest.setTaskCompletedOn(RequestUtil.getDate(allRequestParams, "taskCompletedOn"));
}
if (allRequestParams.get("taskCompletedBefore") != null) {
queryRequest.setTaskCompletedBefore(RequestUtil.getDate(allRequestParams, "taskCompletedBefore"));
}
if (allRequestParams.get("taskCompletedAfter") != null) {
queryRequest.setTaskCompletedAfter(RequestUtil.getDate(allRequestParams, "taskCompletedAfter"));
}
if (allRequestParams.get("includeTaskLocalVariables") != null) {
queryRequest.setIncludeTaskLocalVariables(Boolean.valueOf(allRequestParams.get("includeTaskLocalVariables")));
}
if (allRequestParams.get("includeProcessVariables") != null) {
queryRequest.setIncludeProcessVariables(Boolean.valueOf(allRequestParams.get("includeProcessVariables")));
}
if (allRequestParams.get("tenantId") != null) {
queryRequest.setTenantId(allRequestParams.get("tenantId"));
}
if (allRequestParams.get("tenantIdLike") != null) {
queryRequest.setTenantIdLike(allRequestParams.get("tenantIdLike"));
}
if (allRequestParams.get("withoutTenantId") != null) {
queryRequest.setWithoutTenantId(Boolean.valueOf(allRequestParams.get("withoutTenantId")));
}
if (allRequestParams.get("taskCandidateGroup") != null) {
queryRequest.setTaskCandidateGroup(allRequestParams.get("taskCandidateGroup"));
}
String serverRootUrl = uriInfo.getBaseUri().toString().replace("/history/historic-task-instances", "");
DataResponse dataResponse = getQueryResponse(queryRequest, allRequestParams, serverRootUrl);
return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-business-process by wso2.
the class HistoricVariableInstanceService method getHistoricActivityInstances.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getHistoricActivityInstances() {
HistoricVariableInstanceQueryRequest query = new HistoricVariableInstanceQueryRequest();
// Populate query based on request
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
if (allRequestParams.get("excludeTaskVariables") != null) {
query.setExcludeTaskVariables(Boolean.valueOf(allRequestParams.get("excludeTaskVariables")));
}
if (allRequestParams.get("taskId") != null) {
query.setTaskId(allRequestParams.get("taskId"));
}
if (allRequestParams.get("executionId") != null) {
query.setExecutionId(allRequestParams.get("executionId"));
}
if (allRequestParams.get("processInstanceId") != null) {
query.setProcessInstanceId(allRequestParams.get("processInstanceId"));
}
if (allRequestParams.get("variableName") != null) {
query.setVariableName(allRequestParams.get("variableName"));
}
if (allRequestParams.get("variableNameLike") != null) {
query.setVariableNameLike(allRequestParams.get("variableNameLike"));
}
DataResponse dataResponse = getQueryResponse(query, allRequestParams);
return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-business-process by wso2.
the class HistoricActivitiInstanceQueryService method queryActivityInstances.
@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response queryActivityInstances(HistoricActivityInstanceQueryRequest 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.identity.application.common.model.Property in project carbon-business-process by wso2.
the class BaseTaskService method getTasksFromQueryRequest.
protected DataResponse getTasksFromQueryRequest(TaskQueryRequest request, UriInfo uriInfo, Map<String, String> requestParams) {
if (requestParams == null) {
requestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
requestParams.put(property, value);
}
}
}
TaskService taskService = BPMNOSGIService.getTaskService();
TaskQuery taskQuery = taskService.createTaskQuery();
if (request.getName() != null) {
taskQuery.taskName(request.getName());
}
if (request.getNameLike() != null) {
taskQuery.taskNameLike(request.getNameLike());
}
if (request.getDescription() != null) {
taskQuery.taskDescription(request.getDescription());
}
if (request.getDescriptionLike() != null) {
taskQuery.taskDescriptionLike(request.getDescriptionLike());
}
if (request.getPriority() != null) {
taskQuery.taskPriority(request.getPriority());
}
if (request.getMinimumPriority() != null) {
taskQuery.taskMinPriority(request.getMinimumPriority());
}
if (request.getMaximumPriority() != null) {
taskQuery.taskMaxPriority(request.getMaximumPriority());
}
if (request.getAssignee() != null) {
taskQuery.taskAssignee(request.getAssignee());
}
if (request.getAssigneeLike() != null) {
taskQuery.taskAssigneeLike(request.getAssigneeLike());
}
if (request.getOwner() != null) {
taskQuery.taskOwner(request.getOwner());
}
if (request.getOwnerLike() != null) {
taskQuery.taskOwnerLike(request.getOwnerLike());
}
if (request.getUnassigned() != null) {
taskQuery.taskUnassigned();
}
if (request.getDelegationState() != null) {
DelegationState state = getDelegationState(request.getDelegationState());
if (state != null) {
taskQuery.taskDelegationState(state);
}
}
if (request.getCandidateUser() != null) {
taskQuery.taskCandidateUser(request.getCandidateUser());
}
if (request.getInvolvedUser() != null) {
taskQuery.taskInvolvedUser(request.getInvolvedUser());
}
if (request.getCandidateGroup() != null) {
taskQuery.taskCandidateGroup(request.getCandidateGroup());
}
if (request.getCandidateGroupIn() != null) {
taskQuery.taskCandidateGroupIn(request.getCandidateGroupIn());
}
if (request.getProcessInstanceId() != null) {
taskQuery.processInstanceId(request.getProcessInstanceId());
}
if (request.getProcessInstanceBusinessKey() != null) {
taskQuery.processInstanceBusinessKey(request.getProcessInstanceBusinessKey());
}
if (request.getExecutionId() != null) {
taskQuery.executionId(request.getExecutionId());
}
if (request.getCreatedOn() != null) {
taskQuery.taskCreatedOn(request.getCreatedOn());
}
if (request.getCreatedBefore() != null) {
taskQuery.taskCreatedBefore(request.getCreatedBefore());
}
if (request.getCreatedAfter() != null) {
taskQuery.taskCreatedAfter(request.getCreatedAfter());
}
if (request.getExcludeSubTasks() != null) {
if (request.getExcludeSubTasks()) {
taskQuery.excludeSubtasks();
}
}
if (request.getTaskDefinitionKey() != null) {
taskQuery.taskDefinitionKey(request.getTaskDefinitionKey());
}
if (request.getTaskDefinitionKeyLike() != null) {
taskQuery.taskDefinitionKeyLike(request.getTaskDefinitionKeyLike());
}
if (request.getDueDate() != null) {
taskQuery.taskDueDate(request.getDueDate());
}
if (request.getDueBefore() != null) {
taskQuery.taskDueBefore(request.getDueBefore());
}
if (request.getDueAfter() != null) {
taskQuery.taskDueAfter(request.getDueAfter());
}
if (request.getWithoutDueDate() != null && request.getWithoutDueDate()) {
taskQuery.withoutTaskDueDate();
}
if (request.getActive() != null) {
if (request.getActive().booleanValue()) {
taskQuery.active();
} else {
taskQuery.suspended();
}
}
if (request.getIncludeTaskLocalVariables() != null) {
if (request.getIncludeTaskLocalVariables()) {
taskQuery.includeTaskLocalVariables();
}
}
if (request.getIncludeProcessVariables() != null) {
if (request.getIncludeProcessVariables()) {
taskQuery.includeProcessVariables();
}
}
if (request.getProcessInstanceBusinessKeyLike() != null) {
taskQuery.processInstanceBusinessKeyLike(request.getProcessInstanceBusinessKeyLike());
}
if (request.getProcessDefinitionKey() != null) {
taskQuery.processDefinitionKey(request.getProcessDefinitionKey());
}
if (request.getProcessDefinitionKeyLike() != null) {
taskQuery.processDefinitionKeyLike(request.getProcessDefinitionKeyLike());
}
if (request.getProcessDefinitionName() != null) {
taskQuery.processDefinitionName(request.getProcessDefinitionName());
}
if (request.getProcessDefinitionNameLike() != null) {
taskQuery.processDefinitionNameLike(request.getProcessDefinitionNameLike());
}
if (request.getTaskVariables() != null) {
addTaskvariables(taskQuery, request.getTaskVariables());
}
if (request.getProcessInstanceVariables() != null) {
addProcessvariables(taskQuery, request.getProcessInstanceVariables());
}
if (request.getTenantId() != null) {
taskQuery.taskTenantId(request.getTenantId());
}
if (request.getTenantIdLike() != null) {
taskQuery.taskTenantIdLike(request.getTenantIdLike());
}
if (Boolean.TRUE.equals(request.getWithoutTenantId())) {
taskQuery.taskWithoutTenantId();
}
if (request.getCandidateOrAssigned() != null) {
taskQuery.taskCandidateOrAssigned(request.getCandidateOrAssigned());
}
DataResponse dataResponse = new TaskPaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, request, taskQuery, "id", properties);
return dataResponse;
// return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.identity.application.common.model.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();
}
Aggregations