use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskQueryImpl method list.
@Override
public List<TaskSummary> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<TaskSummary> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
RowBounds rowBounds = new RowBounds(offset, limit);
List<TaskSummaryImpl> tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
throw e;
} catch (NotAuthorizedException e) {
throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class ClassificationServiceImpl method deleteClassification.
@Override
public void deleteClassification(String classificationKey, String domain) throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to deleteClassification(key = {}, domain = {})", classificationKey, domain);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
try {
taskanaEngine.openConnection();
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
if (classification == null) {
throw new ClassificationNotFoundException(classificationKey, domain, "The classification " + classificationKey + "wasn't found in the domain " + domain);
}
List<AttachmentSummaryImpl> attachments = taskanaEngine.getSqlSession().getMapper(AttachmentMapper.class).findAttachmentSummariesByClassificationId(classification.getId());
if (!attachments.isEmpty()) {
throw new ClassificationInUseException("Classification " + classification.getId() + " is used by Attachment " + attachments.get(0).getId());
}
if (domain.equals("")) {
// master mode - delete all associated classifications in every domain.
List<String> domains = this.classificationMapper.getDomainsForClassification(classificationKey);
domains.remove("");
for (String classificationDomain : domains) {
deleteClassification(classificationKey, classificationDomain);
}
}
TaskServiceImpl taskService = (TaskServiceImpl) taskanaEngine.getTaskService();
try {
List<TaskSummary> classificationTasks = taskService.createTaskQuery().classificationKeyIn(classificationKey).list();
if (classificationTasks.stream().anyMatch(t -> domain.equals(t.getClassificationSummary().getDomain()))) {
throw new ClassificationInUseException("There are Tasks that belong to this classification or a child classification. Please complete them and try again.");
}
} catch (NotAuthorizedToQueryWorkbasketException e) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<String> childKeys = this.classificationMapper.getChildrenOfClassification(classification.getId());
for (String key : childKeys) {
this.deleteClassification(key, domain);
}
this.classificationMapper.deleteClassificationInDomain(classificationKey, domain);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteClassification()");
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskController method getTasks.
@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
TaskQuery query = taskService.createTaskQuery();
query = applyFilterParams(query, params);
query = applySortingParams(query, params);
PageMetadata pageMetadata = null;
List<TaskSummary> taskSummaries = null;
String page = params.getFirst(PAGING_PAGE);
String pageSize = params.getFirst(PAGING_PAGE_SIZE);
if (page != null && pageSize != null) {
// paging
long totalElements = query.count();
pageMetadata = initPageMetadata(pageSize, page, totalElements);
taskSummaries = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
} else if (page == null && pageSize == null) {
// not paging
taskSummaries = query.list();
} else {
throw new InvalidArgumentException("Paging information is incomplete.");
}
TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries, pageMetadata);
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class WorkbasketServiceImplTest method testDeleteWorkbasketIsUsed.
@Test(expected = WorkbasketInUseException.class)
public void testDeleteWorkbasketIsUsed() throws NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException, WorkbasketNotFoundException {
Workbasket wb = createTestWorkbasket("WBI:0", "wb-key");
List<TaskSummary> usages = Arrays.asList(new TaskSummaryImpl(), new TaskSummaryImpl());
doReturn(wb).when(cutSpy).getWorkbasket(wb.getId());
doReturn(sqlSessionMock).when(taskanaEngineImplMock).getSqlSession();
doReturn(taskMapperMock).when(sqlSessionMock).getMapper(TaskMapper.class);
doReturn(new Long(1)).when(taskMapperMock).countTasksInWorkbasket(any());
try {
cutSpy.deleteWorkbasket(wb.getId());
} catch (WorkbasketNotFoundException e) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(cutSpy, times(1)).getWorkbasket(wb.getId());
verify(taskanaEngineImplMock, times(1)).getTaskService();
verify(taskServiceMock, times(1)).createTaskQuery();
verify(taskQueryMock, times(1)).workbasketIdIn(wb.getId());
verify(taskQueryMock, times(1)).list();
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw e;
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskServiceImplIntExplicitTest method should_ReturnList_when_BuilderIsUsed.
@WithAccessId(userName = "Elena", groupNames = { "DummyGroup", "businessadmin" })
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException, WorkbasketAlreadyExistException, DomainNotFoundException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
generateSampleAccessItems();
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("k1", "DOMAIN_A");
workbasket.setName("workbasket");
Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
classificationService.createClassification(classification);
// set id manually for authorization tests
workbasket.setId("1");
workbasket.setType(WorkbasketType.GROUP);
workbasket = (WorkbasketImpl) workbasketService.createWorkbasket(workbasket);
Task task = taskServiceImpl.newTask(workbasket.getId());
task.setName("Unit Test Task");
task.setClassificationKey(classification.getKey());
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = taskServiceImpl.createTask(task);
List<TaskSummary> results = taskServiceImpl.createTaskQuery().nameIn("bla", "test").descriptionLike("test").priorityIn(1, 2, 2).stateIn(TaskState.CLAIMED).workbasketKeyDomainIn(new KeyDomain("k1", "DOMAIN_A")).ownerIn("test", "test2", "bla").customAttributeLike("13", "test").classificationKeyIn("pId1", "pId2").primaryObjectReferenceCompanyIn("first comp", "sonstwo gmbh").primaryObjectReferenceSystemIn("sys").primaryObjectReferenceTypeIn("type1", "type2").primaryObjectReferenceSystemInstanceIn("sysInst1", "sysInst2").primaryObjectReferenceValueIn("val1", "val2", "val3").list();
Assert.assertEquals(0, results.size());
connection.commit();
}
Aggregations