TSK-280 add ids to NotFoundExceptions
This commit is contained in:
parent
ab5c58280c
commit
04221a3fa8
|
@ -5,8 +5,25 @@ package pro.taskana.exceptions;
|
|||
*/
|
||||
public class ClassificationNotFoundException extends NotFoundException {
|
||||
|
||||
public ClassificationNotFoundException(String msg) {
|
||||
super(msg);
|
||||
private String key;
|
||||
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;
|
||||
|
|
|
@ -5,8 +5,15 @@ package pro.taskana.exceptions;
|
|||
*/
|
||||
public class NotFoundException extends TaskanaException {
|
||||
|
||||
public NotFoundException(String id) {
|
||||
super(id);
|
||||
String id;
|
||||
|
||||
public NotFoundException(String id, String message) {
|
||||
super(message);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -5,8 +5,8 @@ package pro.taskana.exceptions;
|
|||
*/
|
||||
public class TaskNotFoundException extends NotFoundException {
|
||||
|
||||
public TaskNotFoundException(String id) {
|
||||
super("Task '" + id + "' not found");
|
||||
public TaskNotFoundException(String id, String msg) {
|
||||
super(id, msg);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -5,8 +5,25 @@ package pro.taskana.exceptions;
|
|||
*/
|
||||
public class WorkbasketNotFoundException extends NotFoundException {
|
||||
|
||||
public WorkbasketNotFoundException(String id) {
|
||||
super("Workbasket with '" + id + "' not found");
|
||||
private String key;
|
||||
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;
|
||||
|
|
|
@ -215,7 +215,7 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
@Override
|
||||
public Classification getClassification(String id) throws ClassificationNotFoundException {
|
||||
if (id == null) {
|
||||
throw new ClassificationNotFoundException(
|
||||
throw new ClassificationNotFoundException(id,
|
||||
"Classification for id " + id + " was not found.");
|
||||
}
|
||||
LOGGER.debug("entry to getClassification(id = {})", id);
|
||||
|
@ -225,7 +225,7 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
result = classificationMapper.findById(id);
|
||||
if (result == null) {
|
||||
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;
|
||||
} finally {
|
||||
|
@ -238,8 +238,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
public Classification getClassification(String key, String domain) throws ClassificationNotFoundException {
|
||||
LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain);
|
||||
if (key == null) {
|
||||
throw new ClassificationNotFoundException(
|
||||
"Classification for key " + key + " and domain " + domain + " was not found.");
|
||||
throw new ClassificationNotFoundException(key, domain,
|
||||
"Classification for null key and domain " + domain + " was not found.");
|
||||
}
|
||||
LOGGER.debug("entry to getClassification(key = {}, domain = {})", key, domain);
|
||||
Classification result = null;
|
||||
|
@ -252,7 +252,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
LOGGER.error(
|
||||
"Classification for key {} and domain {} was not found. Throwing ClassificationNotFoundException",
|
||||
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;
|
||||
|
@ -299,7 +300,7 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
taskanaEngine.openConnection();
|
||||
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
|
||||
if (classification == null) {
|
||||
throw new ClassificationNotFoundException(
|
||||
throw new ClassificationNotFoundException(classificationKey, domain,
|
||||
"The classification " + classificationKey + "wasn't found in the domain " + domain);
|
||||
}
|
||||
|
||||
|
|
|
@ -247,7 +247,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
.findFirst()
|
||||
.orElse(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();
|
||||
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
|
||||
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
|
||||
|
@ -355,7 +356,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
return resultTask;
|
||||
} else {
|
||||
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 {
|
||||
taskanaEngine.returnConnection();
|
||||
|
@ -512,7 +513,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
.findFirst()
|
||||
.orElse(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();
|
||||
} else if (!sourceWorkbaskets.stream()
|
||||
.anyMatch(wb -> taskSummary.getWorkbasketKey().equals(wb.getKey()))) {
|
||||
|
@ -975,7 +977,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
.findFirst()
|
||||
.orElse(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();
|
||||
} else {
|
||||
if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) {
|
||||
|
|
|
@ -68,7 +68,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.error(
|
||||
"Method getWorkbasket() didn't find workbasket with ID {}. Throwing WorkbasketNotFoundException",
|
||||
workbasketId);
|
||||
throw new WorkbasketNotFoundException(workbasketId);
|
||||
throw new WorkbasketNotFoundException(workbasketId,
|
||||
"Workbasket with id " + workbasketId + " was not found.");
|
||||
}
|
||||
this.checkAuthorization(workbasketId, WorkbasketPermission.READ);
|
||||
return result;
|
||||
|
@ -90,7 +91,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.error(
|
||||
"Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException",
|
||||
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);
|
||||
return result;
|
||||
|
@ -279,7 +281,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
public void checkAuthorization(String workbasketId,
|
||||
WorkbasketPermission workbasketPermission) throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
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);
|
||||
}
|
||||
|
@ -289,7 +292,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
WorkbasketPermission workbasketPermission)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ public class WorkbasketDefinitionController {
|
|||
distributionTargets.add(idConversion.get(oldId));
|
||||
} else {
|
||||
throw new WorkbasketNotFoundException(
|
||||
oldId,
|
||||
String.format(
|
||||
"invalid import state: Workbasket '%s' does not exist in the given import list",
|
||||
oldId));
|
||||
|
|
Loading…
Reference in New Issue