use of pro.taskana.TaskSummary in project taskana by Taskana.
the class UpdateWorkbasketAuthorizationsAccTest method testUpdatedAccessItemLeadsToNotAuthorizedException.
@WithAccessId(userName = "user_1_1", groupNames = { "group_2", "businessadmin" })
@Test
public void testUpdatedAccessItemLeadsToNotAuthorizedException() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
TaskService taskService = taskanaEngine.getTaskService();
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
String wbKey = "USER_2_1";
String wbDomain = "DOMAIN_A";
String groupName = "group_2";
Task newTask = taskService.newTask(wbKey, wbDomain);
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
Task createdTask = taskService.createTask(newTask);
List<TaskSummary> tasks = taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
Assert.assertEquals(1, tasks.size());
assertThat(createdTask, not(equalTo(null)));
List<WorkbasketAccessItem> accessItems = workbasketService.getWorkbasketAccessItems("WBI:100000000000000000000000000000000008");
WorkbasketAccessItem theAccessItem = accessItems.stream().filter(x -> groupName.equals(x.getAccessId())).findFirst().orElse(null);
Assert.assertTrue(theAccessItem != null);
theAccessItem.setPermOpen(false);
workbasketService.updateWorkbasketAccessItem(theAccessItem);
try {
taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
fail("NotAuthorizedToQueryWorkbasketException was expected ");
} catch (NotAuthorizedToQueryWorkbasketException ignored) {
// nothing to do
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskFilter method inspectParams.
public List<TaskSummary> inspectParams(MultiValueMap<String, String> params) throws NotAuthorizedException, InvalidArgumentException {
TaskQuery taskQuery = taskService.createTaskQuery();
// apply filters
if (params.containsKey(NAME)) {
String[] names = extractCommaSeperatedFields(params.get(NAME));
taskQuery.nameIn(names);
}
if (params.containsKey(DESCRIPTION)) {
taskQuery.descriptionLike(params.get(DESCRIPTION).get(0));
}
if (params.containsKey(PRIORITY)) {
String[] prioritesInString = extractCommaSeperatedFields(params.get(PRIORITY));
int[] priorites = extractPriorities(prioritesInString);
taskQuery.priorityIn(priorites);
}
if (params.containsKey(STATE)) {
TaskState[] states = extractStates(params);
taskQuery.stateIn(states);
}
if (params.containsKey(CLASSIFICATION_KEY)) {
String[] classificationKeys = extractCommaSeperatedFields(params.get(CLASSIFICATION_KEY));
taskQuery.classificationKeyIn(classificationKeys);
}
if (params.containsKey(WORKBASKET_ID)) {
String[] workbaskets = extractCommaSeperatedFields(params.get(WORKBASKET_ID));
taskQuery.workbasketIdIn(workbaskets);
}
if (params.containsKey(OWNER)) {
String[] owners = extractCommaSeperatedFields(params.get(OWNER));
taskQuery.ownerIn(owners);
}
// objectReference
if (params.keySet().stream().filter(s -> s.startsWith(POR)).toArray().length > 0) {
if (params.containsKey(POR_COMPANY)) {
String[] companies = extractCommaSeperatedFields(params.get(POR_COMPANY));
taskQuery.primaryObjectReferenceCompanyIn(companies);
}
if (params.containsKey(POR_SYSTEM)) {
String[] systems = extractCommaSeperatedFields(params.get(POR_SYSTEM));
taskQuery.primaryObjectReferenceSystemIn(systems);
}
if (params.containsKey(POR_SYSTEM_INSTANCE)) {
String[] systemInstances = extractCommaSeperatedFields(params.get(POR_SYSTEM_INSTANCE));
taskQuery.primaryObjectReferenceSystemInstanceIn(systemInstances);
}
if (params.containsKey(POR_TYPE)) {
String[] types = extractCommaSeperatedFields(params.get(POR_TYPE));
taskQuery.primaryObjectReferenceTypeIn(types);
}
if (params.containsKey(POR_VALUE)) {
String[] values = extractCommaSeperatedFields(params.get(POR_VALUE));
taskQuery.primaryObjectReferenceValueIn(values);
}
}
if (params.containsKey(IS_READ)) {
taskQuery.readEquals(Boolean.getBoolean(params.get(IS_READ).get(0)));
}
if (params.containsKey(IS_TRANSFERRED)) {
taskQuery.transferredEquals(Boolean.getBoolean(params.get(IS_TRANSFERRED).get(0)));
}
return taskQuery.list();
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskServiceImpl method updateTasks.
@Override
public List<String> updateTasks(ObjectReference selectionCriteria, Map<String, String> customFieldsToUpdate) throws InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to updateTasks(selectionCriteria = {}, customFieldsToUpdate = {})", selectionCriteria, customFieldsToUpdate);
}
if (customFieldsToUpdate == null || customFieldsToUpdate.isEmpty()) {
LOGGER.warn("The customFieldsToUpdate argument to updateTasks must not be empty. Throwing InvalidArgumentException.");
throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks must not be empty.");
}
validateObjectReference(selectionCriteria, "ObjectReference", "updateTasks call");
Set<String> allowedKeys = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"));
try {
taskanaEngine.openConnection();
CustomPropertySelector fieldSelector = new CustomPropertySelector();
TaskImpl newTask = new TaskImpl();
newTask.setModified(Instant.now());
for (Map.Entry<String, String> entry : customFieldsToUpdate.entrySet()) {
String key = entry.getKey();
if (!allowedKeys.contains(key)) {
LOGGER.warn("The customFieldsToUpdate argument to updateTasks contains invalid key {}.", key);
throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks contains invalid key " + key);
} else {
fieldSelector.setCustomProperty(key, true);
newTask.setCustomAttribute(key, entry.getValue());
}
}
// use query in order to find only those tasks that are visible to the current user
List<TaskSummary> taskSummaries = createTaskQuery().primaryObjectReferenceCompanyIn(selectionCriteria.getCompany()).primaryObjectReferenceSystemIn(selectionCriteria.getSystem()).primaryObjectReferenceSystemInstanceIn(selectionCriteria.getSystemInstance()).primaryObjectReferenceTypeIn(selectionCriteria.getType()).primaryObjectReferenceValueIn(selectionCriteria.getValue()).list();
List<String> taskIds = new ArrayList<>();
if (!taskSummaries.isEmpty()) {
taskIds = taskSummaries.stream().map(TaskSummary::getTaskId).collect(Collectors.toList());
taskMapper.updateTasks(taskIds, newTask, fieldSelector);
LOGGER.debug("updateTasks() updated the following tasks: {} ", LoggerUtils.listToString(taskIds));
} else {
LOGGER.debug("updateTasks() found no tasks for update ");
}
return taskIds;
} finally {
LOGGER.debug("exit from deleteTasks().");
taskanaEngine.returnConnection();
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskQueryImpl method single.
@Override
public TaskSummary single() {
LOGGER.debug("entry to single(), this = {}", this);
TaskSummary result = null;
try {
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
TaskSummaryImpl taskSummaryImpl = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
if (taskSummaryImpl == null) {
return null;
}
List<TaskSummaryImpl> tasks = new ArrayList<>();
tasks.add(taskSummaryImpl);
List<TaskSummary> augmentedList = taskService.augmentTaskSummariesByContainedSummaries(tasks);
result = augmentedList.get(0);
return result;
} catch (NotAuthorizedException e) {
throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskQueryImpl method list.
@Override
public List<TaskSummary> list() {
List<TaskSummary> result = new ArrayList<>();
try {
LOGGER.debug("entry to list(), this = {}", this);
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
List<TaskSummaryImpl> tasks = new ArrayList<>();
tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("mapper returned {} resulting Objects: {} ", tasks.size(), LoggerUtils.listToString(tasks));
}
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} 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(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
Aggregations