use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.
the class TaskOperationsImpl method addAttachment.
/**
* Add attachment to a task. Returns an identifier for the attachment.
* @param taskIdentifier : task identifier
* @param name : attachment name
* @param accessType : access type
* @param contentType : content type
* @param attachment : attachment ID (String)
* @return
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws IllegalAccessFault
*/
public boolean addAttachment(URI taskIdentifier, String name, String accessType, String contentType, Object attachment) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
final Long taskId = validateTaskId(taskIdentifier);
final String attachmentID = (String) attachment;
try {
Boolean isAdded = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Boolean>() {
public Boolean call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO taskDAO = daoConn.getTask(taskId);
validateTaskTenant(taskDAO);
try {
boolean isAdded = taskDAO.addAttachment(TransformerUtils.generateAttachmentDAOFromID(taskDAO, attachmentID));
if (!isAdded) {
throw new HumanTaskException("Attachment with id: " + attachmentID + "was not associated " + "task with id:" + taskId);
}
return isAdded;
} catch (HumanTaskException ex) {
String errMsg = "getAttachmentInfos operation failed. Reason: ";
log.error(errMsg + ex.getLocalizedMessage(), ex);
throw ex;
}
}
});
return isAdded;
} catch (Exception ex) {
handleException(ex);
}
return false;
}
use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.
the class TaskOperationsImpl method authoriseToLoadTask.
/**
* Throws an exception if the current user is not allowed to perform loadTask() operation
* @param taskId
*/
private void authoriseToLoadTask(TaskDAO task) throws Exception {
List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoles = new ArrayList<GenericHumanRoleDAO.GenericHumanRoleType>();
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR);
HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
PeopleQueryEvaluator pqe = taskEngine.getPeopleQueryEvaluator();
OrganizationalEntityDAO invoker = taskEngine.getScheduler().execTransaction(new Callable<OrganizationalEntityDAO>() {
@Override
public OrganizationalEntityDAO call() throws Exception {
return HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(getCaller(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
}
});
if (!OperationAuthorizationUtil.authoriseUser(task, invoker, allowedRoles, pqe)) {
String errorMsg = String.format("The user[%s] cannot perform loadTask()" + " operation as either he is in EXCLUDED_OWNERS role or he is not in task roles [%s]", invoker.getName(), allowedRoles);
log.error(errorMsg);
throw new HumanTaskIllegalAccessException("Access Denied. You are not authorized to perform this task");
}
}
use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.
the class CommonTaskUtil method createNewTaskEvent.
/**
* Creates a new TaskEventInfo object for the task creation event.
*
* @param task : The newly created task object.
*
* @return : The respective TaskEventInfo object for the task creation event.
*/
public static TaskEventInfo createNewTaskEvent(TaskDAO task) {
TaskEventInfo createTaskEvent = new TaskEventInfo();
createTaskEvent.setEventType(TaskEventType.CREATE);
createTaskEvent.setTimestamp(task.getCreatedOn());
// TODO - how to handle the event initiator for create task event ?
// createTaskEvent.setEventInitiator(null);
createTaskEvent.setTaskInfo(populateTaskInfo(task));
return createTaskEvent;
}
use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.
the class CommonTaskUtil method populateTaskInfo.
/**
* Creates the TaskInfo object from the provided TaskDAO object.
*
* @param taskDAO : The original task dao object
* @return : The representational TaskInfo.
*/
public static TaskInfo populateTaskInfo(TaskDAO taskDAO) {
TaskInfo taskInfo = new TaskInfo();
taskInfo.setId(taskDAO.getId());
taskInfo.setCreatedDate(taskDAO.getCreatedOn());
taskInfo.setName(taskDAO.getName());
if (getDefaultPresentationDescription(taskDAO) != null) {
taskInfo.setDescription(getDefaultPresentationDescription(taskDAO).getValue());
}
if (getActualOwner(taskDAO) != null) {
taskInfo.setOwner(getActualOwner(taskDAO).getName());
}
if (getDefaultPresentationName(taskDAO) != null) {
taskInfo.setName(getDefaultPresentationName(taskDAO).getValue());
}
if (getDefaultPresentationSubject(taskDAO) != null) {
taskInfo.setSubject(getDefaultPresentationSubject(taskDAO).getValue());
}
taskInfo.setStatus(taskDAO.getStatus());
taskInfo.setType(taskDAO.getType());
taskInfo.setModifiedDate(taskDAO.getUpdatedOn());
taskInfo.setStatusBeforeSuspension(taskDAO.getStatusBeforeSuspension());
return taskInfo;
}
use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.
the class CommonTaskUtil method populateTaskEventInfo.
/**
* Create the TaskEventInfo object from the EventDAO and the TaskDAO.
* @param eventDAO : The event
* @param taskDAO : The related task dao.
*
* @return : The new TaskEventInfo object.
*/
public static TaskEventInfo populateTaskEventInfo(EventDAO eventDAO, TaskDAO taskDAO) {
TaskEventInfo eventInfo = new TaskEventInfo();
eventInfo.setTimestamp(eventDAO.getTimeStamp());
eventInfo.setEventInitiator(eventDAO.getUser());
eventInfo.setEventType(eventDAO.getType());
eventInfo.setNewState(eventDAO.getNewState());
eventInfo.setOldState(eventDAO.getOldState());
eventInfo.setTaskInfo(populateTaskInfo(taskDAO));
return eventInfo;
}
Aggregations