use of org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection in project carbon-business-process by wso2.
the class TaskOperationServiceImpl method simpleQuery.
public TTaskSimpleQueryResultSet simpleQuery(final TSimpleQueryInput tSimpleQueryInput) throws IllegalStateFault, IllegalArgumentFault {
final int[] taskCount = new int[1];
try {
List<TaskDAO> matchingTasks = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<List<TaskDAO>>() {
public List<TaskDAO> call() throws Exception {
HumanTaskDAOConnection daoConn = HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection();
SimpleQueryCriteria queryCriteria = TransformerUtils.transformSimpleTaskQuery(tSimpleQueryInput);
queryCriteria.setCallerTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
queryCriteria.setCaller(getCaller());
// queryCriteria.setPageSize(HumanTaskConstants.ITEMS_PER_PAGE);
TStatus[] statuses = tSimpleQueryInput.getStatus();
Set<TaskStatus> statusSet = new HashSet<TaskStatus>();
if (statuses != null && statuses.length > 0) {
for (TStatus status : statuses) {
try {
TaskStatus taskStatus = TaskStatus.valueOf(status.getTStatus().toUpperCase());
statusSet.add(taskStatus);
} catch (IllegalArgumentException ex) {
new IllegalArgumentFault(" Invalid Status ");
}
}
}
if (!statusSet.isEmpty()) {
queryCriteria.setStatuses(new ArrayList(statusSet));
}
if (statuses != null && statuses.length > 0) {
for (TStatus status : statuses) {
try {
TaskStatus taskStatus = TaskStatus.valueOf(status.getTStatus().toUpperCase());
statusSet.add(taskStatus);
} catch (IllegalArgumentException ex) {
new IllegalArgumentFault("Invalid Status");
}
}
}
if (!statusSet.isEmpty()) {
queryCriteria.setStatuses(new ArrayList(statusSet));
}
taskCount[0] = daoConn.getTasksCount(queryCriteria);
if (log.isDebugEnabled()) {
log.debug("No of tasks in the db : " + taskCount[0]);
}
return daoConn.searchTasks(queryCriteria);
}
});
int taskListSize = matchingTasks.size();
int pageSize = tSimpleQueryInput.getPageSize() > 0 ? tSimpleQueryInput.getPageSize() : HumanTaskConstants.ITEMS_PER_PAGE;
int pages = (int) Math.ceil((double) taskCount[0] / pageSize);
if (log.isDebugEnabled()) {
log.debug("No of task pages : " + pages + " with " + pageSize + " tasks per page");
}
TaskDAO[] instanceArray = matchingTasks.toArray(new TaskDAO[taskListSize]);
TTaskSimpleQueryResultSet resultSet = new TTaskSimpleQueryResultSet();
resultSet.setPages(pages);
for (int i = 0; i < taskListSize; i++) {
resultSet.addRow(TransformerUtils.transformToSimpleQueryRow(instanceArray[i]));
}
return resultSet;
} catch (HumanTaskIllegalStateException ex) {
log.error(ex);
throw new IllegalStateFault(ex);
} catch (Exception ex) {
log.error(ex);
throw new IllegalArgumentFault(ex);
}
}
use of org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection in project carbon-business-process by wso2.
the class TaskOperationServiceImpl method loadTask.
public TTaskAbstract loadTask(URI taskIdURI) throws IllegalAccessFault {
try {
final Long taskId = validateTaskId(taskIdURI);
TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {
public TaskDAO call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO task = daoConn.getTask(taskId);
validateTaskTenant(task);
return task;
}
});
return TransformerUtils.transformTask(task, getCaller());
} catch (Exception ex) {
log.error(ex);
throw new IllegalAccessFault(ex);
}
}
use of org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection in project carbon-business-process by wso2.
the class HTQueryBuildHelperImpl method getTaskDataById.
/**
* @param taskId
* @return all the task details for the given taskID
* @throws IllegalAccessFault
* @throws IllegalArgumentFault
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws URI.MalformedURIException
*/
public String[] getTaskDataById(String taskId) throws IllegalAccessFault, IllegalArgumentFault, IllegalStateFault, IllegalOperationFault, URI.MalformedURIException {
String[] output = { "" };
List<String> outputList = new ArrayList<>();
TaskDAO task;
URI uri = new URI(taskId);
try {
final Long validatedTaskId = validateTaskId(uri);
task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {
public TaskDAO call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO task = daoConn.getTask(validatedTaskId);
return task;
}
});
} catch (Exception ex) {
throw new IllegalAccessFault(ex);
}
GenericHumanRoleDAO.GenericHumanRoleType[] genericHumanRoleTypes = GenericHumanRoleDAO.GenericHumanRoleType.values();
MessageDAO inputMessageDAO = task.getInputMessage();
MessageDAO outputMessageDAO = task.getOutputMessage();
String description = task.getTaskDescription("text/plain");
String titleString = String.format("%1$-" + 25 + "s", "Task Name") + ":" + task.getName();
outputList.add(titleString);
for (int i = 0; i < genericHumanRoleTypes.length; i++) {
List<OrganizationalEntityDAO> organizationalEntityDAOs = CommonTaskUtil.getOrgEntitiesForRole(task, genericHumanRoleTypes[i]);
if (organizationalEntityDAOs.size() > 0) {
String taskDataString = String.format("%1$-" + 25 + "s", genericHumanRoleTypes[i]) + ":";
for (int j = 0; j < organizationalEntityDAOs.size(); j++) {
taskDataString = taskDataString + organizationalEntityDAOs.get(j).getName() + " [" + organizationalEntityDAOs.get(j).getOrgEntityType() + "] ";
}
outputList.add(taskDataString);
}
}
if (description != null) {
String taskDescriptionString = String.format("%1$-" + 25 + "s", "Task Description") + ":" + task.getTaskDescription("text/plain");
outputList.add(taskDescriptionString);
}
Element inputBodyData = inputMessageDAO.getBodyData();
if (inputBodyData != null) {
String inputMsgStr = String.format("%1$-" + 25 + "s", "Task Input") + ":" + "\n" + DOMUtils.domToString(inputBodyData);
outputList.add(inputMsgStr);
}
if (outputMessageDAO != null) {
Element outputBodyData = outputMessageDAO.getBodyData();
if (outputBodyData != null) {
String outputMessageStr = String.format("%1$-" + 25 + "s", "Task Output") + ":" + "\n" + DOMUtils.domToString(outputBodyData);
outputList.add(outputMessageStr);
}
}
output = new String[outputList.size()];
int i = 0;
for (Object o : outputList) {
output[i++] = o.toString();
}
return output;
}
use of org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection 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.HumanTaskDAOConnection in project carbon-business-process by wso2.
the class HTRenderingApiImpl method getTaskDAO.
/**
* Function to retrieve task DAO
*
* @param taskIdURI task ID
* @return task DAO
* @throws Exception
* @throws IllegalArgumentException
*/
private TaskDAO getTaskDAO(URI taskIdURI) throws IllegalArgumentException, HumanTaskIllegalAccessException, Exception {
final Long taskId = validateTaskId(taskIdURI);
TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {
public TaskDAO call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO task = daoConn.getTask(taskId);
validateTaskTenant(task);
return task;
}
});
return task;
}
Aggregations