TSK-2016: replaced MapCreator methods with Map#of calls

This commit is contained in:
Mustapha Zorgati 2023-03-16 00:43:34 +01:00
parent 2592a7f562
commit d3b59dfd6a
32 changed files with 123 additions and 155 deletions

View File

@ -1,6 +1,6 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import pro.taskana.common.internal.util.MapCreator; import java.util.Map;
/** /**
* This exception is thrown when an attempt is made to update an object that has already been * This exception is thrown when an attempt is made to update an object that has already been
@ -16,7 +16,7 @@ public class ConcurrencyException extends TaskanaException {
String.format( String.format(
"The entity with id '%s' cannot be updated since it has been modified while editing.", "The entity with id '%s' cannot be updated since it has been modified while editing.",
entityId), entityId),
ErrorCode.of(ERROR_KEY, MapCreator.of("entityId", entityId))); ErrorCode.of(ERROR_KEY, Map.of("entityId", ensureNullIsHandled(entityId))));
this.entityId = entityId; this.entityId = entityId;
} }

View File

@ -1,6 +1,6 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import pro.taskana.common.internal.util.MapCreator; import java.util.Map;
/** This exception is thrown when the specified domain is not found in the configuration. */ /** This exception is thrown when the specified domain is not found in the configuration. */
public class DomainNotFoundException extends TaskanaException { public class DomainNotFoundException extends TaskanaException {
@ -11,7 +11,7 @@ public class DomainNotFoundException extends TaskanaException {
public DomainNotFoundException(String domain) { public DomainNotFoundException(String domain) {
super( super(
String.format("Domain '%s' does not exist in the configuration", domain), String.format("Domain '%s' does not exist in the configuration", domain),
ErrorCode.of(ERROR_KEY, MapCreator.of("domain", domain))); ErrorCode.of(ERROR_KEY, Map.of("domain", ensureNullIsHandled(domain))));
this.domain = domain; this.domain = domain;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import pro.taskana.common.api.TaskanaRole; import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.internal.util.MapCreator;
/** /**
* This exception is thrown when the current user is not in a certain {@linkplain TaskanaRole role} * This exception is thrown when the current user is not in a certain {@linkplain TaskanaRole role}
@ -19,7 +19,11 @@ public class NotAuthorizedException extends TaskanaException {
String.format( String.format(
"Not authorized. The current user '%s' is not member of role(s) '%s'.", "Not authorized. The current user '%s' is not member of role(s) '%s'.",
currentUserId, Arrays.toString(roles)), currentUserId, Arrays.toString(roles)),
ErrorCode.of(ERROR_KEY, MapCreator.of("roles", roles, "currentUserId", currentUserId))); ErrorCode.of(
ERROR_KEY,
Map.ofEntries(
Map.entry("roles", ensureNullIsHandled(roles)),
Map.entry("currentUserId", ensureNullIsHandled(currentUserId)))));
this.currentUserId = currentUserId; this.currentUserId = currentUserId;
this.roles = roles; this.roles = roles;

View File

@ -1,5 +1,7 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import java.io.Serializable;
/** common base class for TASKANA's checked exceptions. */ /** common base class for TASKANA's checked exceptions. */
public class TaskanaException extends Exception { public class TaskanaException extends Exception {
@ -18,6 +20,10 @@ public class TaskanaException extends Exception {
return errorCode; return errorCode;
} }
protected static Serializable ensureNullIsHandled(Serializable o) {
return o == null ? "null" : o;
}
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() return getClass().getSimpleName()

View File

@ -1,5 +1,7 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import java.io.Serializable;
/** The common base class for TASKANA's runtime exceptions. */ /** The common base class for TASKANA's runtime exceptions. */
public class TaskanaRuntimeException extends RuntimeException { public class TaskanaRuntimeException extends RuntimeException {
@ -18,6 +20,10 @@ public class TaskanaRuntimeException extends RuntimeException {
return errorCode; return errorCode;
} }
protected static Serializable ensureNullIsHandled(Serializable o) {
return o == null ? "null" : o;
}
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() return getClass().getSimpleName()

View File

@ -1,6 +1,6 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import pro.taskana.common.internal.util.MapCreator; import java.util.Map;
/** /**
* This exception is thrown when the database name doesn't match to one of the desired databases. * This exception is thrown when the database name doesn't match to one of the desired databases.
@ -13,7 +13,8 @@ public class UnsupportedDatabaseException extends TaskanaRuntimeException {
public UnsupportedDatabaseException(String databaseProductName) { public UnsupportedDatabaseException(String databaseProductName) {
super( super(
String.format("Database '%s' is not supported", databaseProductName), String.format("Database '%s' is not supported", databaseProductName),
ErrorCode.of(ERROR_KEY, MapCreator.of("databaseProductName", databaseProductName))); ErrorCode.of(
ERROR_KEY, Map.of("databaseProductName", ensureNullIsHandled(databaseProductName))));
this.databaseProductName = databaseProductName; this.databaseProductName = databaseProductName;
} }

View File

@ -1,7 +1,7 @@
package pro.taskana.common.api.exceptions; package pro.taskana.common.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.CustomHoliday; import pro.taskana.common.api.CustomHoliday;
import pro.taskana.common.internal.util.MapCreator;
/** This exception is thrown when an entry for the {@linkplain CustomHoliday} has a wrong format. */ /** This exception is thrown when an entry for the {@linkplain CustomHoliday} has a wrong format. */
public class WrongCustomHolidayFormatException extends TaskanaRuntimeException { public class WrongCustomHolidayFormatException extends TaskanaRuntimeException {
@ -15,7 +15,7 @@ public class WrongCustomHolidayFormatException extends TaskanaRuntimeException {
"Wrong format for custom holiday entry '%s'! The format should be 'dd.MM' " "Wrong format for custom holiday entry '%s'! The format should be 'dd.MM' "
+ "i.e. 01.05 for the first of May.", + "i.e. 01.05 for the first of May.",
customHoliday), customHoliday),
ErrorCode.of(ERROR_KEY, MapCreator.of("customHoliday", customHoliday))); ErrorCode.of(ERROR_KEY, Map.of("customHoliday", ensureNullIsHandled(customHoliday))));
this.customHoliday = customHoliday; this.customHoliday = customHoliday;
} }

View File

@ -1,57 +0,0 @@
package pro.taskana.common.internal.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/* This class will be removed once we fully migrate from JDK8*/
public class MapCreator {
private MapCreator() {
throw new IllegalStateException("Utility class");
}
public static <K, V> Map<K, V> of() {
return Collections.emptyMap();
}
public static <K, V> Map<K, V> of(K k1, V v1) {
Map<K, V> map = new HashMap<>();
map.put(k1, v1);
return map;
}
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) {
Map<K, V> map = new HashMap<>();
map.put(k1, v1);
map.put(k2, v2);
return map;
}
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
Map<K, V> map = new HashMap<>();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
return map;
}
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
Map<K, V> map = new HashMap<>();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
return map;
}
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
Map<K, V> map = new HashMap<>();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
map.put(k5, v5);
return map;
}
}

View File

@ -70,7 +70,6 @@ import pro.taskana.common.internal.Interval;
import pro.taskana.common.internal.TaskanaEngineImpl; import pro.taskana.common.internal.TaskanaEngineImpl;
import pro.taskana.common.internal.jobs.JobScheduler; import pro.taskana.common.internal.jobs.JobScheduler;
import pro.taskana.common.internal.logging.LoggingAspect; import pro.taskana.common.internal.logging.LoggingAspect;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.common.internal.workingtime.HolidaySchedule; import pro.taskana.common.internal.workingtime.HolidaySchedule;
import pro.taskana.common.internal.workingtime.WorkingTimeCalculatorImpl; import pro.taskana.common.internal.workingtime.WorkingTimeCalculatorImpl;
import pro.taskana.testapi.TaskanaIntegrationTest; import pro.taskana.testapi.TaskanaIntegrationTest;
@ -225,7 +224,7 @@ class ArchitectureTest {
.should() .should()
.onlyDependOnClassesThat( .onlyDependOnClassesThat(
resideOutsideOfPackage("..pro.taskana..internal..") resideOutsideOfPackage("..pro.taskana..internal..")
.or(assignableTo(LoggingAspect.class).or(assignableTo(MapCreator.class)))) .or(assignableTo(LoggingAspect.class)))
.check(importedClasses); .check(importedClasses);
} }

View File

@ -1,9 +1,9 @@
package pro.taskana.classification.api.exceptions; package pro.taskana.classification.api.exceptions;
import java.util.Map;
import pro.taskana.classification.api.models.Classification; import pro.taskana.classification.api.models.Classification;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
/** /**
* This exception is thrown when a {@linkplain Classification} does already exits, but was tried to * This exception is thrown when a {@linkplain Classification} does already exits, but was tried to
@ -23,7 +23,11 @@ public class ClassificationAlreadyExistException extends TaskanaException {
public ClassificationAlreadyExistException(String key, String domain) { public ClassificationAlreadyExistException(String key, String domain) {
super( super(
String.format("A Classification with key '%s' already exists in domain '%s'.", key, domain), String.format("A Classification with key '%s' already exists in domain '%s'.", key, domain),
ErrorCode.of(ERROR_KEY, MapCreator.of("classificationKey", key, "domain", domain))); ErrorCode.of(
ERROR_KEY,
Map.ofEntries(
Map.entry("classificationKey", ensureNullIsHandled(key)),
Map.entry("domain", ensureNullIsHandled(domain)))));
classificationKey = key; classificationKey = key;
this.domain = domain; this.domain = domain;
} }

View File

@ -1,9 +1,9 @@
package pro.taskana.classification.api.exceptions; package pro.taskana.classification.api.exceptions;
import java.util.Map;
import pro.taskana.classification.api.models.Classification; import pro.taskana.classification.api.models.Classification;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.Attachment; import pro.taskana.task.api.models.Attachment;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
@ -28,11 +28,9 @@ public class ClassificationInUseException extends TaskanaException {
classification.getId(), classification.getKey(), classification.getDomain()), classification.getId(), classification.getKey(), classification.getDomain()),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, ERROR_KEY,
MapCreator.of( Map.ofEntries(
"classificationKey", Map.entry("classificationKey", ensureNullIsHandled(classification.getKey())),
classification.getKey(), Map.entry("domain", ensureNullIsHandled(classification.getDomain())))),
"domain",
classification.getDomain())),
cause); cause);
classificationKey = classification.getKey(); classificationKey = classification.getKey();
domain = classification.getDomain(); domain = classification.getDomain();

View File

@ -1,9 +1,9 @@
package pro.taskana.classification.api.exceptions; package pro.taskana.classification.api.exceptions;
import java.util.Map;
import pro.taskana.classification.api.models.Classification; import pro.taskana.classification.api.models.Classification;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
/** Thrown if a specific {@linkplain Classification} is not in the database. */ /** Thrown if a specific {@linkplain Classification} is not in the database. */
public class ClassificationNotFoundException extends TaskanaException { public class ClassificationNotFoundException extends TaskanaException {
@ -17,7 +17,8 @@ public class ClassificationNotFoundException extends TaskanaException {
public ClassificationNotFoundException(String classificationId) { public ClassificationNotFoundException(String classificationId) {
super( super(
String.format("Classification with id '%s' wasn't found", classificationId), String.format("Classification with id '%s' wasn't found", classificationId),
ErrorCode.of(ERROR_KEY_ID, MapCreator.of("classificationId", classificationId))); ErrorCode.of(
ERROR_KEY_ID, Map.of("classificationId", ensureNullIsHandled(classificationId))));
this.classificationId = classificationId; this.classificationId = classificationId;
classificationKey = null; classificationKey = null;
domain = null; domain = null;
@ -28,7 +29,10 @@ public class ClassificationNotFoundException extends TaskanaException {
String.format( String.format(
"Classification with key '%s' and domain '%s' could not be found", key, domain), "Classification with key '%s' and domain '%s' could not be found", key, domain),
ErrorCode.of( ErrorCode.of(
ERROR_KEY_KEY_DOMAIN, MapCreator.of("classificationKey", key, "domain", domain))); ERROR_KEY_KEY_DOMAIN,
Map.ofEntries(
Map.entry("classificationKey", ensureNullIsHandled(key)),
Map.entry("domain", ensureNullIsHandled(domain)))));
this.classificationKey = key; this.classificationKey = key;
this.domain = domain; this.domain = domain;
classificationId = null; classificationId = null;

View File

@ -1,9 +1,9 @@
package pro.taskana.classification.api.exceptions; package pro.taskana.classification.api.exceptions;
import java.util.Map;
import pro.taskana.classification.api.models.Classification; import pro.taskana.classification.api.models.Classification;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
/** /**
* This exception is thrown when the {@linkplain Classification#getServiceLevel() service level} of * This exception is thrown when the {@linkplain Classification#getServiceLevel() service level} of
@ -30,13 +30,10 @@ public class MalformedServiceLevelException extends TaskanaException {
serviceLevel, classificationKey, domain), serviceLevel, classificationKey, domain),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, ERROR_KEY,
MapCreator.of( Map.ofEntries(
"classificationKey", Map.entry("classificationKey", classificationKey),
classificationKey, Map.entry("domain", domain),
"domain", Map.entry("serviceLevel", serviceLevel))));
domain,
"serviceLevel",
serviceLevel)));
this.serviceLevel = serviceLevel; this.serviceLevel = serviceLevel;
this.classificationKey = classificationKey; this.classificationKey = classificationKey;
this.domain = domain; this.domain = domain;

View File

@ -1,8 +1,8 @@
package pro.taskana.spi.history.api.exceptions; package pro.taskana.spi.history.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.spi.history.api.events.task.TaskHistoryEvent; import pro.taskana.spi.history.api.events.task.TaskHistoryEvent;
/** /**
@ -17,7 +17,7 @@ public class TaskanaHistoryEventNotFoundException extends TaskanaException {
public TaskanaHistoryEventNotFoundException(String historyEventId) { public TaskanaHistoryEventNotFoundException(String historyEventId) {
super( super(
String.format("TaskHistoryEvent with id '%s' was not found", historyEventId), String.format("TaskHistoryEvent with id '%s' was not found", historyEventId),
ErrorCode.of(ERROR_KEY, MapCreator.of("historyEventId", historyEventId))); ErrorCode.of(ERROR_KEY, Map.of("historyEventId", ensureNullIsHandled(historyEventId))));
this.historyEventId = historyEventId; this.historyEventId = historyEventId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.Attachment; import pro.taskana.task.api.models.Attachment;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
@ -24,7 +24,11 @@ public class AttachmentPersistenceException extends TaskanaException {
"Cannot insert Attachment with id '%s' for Task with id '%s' " "Cannot insert Attachment with id '%s' for Task with id '%s' "
+ "because it already exists.", + "because it already exists.",
attachmentId, taskId), attachmentId, taskId),
ErrorCode.of(ERROR_KEY, MapCreator.of("attachmentId", attachmentId, "taskId", taskId)), ErrorCode.of(
ERROR_KEY,
Map.ofEntries(
Map.entry("attachmentId", ensureNullIsHandled(attachmentId)),
Map.entry("taskId", ensureNullIsHandled(taskId)))),
cause); cause);
this.attachmentId = attachmentId; this.attachmentId = attachmentId;
this.taskId = taskId; this.taskId = taskId;

View File

@ -1,9 +1,9 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.CallbackState; import pro.taskana.task.api.CallbackState;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
import pro.taskana.task.internal.models.MinimalTaskSummary; import pro.taskana.task.internal.models.MinimalTaskSummary;
@ -27,13 +27,10 @@ public class InvalidCallbackStateException extends TaskanaException {
taskId, Arrays.toString(requiredCallbackStates), taskCallbackState), taskId, Arrays.toString(requiredCallbackStates), taskCallbackState),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, ERROR_KEY,
MapCreator.of( Map.ofEntries(
"taskId", Map.entry("taskId", ensureNullIsHandled(taskId)),
taskId, Map.entry("taskCallbackState", ensureNullIsHandled(taskCallbackState)),
"taskCallbackState", Map.entry("requiredCallbackStates", ensureNullIsHandled(requiredCallbackStates)))));
taskCallbackState,
"requiredCallbackStates",
requiredCallbackStates)));
this.taskId = taskId; this.taskId = taskId;
this.taskCallbackState = taskCallbackState; this.taskCallbackState = taskCallbackState;
this.requiredCallbackStates = requiredCallbackStates; this.requiredCallbackStates = requiredCallbackStates;

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
/** This exception is thrown when the current user is not the owner of the {@linkplain Task}. */ /** This exception is thrown when the current user is not the owner of the {@linkplain Task}. */
@ -14,7 +14,7 @@ public class InvalidOwnerException extends TaskanaException {
public InvalidOwnerException(String currentUserId, String taskId) { public InvalidOwnerException(String currentUserId, String taskId) {
super( super(
String.format("User '%s' is not owner of Task '%s'", currentUserId, taskId), String.format("User '%s' is not owner of Task '%s'", currentUserId, taskId),
ErrorCode.of(ERROR_KEY, MapCreator.of("taskId", taskId, "currentUserId", currentUserId))); ErrorCode.of(ERROR_KEY, Map.of("taskId", taskId, "currentUserId", currentUserId)));
this.taskId = taskId; this.taskId = taskId;
this.currentUserId = currentUserId; this.currentUserId = currentUserId;
} }

View File

@ -1,9 +1,9 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.TaskState; import pro.taskana.task.api.TaskState;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
@ -26,13 +26,10 @@ public class InvalidTaskStateException extends TaskanaException {
taskId, taskState, Arrays.toString(requiredTaskStates)), taskId, taskState, Arrays.toString(requiredTaskStates)),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, ERROR_KEY,
MapCreator.of( Map.ofEntries(
"taskId", Map.entry("taskId", taskId),
taskId, Map.entry("taskState", taskState),
"taskState", Map.entry("requiredTaskStates", requiredTaskStates))));
taskState,
"requiredTaskStates",
requiredTaskStates)));
this.taskId = taskId; this.taskId = taskId;
this.taskState = taskState; this.taskState = taskState;

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.TaskComment; import pro.taskana.task.api.models.TaskComment;
/** /**
@ -22,7 +22,9 @@ public class NotAuthorizedOnTaskCommentException extends TaskanaException {
currentUserId, taskCommentId), currentUserId, taskCommentId),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, ERROR_KEY,
MapCreator.of("currentUserId", currentUserId, "taskCommentId", taskCommentId))); Map.ofEntries(
Map.entry("currentUserId", ensureNullIsHandled(currentUserId)),
Map.entry("taskCommentId", ensureNullIsHandled(taskCommentId)))));
this.currentUserId = currentUserId; this.currentUserId = currentUserId;
this.taskCommentId = taskCommentId; this.taskCommentId = taskCommentId;

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.ObjectReference; import pro.taskana.task.api.models.ObjectReference;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
@ -26,7 +26,10 @@ public class ObjectReferencePersistenceException extends TaskanaException {
+ "because it already exists.", + "because it already exists.",
objectReferenceId, taskId), objectReferenceId, taskId),
ErrorCode.of( ErrorCode.of(
ERROR_KEY, MapCreator.of("objectReferenceId", objectReferenceId, "taskId", taskId)), ERROR_KEY,
Map.ofEntries(
Map.entry("objectReferenceId", ensureNullIsHandled(objectReferenceId)),
Map.entry("taskId", ensureNullIsHandled(taskId)))),
cause); cause);
this.objectReferenceId = objectReferenceId; this.objectReferenceId = objectReferenceId;
this.taskId = taskId; this.taskId = taskId;

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
/** /**
@ -17,7 +17,7 @@ public class TaskAlreadyExistException extends TaskanaException {
public TaskAlreadyExistException(String externalId) { public TaskAlreadyExistException(String externalId) {
super( super(
String.format("Task with external id '%s' already exists", externalId), String.format("Task with external id '%s' already exists", externalId),
ErrorCode.of(ERROR_KEY, MapCreator.of("externalTaskId", externalId))); ErrorCode.of(ERROR_KEY, Map.of("externalTaskId", ensureNullIsHandled(externalId))));
this.externalId = externalId; this.externalId = externalId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.TaskComment; import pro.taskana.task.api.models.TaskComment;
/** This exception is thrown when a specific {@linkplain TaskComment} is not in the database. */ /** This exception is thrown when a specific {@linkplain TaskComment} is not in the database. */
@ -14,7 +14,7 @@ public class TaskCommentNotFoundException extends TaskanaException {
public TaskCommentNotFoundException(String taskCommentId) { public TaskCommentNotFoundException(String taskCommentId) {
super( super(
String.format("TaskComment with id '%s' was not found", taskCommentId), String.format("TaskComment with id '%s' was not found", taskCommentId),
ErrorCode.of(ERROR_KEY, MapCreator.of("taskCommentId", taskCommentId))); ErrorCode.of(ERROR_KEY, Map.of("taskCommentId", ensureNullIsHandled(taskCommentId))));
this.taskCommentId = taskCommentId; this.taskCommentId = taskCommentId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.task.api.exceptions; package pro.taskana.task.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.task.api.models.Task; import pro.taskana.task.api.models.Task;
/** This exception is thrown when a specific {@linkplain Task} is not in the database. */ /** This exception is thrown when a specific {@linkplain Task} is not in the database. */
@ -14,7 +14,7 @@ public class TaskNotFoundException extends TaskanaException {
public TaskNotFoundException(String taskId) { public TaskNotFoundException(String taskId) {
super( super(
String.format("Task with id '%s' was not found.", taskId), String.format("Task with id '%s' was not found.", taskId),
ErrorCode.of(ERROR_KEY, MapCreator.of("taskId", taskId))); ErrorCode.of(ERROR_KEY, Map.of("taskId", ensureNullIsHandled(taskId))));
this.taskId = taskId; this.taskId = taskId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.user.api.exceptions; package pro.taskana.user.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.user.api.models.User; import pro.taskana.user.api.models.User;
/** /**
@ -16,7 +16,7 @@ public class UserAlreadyExistException extends TaskanaException {
public UserAlreadyExistException(String userId, Exception cause) { public UserAlreadyExistException(String userId, Exception cause) {
super( super(
String.format("User with id '%s' already exists.", userId), String.format("User with id '%s' already exists.", userId),
ErrorCode.of(ERROR_KEY, MapCreator.of("userId", userId)), ErrorCode.of(ERROR_KEY, Map.of("userId", ensureNullIsHandled(userId))),
cause); cause);
this.userId = userId; this.userId = userId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.user.api.exceptions; package pro.taskana.user.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.user.api.models.User; import pro.taskana.user.api.models.User;
/** /**
@ -16,7 +16,7 @@ public class UserNotFoundException extends TaskanaException {
public UserNotFoundException(String userId) { public UserNotFoundException(String userId) {
super( super(
String.format("User with id '%s' was not found.", userId), String.format("User with id '%s' was not found.", userId),
ErrorCode.of(ERROR_KEY, MapCreator.of("userId", userId))); ErrorCode.of(ERROR_KEY, Map.of("userId", ensureNullIsHandled(userId))));
this.userId = userId; this.userId = userId;
} }

View File

@ -1,9 +1,9 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.WorkbasketPermission; import pro.taskana.workbasket.api.WorkbasketPermission;
import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.api.models.Workbasket;
@ -30,13 +30,10 @@ public class NotAuthorizedOnWorkbasketException extends TaskanaException {
currentUserId, Arrays.toString(requiredPermissions), workbasketId), currentUserId, Arrays.toString(requiredPermissions), workbasketId),
ErrorCode.of( ErrorCode.of(
ERROR_KEY_ID, ERROR_KEY_ID,
MapCreator.of( Map.ofEntries(
"currentUserId", Map.entry("currentUserId", ensureNullIsHandled(currentUserId)),
currentUserId, Map.entry("workbasketId", ensureNullIsHandled(workbasketId)),
"workbasketId", Map.entry("requiredPermissions", ensureNullIsHandled(requiredPermissions)))));
workbasketId,
"requiredPermissions",
requiredPermissions)));
this.currentUserId = currentUserId; this.currentUserId = currentUserId;
this.requiredPermissions = requiredPermissions; this.requiredPermissions = requiredPermissions;
@ -57,15 +54,11 @@ public class NotAuthorizedOnWorkbasketException extends TaskanaException {
currentUserId, Arrays.toString(requiredPermissions), workbasketKey, domain), currentUserId, Arrays.toString(requiredPermissions), workbasketKey, domain),
ErrorCode.of( ErrorCode.of(
ERROR_KEY_KEY_DOMAIN, ERROR_KEY_KEY_DOMAIN,
MapCreator.of( Map.ofEntries(
"currentUserId", Map.entry("currentUserId", ensureNullIsHandled(currentUserId)),
currentUserId, Map.entry("workbasketKey", ensureNullIsHandled(workbasketKey)),
"workbasketKey", Map.entry("domain", ensureNullIsHandled(domain)),
workbasketKey, Map.entry("requiredPermissions", ensureNullIsHandled(requiredPermissions)))));
"domain",
domain,
"requiredPermissions",
requiredPermissions)));
this.currentUserId = currentUserId; this.currentUserId = currentUserId;
this.requiredPermissions = requiredPermissions; this.requiredPermissions = requiredPermissions;

View File

@ -1,8 +1,8 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.models.WorkbasketAccessItem; import pro.taskana.workbasket.api.models.WorkbasketAccessItem;
/** /**
@ -20,7 +20,11 @@ public class WorkbasketAccessItemAlreadyExistException extends TaskanaException
String.format( String.format(
"WorkbasketAccessItem with access id '%s' and workbasket id '%s' already exists.", "WorkbasketAccessItem with access id '%s' and workbasket id '%s' already exists.",
accessId, workbasketId), accessId, workbasketId),
ErrorCode.of(ERROR_KEY, MapCreator.of("accessId", accessId, "workbasketId", workbasketId))); ErrorCode.of(
ERROR_KEY,
Map.ofEntries(
Map.entry("accessId", ensureNullIsHandled(accessId)),
Map.entry("workbasketId", ensureNullIsHandled(workbasketId)))));
this.accessId = accessId; this.accessId = accessId;
this.workbasketId = workbasketId; this.workbasketId = workbasketId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.api.models.Workbasket;
/** /**
@ -18,7 +18,11 @@ public class WorkbasketAlreadyExistException extends TaskanaException {
public WorkbasketAlreadyExistException(String key, String domain) { public WorkbasketAlreadyExistException(String key, String domain) {
super( super(
String.format("A Workbasket with key '%s' already exists in domain '%s'.", key, domain), String.format("A Workbasket with key '%s' already exists in domain '%s'.", key, domain),
ErrorCode.of(ERROR_KEY, MapCreator.of("workbasketKey", key, "domain", domain))); ErrorCode.of(
ERROR_KEY,
Map.ofEntries(
Map.entry("workbasketKey", ensureNullIsHandled(key)),
Map.entry("domain", ensureNullIsHandled(domain)))));
this.key = key; this.key = key;
this.domain = domain; this.domain = domain;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.api.models.Workbasket;
/** /**
@ -19,7 +19,7 @@ public class WorkbasketInUseException extends TaskanaException {
String.format( String.format(
"Workbasket '%s' contains non-completed Tasks and can't be marked for deletion.", "Workbasket '%s' contains non-completed Tasks and can't be marked for deletion.",
workbasketId), workbasketId),
ErrorCode.of(ERROR_KEY, MapCreator.of("workbasketId", workbasketId))); ErrorCode.of(ERROR_KEY, Map.of("workbasketId", ensureNullIsHandled(workbasketId))));
this.workbasketId = workbasketId; this.workbasketId = workbasketId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.api.models.Workbasket;
/** /**
@ -19,7 +19,7 @@ public class WorkbasketMarkedForDeletionException extends TaskanaException {
String.format( String.format(
"Workbasket with id '%s' could not be deleted, but was marked for deletion.", "Workbasket with id '%s' could not be deleted, but was marked for deletion.",
workbasketId), workbasketId),
ErrorCode.of(ERROR_KEY, MapCreator.of("workbasketId", workbasketId))); ErrorCode.of(ERROR_KEY, Map.of("workbasketId", ensureNullIsHandled(workbasketId))));
this.workbasketId = workbasketId; this.workbasketId = workbasketId;
} }

View File

@ -1,8 +1,8 @@
package pro.taskana.workbasket.api.exceptions; package pro.taskana.workbasket.api.exceptions;
import java.util.Map;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.api.models.Workbasket;
/** This exception is thrown when a specific {@linkplain Workbasket} is not in the database. */ /** This exception is thrown when a specific {@linkplain Workbasket} is not in the database. */
@ -17,7 +17,7 @@ public class WorkbasketNotFoundException extends TaskanaException {
public WorkbasketNotFoundException(String id) { public WorkbasketNotFoundException(String id) {
super( super(
String.format("Workbasket with id '%s' was not found.", id), String.format("Workbasket with id '%s' was not found.", id),
ErrorCode.of(ERROR_KEY_ID, MapCreator.of("workbasketId", id))); ErrorCode.of(ERROR_KEY_ID, Map.of("workbasketId", ensureNullIsHandled(id))));
this.id = id; this.id = id;
key = null; key = null;
domain = null; domain = null;
@ -26,7 +26,11 @@ public class WorkbasketNotFoundException extends TaskanaException {
public WorkbasketNotFoundException(String key, String domain) { public WorkbasketNotFoundException(String key, String domain) {
super( super(
String.format("Workbasket with key '%s' and domain '%s' was not found.", key, domain), String.format("Workbasket with key '%s' and domain '%s' was not found.", key, domain),
ErrorCode.of(ERROR_KEY_KEY_DOMAIN, MapCreator.of("workbasketKey", key, "domain", domain))); ErrorCode.of(
ERROR_KEY_KEY_DOMAIN,
Map.ofEntries(
Map.entry("workbasketKey", ensureNullIsHandled(key)),
Map.entry("domain", ensureNullIsHandled(domain)))));
id = null; id = null;
this.key = key; this.key = key;
this.domain = domain; this.domain = domain;

View File

@ -45,7 +45,6 @@ import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.api.exceptions.TaskanaRuntimeException; import pro.taskana.common.api.exceptions.TaskanaRuntimeException;
import pro.taskana.common.api.exceptions.UnsupportedDatabaseException; import pro.taskana.common.api.exceptions.UnsupportedDatabaseException;
import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException; import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException;
import pro.taskana.common.internal.util.MapCreator;
import pro.taskana.common.rest.models.ExceptionRepresentationModel; import pro.taskana.common.rest.models.ExceptionRepresentationModel;
import pro.taskana.spi.history.api.exceptions.TaskanaHistoryEventNotFoundException; import pro.taskana.spi.history.api.exceptions.TaskanaHistoryEventNotFoundException;
import pro.taskana.task.api.exceptions.AttachmentPersistenceException; import pro.taskana.task.api.exceptions.AttachmentPersistenceException;
@ -190,8 +189,7 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
ErrorCode errorCode = ErrorCode errorCode =
wrongQueryParameters.length != 0 wrongQueryParameters.length != 0
? ErrorCode.of( ? ErrorCode.of(
ERROR_KEY_QUERY_MALFORMED, ERROR_KEY_QUERY_MALFORMED, Map.of("malformedQueryParameters", wrongQueryParameters))
MapCreator.of("malformedQueryParameters", wrongQueryParameters))
: null; : null;
return buildResponse(errorCode, ex, request, HttpStatus.BAD_REQUEST); return buildResponse(errorCode, ex, request, HttpStatus.BAD_REQUEST);