Commit 301372c7 authored by Bergamote Orange's avatar Bergamote Orange
Browse files

MR comments & optimize imports

parent daa9e1aa
......@@ -22,15 +22,18 @@ public class ClusterIndexGenerationStepBatchConfig {
@Autowired
private BatchProperties batchProperties;
@Autowired
private ObjectMapper objectMapper;
@Bean
public Step clusterIndexGeneration(final ObjectMapper objectMapper) {
public Step clusterIndexGeneration() {
return stepBuilderFactory.get("clusterIndexGeneration")
.tasklet(generateClusterIndex(objectMapper))
.tasklet(generateClusterIndex())
.build();
}
@Bean
public Tasklet generateClusterIndex(final ObjectMapper objectMapper) {
public Tasklet generateClusterIndex() {
return new GenerateClusterIndexTasklet(batchProperties, prefixesStorageService, objectMapper);
}
}
......@@ -47,11 +47,17 @@ public class IndexationStepBatchConfig {
@Autowired
private ClusterPeriodModelsMapper mapper;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean
public Step clustersIndexation(final ObjectMapper objectMapper, final JdbcTemplate jdbcTemplate) {
public Step clustersIndexation() {
return this.stepBuilderFactory.get("clustersIndexation")
.partitioner("partitioner", prefixPartitioner())
.partitionHandler(partitionHandler(objectMapper, jdbcTemplate))
.partitionHandler(partitionHandler())
.build();
}
......@@ -62,16 +68,16 @@ public class IndexationStepBatchConfig {
}
@Bean
public TaskExecutorPartitionHandler partitionHandler(final ObjectMapper objectMapper, final JdbcTemplate jdbcTemplate) {
public TaskExecutorPartitionHandler partitionHandler() {
final TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setGridSize(properties.getGridSize());
partitionHandler.setStep(partitionedClustersIndexation(objectMapper, jdbcTemplate));
partitionHandler.setStep(partitionedClustersIndexation());
partitionHandler.setTaskExecutor(indexationTaskExecutor());
return partitionHandler;
}
@Bean
public Step partitionedClustersIndexation(final ObjectMapper objectMapper, final JdbcTemplate jdbcTemplate) {
public Step partitionedClustersIndexation() {
return stepBuilderFactory.get("partitionedClustersIndexation")
.<Map.Entry<String, List<String>>, ClusterFile>chunk(properties.getIndexationStepChunkSize())
.reader(memoryMapItemReader(null, null))
......
......@@ -17,15 +17,18 @@ public class PurgeIntermediateTableStepBatchConfig {
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean
public Step purgeIntermediateTable(final JdbcTemplate jdbcTemplate) {
public Step purgeIntermediateTable() {
return stepBuilderFactory.get("purgeIntermediateTable")
.tasklet(clearTable(jdbcTemplate))
.tasklet(clearTable())
.build();
}
@Bean
public Tasklet clearTable(final JdbcTemplate jdbcTemplate) {
public Tasklet clearTable() {
return (contribution, chunkContext) -> {
jdbcTemplate.execute(SQL_TRUNCATE_TABLE_CLUSTERPERIODS);
return RepeatStatus.FINISHED;
......
package fr.gouv.clea.indexation.index;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import fr.gouv.clea.config.BatchProperties;
import fr.gouv.clea.indexation.model.output.ClusterFileIndex;
import fr.gouv.clea.service.PrefixesStorageService;
......@@ -57,7 +56,6 @@ public class GenerateClusterIndexTasklet implements Tasklet {
Path jsonPath = Path.of(outputPath, CLUSTER_INDEX_FILENAME);
File jsonIndex = jsonPath.toFile();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(jsonIndex, clusterFileIndex);
}
}
package fr.gouv.clea.indexation.writer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import fr.gouv.clea.config.BatchProperties;
import fr.gouv.clea.indexation.model.output.ClusterFile;
import lombok.extern.slf4j.Slf4j;
......@@ -52,10 +51,9 @@ public class IndexationWriter implements ItemWriter<ClusterFile> {
void generateClusterFile(final ClusterFile clusterFile, final Path directoryOutputPath) {
final Path jsonClusterPath = Path.of(directoryOutputPath.toString(), clusterFile.getName()+JSON_FILE_EXTENSION);
final Path jsonClusterPath = Path.of(directoryOutputPath.toString(), clusterFile.getName() + JSON_FILE_EXTENSION);
log.debug("Generating cluster file : {}", jsonClusterPath);
File jsonClusterFile = jsonClusterPath.toFile();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
try {
objectMapper.writeValue(jsonClusterFile, clusterFile.getItems());
} catch (IOException e) {
......
......@@ -6,7 +6,6 @@ spring:
jpa:
hibernate.ddl-auto: none
database-platform: org.hibernate.dialect.PostgreSQL95Dialect # even with h2 database
batch:
# Manage it's batch metadata tables
initialize-schema: never
......@@ -17,6 +16,9 @@ spring:
enabled: "false"
baseline-on-migrate: "true"
locations: classpath:db/migration/{vendor}
jackson:
serialization:
indent-output: true
clea:
batch:
......
......@@ -5,7 +5,6 @@ import fr.gouv.clea.dto.SinglePlaceCluster;
import fr.gouv.clea.dto.SinglePlaceClusterPeriod;
import fr.gouv.clea.mapper.ClusterPeriodModelsMapper;
import fr.gouv.clea.mapper.ClusterPeriodModelsMapperImpl;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
......
......@@ -7,7 +7,6 @@ import fr.gouv.clea.dto.SinglePlaceExposedVisits;
import fr.gouv.clea.entity.ExposedVisit;
import fr.gouv.clea.identification.RiskConfigurationService;
import fr.gouv.clea.identification.RiskLevelConfig;
import fr.gouv.clea.identification.processor.SinglePlaceExposedVisitsProcessor;
import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......
package fr.gouv.clea.indexation.index;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import fr.gouv.clea.config.BatchProperties;
import fr.gouv.clea.indexation.model.output.ClusterFileIndex;
import fr.gouv.clea.service.PrefixesStorageService;
......@@ -17,7 +16,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import static fr.gouv.clea.config.BatchConstants.CLUSTER_INDEX_FILENAME;
......@@ -54,7 +52,6 @@ class GenerateClusterIndexTaskletTest {
tasklet.generateClusterIndex(jobId, prefixes);
verify(objectMapper, times(1)).enable(SerializationFeature.INDENT_OUTPUT);
verify(objectMapper, times(1)).writeValue(eq(jsonIndex), clusterFileIndexCaptor.capture());
assertThat(clusterFileIndexCaptor.getValue().getPrefixes()).containsExactlyElementsOf(prefixes);
assertThat(clusterFileIndexCaptor.getValue().getIteration()).isEqualTo(jobId.intValue());
......
package fr.gouv.clea.indexation.reader;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
......
package fr.gouv.clea.indexation.writer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import fr.gouv.clea.config.BatchProperties;
import fr.gouv.clea.indexation.model.output.ClusterFile;
import fr.gouv.clea.indexation.model.output.ClusterFileIndex;
import fr.gouv.clea.indexation.model.output.ClusterFileItem;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
......@@ -14,17 +11,14 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.internal.verification.Times;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
import static fr.gouv.clea.config.BatchConstants.JSON_FILE_EXTENSION;
import static org.mockito.ArgumentMatchers.eq;
@ExtendWith(MockitoExtension.class)
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
......@@ -54,7 +48,6 @@ public class IndexationWriterTest {
writer.generateClusterFile(clusterFile, Path.of(directoryOutputPath));
final File expectedFilePath = Path.of(directoryOutputPath, clusterFile.getName() + JSON_FILE_EXTENSION).toFile();
Mockito.verify(objectMapper, Mockito.times(1)).enable(SerializationFeature.INDENT_OUTPUT);
Mockito.verify(objectMapper, Mockito.times(1)).writeValue(expectedFilePath, clusterFile.getItems());
}
}
package fr.gouv.clea.prefixes;
import fr.gouv.clea.indexation.model.output.Prefix;
import fr.gouv.clea.service.PrefixesStorageService;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
......@@ -11,7 +10,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.ArgumentMatchers.anyString;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment