use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class BaseTaskService method addGlobalVariables.
protected void addGlobalVariables(Task task, Map<String, RestVariable> variableMap, String baseUri) {
if (task.getExecutionId() != null) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
Map<String, Object> rawVariables = runtimeService.getVariables(task.getExecutionId());
List<RestVariable> globalVariables = new RestResponseFactory().createRestVariables(rawVariables, task.getId(), RestResponseFactory.VARIABLE_TASK, RestVariable.RestVariableScope.GLOBAL, baseUri);
// since local variables get precedence over global ones at all times.
for (RestVariable var : globalVariables) {
if (!variableMap.containsKey(var.getName())) {
variableMap.put(var.getName(), var);
}
}
}
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class BaseTaskService method setBinaryVariable.
protected RestVariable setBinaryVariable(MultipartBody multipartBody, Task task, boolean isNew, UriInfo uriInfo) throws IOException {
boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled) {
log.debug("Processing Binary variables");
}
Object result = null;
List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments = multipartBody.getAllAttachments();
int attachmentSize = attachments.size();
if (attachmentSize <= 0) {
throw new ActivitiIllegalArgumentException("No Attachments found with the request body");
}
AttachmentDataHolder attachmentDataHolder = new AttachmentDataHolder();
for (int i = 0; i < attachmentSize; i++) {
org.apache.cxf.jaxrs.ext.multipart.Attachment attachment = attachments.get(i);
String contentDispositionHeaderValue = attachment.getHeader("Content-Disposition");
String contentType = attachment.getHeader("Content-Type");
if (debugEnabled) {
log.debug("Going to iterate:" + i);
log.debug("contentDisposition:" + contentDispositionHeaderValue);
}
if (contentDispositionHeaderValue != null) {
contentDispositionHeaderValue = contentDispositionHeaderValue.trim();
Map<String, String> contentDispositionHeaderValueMap = Utils.processContentDispositionHeader(contentDispositionHeaderValue);
String dispositionName = contentDispositionHeaderValueMap.get("name");
DataHandler dataHandler = attachment.getDataHandler();
OutputStream outputStream = null;
if ("name".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Binary Variable Name Reading error occured", e);
}
if (outputStream != null) {
String fileName = outputStream.toString();
attachmentDataHolder.setName(fileName);
}
} else if ("type".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("\"Binary Variable Type Reading error occured", e);
}
if (outputStream != null) {
String typeName = outputStream.toString();
attachmentDataHolder.setType(typeName);
}
} else if ("scope".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Binary Variable scopeDescription Reading error " + "occured", e);
}
if (outputStream != null) {
String scope = outputStream.toString();
attachmentDataHolder.setScope(scope);
}
}
if (contentType != null) {
if ("file".equals(dispositionName)) {
InputStream inputStream = null;
try {
inputStream = dataHandler.getInputStream();
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Error Occured During processing empty body.", e);
}
if (inputStream != null) {
attachmentDataHolder.setContentType(contentType);
byte[] attachmentArray = new byte[0];
try {
attachmentArray = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Processing BinaryV variable Body Failed.", e);
}
attachmentDataHolder.setAttachmentArray(attachmentArray);
}
}
}
}
}
attachmentDataHolder.printDebug();
String variableScope = attachmentDataHolder.getScope();
String variableName = attachmentDataHolder.getName();
String variableType = attachmentDataHolder.getType();
byte[] attachmentArray = attachmentDataHolder.getAttachmentArray();
try {
if (variableName == null) {
throw new ActivitiIllegalArgumentException("No variable name was found in request body.");
}
if (attachmentArray == null) {
throw new ActivitiIllegalArgumentException("Empty attachment body was found in request body after " + "decoding the request" + ".");
}
if (variableType != null) {
if (!RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType) && !RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variableType)) {
throw new ActivitiIllegalArgumentException("Only 'binary' and 'serializable' are supported as variable type.");
}
} else {
attachmentDataHolder.setType(RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE);
}
RestVariable.RestVariableScope scope = RestVariable.RestVariableScope.LOCAL;
if (variableScope != null) {
scope = RestVariable.getScopeFromString(variableScope);
}
if (variableScope != null) {
scope = RestVariable.getScopeFromString(variableScope);
}
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType)) {
// Use raw bytes as variable value
setVariable(task, variableName, attachmentArray, scope, isNew);
} else {
// Try deserializing the object
try (InputStream inputStream = new ByteArrayInputStream(attachmentArray);
ObjectInputStream stream = new ObjectInputStream(inputStream)) {
Object value = stream.readObject();
setVariable(task, variableName, value, scope, isNew);
}
}
return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType, task.getId(), null, null, uriInfo.getBaseUri().toString());
} catch (IOException ioe) {
throw new ActivitiIllegalArgumentException("Error getting binary variable", ioe);
} catch (ClassNotFoundException ioe) {
throw new BPMNContentNotSupportedException("The provided body contains a serialized object for which the class is nog found: " + ioe.getMessage());
}
}
use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.
the class UserSubstitutionService method substitute.
/**
* Add new addSubstituteInfo record.
* Following request body parameters are required,
* assignee : optional, logged in user is used if not provided
* substitute : required
* startTime : optional, current timestamp if not provided, the timestamp the substitution should start in ISO format
* endTime : optional, considered as forever if not provided, the timestamp the substitution should end in ISO format
* @param request
* @return 201 created response with the resource location. 405 if substitution disabled
*/
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response substitute(SubstitutionRequest request) {
try {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
String assignee = getRequestedAssignee(request.getAssignee());
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();
// at this point, substitution is enabled by default
UserSubstitutionUtils.handleNewSubstituteAddition(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
return Response.created(new URI("substitutes/" + assignee)).build();
} catch (UserStoreException e) {
throw new ActivitiException("Error accessing User Store", e);
} catch (URISyntaxException e) {
throw new ActivitiException("Response location URI creation header", e);
} catch (ActivitiIllegalArgumentException e) {
throw new ActivitiIllegalArgumentException(e.getMessage());
}
}
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 over time i.e. tasks started and completed over the months
*
* @return array with the no. of tasks started and completed over the months
*/
@GET
@Path("/task-instances/count/variation")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder taskVariationOverTime() {
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()).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()).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()).suspended().list();
for (Task instance : taskSuspended) {
int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
}
Collections.addAll(list, taskStatPerMonths);
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 ProcessStatisticsService method getTasks.
/**
* Return all the tasks/activities in a process
* @param pId process instance id
* @return all the tasks/activities in a process
*/
@GET
@Path("/task-instances/{pId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getTasks(@PathParam("pId") String pId) {
ResponseHolder response = new ResponseHolder();
List<Object> list = new ArrayList();
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(pId);
if (processDefinition != null) {
for (ActivityImpl activity : processDefinition.getActivities()) {
TaskInfo taskInfo = new TaskInfo();
String taskDefKey = activity.getId();
String type = (String) activity.getProperty("type");
String taskName = (String) activity.getProperty("name");
taskInfo.setTaskDefinitionKey(taskDefKey);
taskInfo.setType(type);
taskInfo.setName(taskName);
list.add(taskInfo);
}
}
response.setData(list);
return response;
}
Aggregations