TSK-280 add ids to NotFoundExceptions

This commit is contained in:
BerndBreier 2018-03-05 15:01:09 +01:00 committed by Holger Hagen
parent ab5c58280c
commit 04221a3fa8
8 changed files with 72 additions and 22 deletions

View File

@ -5,8 +5,25 @@ package pro.taskana.exceptions;
*/ */
public class ClassificationNotFoundException extends NotFoundException { public class ClassificationNotFoundException extends NotFoundException {
public ClassificationNotFoundException(String msg) { private String key;
super(msg); private String domain;
public ClassificationNotFoundException(String id, String msg) {
super(id, msg);
}
public ClassificationNotFoundException(String key, String domain, String msg) {
super(null, msg);
this.key = key;
this.domain = domain;
}
public String getKey() {
return key;
}
public String getDomain() {
return domain;
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -5,8 +5,15 @@ package pro.taskana.exceptions;
*/ */
public class NotFoundException extends TaskanaException { public class NotFoundException extends TaskanaException {
public NotFoundException(String id) { String id;
super(id);
public NotFoundException(String id, String message) {
super(message);
this.id = id;
}
public String getId() {
return id;
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -5,8 +5,8 @@ package pro.taskana.exceptions;
*/ */
public class TaskNotFoundException extends NotFoundException { public class TaskNotFoundException extends NotFoundException {
public TaskNotFoundException(String id) { public TaskNotFoundException(String id, String msg) {
super("Task '" + id + "' not found"); super(id, msg);
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -5,8 +5,25 @@ package pro.taskana.exceptions;
*/ */
public class WorkbasketNotFoundException extends NotFoundException { public class WorkbasketNotFoundException extends NotFoundException {
public WorkbasketNotFoundException(String id) { private String key;
super("Workbasket with '" + id + "' not found"); private String domain;
public WorkbasketNotFoundException(String id, String msg) {
super(id, msg);
}
public WorkbasketNotFoundException(String key, String domain, String msg) {
super(null, msg);
this.key = key;
this.domain = domain;
}
public String getKey() {
return key;
}
public String getDomain() {
return domain;
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -215,7 +215,7 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override @Override
public Classification getClassification(String id) throws ClassificationNotFoundException { public Classification getClassification(String id) throws ClassificationNotFoundException {
if (id == null) { if (id == null) {
throw new ClassificationNotFoundException( throw new ClassificationNotFoundException(id,
"Classification for id " + id + " was not found."); "Classification for id " + id + " was not found.");
} }
LOGGER.debug("entry to getClassification(id = {})", id); LOGGER.debug("entry to getClassification(id = {})", id);
@ -225,7 +225,7 @@ public class ClassificationServiceImpl implements ClassificationService {
result = classificationMapper.findById(id); result = classificationMapper.findById(id);
if (result == null) { if (result == null) {
LOGGER.error("Classification for id {} was not found. Throwing ClassificationNotFoundException", id); LOGGER.error("Classification for id {} was not found. Throwing ClassificationNotFoundException", id);
throw new ClassificationNotFoundException("Classification for id " + id + " was not found"); throw new ClassificationNotFoundException(id, "Classification for id " + id + " was not found");
} }
return result; return result;
} finally { } finally {
@ -238,8 +238,8 @@ public class ClassificationServiceImpl implements ClassificationService {
public Classification getClassification(String key, String domain) throws ClassificationNotFoundException { public Classification getClassification(String key, String domain) throws ClassificationNotFoundException {
LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain); LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain);
if (key == null) { if (key == null) {
throw new ClassificationNotFoundException( throw new ClassificationNotFoundException(key, domain,
"Classification for key " + key + " and domain " + domain + " was not found."); "Classification for null key and domain " + domain + " was not found.");
} }
LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain); LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain);
Classification result = null; Classification result = null;
@ -252,7 +252,8 @@ public class ClassificationServiceImpl implements ClassificationService {
LOGGER.error( LOGGER.error(
"Classification for key {} and domain {} was not found. Throwing ClassificationNotFoundException", "Classification for key {} and domain {} was not found. Throwing ClassificationNotFoundException",
key, domain); key, domain);
throw new ClassificationNotFoundException("Classification for key " + key + " was not found"); throw new ClassificationNotFoundException(key, domain,
"Classification for key " + key + " was not found");
} }
} }
return result; return result;
@ -299,7 +300,7 @@ public class ClassificationServiceImpl implements ClassificationService {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain); Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
if (classification == null) { if (classification == null) {
throw new ClassificationNotFoundException( throw new ClassificationNotFoundException(classificationKey, domain,
"The classification " + classificationKey + "wasn't found in the domain " + domain); "The classification " + classificationKey + "wasn't found in the domain " + domain);
} }

View File

@ -247,7 +247,8 @@ public class TaskServiceImpl implements TaskService {
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (taskSummary == null) { if (taskSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId)); bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "task with id "
+ currentTaskId + " was not found."));
taskIdIterator.remove(); taskIdIterator.remove();
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) { } else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId)); bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
@ -355,7 +356,7 @@ public class TaskServiceImpl implements TaskService {
return resultTask; return resultTask;
} else { } else {
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id); LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id); throw new TaskNotFoundException(id, "Task with id " + id + " was not found");
} }
} finally { } finally {
taskanaEngine.returnConnection(); taskanaEngine.returnConnection();
@ -512,7 +513,8 @@ public class TaskServiceImpl implements TaskService {
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (taskSummary == null) { if (taskSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId)); bulkLog.addError(currentTaskId,
new TaskNotFoundException(currentTaskId, "Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove(); taskIdIterator.remove();
} else if (!sourceWorkbaskets.stream() } else if (!sourceWorkbaskets.stream()
.anyMatch(wb -> taskSummary.getWorkbasketKey().equals(wb.getKey()))) { .anyMatch(wb -> taskSummary.getWorkbasketKey().equals(wb.getKey()))) {
@ -975,7 +977,8 @@ public class TaskServiceImpl implements TaskService {
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (foundSummary == null) { if (foundSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId)); bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId,
"Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove(); taskIdIterator.remove();
} else { } else {
if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) { if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) {

View File

@ -68,7 +68,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.error( LOGGER.error(
"Method getWorkbasket() didn't find workbasket with ID {}. Throwing WorkbasketNotFoundException", "Method getWorkbasket() didn't find workbasket with ID {}. Throwing WorkbasketNotFoundException",
workbasketId); workbasketId);
throw new WorkbasketNotFoundException(workbasketId); throw new WorkbasketNotFoundException(workbasketId,
"Workbasket with id " + workbasketId + " was not found.");
} }
this.checkAuthorization(workbasketId, WorkbasketPermission.READ); this.checkAuthorization(workbasketId, WorkbasketPermission.READ);
return result; return result;
@ -90,7 +91,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.error( LOGGER.error(
"Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException", "Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException",
workbasketKey); workbasketKey);
throw new WorkbasketNotFoundException(workbasketKey); throw new WorkbasketNotFoundException(workbasketKey, domain,
"Workbasket with key " + workbasketKey + " and domain " + domain + " was not found.");
} }
this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ); this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ);
return result; return result;
@ -279,7 +281,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public void checkAuthorization(String workbasketId, public void checkAuthorization(String workbasketId,
WorkbasketPermission workbasketPermission) throws NotAuthorizedException, WorkbasketNotFoundException { WorkbasketPermission workbasketPermission) throws NotAuthorizedException, WorkbasketNotFoundException {
if (workbasketMapper.findById(workbasketId) == null) { if (workbasketMapper.findById(workbasketId) == null) {
throw new WorkbasketNotFoundException(workbasketId); throw new WorkbasketNotFoundException(workbasketId,
"Workbasket with id " + workbasketId + " was not found.");
} }
checkAuthorization(null, null, workbasketId, workbasketPermission); checkAuthorization(null, null, workbasketId, workbasketPermission);
} }
@ -289,7 +292,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
WorkbasketPermission workbasketPermission) WorkbasketPermission workbasketPermission)
throws NotAuthorizedException, WorkbasketNotFoundException { throws NotAuthorizedException, WorkbasketNotFoundException {
if (workbasketMapper.findByKeyAndDomain(workbasketKey, domain) == null) { if (workbasketMapper.findByKeyAndDomain(workbasketKey, domain) == null) {
throw new WorkbasketNotFoundException(workbasketKey + " - " + domain); throw new WorkbasketNotFoundException(workbasketKey, domain,
"Workbasket with key " + workbasketKey + " and domain " + domain + " was not found");
} }
checkAuthorization(workbasketKey, domain, null, workbasketPermission); checkAuthorization(workbasketKey, domain, null, workbasketPermission);
} }

View File

@ -131,6 +131,7 @@ public class WorkbasketDefinitionController {
distributionTargets.add(idConversion.get(oldId)); distributionTargets.add(idConversion.get(oldId));
} else { } else {
throw new WorkbasketNotFoundException( throw new WorkbasketNotFoundException(
oldId,
String.format( String.format(
"invalid import state: Workbasket '%s' does not exist in the given import list", "invalid import state: Workbasket '%s' does not exist in the given import list",
oldId)); oldId));