Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/8079-display-log-files' into 807…
Browse files Browse the repository at this point in the history
…9-display-log-files

# Conflicts:
#	service/src/main/java/greencity/service/DotenvServiceImpl.java
#	service/src/test/java/greencity/service/LogFileServiceImplTest.java
  • Loading branch information
Warded120 committed Feb 21, 2025
2 parents 6c37e94 + 68ff066 commit 1cb4c4c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ResponseEntity<PageableDto<LogFileMetadataDto>> listLogFiles(
description = "Filters for logs",
name = "LogFileFilterDto",
type = "object",
example = LogFileRequestDto.defaultJson) @RequestBody(required = false) @Valid LogFileRequestDto requestDto,
example = LogFileRequestDto.defaultJson) @RequestBody @Valid LogFileRequestDto requestDto,
@Parameter(hidden = true) Pageable page) {
return ResponseEntity.status(HttpStatus.OK)
.body(logFileService.listLogFiles(page, requestDto.filterDto(), requestDto.secretKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class AppConstant {
public static final String USER_PLACEHOLDER = "{user}";
public static final String TWO_USERS = "TWO_USERS";
public static final String THREE_OR_MORE_USERS = "THREE_OR_MORE_USERS";
public static final String DOTENV_FILENAME = "secretKeys.env";
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public class ErrorMessage {
public static final String LOG_FILE_NOT_FOUND = "No file found with name: %s";
public static final String CANNOT_READ_LOG_FILE = "Error reading log file: %s";
public static final String BAD_SECRET_KEY = "The given secret key is incorrect";
public static final String DOTENV_DELETED_OR_NOT_FOUND = ".env file already deleted or not found";
public static final String CANNOT_DELETE_DOTENV = "Failed to delete .env file";
public static final String FUNCTIONALITY_NOT_AVAILABLE = "Functionality is not available";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import greencity.dto.logs.filter.LogFileFilterDto;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

public record LogFileRequestDto(
String secretKey,
@NotNull String secretKey,
@Valid LogFileFilterDto filterDto) {
public static final String defaultJson = """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import greencity.exception.exceptions.BadRequestException;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ByteSizeRangeTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class DateRangeTest {

Expand Down
3 changes: 2 additions & 1 deletion service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<commons.collections4.version>4.4</commons.collections4.version>
<google.cloud.storage.version>2.29.1</google.cloud.storage.version>
<apache.commons.version>3.13.0</apache.commons.version>
<io.github.cdimascio.dotenv.version>3.1.0</io.github.cdimascio.dotenv.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -131,7 +132,7 @@
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>3.1.0</version>
<version>${io.github.cdimascio.dotenv.version}</version>
</dependency>
</dependencies>
</project>
5 changes: 2 additions & 3 deletions service/src/main/java/greencity/config/DotenvConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package greencity.config;

import greencity.constant.AppConstant;
import greencity.constant.ErrorMessage;
import greencity.exception.exceptions.FunctionalityNotAvailableException;
import io.github.cdimascio.dotenv.Dotenv;
Expand All @@ -11,13 +12,11 @@
@Configuration
@Lazy
public class DotenvConfig {
private static final String DOTENV_FILENAME = "secretKeys.env";

@Bean
Dotenv dotenv() {
try {
return Dotenv.configure()
.filename(DOTENV_FILENAME)
.filename(AppConstant.DOTENV_FILENAME)
.load();
} catch (DotenvException ex) {
throw new FunctionalityNotAvailableException(ErrorMessage.FUNCTIONALITY_NOT_AVAILABLE);
Expand Down
14 changes: 4 additions & 10 deletions service/src/main/java/greencity/service/DotenvServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package greencity.service;

import greencity.constant.AppConstant;
import greencity.constant.ErrorMessage;
import greencity.exception.exceptions.BadSecretKeyException;
import greencity.exception.exceptions.FunctionalityNotAvailableException;
Expand All @@ -16,13 +17,10 @@
@Profile({"dev", "test"})
public class DotenvServiceImpl implements DotenvService {
private Dotenv dotenv;

private final PasswordEncoder passwordEncoder;

private static final String DOTENV_FILENAME = "secretKeys.env";

public DotenvServiceImpl(PasswordEncoder passwordEncoder,
Dotenv dotenv) {
Dotenv dotenv) {
this.passwordEncoder = passwordEncoder;
this.dotenv = dotenv;
}
Expand All @@ -47,13 +45,9 @@ public void validateSecretKey(String secretKey) {
public void deleteDotenvFile(String secretKey) {
validateSecretKey(secretKey);

String dotenvFilePath = System.getProperty("user.dir") + File.separator + DOTENV_FILENAME;
String dotenvFilePath = System.getProperty("user.dir") + File.separator + AppConstant.DOTENV_FILENAME;
File dotenvFile = new File(dotenvFilePath);

if (!Files.exists(dotenvFile.toPath())) {
throw new FunctionalityNotAvailableException(ErrorMessage.DOTENV_DELETED_OR_NOT_FOUND);
}

try {
if (!Files.deleteIfExists(dotenvFile.toPath())) {
throw new FunctionalityNotAvailableException(ErrorMessage.CANNOT_DELETE_DOTENV);
Expand All @@ -77,7 +71,7 @@ public void deleteDotenvFile(String secretKey) {
void reloadEnvFile() {
try {
dotenv = Dotenv.configure()
.filename(DOTENV_FILENAME)
.filename(AppConstant.DOTENV_FILENAME)
.load();
} catch (DotenvException ex) {
throw new FunctionalityNotAvailableException(ErrorMessage.FUNCTIONALITY_NOT_AVAILABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.*;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mockStatic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@
import java.nio.file.Files;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class LogFileServiceImplTest {
Expand Down

0 comments on commit 1cb4c4c

Please sign in to comment.