TSK-121 Implement Holgers comments - make SystemException unchecked and map ClassificationNotFoundException to SystemException when working with existing tasks.

This commit is contained in:
BerndBreier 2018-01-11 08:46:56 +01:00 committed by Holger Hagen
parent 7ee001950d
commit 46fe48fd36
7 changed files with 43 additions and 130 deletions

View File

@ -18,7 +18,7 @@ public interface BaseQuery<T> {
* *
* @return List containing elements of type T * @return List containing elements of type T
* @throws NotAuthorizedException * @throws NotAuthorizedException
* if the permissions are not granted for this specific interaction with query. * if the user is not authorized to perform this query
*/ */
List<T> list() throws NotAuthorizedException; List<T> list() throws NotAuthorizedException;
@ -28,10 +28,10 @@ public interface BaseQuery<T> {
* @param offset * @param offset
* index of the first element which should be returned. * index of the first element which should be returned.
* @param limit * @param limit
* amount of elements which should be returned beginning on offset. * number of elements which should be returned beginning with offset.
* @return List containing elements of type T * @return List containing elements of type T
* @throws NotAuthorizedException * @throws NotAuthorizedException
* if the permissions are not granted for this specific interaction with query. * if the user is not authorized to perform this query
*/ */
List<T> list(int offset, int limit) throws NotAuthorizedException; List<T> list(int offset, int limit) throws NotAuthorizedException;
@ -40,7 +40,7 @@ public interface BaseQuery<T> {
* *
* @return T a single object of given Type. * @return T a single object of given Type.
* @throws NotAuthorizedException * @throws NotAuthorizedException
* if the permissions for interactions are not granted. * if the user is not authorized to perform this query
*/ */
T single() throws NotAuthorizedException; T single() throws NotAuthorizedException;

View File

@ -36,8 +36,8 @@ public interface ClassificationService {
List<Classification> getAllClassificationsWithKey(String key, String domain); List<Classification> getAllClassificationsWithKey(String key, String domain);
/** /**
* Get the Classification for key and domain. If there's no specification for the given domain, it returns the root * Get the Classification for key and domain. If there's no Classification in the given domain, return the
* domain. * Classification from the root domain.
* *
* @param key * @param key
* the key of the searched-for classifications * the key of the searched-for classifications
@ -45,7 +45,7 @@ public interface ClassificationService {
* the domain of the searched-for classifications * the domain of the searched-for classifications
* @return If exist: domain-specific classification, else root classification * @return If exist: domain-specific classification, else root classification
* @throws ClassificationNotFoundException * @throws ClassificationNotFoundException
* if no classification is found that matches key and domain. * if no classification is found that matches the key either in domain or in the root domain.
*/ */
Classification getClassification(String key, String domain) throws ClassificationNotFoundException; Classification getClassification(String key, String domain) throws ClassificationNotFoundException;

View File

@ -32,11 +32,9 @@ public interface TaskService {
* if the state of the task with taskId is not {@link TaskState#READY} * if the state of the task with taskId is not {@link TaskState#READY}
* @throws InvalidOwnerException * @throws InvalidOwnerException
* if the task with taskId is claimed by some else * if the task with taskId is claimed by some else
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task claim(String taskId) Task claim(String taskId)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException; throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
/** /**
* Claim an existing task for the current user. Enable forced claim. * Claim an existing task for the current user. Enable forced claim.
@ -52,11 +50,9 @@ public interface TaskService {
* if the state of the task with taskId is not {@link TaskState#READY} * if the state of the task with taskId is not {@link TaskState#READY}
* @throws InvalidOwnerException * @throws InvalidOwnerException
* if the task with taskId is claimed by someone else * if the task with taskId is claimed by someone else
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task claim(String taskId, boolean forceClaim) Task claim(String taskId, boolean forceClaim)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException; throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
/** /**
* Complete a claimed Task as owner/admin and update State and Timestamps. * Complete a claimed Task as owner/admin and update State and Timestamps.
@ -70,11 +66,9 @@ public interface TaskService {
* if the given Task can´t be found in DB. * if the given Task can´t be found in DB.
* @throws InvalidOwnerException * @throws InvalidOwnerException
* if current user is not the task-owner or administrator. * if current user is not the task-owner or administrator.
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task completeTask(String taskId) Task completeTask(String taskId)
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException; throws TaskNotFoundException, InvalidOwnerException, InvalidStateException;
/** /**
* Complete a claimed Task and update State and Timestamps. * Complete a claimed Task and update State and Timestamps.
@ -90,11 +84,9 @@ public interface TaskService {
* if the given Task can´t be found in DB. * if the given Task can´t be found in DB.
* @throws InvalidOwnerException * @throws InvalidOwnerException
* if current user is not the task-owner or administrator. * if current user is not the task-owner or administrator.
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task completeTask(String taskId, boolean isForced) Task completeTask(String taskId, boolean isForced)
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException; throws TaskNotFoundException, InvalidOwnerException, InvalidStateException;
/** /**
* Persists a not persisted Task which does not exist already. * Persists a not persisted Task which does not exist already.
@ -127,10 +119,8 @@ public interface TaskService {
* @return the Task * @return the Task
* @throws TaskNotFoundException * @throws TaskNotFoundException
* thrown of the {@link Task} with taskId is not found * thrown of the {@link Task} with taskId is not found
* @throws ClassificationNotFoundException
* if the classification associated to the task is not found
*/ */
Task getTask(String taskId) throws TaskNotFoundException, ClassificationNotFoundException; Task getTask(String taskId) throws TaskNotFoundException;
/** /**
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag. * Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
@ -148,12 +138,9 @@ public interface TaskService {
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket * Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
* @throws InvalidWorkbasketException * @throws InvalidWorkbasketException
* Thrown if either the source or the target workbasket has a missing required property * Thrown if either the source or the target workbasket has a missing required property
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task transfer(String taskId, String workbasketKey) Task transfer(String taskId, String workbasketKey)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException;
ClassificationNotFoundException;
/** /**
* Marks a task as read. * Marks a task as read.
@ -165,10 +152,8 @@ public interface TaskService {
* @return the updated Task * @return the updated Task
* @throws TaskNotFoundException * @throws TaskNotFoundException
* Thrown if the {@link Task} with taskId was not found * Thrown if the {@link Task} with taskId was not found
* @throws ClassificationNotFoundException
* if the task refers to a classification that cannot be found
*/ */
Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException, ClassificationNotFoundException; Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException;
/** /**
* This method provides a query builder for quering the database. * This method provides a query builder for quering the database.

View File

@ -188,7 +188,7 @@ public class TaskQueryImpl implements TaskQuery {
} }
@Override @Override
public List<Task> list() throws NotAuthorizedException, SystemException { public List<Task> list() throws NotAuthorizedException {
LOGGER.debug("entry to list(), this = {}", this); LOGGER.debug("entry to list(), this = {}", this);
List<Task> result = new ArrayList<>(); List<Task> result = new ArrayList<>();
try { try {
@ -218,7 +218,7 @@ public class TaskQueryImpl implements TaskQuery {
} }
@Override @Override
public List<Task> list(int offset, int limit) throws NotAuthorizedException, SystemException { public List<Task> list(int offset, int limit) throws NotAuthorizedException {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this); LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<Task> result = new ArrayList<>(); List<Task> result = new ArrayList<>();
try { try {
@ -249,7 +249,7 @@ public class TaskQueryImpl implements TaskQuery {
} }
@Override @Override
public TaskImpl single() throws NotAuthorizedException, SystemException { public TaskImpl single() throws NotAuthorizedException {
LOGGER.debug("entry to single(), this = {}", this); LOGGER.debug("entry to single(), this = {}", this);
TaskImpl taskImpl = null; TaskImpl taskImpl = null;
try { try {
@ -291,170 +291,85 @@ public class TaskQueryImpl implements TaskQuery {
return name; return name;
} }
public void setName(String[] name) {
this.name = name;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) {
this.description = description;
}
public int[] getPriority() { public int[] getPriority() {
return priority; return priority;
} }
public void setPriority(int[] priority) {
this.priority = priority;
}
public TaskState[] getStates() { public TaskState[] getStates() {
return states; return states;
} }
public void setStates(TaskState[] states) {
this.states = states;
}
public String[] getClassificationKey() { public String[] getClassificationKey() {
return classificationKey; return classificationKey;
} }
public void setClassificationKey(String[] classificationKey) {
this.classificationKey = classificationKey;
}
public String[] getWorkbasketKey() { public String[] getWorkbasketKey() {
return workbasketKey; return workbasketKey;
} }
public void setWorkbasketKey(String[] workbasketKey) {
this.workbasketKey = workbasketKey;
}
public String[] getDomain() { public String[] getDomain() {
return domain; return domain;
} }
public void setDomain(String[] domain) {
this.domain = domain;
}
public String[] getOwner() { public String[] getOwner() {
return owner; return owner;
} }
public void setOwner(String[] owner) {
this.owner = owner;
}
public String[] getCustomFields() { public String[] getCustomFields() {
return customFields; return customFields;
} }
public void setCustomFields(String[] customFields) {
this.customFields = customFields;
}
public Boolean getIsRead() { public Boolean getIsRead() {
return isRead; return isRead;
} }
public void setIsRead(Boolean isRead) {
this.isRead = isRead;
}
public Boolean getIsTransferred() { public Boolean getIsTransferred() {
return isTransferred; return isTransferred;
} }
public void setIsTransferred(Boolean isTransferred) {
this.isTransferred = isTransferred;
}
public String[] getPorCompanyIn() { public String[] getPorCompanyIn() {
return porCompanyIn; return porCompanyIn;
} }
public void setPorCompanyIn(String[] porCompanyIn) {
this.porCompanyIn = porCompanyIn;
}
public String getPorCompanyLike() { public String getPorCompanyLike() {
return porCompanyLike; return porCompanyLike;
} }
public void setPorCompanyLike(String porCompanyLike) {
this.porCompanyLike = porCompanyLike;
}
public String[] getPorSystemIn() { public String[] getPorSystemIn() {
return porSystemIn; return porSystemIn;
} }
public void setPorSystemIn(String[] porSystemIn) {
this.porSystemIn = porSystemIn;
}
public String getPorSystemLike() { public String getPorSystemLike() {
return porSystemLike; return porSystemLike;
} }
public void setPorSystemLike(String porSystemLike) {
this.porSystemLike = porSystemLike;
}
public String[] getPorSystemInstanceIn() { public String[] getPorSystemInstanceIn() {
return porSystemInstanceIn; return porSystemInstanceIn;
} }
public void setPorSystemInstanceIn(String[] porSystemInstanceIn) {
this.porSystemInstanceIn = porSystemInstanceIn;
}
public String getPorSystemInstanceLike() { public String getPorSystemInstanceLike() {
return porSystemInstanceLike; return porSystemInstanceLike;
} }
public void setPorSystemInstanceLike(String porSystemInstanceLike) {
this.porSystemInstanceLike = porSystemInstanceLike;
}
public String[] getPorTypeIn() { public String[] getPorTypeIn() {
return porTypeIn; return porTypeIn;
} }
public void setPorTypeIn(String[] porTypeIn) {
this.porTypeIn = porTypeIn;
}
public String getPorTypeLike() { public String getPorTypeLike() {
return porTypeLike; return porTypeLike;
} }
public void setPorTypeLike(String porTypeLike) {
this.porTypeLike = porTypeLike;
}
public String[] getPorValueIn() { public String[] getPorValueIn() {
return porValueIn; return porValueIn;
} }
public void setPorValueIn(String[] porValueIn) {
this.porValueIn = porValueIn;
}
public String getPorValueLike() { public String getPorValueLike() {
return porValueLike; return porValueLike;
} }
public void setPorValueLike(String porValueLike) {
this.porValueLike = porValueLike;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -24,6 +24,7 @@ import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.InvalidWorkbasketException; import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.TaskAlreadyExistException; import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
@ -70,13 +71,13 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task claim(String taskId) public Task claim(String taskId)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException { throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
return claim(taskId, false); return claim(taskId, false);
} }
@Override @Override
public Task claim(String taskId, boolean forceClaim) public Task claim(String taskId, boolean forceClaim)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException { throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
String userId = CurrentUserContext.getUserid(); String userId = CurrentUserContext.getUserid();
LOGGER.debug("entry to claim(id = {}, forceClaim = {}, userId = {})", taskId, forceClaim, userId); LOGGER.debug("entry to claim(id = {}, forceClaim = {}, userId = {})", taskId, forceClaim, userId);
TaskImpl task = null; TaskImpl task = null;
@ -113,18 +114,19 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task completeTask(String taskId) public Task completeTask(String taskId)
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException { throws TaskNotFoundException, InvalidOwnerException, InvalidStateException {
return completeTask(taskId, false); return completeTask(taskId, false);
} }
@Override @Override
public Task completeTask(String taskId, boolean isForced) public Task completeTask(String taskId, boolean isForced)
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException { throws TaskNotFoundException, InvalidOwnerException, InvalidStateException {
LOGGER.debug("entry to completeTask(id = {}, isForced {})", taskId, isForced); LOGGER.debug("entry to completeTask(id = {}, isForced {})", taskId, isForced);
TaskImpl task = null; TaskImpl task = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
task = (TaskImpl) this.getTask(taskId); task = (TaskImpl) this.getTask(taskId);
// check pre-conditions for non-forced invocation // check pre-conditions for non-forced invocation
if (!isForced) { if (!isForced) {
if (task.getClaimed() == null || task.getState() != TaskState.CLAIMED) { if (task.getClaimed() == null || task.getState() != TaskState.CLAIMED) {
@ -193,7 +195,7 @@ public class TaskServiceImpl implements TaskService {
} }
@Override @Override
public Task getTask(String id) throws TaskNotFoundException, ClassificationNotFoundException { public Task getTask(String id) throws TaskNotFoundException {
LOGGER.debug("entry to getTaskById(id = {})", id); LOGGER.debug("entry to getTaskById(id = {})", id);
TaskImpl result = null; TaskImpl result = null;
try { try {
@ -204,7 +206,18 @@ public class TaskServiceImpl implements TaskService {
List<Attachment> attachments = setAttachmentObjRef( List<Attachment> attachments = setAttachmentObjRef(
attachmentMapper.findAttachmentsByTaskId(result.getId())); attachmentMapper.findAttachmentsByTaskId(result.getId()));
result.setAttachments(attachments); result.setAttachments(attachments);
Classification classification = this.classificationService.getClassificationByTask(result); Classification classification;
try {
classification = this.classificationService.getClassificationByTask(result);
} catch (ClassificationNotFoundException e) {
LOGGER.debug(
"getTask(taskId = {}) caught a ClassificationNotFoundException when attemptin to get "
+ "the classification for the task. Throwing a SystemException ",
id);
throw new SystemException(
"TaskService.getTask could not find the classification associated to " + id);
}
result.setClassification(classification); result.setClassification(classification);
return result; return result;
} else { } else {
@ -219,8 +232,7 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task transfer(String taskId, String destinationWorkbasketKey) public Task transfer(String taskId, String destinationWorkbasketKey)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
ClassificationNotFoundException {
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketKey = {})", taskId, destinationWorkbasketKey); LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketKey = {})", taskId, destinationWorkbasketKey);
Task result = null; Task result = null;
try { try {
@ -259,7 +271,7 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task setTaskRead(String taskId, boolean isRead) public Task setTaskRead(String taskId, boolean isRead)
throws TaskNotFoundException, ClassificationNotFoundException { throws TaskNotFoundException {
LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead); LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead);
Task result = null; Task result = null;
try { try {

View File

@ -25,7 +25,7 @@ public interface QueryMapper {
String CLASSIFICATION_FINDBYKEYANDDOMAIN = "pro.taskana.model.mappings.ClassificationMapper.findByKeyAndDomain"; String CLASSIFICATION_FINDBYKEYANDDOMAIN = "pro.taskana.model.mappings.ClassificationMapper.findByKeyAndDomain";
String CLASSIFICATION_FINDBYID = "pro.taskana.model.mappings.ClassificationMapper.findById"; String CLASSIFICATION_FINDBYID = "pro.taskana.model.mappings.ClassificationMapper.findById";
@Select("<script>SELECT t.ID, t.CREATED, t.CLAIMED, t.COMPLETED, t.MODIFIED, t.PLANNED, t.DUE, t.NAME, t.DESCRIPTION, t.PRIORITY, t.STATE, t.CLASSIFICATION_KEY, t.WORKBASKET_KEY, t.BUSINESS_PROCESS_ID, t.PARENT_BUSINESS_PROCESS_ID, t.OWNER, t.POR_COMPANY, t.POR_SYSTEM, t.POR_INSTANCE, t.POR_TYPE, t.POR_VALUE, t.IS_READ, t.IS_TRANSFERRED, t.CUSTOM_1, t.CUSTOM_2, t.CUSTOM_3, t.CUSTOM_4, t.CUSTOM_5, t.CUSTOM_6, t.CUSTOM_7, t.CUSTOM_8, t.CUSTOM_9, t.CUSTOM_10 " @Select("<script>SELECT t.ID, t.CREATED, t.CLAIMED, t.COMPLETED, t.MODIFIED, t.PLANNED, t.DUE, t.NAME, t.DESCRIPTION, t.PRIORITY, t.STATE, t.CLASSIFICATION_KEY, t.DOMAIN, t.WORKBASKET_KEY, t.BUSINESS_PROCESS_ID, t.PARENT_BUSINESS_PROCESS_ID, t.OWNER, t.POR_COMPANY, t.POR_SYSTEM, t.POR_INSTANCE, t.POR_TYPE, t.POR_VALUE, t.IS_READ, t.IS_TRANSFERRED, t.CUSTOM_1, t.CUSTOM_2, t.CUSTOM_3, t.CUSTOM_4, t.CUSTOM_5, t.CUSTOM_6, t.CUSTOM_7, t.CUSTOM_8, t.CUSTOM_9, t.CUSTOM_10 "
+ "FROM TASK t " + "FROM TASK t "
+ "<where>" + "<where>"
+ "<if test='name != null'>AND t.NAME IN(<foreach item='item' collection='name' separator=',' >#{item}</foreach>)</if> " + "<if test='name != null'>AND t.NAME IN(<foreach item='item' collection='name' separator=',' >#{item}</foreach>)</if> "

View File

@ -48,6 +48,7 @@ public interface TaskMapper {
@Result(property = "state", column = "STATE"), @Result(property = "state", column = "STATE"),
@Result(property = "workbasketKey", column = "WORKBASKET_KEY"), @Result(property = "workbasketKey", column = "WORKBASKET_KEY"),
@Result(property = "classificationKey", column = "CLASSIFICATION_KEY"), @Result(property = "classificationKey", column = "CLASSIFICATION_KEY"),
@Result(property = "domain", column = "DOMAIN"),
@Result(property = "businessProcessId", column = "BUSINESS_PROCESS_ID"), @Result(property = "businessProcessId", column = "BUSINESS_PROCESS_ID"),
@Result(property = "parentBusinessProcessId", column = "PARENT_BUSINESS_PROCESS_ID"), @Result(property = "parentBusinessProcessId", column = "PARENT_BUSINESS_PROCESS_ID"),
@Result(property = "owner", column = "OWNER"), @Result(property = "owner", column = "OWNER"),