Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ permissions:
actions: write
id-token: write
contents: write
checks: write

concurrency:
# On master, we don't want any jobs cancelled so the sha is used to name the group
Expand Down Expand Up @@ -91,7 +92,7 @@ jobs:
restore-keys: ${{ runner.os }}-sonar

- name: Build with Gradle
run: ./gradlew -q --no-daemon --scan build
run: ./gradlew -q build

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
Expand Down Expand Up @@ -144,7 +145,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Publish with Gradle
run: ./gradlew -q --no-daemon --scan publish
run: ./gradlew -q publish

- name: Release with Gradle
run: ./gradlew -q --no-daemon --scan jreleaserFullRelease --no-configuration-cache --full-stacktrace
run: ./gradlew -q jreleaserFullRelease --no-configuration-cache --full-stacktrace
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.tkaczenko.auditor.cleanup.service;
package io.github.tkaczenko.auditor.cleanup.internal.service;

import io.github.tkaczenko.auditor.core.model.AuditRequestResponse;
import io.github.tkaczenko.auditor.core.repository.AuditRequestResponseRepository;
import io.github.tkaczenko.auditor.core.internal.entity.AuditRequestResponse;
import io.github.tkaczenko.auditor.core.internal.repository.AuditRequestResponseRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/** Provides utility classes and services for cleaning up audited data. */
package io.github.tkaczenko.auditor.cleanup.service;
package io.github.tkaczenko.auditor.cleanup.internal.service;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core;
package io.github.tkaczenko.auditor.core.api;

/** Provides methods to determine the execution of a specific request. */
public interface Auditable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the core functionality for the Auditor.
* This package contains classes/interfaces exposed to library users.
*/
package io.github.tkaczenko.auditor.core.api;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core;
package io.github.tkaczenko.auditor.core.api.reader;

/**
* Provides an interface for reading and processing HTTP data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.tkaczenko.auditor.core;
package io.github.tkaczenko.auditor.core.api.reader.body;

import io.github.tkaczenko.auditor.core.api.reader.HttpReader;
import java.io.InputStream;
import java.nio.charset.Charset;
import lombok.SneakyThrows;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.tkaczenko.auditor.core;
package io.github.tkaczenko.auditor.core.api.reader.headers;

import io.github.tkaczenko.auditor.core.api.reader.HttpReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal;

import io.github.tkaczenko.auditor.core.model.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.service.AuditService;
import io.github.tkaczenko.auditor.core.internal.service.ThreadLocalAuditRequestResponseContext;
import java.time.LocalDateTime;
import java.util.Optional;
import lombok.Builder;
Expand Down Expand Up @@ -28,8 +30,10 @@ public class AuditFacade {
*/
public void setRequest(AuditRequest auditRequest) {
var auditRequestBuilder =
Optional.ofNullable(AuditRequestContext.getAuditRequestResponseBuilderThreadLocal())
.orElseGet(AuditRequestContext::initializeAuditRequestBuilderThreadLocal);
Optional.ofNullable(
ThreadLocalAuditRequestResponseContext.getAuditRequestResponseBuilderThreadLocal())
.orElseGet(
ThreadLocalAuditRequestResponseContext::initializeAuditRequestBuilderThreadLocal);

auditRequestBuilder
.createDateTime(auditRequest.createDateTime)
Expand All @@ -39,7 +43,8 @@ public void setRequest(AuditRequest auditRequest) {
.requestBody(auditRequest.requestBody)
.remoteAddress(auditRequest.remoteAddress);

AuditRequestContext.setAuditRequestResponseBuilderThreadLocal(auditRequestBuilder);
ThreadLocalAuditRequestResponseContext.setAuditRequestResponseBuilderThreadLocal(
auditRequestBuilder);
}

/**
Expand All @@ -50,7 +55,8 @@ public void setRequest(AuditRequest auditRequest) {
* @param auditResponse the audit response object containing the necessary details
*/
public void setResponse(AuditResponse auditResponse) {
var auditRequestBuilder = AuditRequestContext.getAuditRequestResponseBuilderThreadLocal();
var auditRequestBuilder =
ThreadLocalAuditRequestResponseContext.getAuditRequestResponseBuilderThreadLocal();

auditRequestBuilder
.error(auditResponse.error())
Expand All @@ -59,7 +65,8 @@ public void setResponse(AuditResponse auditResponse) {
.responseBody(auditResponse.responseBody())
.spendTimeInMs(auditResponse.callDurationMillis());

AuditRequestContext.setAuditRequestResponseBuilderThreadLocal(auditRequestBuilder);
ThreadLocalAuditRequestResponseContext.setAuditRequestResponseBuilderThreadLocal(
auditRequestBuilder);
}

/**
Expand All @@ -70,7 +77,8 @@ public void setResponse(AuditResponse auditResponse) {
* @param requestType the type of request, e.g., "GET_REPORT", "POST_TRANSACTION", etc.
*/
public void save(String error, String provider, String requestType) {
var auditRequestBuilder = AuditRequestContext.getAuditRequestResponseBuilderThreadLocal();
var auditRequestBuilder =
ThreadLocalAuditRequestResponseContext.getAuditRequestResponseBuilderThreadLocal();

AuditRequestResponseDto dto =
auditRequestBuilder.provider(provider).requestType(requestType).build();
Expand All @@ -87,7 +95,7 @@ public void save(String error, String provider, String requestType) {
}

auditService.save(dto);
AuditRequestContext.initializeAuditRequestBuilderThreadLocal();
ThreadLocalAuditRequestResponseContext.initializeAuditRequestBuilderThreadLocal();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core.model.dto;
package io.github.tkaczenko.auditor.core.internal.dto;

import java.time.LocalDateTime;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* used in the auditor core module. DTOs are used to transfer data between different layers of the
* application, such as the controller and the service layer.
*/
package io.github.tkaczenko.auditor.core.model.dto;
package io.github.tkaczenko.auditor.core.internal.dto;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core.model;
package io.github.tkaczenko.auditor.core.internal.entity;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* represent the main entities and data structures used throughout the application. This package
* includes classes for managing audit logs, and other core functionality.
*/
package io.github.tkaczenko.auditor.core.model;
package io.github.tkaczenko.auditor.core.internal.entity;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.factory;

import io.github.tkaczenko.auditor.core.HttpReader;
import io.github.tkaczenko.auditor.core.api.reader.HttpReader;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.tkaczenko.auditor.core.service.reader;
package io.github.tkaczenko.auditor.core.internal.factory.body;

import io.github.tkaczenko.auditor.core.BodyHttpReader;
import io.github.tkaczenko.auditor.core.service.HttpReaderFactory;
import io.github.tkaczenko.auditor.core.api.reader.body.BodyHttpReader;
import io.github.tkaczenko.auditor.core.internal.factory.HttpReaderFactory;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.tkaczenko.auditor.core.service.reader;
package io.github.tkaczenko.auditor.core.internal.factory.headers;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import io.github.tkaczenko.auditor.core.HeadersHttpReader;
import io.github.tkaczenko.auditor.core.service.HttpReaderFactory;
import io.github.tkaczenko.auditor.core.api.reader.headers.HeadersHttpReader;
import io.github.tkaczenko.auditor.core.internal.factory.HttpReaderFactory;
import java.util.List;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Provides classes and interfaces for reading data from various sources. The main entry point is
* the {@link io.github.tkaczenko.auditor.core.api.reader.HttpReader} interface, which defines the
* contract for reading data. Implementations of this interface can be used to read data from
* different sources, such as requests, responses for HTTP clients. The package also includes
* utility classes and helper methods to facilitate the reading of data.
*/
package io.github.tkaczenko.auditor.core.internal.factory;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tkaczenko.auditor.core.repository;
package io.github.tkaczenko.auditor.core.internal.repository;

import io.github.tkaczenko.auditor.core.model.AuditRequestResponse;
import io.github.tkaczenko.auditor.core.internal.entity.AuditRequestResponse;
import org.springframework.data.repository.NoRepositoryBean;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core.repository;
package io.github.tkaczenko.auditor.core.internal.repository;

import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* the methods for interacting with the underlying data storage, such as querying, creating,
* updating, and deleting entities.
*/
package io.github.tkaczenko.auditor.core.repository;
package io.github.tkaczenko.auditor.core.internal.repository;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.service;

import java.time.LocalDateTime;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.service;

import io.github.tkaczenko.auditor.core.config.PropertiesConfig.PersistingProperties;
import io.github.tkaczenko.auditor.core.model.AuditRequestResponse;
import io.github.tkaczenko.auditor.core.model.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.repository.AuditRequestResponseRepository;
import io.github.tkaczenko.auditor.core.internal.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.entity.AuditRequestResponse;
import io.github.tkaczenko.auditor.core.internal.repository.AuditRequestResponseRepository;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.service;

import io.github.tkaczenko.auditor.core.model.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.dto.AuditRequestResponseDto;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -9,17 +9,18 @@
* initializing, setting, and clearing the thread-local {@link
* AuditRequestResponseDto.AuditRequestResponseDtoBuilder} instance.
*
* <p>The {@link AuditRequestContext} class serves as a utility for managing the lifecycle of the
* {@link AuditRequestResponseDto.AuditRequestResponseDtoBuilder} instance. It ensures that the
* builder is properly initialized, set, and cleared within the current thread's context.
* <p>The {@link ThreadLocalAuditRequestResponseContext} class serves as a utility for managing the
* lifecycle of the {@link AuditRequestResponseDto.AuditRequestResponseDtoBuilder} instance. It
* ensures that the builder is properly initialized, set, and cleared within the current thread's
* context.
*
* <p>This class follows the Utility Class pattern, as it contains only static methods and does not
* require instantiation. It provides a centralized and thread-safe way to work with the
* AuditRequestResponseDto builder.
*/
@Slf4j
@UtilityClass
public class AuditRequestContext {
public class ThreadLocalAuditRequestResponseContext {

private static final ThreadLocal<AuditRequestResponseDto.AuditRequestResponseDtoBuilder>
auditRequestResponseBuilderThreadLocal = new ThreadLocal<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* Provides the core services for the Auditor. This package contains the main business
* logic and functionality of the Auditor.
*/
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.service;

This file was deleted.

17 changes: 12 additions & 5 deletions auditor.core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
module auditor.core {
exports io.github.tkaczenko.auditor.core;
exports io.github.tkaczenko.auditor.core.config;
exports io.github.tkaczenko.auditor.core.model;
exports io.github.tkaczenko.auditor.core.repository;
exports io.github.tkaczenko.auditor.core.service;
exports io.github.tkaczenko.auditor.core.service.reader;
exports io.github.tkaczenko.auditor.core.internal.repository;
exports io.github.tkaczenko.auditor.core.internal;
exports io.github.tkaczenko.auditor.core.api;
exports io.github.tkaczenko.auditor.core.api.reader;
exports io.github.tkaczenko.auditor.core.api.reader.body;
exports io.github.tkaczenko.auditor.core.api.reader.headers;
exports io.github.tkaczenko.auditor.core.internal.service;
exports io.github.tkaczenko.auditor.core.internal.factory;
exports io.github.tkaczenko.auditor.core.internal.factory.headers;
exports io.github.tkaczenko.auditor.core.internal.factory.body;
exports io.github.tkaczenko.auditor.core.internal.entity;

requires com.fasterxml.jackson.annotation;
requires com.fasterxml.jackson.databind;
Expand All @@ -24,5 +31,5 @@
requires spring.data.jpa;
requires spring.tx;
requires spring.web;
requires com.github.spotbugs.annotations;
requires com.github.spotbugs.annotations;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;

import io.github.tkaczenko.auditor.core.model.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.dto.AuditRequestResponseDto;
import io.github.tkaczenko.auditor.core.internal.service.AuditService;
import io.github.tkaczenko.auditor.core.internal.service.ThreadLocalAuditRequestResponseContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -55,7 +57,7 @@ void setRequest() {
auditFacade.setRequest(EXPECTED_AUDIT_REQUEST);

AuditRequestResponseDto actual =
AuditRequestContext.getAuditRequestResponseBuilderThreadLocal().build();
ThreadLocalAuditRequestResponseContext.getAuditRequestResponseBuilderThreadLocal().build();

assertEquals(EXPECTED_AUDIT_REQUEST.url(), actual.getUrl());
assertEquals(EXPECTED_AUDIT_REQUEST.requestMethod(), actual.getRequestMethod());
Expand All @@ -69,7 +71,7 @@ void setResponse() {
auditFacade.setResponse(EXPECTED_AUDIT_RESPONSE);

AuditRequestResponseDto actual =
AuditRequestContext.getAuditRequestResponseBuilderThreadLocal().build();
ThreadLocalAuditRequestResponseContext.getAuditRequestResponseBuilderThreadLocal().build();

assertEquals(EXPECTED_AUDIT_RESPONSE.error(), actual.getError());
assertEquals(EXPECTED_AUDIT_RESPONSE.responseBody(), actual.getResponseBody());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tkaczenko.auditor.core.model;
package io.github.tkaczenko.auditor.core.internal.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.tkaczenko.auditor.core.service;
package io.github.tkaczenko.auditor.core.internal.factory;

import static org.junit.jupiter.api.Assertions.assertTrue;

import io.github.tkaczenko.auditor.core.HttpReader;
import io.github.tkaczenko.auditor.core.api.reader.HttpReader;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.tkaczenko.auditor.core.service.reader;
package io.github.tkaczenko.auditor.core.internal.factory.body;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import io.github.tkaczenko.auditor.core.BodyHttpReader;
import io.github.tkaczenko.auditor.core.api.reader.body.BodyHttpReader;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down
Loading