Skip to content

Commit 92289f6

Browse files
committed
feat: update dependencies
1 parent 0ece3ee commit 92289f6

File tree

15 files changed

+149
-170
lines changed

15 files changed

+149
-170
lines changed

pom.xml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.4.4</version>
8+
<version>2.7.15</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.springbatch.excel</groupId>
@@ -14,8 +14,8 @@
1414
<name>tutorial</name>
1515
<description>Demo project for Spring Boot</description>
1616
<properties>
17-
<java.version>1.8</java.version>
18-
<poi.version>4.1.2</poi.version>
17+
<java.version>20</java.version>
18+
<poi.version>5.2.4</poi.version>
1919
</properties>
2020
<dependencies>
2121
<dependency>
@@ -58,22 +58,5 @@
5858

5959
</dependencies>
6060

61-
<build>
62-
<plugins>
63-
<plugin>
64-
<groupId>org.springframework.boot</groupId>
65-
<artifactId>spring-boot-maven-plugin</artifactId>
66-
<configuration>
67-
<excludes>
68-
<exclude>
69-
<groupId>org.projectlombok</groupId>
70-
<artifactId>lombok</artifactId>
71-
</exclude>
72-
</excludes>
73-
</configuration>
74-
</plugin>
75-
</plugins>
76-
</build>
77-
7861

7962
</project>

run-database-mongo.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Exécuter MongoDB Container
4+
docker run -d -p 27017:27017 \
5+
--name test-mongo \
6+
-v mongo-data:/data/db \
7+
-e MONGODB_INITDB_ROOT_USERNAME=admin \
8+
-e MONGODB_INITDB_ROOT_PASSWORD=pass \
9+
-e MONGODB_INITDB_DATABASE=spring_batch_excel_mongodb_db \
10+
mongo:latest
11+
12+
13+
# Exécuter MongoDB Express Container
14+
docker run --link test-mongo:mongo \
15+
-p 8222:8222 \
16+
-e ME_CONFIG_MONGODB_URL="mongodb://mongo:27017" \
17+
-e PORT=8222 \
18+
mongo-express
19+
20+
# "Utilisateur MongoDB Express: admin"
21+
# "Mot de passe MongoDB Express: pass"
22+
23+

src/main/java/com/springbatch/excel/tutorial/batch/BatchConfiguration.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.springbatch.excel.tutorial.batch.processors.EmployeeItemProcessor;
55
import com.springbatch.excel.tutorial.batch.validators.EmployeeJobParametersValidator;
66
import com.springbatch.excel.tutorial.domain.Employee;
7+
import lombok.RequiredArgsConstructor;
78
import org.springframework.batch.core.Job;
89
import org.springframework.batch.core.JobParametersValidator;
910
import org.springframework.batch.core.Step;
@@ -27,17 +28,13 @@
2728
*/
2829
@EnableBatchProcessing
2930
@Configuration
31+
@RequiredArgsConstructor
3032
public class BatchConfiguration {
3133

3234
public final JobBuilderFactory jobBuilderFactory;
3335

3436
public final StepBuilderFactory stepBuilderFactory;
3537

36-
public BatchConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
37-
this.jobBuilderFactory = jobBuilderFactory;
38-
this.stepBuilderFactory = stepBuilderFactory;
39-
}
40-
4138
@Bean
4239
public JobParametersValidator jobParametersValidator() {
4340
return new EmployeeJobParametersValidator();
@@ -62,13 +59,16 @@ public ItemReader<Employee> itemReader() {
6259

6360
@Bean
6461
public MongoItemWriter<Employee> writer(MongoTemplate mongoTemplate) {
65-
return new MongoItemWriterBuilder<Employee>().template(mongoTemplate).collection("employee")
62+
return new MongoItemWriterBuilder<Employee>()
63+
.template(mongoTemplate)
64+
.collection("employee")
6665
.build();
6766
}
6867

6968

7069
/**
7170
* step declaration
71+
*
7272
* @return {@link Step}
7373
*/
7474
@Bean
@@ -81,10 +81,9 @@ public Step employeeStep(MongoItemWriter<Employee> itemWriter) {
8181
.build();
8282
}
8383

84-
85-
8684
/**
8785
* job declaration
86+
*
8887
* @param listener {@link JobCompletionListener}
8988
* @return {@link Job}
9089
*/

src/main/java/com/springbatch/excel/tutorial/batch/EmployeeItemReader.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import com.springbatch.excel.tutorial.batch.mappers.EmployeeItemRowMapper;
44
import com.springbatch.excel.tutorial.domain.Employee;
55
import com.springbatch.excel.tutorial.support.poi.AbstractExcelPoi;
6+
import lombok.extern.slf4j.Slf4j;
67
import org.apache.poi.ss.formula.eval.NotImplementedException;
7-
import org.slf4j.Logger;
8-
import org.slf4j.LoggerFactory;
98
import org.springframework.batch.core.ExitStatus;
109
import org.springframework.batch.core.StepExecution;
1110
import org.springframework.batch.core.StepExecutionListener;
@@ -15,10 +14,9 @@
1514

1615
import java.util.List;
1716

17+
@Slf4j
1818
@Component
19-
public class EmployeeItemReader extends AbstractExcelPoi<Employee> implements ItemReader<Employee> , StepExecutionListener {
20-
21-
private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeItemReader.class);
19+
public class EmployeeItemReader extends AbstractExcelPoi<Employee> implements ItemReader<Employee>, StepExecutionListener {
2220

2321
private int employeeIndex = 0;
2422

@@ -40,7 +38,7 @@ public Employee read() {
4038
// read data in file
4139
employeeList = read(path, new EmployeeItemRowMapper());
4240

43-
if(!employeeList.isEmpty()) {
41+
if (!employeeList.isEmpty()) {
4442

4543
if (employeeIndex < employeeList.size()) {
4644
employee = employeeList.get(employeeIndex);
@@ -50,14 +48,14 @@ public Employee read() {
5048
}
5149
}
5250
} catch (Exception e) {
53-
LOGGER.warn("Cannot read the excel file: {}", e.getMessage());
51+
log.warn("Cannot read the excel file: {}", e.getMessage());
5452
}
5553

5654
return employee;
5755
}
5856

5957
@Override
60-
public void write(String filePath , List<Employee> aList) {
58+
public void write(String filePath, List<Employee> aList) {
6159
throw new NotImplementedException("No need to implement this method in the context");
6260
}
6361

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.springbatch.excel.tutorial.batch;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
55
import org.springframework.batch.core.Job;
66
import org.springframework.batch.core.JobParameters;
77
import org.springframework.batch.core.JobParametersBuilder;
@@ -19,38 +19,33 @@
1919
/**
2020
* @author aek
2121
*/
22+
@Slf4j
2223
@Component
24+
@RequiredArgsConstructor
2325
public class EmployeeJobLauncher {
2426

25-
private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeJobLauncher.class);
26-
2727
private final Job job;
2828

2929
private final JobLauncher jobLauncher;
3030

3131
@Value("${employee.excel.processingfolder}")
3232
private String processingDir;
3333

34-
EmployeeJobLauncher(Job job, JobLauncher jobLauncher) {
35-
this.job = job;
36-
this.jobLauncher = jobLauncher;
37-
}
38-
3934
// run every 2 min
4035
@Scheduled(fixedRate = 120000)
4136
void launchFileToJob() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobInstanceAlreadyCompleteException, JobRestartException {
42-
LOGGER.info("Starting job");
37+
log.info("Starting job");
4338
String excelFilePath = String.format("%s/employee.xlsx", processingDir);
4439

4540
JobParameters params = new JobParametersBuilder()
46-
.addLong("jobId",System.currentTimeMillis())
47-
.addDate("currentTime",new Date())
48-
.addString("excelPath",excelFilePath)
41+
.addLong("jobId", System.currentTimeMillis())
42+
.addDate("currentTime", new Date())
43+
.addString("excelPath", excelFilePath)
4944
.toJobParameters();
5045

5146
jobLauncher.run(job, params);
5247

53-
LOGGER.info("Stopping job");
48+
log.info("Stopping job");
5449
}
5550

5651
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
package com.springbatch.excel.tutorial.batch.listeners;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
3+
import lombok.extern.slf4j.Slf4j;
54
import org.springframework.batch.core.BatchStatus;
65
import org.springframework.batch.core.JobExecution;
76
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
87
import org.springframework.stereotype.Component;
98

109
import java.util.Date;
1110

11+
@Slf4j
1212
@Component
1313
public class JobCompletionListener extends JobExecutionListenerSupport {
1414

15-
private static final Logger LOGGER = LoggerFactory.getLogger(JobCompletionListener.class);
16-
1715
@Override
1816
public void afterJob(JobExecution jobExecution) {
1917

2018
String jobId = jobExecution.getJobParameters().getString("jobId");
2119
String excelFilePath = jobExecution.getJobParameters().getString("excelPath");
2220

23-
// get job's start time
21+
// get job's start time
2422
Date start = jobExecution.getCreateTime();
2523
// get job's end time
2624
Date end = jobExecution.getEndTime();
2725

28-
if(jobExecution.getStatus() == BatchStatus.COMPLETED) {
26+
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
2927

30-
LOGGER.info("==========JOB FINISHED=======");
31-
LOGGER.info("JobId : {}",jobId);
32-
LOGGER.info("excel Path : {}",excelFilePath);
33-
LOGGER.info("Start Date: {}", start);
34-
LOGGER.info("End Date: {}", end);
35-
LOGGER.info("==============================");
28+
log.info("==========JOB FINISHED=======");
29+
log.info("JobId : {}", jobId);
30+
log.info("excel Path : {}", excelFilePath);
31+
log.info("Start Date: {}", start);
32+
log.info("End Date: {}", end);
33+
log.info("==============================");
3634
}
3735

3836
}
3937

40-
}
38+
}

src/main/java/com/springbatch/excel/tutorial/batch/mappers/EmployeeItemRowMapper.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ public class EmployeeItemRowMapper extends CellFactory implements RowMapper<Empl
1010

1111
@Override
1212
public Employee transformerRow(Row row) {
13-
Employee employee = new Employee();
14-
15-
employee.setFirstName((String) getCellValue(row.getCell(0)));
16-
employee.setLastName((String) getCellValue(row.getCell(1)));
17-
employee.setNumber((String) getCellValue(row.getCell(2)));
18-
employee.setEmail((String) getCellValue(row.getCell(3)));
19-
employee.setDepartment((String) getCellValue(row.getCell(4)));
20-
employee.setSalary((Double) getCellValue(row.getCell(5)));
21-
22-
return employee;
13+
return new Employee(null,
14+
(String) getCellValue(row.getCell(0)),
15+
(String) getCellValue(row.getCell(1)),
16+
(String) getCellValue(row.getCell(2)),
17+
(String) getCellValue(row.getCell(3)),
18+
(String) getCellValue(row.getCell(4)),
19+
(Double) getCellValue(row.getCell(5)));
2320
}
2421
}

0 commit comments

Comments
 (0)