Skip to content
Snippets Groups Projects
Commit 13a61a76 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2652 cleanup Exception/Log handling

parent 0b1767e1
Branches
Tags
No related merge requests found
...@@ -26,8 +26,7 @@ public class UserService { ...@@ -26,8 +26,7 @@ public class UserService {
} }
private User addIdUser(User user, User persistedUser) { private User addIdUser(User user, User persistedUser) {
user.setId(persistedUser.getId()); return user.toBuilder().id(persistedUser.getId()).build();
return user;
} }
public void markUnsyncedUsersAsDeleted(long lastSyncTimestamp) { public void markUnsyncedUsersAsDeleted(long lastSyncTimestamp) {
......
package de.itvsh.kop.user.common.errorhandling;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import lombok.extern.log4j.Log4j2;
@Log4j2
public class ExceptionHandler {
@Provider
class KeycloakUnavailableExceptionMapper implements ExceptionMapper<KeycloakUnavailableException> {
@Override
public Response toResponse(KeycloakUnavailableException exception) {
LOG.error(exception.getMessage());
return buildInternalServerErrorResponse(exception);
}
}
Response buildInternalServerErrorResponse(TechnicalException exception) {
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(exception.getMessage())
.build();
}
}
\ No newline at end of file
...@@ -19,6 +19,7 @@ import de.itvsh.kop.user.User; ...@@ -19,6 +19,7 @@ import de.itvsh.kop.user.User;
import de.itvsh.kop.user.UserResourceMapper; import de.itvsh.kop.user.UserResourceMapper;
import de.itvsh.kop.user.common.errorhandling.KeycloakClientException; import de.itvsh.kop.user.common.errorhandling.KeycloakClientException;
import de.itvsh.kop.user.common.errorhandling.KeycloakUnavailableException; import de.itvsh.kop.user.common.errorhandling.KeycloakUnavailableException;
import io.quarkus.logging.Log;
@ApplicationScoped @ApplicationScoped
class KeycloakApiService { class KeycloakApiService {
...@@ -54,9 +55,13 @@ class KeycloakApiService { ...@@ -54,9 +55,13 @@ class KeycloakApiService {
try { try {
return runnable.get(); return runnable.get();
} catch (ClientErrorException e) { } catch (ClientErrorException e) {
throw new KeycloakClientException(properties.user(), properties.realm(), keycloakUrl, e); var exception = new KeycloakClientException(properties.user(), properties.realm(), keycloakUrl, e);
Log.error(exception.getMessage());
throw exception;
} catch (ProcessingException | IllegalStateException e) { } catch (ProcessingException | IllegalStateException e) {
throw new KeycloakUnavailableException(properties.user(), properties.realm(), keycloakUrl, e); var exception = new KeycloakUnavailableException(properties.user(), properties.realm(), keycloakUrl, e);
Log.error(exception.getMessage());
throw exception;
} }
} }
} }
\ No newline at end of file
...@@ -32,13 +32,11 @@ public class LockService { ...@@ -32,13 +32,11 @@ public class LockService {
} }
public void unlock(Lock lock) { public void unlock(Lock lock) {
LOG.info("Delete lock...");
repository.delete(lock); repository.delete(lock);
LOG.info("Lock deleted"); LOG.info("Lock deleted");
} }
public void lock(Instant timestamp) { public void lock(Instant timestamp) {
LOG.info("Create lock...");
repository.persist(Lock.builder().timestamp(timestamp.toEpochMilli()).build()); repository.persist(Lock.builder().timestamp(timestamp.toEpochMilli()).build());
LOG.info("Lock created"); LOG.info("Lock created");
} }
......
...@@ -41,6 +41,7 @@ class SyncService { ...@@ -41,6 +41,7 @@ class SyncService {
.forEach(user -> userService.save(addLastSyncTimestamp(user, lock))); .forEach(user -> userService.save(addLastSyncTimestamp(user, lock)));
userService.markUnsyncedUsersAsDeleted(lock.getTimestamp()); userService.markUnsyncedUsersAsDeleted(lock.getTimestamp());
LOG.info("sync successful.");
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error syncing user", e); LOG.error("Error syncing user", e);
} finally { } finally {
......
package de.itvsh.kop.user; package de.itvsh.kop.user;
import static org.assertj.core.api.Assertions.*;
import javax.inject.Inject; import javax.inject.Inject;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest @QuarkusTest
...@@ -25,7 +25,7 @@ class UserRepositoryTest { ...@@ -25,7 +25,7 @@ class UserRepositoryTest {
user2 = UserTestFactory.createBuilder().externalId("unknown").build(); user2 = UserTestFactory.createBuilder().externalId("unknown").build();
repository.persist(user2); repository.persist(user2);
user2.setExternalId(null); user2 = user2.toBuilder().externalId(null).build();
} }
@Test @Test
...@@ -48,7 +48,7 @@ class UserRepositoryTest { ...@@ -48,7 +48,7 @@ class UserRepositoryTest {
void shouldNotFindByEmptyEmail() { void shouldNotFindByEmptyEmail() {
var user = UserTestFactory.createBuilder().externalId("unknown").email(null).build(); var user = UserTestFactory.createBuilder().externalId("unknown").email(null).build();
repository.persist(user); repository.persist(user);
user.setExternalId(null); user = user.toBuilder().externalId(null).build();
var res = repository.findByEmail(user.getEmail()); var res = repository.findByEmail(user.getEmail());
assertThat(res).isEmpty(); assertThat(res).isEmpty();
......
package de.itvsh.kop.user.common.errorhandling;
class ExceptionHandlerITCase {
// TODO
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment