use of org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria 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.SimpleQueryCriteria in project carbon-business-process by wso2.
the class HumanTaskDAOConnectionImpl method getTasksCount.
public int getTasksCount(SimpleQueryCriteria queryCriteria) {
HumanTaskJPQLQueryBuilder queryBuilder = new HumanTaskJPQLQueryBuilder(queryCriteria, entityManager);
Query countQuery = queryBuilder.buildCount();
int firstResult = Integer.parseInt(countQuery.getSingleResult().toString());
return firstResult;
}
use of org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria in project carbon-business-process by wso2.
the class HumanTaskDAOConnectionImpl method removeTasks.
public void removeTasks(SimpleQueryCriteria queryCriteria) {
HumanTaskJPQLQueryBuilder queryBuilder = new HumanTaskJPQLQueryBuilder(queryCriteria, entityManager);
Query taskQuery = queryBuilder.build();
taskQuery.executeUpdate();
}
use of org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria in project carbon-business-process by wso2.
the class RemovableTaskCleanupJob method execute.
/**
* The task clean up execution logic.
*/
public void execute() {
HumanTaskServerConfiguration serverConfiguration = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getServerConfig();
final SimpleQueryCriteria queryCriteria = createQueryCriteria(serverConfiguration);
log.info("Running the task cleanup service.....");
try {
HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {
public Object call() throws Exception {
HumanTaskDAOConnection daoConnection = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection();
daoConnection.removeTasks(queryCriteria);
return null;
}
});
} catch (Exception ex) {
String errMsg = "Task Cleanup operation failed! :";
log.error(errMsg, ex);
throw new HumanTaskRuntimeException(errMsg, ex);
}
}
use of org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria in project carbon-business-process by wso2.
the class RemovableTaskCleanupJob method createQueryCriteria.
/**
* Create task removal query criteria.
*
* @param serverConfiguration : The server config.
* @return : The SimpleQueryCriteria.
*/
private SimpleQueryCriteria createQueryCriteria(HumanTaskServerConfiguration serverConfiguration) {
SimpleQueryCriteria queryCriteria = new SimpleQueryCriteria();
queryCriteria.setSimpleQueryType(SimpleQueryCriteria.QueryType.REMOVE_TASKS);
queryCriteria.setStatuses(serverConfiguration.getRemovableTaskStatuses());
return queryCriteria;
}
Aggregations