From 6f344c93633afbf9b47bbca12f9867d2f7b96666 Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Mon, 2 Aug 2021 06:14:00 +0200 Subject: [PATCH] TSK-1647: automatic refactoring --- .../docs/asciidoc/simplehistory-rest-api.adoc | 13 ++ .../internal/ClassificationQueryImpl.java | 16 +- .../task/internal/models/TaskImpl.java | 176 +++++++++--------- .../internal/WorkbasketQueryImpl.java | 16 +- .../src/docs/asciidoc/rest-api.adoc | 3 +- .../rest/TaskanaRestExceptionHandler.java | 13 +- 6 files changed, 129 insertions(+), 108 deletions(-) diff --git a/history/taskana-simplehistory-rest-spring/src/docs/asciidoc/simplehistory-rest-api.adoc b/history/taskana-simplehistory-rest-spring/src/docs/asciidoc/simplehistory-rest-api.adoc index 55c117778..43cb8422d 100644 --- a/history/taskana-simplehistory-rest-spring/src/docs/asciidoc/simplehistory-rest-api.adoc +++ b/history/taskana-simplehistory-rest-spring/src/docs/asciidoc/simplehistory-rest-api.adoc @@ -15,6 +15,19 @@ Most of our resources contain a `_links` section which contains navigation links Besides, helping to navigate through our REST API, the navigation links also encapsulate the API. Using HATEOAS allows us to change some endpoints without modifying your frontend. +=== Errors + +In order to support multilingual websites, TASKANA uses error codes to define which error occurred. +Additionally, an optional set of message variables, containing some technical information, is added, so that the website can describe the error with all details. + +The table below is an addition to the already documented TASKANA REST Service ErrorCodes + +[%autowidth,width="100%"] +|=== +| Status Code | Key | Message Variables +| *404 NOT_FOUND* | HISTORY_EVENT_NOT_FOUND | historyEventId +|=== + == History event include::{snippets}/TaskHistoryEventControllerRestDocTest/getAllTaskHistoryEventsDocTest/auto-section.adoc[] diff --git a/lib/taskana-core/src/main/java/pro/taskana/classification/internal/ClassificationQueryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/classification/internal/ClassificationQueryImpl.java index 3f88d6c9c..20c9da7c4 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/classification/internal/ClassificationQueryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/classification/internal/ClassificationQueryImpl.java @@ -134,14 +134,6 @@ public class ClassificationQueryImpl implements ClassificationQuery { return this; } - private void validateAllTimeIntervals(TimeInterval[] createdIn) { - for (TimeInterval ti : createdIn) { - if (!ti.isValid()) { - throw new IllegalArgumentException("TimeInterval " + ti + " is invalid."); - } - } - } - @Override public ClassificationQuery nameIn(String... nameIn) { this.nameIn = nameIn; @@ -537,6 +529,14 @@ public class ClassificationQueryImpl implements ClassificationQuery { return orderColumns; } + private void validateAllTimeIntervals(TimeInterval[] createdIn) { + for (TimeInterval ti : createdIn) { + if (!ti.isValid()) { + throw new IllegalArgumentException("TimeInterval " + ti + " is invalid."); + } + } + } + private ClassificationQuery addOrderCriteria(String columnName, SortDirection sortDirection) { String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection); diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/internal/models/TaskImpl.java b/lib/taskana-core/src/main/java/pro/taskana/task/internal/models/TaskImpl.java index 2adbb69d6..c20e0e707 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/internal/models/TaskImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/internal/models/TaskImpl.java @@ -307,93 +307,93 @@ public class TaskImpl extends TaskSummaryImpl implements Task { @Override public String toString() { return "TaskImpl [customAttributes=" - + customAttributes - + ", callbackInfo=" - + callbackInfo - + ", callbackState=" - + callbackState - + ", attachments=" - + attachments - + ", id=" - + id - + ", externalId=" - + externalId - + ", created=" - + created - + ", claimed=" - + claimed - + ", completed=" - + completed - + ", modified=" - + modified - + ", planned=" - + planned - + ", received=" - + received - + ", due=" - + due - + ", name=" - + name - + ", creator=" - + creator - + ", note=" - + note - + ", description=" - + description - + ", priority=" - + priority - + ", state=" - + state - + ", classificationSummary=" - + classificationSummary - + ", workbasketSummary=" - + workbasketSummary - + ", businessProcessId=" - + businessProcessId - + ", parentBusinessProcessId=" - + parentBusinessProcessId - + ", owner=" - + owner - + ", primaryObjRef=" - + primaryObjRef - + ", isRead=" - + isRead - + ", isTransferred=" - + isTransferred - + ", attachmentSummaries=" - + attachmentSummaries - + ", custom1=" - + custom1 - + ", custom2=" - + custom2 - + ", custom3=" - + custom3 - + ", custom4=" - + custom4 - + ", custom5=" - + custom5 - + ", custom6=" - + custom6 - + ", custom7=" - + custom7 - + ", custom8=" - + custom8 - + ", custom9=" - + custom9 - + ", custom10=" - + custom10 - + ", custom11=" - + custom11 - + ", custom12=" - + custom12 - + ", custom13=" - + custom13 - + ", custom14=" - + custom14 - + ", custom15=" - + custom15 - + ", custom16=" - + custom16 - + "]"; + + customAttributes + + ", callbackInfo=" + + callbackInfo + + ", callbackState=" + + callbackState + + ", attachments=" + + attachments + + ", id=" + + id + + ", externalId=" + + externalId + + ", created=" + + created + + ", claimed=" + + claimed + + ", completed=" + + completed + + ", modified=" + + modified + + ", planned=" + + planned + + ", received=" + + received + + ", due=" + + due + + ", name=" + + name + + ", creator=" + + creator + + ", note=" + + note + + ", description=" + + description + + ", priority=" + + priority + + ", state=" + + state + + ", classificationSummary=" + + classificationSummary + + ", workbasketSummary=" + + workbasketSummary + + ", businessProcessId=" + + businessProcessId + + ", parentBusinessProcessId=" + + parentBusinessProcessId + + ", owner=" + + owner + + ", primaryObjRef=" + + primaryObjRef + + ", isRead=" + + isRead + + ", isTransferred=" + + isTransferred + + ", attachmentSummaries=" + + attachmentSummaries + + ", custom1=" + + custom1 + + ", custom2=" + + custom2 + + ", custom3=" + + custom3 + + ", custom4=" + + custom4 + + ", custom5=" + + custom5 + + ", custom6=" + + custom6 + + ", custom7=" + + custom7 + + ", custom8=" + + custom8 + + ", custom9=" + + custom9 + + ", custom10=" + + custom10 + + ", custom11=" + + custom11 + + ", custom12=" + + custom12 + + ", custom13=" + + custom13 + + ", custom14=" + + custom14 + + ", custom15=" + + custom15 + + ", custom16=" + + custom16 + + "]"; } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/WorkbasketQueryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/WorkbasketQueryImpl.java index 94333ecf5..989fd397b 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/WorkbasketQueryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/WorkbasketQueryImpl.java @@ -142,14 +142,6 @@ public class WorkbasketQueryImpl implements WorkbasketQuery { return this; } - private void validateAllTimeIntervals(TimeInterval[] intervals) { - for (TimeInterval ti : intervals) { - if (!ti.isValid()) { - throw new IllegalArgumentException("TimeInterval " + ti + " is invalid."); - } - } - } - @Override public WorkbasketQuery descriptionLike(String... description) { this.descriptionLike = toUpperCopy(description); @@ -595,6 +587,14 @@ public class WorkbasketQueryImpl implements WorkbasketQuery { } } + private void validateAllTimeIntervals(TimeInterval[] intervals) { + for (TimeInterval ti : intervals) { + if (!ti.isValid()) { + throw new IllegalArgumentException("TimeInterval " + ti + " is invalid."); + } + } + } + private void handleCallerRolesAndAccessIds() { if (!callerRolesAndAccessIdsAlreadyHandled) { callerRolesAndAccessIdsAlreadyHandled = true; diff --git a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc index 53e49c659..045378e88 100644 --- a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc +++ b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc @@ -38,14 +38,13 @@ Additionally, an optional set of message variables, containing some technical in | *403 FORBIDDEN* | WORKBASKET_WITH_KEY_MISMATCHED_PERMISSION | currentUserId, workbasketKey, domain, requiredPermissions | *404 NOT_FOUND* | CLASSIFICATION_WITH_ID_NOT_FOUND | classificationId | *404 NOT_FOUND* | CLASSIFICATION_WITH_KEY_NOT_FOUND | classificationKey, domain -| *404 NOT_FOUND* | HISTORY_EVENT_NOT_FOUND | historyEventId | *404 NOT_FOUND* | TASK_COMMENT_NOT_FOUND | taskCommentId | *404 NOT_FOUND* | TASK_NOT_FOUND | taskId | *404 NOT_FOUND* | WORKBASKET_WITH_ID_NOT_FOUND | workbasketId | *404 NOT_FOUND* | WORKBASKET_WITH_KEY_NOT_FOUND | workbasketKey, domain | *409 CONFLICT* | ATTACHMENT_ALREADY_EXISTS | attachmentId, taskId | *409 CONFLICT* | CLASSIFICATION_ALREADY_EXISTS | classificationKey, domain -| *409 CONFLICT* | ENTITY_NOT_UP_TO_DATE | +| *409 CONFLICT* | ENTITY_NOT_UP_TO_DATE | entityId | *409 CONFLICT* | TASK_ALREADY_EXISTS | externalTaskId | *409 CONFLICT* | WORKBASKET_ACCESS_ITEM_ALREADY_EXISTS | accessId, workbasketId | *409 CONFLICT* | WORKBASKET_ALREADY_EXISTS | workbasketKey, domain diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaRestExceptionHandler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaRestExceptionHandler.java index 4588b9611..cbe4a4081 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaRestExceptionHandler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaRestExceptionHandler.java @@ -30,6 +30,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep import pro.taskana.classification.api.exceptions.ClassificationAlreadyExistException; import pro.taskana.classification.api.exceptions.ClassificationInUseException; import pro.taskana.classification.api.exceptions.ClassificationNotFoundException; +import pro.taskana.classification.api.exceptions.MalformedServiceLevelException; import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.DomainNotFoundException; import pro.taskana.common.api.exceptions.ErrorCode; @@ -38,6 +39,7 @@ import pro.taskana.common.api.exceptions.MismatchedRoleException; import pro.taskana.common.api.exceptions.NotFoundException; import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaRuntimeException; +import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException; import pro.taskana.common.internal.util.MapCreator; import pro.taskana.common.rest.models.ExceptionRepresentationModel; import pro.taskana.spi.history.api.exceptions.TaskanaHistoryEventNotFoundException; @@ -127,7 +129,8 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler InvalidOwnerException.class, InvalidArgumentException.class, DomainNotFoundException.class, - TaskanaException.class + MalformedServiceLevelException.class, + WrongCustomHolidayFormatException.class }) protected ResponseEntity handleBadRequestExceptions(TaskanaException ex, WebRequest req) { return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.BAD_REQUEST); @@ -141,11 +144,17 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler } @ExceptionHandler(TaskanaRuntimeException.class) - protected ResponseEntity handleInternalServerExceptions( + protected ResponseEntity handleUnknownTaskanaRuntimeExceptions( TaskanaRuntimeException ex, WebRequest req) { return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.INTERNAL_SERVER_ERROR); } + @ExceptionHandler(TaskanaException.class) + protected ResponseEntity handleUnknownTaskanaExceptions( + TaskanaException ex, WebRequest req) { + return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.INTERNAL_SERVER_ERROR); + } + @ExceptionHandler(Exception.class) protected ResponseEntity handleGeneralException(Exception ex, WebRequest req) { return buildResponse(ErrorCode.of("UNKNOWN_ERROR"), ex, req, HttpStatus.INTERNAL_SERVER_ERROR);