Skip to content
Snippets Groups Projects
Commit 56999d6b authored by OZGCloud's avatar OZGCloud
Browse files

OZG-1518 OZG-1930 use kop-common; remove moved classes

parent 2b64d7ba
No related branches found
No related tags found
No related merge requests found
Showing
with 17 additions and 110 deletions
package de.itvsh.goofy.common;
import io.grpc.Metadata;
import io.grpc.Metadata.Key;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class GrpcUtil {
public static Key<String> createKeyOf(String key) {
return Key.of(key, Metadata.ASCII_STRING_MARSHALLER);
}
}
\ No newline at end of file
......@@ -22,8 +22,8 @@ import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.kop.common.datatype.StringBasedValue;
import de.itvsh.kop.common.errorhandling.TechnicalException;
public class LinkedResourceDesiralizer extends StdDeserializer<Object> implements ContextualDeserializer {
......
......@@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import lombok.NoArgsConstructor;
@NoArgsConstructor
......
......@@ -23,9 +23,9 @@ import org.springframework.web.multipart.MultipartFile;
import com.google.protobuf.ByteString;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.goofy.common.file.OzgFile;
import de.itvsh.goofy.common.file.OzgFileData;
import de.itvsh.kop.common.errorhandling.TechnicalException;
@RestController
@RequestMapping(BinaryFileController.PATH)
......
......@@ -3,7 +3,7 @@ package de.itvsh.goofy.common.callcontext;
import org.springframework.beans.factory.annotation.Autowired;
import de.itvsh.goofy.common.ContextService;
import de.itvsh.goofy.common.GrpcUtil;
import de.itvsh.kop.common.grpc.GrpcUtil;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
......
......@@ -13,9 +13,9 @@ import org.springframework.stereotype.Service;
import com.auth0.jwt.exceptions.JWTVerificationException;
import de.itvsh.goofy.JwtTokenUtil;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.goofy.common.user.CurrentUserService;
import de.itvsh.goofy.common.user.GoofyUser;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import lombok.extern.log4j.Log4j2;
@Log4j2
......
......@@ -24,6 +24,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import de.itvsh.goofy.common.user.keycloak.KeycloakUnavailableException;
import de.itvsh.kop.common.errorhandling.ExceptionUtil;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import lombok.extern.log4j.Log4j2;
@ControllerAdvice
......
package de.itvsh.goofy.common.errorhandling;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
class ExceptionUtil {
private static final String MESSAGE_WITH_EXCEPTION_ID_TEMPLATE = "%s (ExceptionId: %s)";
public static String formatMessageWithExceptionId(String message, String exceptionId) {
return String.format(ExceptionUtil.MESSAGE_WITH_EXCEPTION_ID_TEMPLATE, message, exceptionId);
}
}
\ No newline at end of file
package de.itvsh.goofy.common.errorhandling;
@FunctionalInterface
public interface FunctionalErrorCode {
String getErrorCode();
}
......@@ -2,6 +2,10 @@ package de.itvsh.goofy.common.errorhandling;
import java.util.UUID;
import de.itvsh.kop.common.errorhandling.ExceptionUtil;
import de.itvsh.kop.common.errorhandling.FunctionalErrorCode;
import de.itvsh.kop.common.errorhandling.IdentifiableException;
public class FunctionalException extends RuntimeException implements IdentifiableException {
private static final long serialVersionUID = 1L;
......
......@@ -13,6 +13,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import de.itvsh.kop.common.errorhandling.ExceptionUtil;
import de.itvsh.kop.common.errorhandling.FunctionalErrorCode;
import io.grpc.Metadata;
import io.grpc.Metadata.Key;
import io.grpc.Status;
......
package de.itvsh.goofy.common.errorhandling;
public interface IdentifiableException {
String getExceptionId();
}
package de.itvsh.goofy.common.errorhandling;
import de.itvsh.kop.common.errorhandling.FunctionalErrorCode;
import lombok.Getter;
@Getter
......
package de.itvsh.goofy.common.errorhandling;
import java.util.UUID;
public class TechnicalException extends RuntimeException implements IdentifiableException {
private static final long serialVersionUID = 1L;
private final String exceptionId;
public TechnicalException(String msg, Throwable cause) {
super(msg, cause);
this.exceptionId = UUID.randomUUID().toString();
}
@Override
public String getMessage() {
return ExceptionUtil.formatMessageWithExceptionId(super.getMessage(), exceptionId);
}
@Override
public String getExceptionId() {
return exceptionId;
}
}
\ No newline at end of file
package de.itvsh.goofy.common.user.keycloak;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.kop.common.errorhandling.TechnicalException;
public class KeycloakUnavailableException extends TechnicalException {
......
......@@ -18,10 +18,10 @@ import org.mockito.Mock;
import com.auth0.jwt.exceptions.JWTVerificationException;
import de.itvsh.goofy.JwtTokenUtil;
import de.itvsh.goofy.common.errorhandling.TechnicalException;
import de.itvsh.goofy.common.user.CurrentUserService;
import de.itvsh.goofy.common.user.GoofyUser;
import de.itvsh.goofy.common.user.UserTestFactory;
import de.itvsh.kop.common.errorhandling.TechnicalException;
class DownloadTokenServiceTest {
......
......@@ -20,6 +20,7 @@ import org.springframework.security.access.AccessDeniedException;
import com.thedeanda.lorem.LoremIpsum;
import de.itvsh.goofy.common.user.keycloak.KeycloakUnavailableException;
import de.itvsh.kop.common.errorhandling.TechnicalException;
class ExceptionControllerTest {
......
package de.itvsh.goofy.common.errorhandling;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
class ExceptionUtilTest {
@Test
void shouldFormatMessage() {
var formattedMessage = ExceptionUtil.formatMessageWithExceptionId("Test message", "42");
assertThat(formattedMessage).isEqualTo("Test message (ExceptionId: 42)");
}
}
\ No newline at end of file
package de.itvsh.goofy.common.errorhandling;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import com.thedeanda.lorem.LoremIpsum;
class TechnicalExceptionTest {
private final String MESSAGE = LoremIpsum.getInstance().getWords(5);
@Test
void shouldIncludeExceptionId() {
var exception = new TechnicalException(MESSAGE, new Throwable());
assertThat(exception.getMessage()).contains(exception.getExceptionId());
assertThat(exception.getExceptionId()).isNotNull();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment