use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class UserSubstitutionService method updateSubstituteInfo.
/**
* Update the substitute info of the given user in the request path. Use the same format used in POST method.
* @param user - user that need to update his substitute info
* @param request - substitute info that need to be updated
* @return
* @throws URISyntaxException
*/
@PUT
@Path("/{user}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateSubstituteInfo(@PathParam("user") String user, SubstitutionRequest request) throws URISyntaxException {
try {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
request.setAssignee(user);
String assignee = getRequestedAssignee(user);
String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
Date endTime = null;
Date startTime = new Date();
DateTime requestStartTime = null;
if (request.getStartTime() != null) {
requestStartTime = new DateTime(request.getStartTime());
startTime = new Date(requestStartTime.getMillis());
}
if (request.getEndTime() != null) {
endTime = validateEndTime(request.getEndTime(), requestStartTime);
}
if (!UserSubstitutionUtils.validateTasksList(request.getTaskList(), assignee)) {
throw new ActivitiIllegalArgumentException("Invalid task list provided, for substitution.");
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
UserSubstitutionUtils.handleUpdateSubstitute(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
return Response.ok().build();
} catch (UserStoreException e) {
throw new ActivitiException("Error accessing User Store", e);
}
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class ProcessStatisticsService method taskVariationOverTime.
/**
* Task variation of user over time i.e. tasks started and completed by the user -- User Performance
*
* @param assignee taskAssignee/User selected to view the user performance of task completion over time
* @return array with the tasks started and completed of the selected user
*/
@GET
@Path("/user-performance/variation/{assignee}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder taskVariationOverTime(@PathParam("assignee") String assignee) throws UserStoreException {
if (!validateCurrentUser(assignee)) {
throw new ActivitiObjectNotFoundException("User with user id " + assignee + "not defined in the system");
}
ResponseHolder response = new ResponseHolder();
List list = new ArrayList();
SimpleDateFormat ft = new SimpleDateFormat("M");
ProcessInstanceStatInfo[] taskStatPerMonths = new ProcessInstanceStatInfo[12];
for (int i = 0; i < taskStatPerMonths.length; i++) {
taskStatPerMonths[i] = new ProcessInstanceStatInfo(MONTHS[i], 0, 0);
}
// Get completed tasks
List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).finished().list();
for (HistoricTaskInstance instance : taskList) {
int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
int endTime = Integer.parseInt(ft.format(instance.getEndTime()));
taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
taskStatPerMonths[endTime - 1].setInstancesCompleted(taskStatPerMonths[endTime - 1].getInstancesCompleted() + 1);
}
// Get active/started tasks
List<Task> taskActive = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).active().list();
for (Task instance : taskActive) {
int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
}
// Get suspended tasks
List<Task> taskSuspended = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).suspended().list();
for (Task instance : taskSuspended) {
int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
}
for (int i = 0; i < taskStatPerMonths.length; i++) {
list.add(taskStatPerMonths[i]);
}
response.setData(list);
return response;
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class WorkflowTaskService method deleteVariable.
@DELETE
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName) {
String scopeString = uriInfo.getQueryParameters().getFirst("scope");
Task task = getTaskFromRequest(taskId);
// Determine scope
RestVariable.RestVariableScope scope = RestVariable.RestVariableScope.LOCAL;
if (scopeString != null) {
scope = RestVariable.getScopeFromString(scopeString);
}
if (!hasVariableOnScope(task, variableName, scope)) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable '" + variableName + "' in scope " + scope.name().toLowerCase(), VariableInstanceEntity.class);
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
TaskService taskService = BPMNOSGIService.getTaskService();
if (scope == RestVariable.RestVariableScope.LOCAL) {
taskService.removeVariableLocal(task.getId(), variableName);
} else {
// Safe to use executionId, as the hasVariableOnScope whould have stopped a global-var update on standalone task
runtimeService.removeVariable(task.getExecutionId(), variableName);
}
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class WorkflowTaskService method deleteTask.
@DELETE
@Path("/{taskId}")
public Response deleteTask(@PathParam("taskId") String taskId) {
Boolean cascadeHistory = false;
if (uriInfo.getQueryParameters().getFirst("cascadeHistory") != null) {
cascadeHistory = Boolean.valueOf(uriInfo.getQueryParameters().getFirst("cascadeHistory"));
}
String deleteReason = uriInfo.getQueryParameters().getFirst("deleteReason");
Task taskToDelete = getTaskFromRequest(taskId);
if (taskToDelete.getExecutionId() != null) {
// Can't delete a task that is part of a process instance
throw new BPMNForbiddenException("Cannot delete a task that is part of a process-instance.");
}
TaskService taskService = BPMNOSGIService.getTaskService();
if (cascadeHistory != null) {
// Ignore delete-reason since the task-history (where the reason is recorded) will be deleted anyway
taskService.deleteTask(taskToDelete.getId(), cascadeHistory);
} else {
// Delete with delete-reason
taskService.deleteTask(taskToDelete.getId(), deleteReason);
}
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class WorkflowTaskService method createTaskVariable.
@POST
@Path("/{taskId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createTaskVariable(@PathParam("taskId") String taskId, @Context HttpServletRequest httpServletRequest) {
Task task = getTaskFromRequest(taskId);
List<RestVariable> inputVariables = new ArrayList<>();
List<RestVariable> resultVariables = new ArrayList<>();
Response.ResponseBuilder responseBuilder = Response.ok();
try {
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
try {
@SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) new ObjectMapper().readValue(httpServletRequest.getInputStream(), List.class);
for (Object restObject : variableObjects) {
RestVariable restVariable = new ObjectMapper().convertValue(restObject, RestVariable.class);
inputVariables.add(restVariable);
}
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("request body could not be transformed to a RestVariable " + "instance.", e);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(getXMLReader(httpServletRequest.getInputStream()));
if (restVariableCollection == null) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
}
List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
if (restVariableList.size() == 0) {
throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
}
for (RestVariable restVariable : restVariableList) {
inputVariables.add(restVariable);
}
} catch (JAXBException | IOException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
}
}
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
}
if (inputVariables.size() == 0) {
throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
}
RestVariable.RestVariableScope sharedScope = null;
RestVariable.RestVariableScope varScope = null;
Map<String, Object> variablesToSet = new HashMap<>();
RestResponseFactory restResponseFactory = new RestResponseFactory();
for (RestVariable var : inputVariables) {
// Validate if scopes match
varScope = var.getVariableScope();
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
if (varScope == null) {
varScope = RestVariable.RestVariableScope.LOCAL;
}
if (sharedScope == null) {
sharedScope = varScope;
}
if (varScope != sharedScope) {
throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
}
if (hasVariableOnScope(task, var.getName(), varScope)) {
throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on task '" + task.getId() + "'.");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, task.getId(), RestResponseFactory.VARIABLE_TASK, false, uriInfo.getBaseUri().toString()));
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
TaskService taskService = BPMNOSGIService.getTaskService();
if (!variablesToSet.isEmpty()) {
if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
taskService.setVariablesLocal(task.getId(), variablesToSet);
} else {
if (task.getExecutionId() != null) {
// Explicitly set on execution, setting non-local variables on task will override local-variables if exists
runtimeService.setVariables(task.getExecutionId(), variablesToSet);
} else {
// Standalone task, no global variables possible
throw new ActivitiIllegalArgumentException("Cannot set global variables on task '" + task.getId() + "', task is not part of process.");
}
}
}
RestVariableCollection restVariableCollection = new RestVariableCollection();
restVariableCollection.setRestVariables(resultVariables);
responseBuilder.entity(restVariableCollection);
return responseBuilder.status(Response.Status.CREATED).build();
}
Aggregations