Skip to content

Commit

Permalink
added codestyle fixes, removed unused dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vadymhrnk committed Mar 1, 2024
1 parent badcc7e commit 4850bb1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240205</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@

@Service
public class JsonFileReaderServiceImpl implements FileReaderService {

public static final String READ_ERROR_MESSAGE = "Can't read from file: %s";
public static final String EMPTY_STRING = "";
public static final String SPACE_REGEX = "\\s+";

@Override
public List<String> readFromFile(String filePath) {
try (BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(filePath))) {
StringBuilder jsonContent = new StringBuilder();
String line;

while ((line = bufferedReader.readLine()) != null) {
jsonContent.append(line.trim().replaceAll("\\s+", ""));
jsonContent.append(line.trim().replaceAll(SPACE_REGEX, EMPTY_STRING));
}

return Collections.singletonList(jsonContent.toString());
} catch (IOException e) {
throw new RuntimeException("Can't read from file: %s".formatted(filePath), e);
throw new RuntimeException(READ_ERROR_MESSAGE.formatted(filePath), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DatabaseInitializer {
public static final String FILE_PATH = "src/main/resources/static/test_report.json";
public static final int FIRST_INDEX = 0;
public static final String ERROR_MESSAGE = "Can't process JSON.";
public static final int UPDATE_RATE_MINUTES = 15;

private final FileReaderService fileReaderService;
private final ObjectMapper objectMapper;
Expand All @@ -40,7 +41,7 @@ private void init() {
reportRepository.save(entity);
}

@Scheduled(fixedRate = 15,timeUnit = TimeUnit.MINUTES)
@Scheduled(fixedRate = UPDATE_RATE_MINUTES, timeUnit = TimeUnit.MINUTES)
public void update() {
Report entity = getReport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@
@Service
@RequiredArgsConstructor
public class ReportServiceImpl implements ReportService {
public static final String REPORT_CACHE_NAME = "reportCache";
public static final int CACHE_CLEAR_RATE_MINUTES = 5;
private final SalesAndTrafficByDateRepository salesAndTrafficByDateRepository;
private final SalesAndTrafficByAsinRepository salesAndTrafficByAsinRepository;
private final SalesAndTrafficByDateMapper salesAndTrafficByDateMapper;
private final SalesAndTrafficByAsinMapper salesAndTrafficByAsinMapper;

@Cacheable(value = "reportCache")
@Cacheable(value = REPORT_CACHE_NAME)
@Override
public List<SalesAndTrafficByDateDto> findAllSalesAndTrafficByDate(Pageable pageable) {
return salesAndTrafficByDateRepository.findAll(pageable).stream()
.map(salesAndTrafficByDateMapper::toDto)
.collect(Collectors.toList());
}

@Cacheable(value = "reportCache")
@Cacheable(value = REPORT_CACHE_NAME)
@Override
public List<SalesAndTrafficByAsinDto> findAllSalesAndTrafficByAsin(Pageable pageable) {
return salesAndTrafficByAsinRepository.findAll(pageable).stream()
.map(salesAndTrafficByAsinMapper::toDto)
.collect(Collectors.toList());
}

@Cacheable(value = "reportCache")
@Cacheable(value = REPORT_CACHE_NAME)
@Override
public List<SalesAndTrafficByDateDto> findAllSalesAndTrafficBySelectedDates(
Pageable pageable,
Expand Down Expand Up @@ -72,7 +74,7 @@ public List<SalesAndTrafficByDateDto> findAllSalesAndTrafficBySelectedDates(
.collect(Collectors.toList());
}

@Cacheable(value = "reportCache")
@Cacheable(value = REPORT_CACHE_NAME)
@Override
public List<SalesAndTrafficByAsinDto> findAllSalesAndTrafficBySelectedAsins(
Pageable pageable,
Expand All @@ -86,8 +88,8 @@ public List<SalesAndTrafficByAsinDto> findAllSalesAndTrafficBySelectedAsins(
.collect(Collectors.toList());
}

@CacheEvict(value = "reportCache", allEntries = true)
@Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES)
@CacheEvict(value = REPORT_CACHE_NAME, allEntries = true)
@Scheduled(fixedRate = CACHE_CLEAR_RATE_MINUTES, timeUnit = TimeUnit.MINUTES)
public void clearCache() {
}
}

0 comments on commit 4850bb1

Please sign in to comment.