Package com.ecom.winners.configurations
Class UserData
java.lang.Object
com.ecom.winners.configurations.UserData
UserData configuration class comprises fetching user data from an API step.
This class consists of all three phases related to reading user's data from API, transforming user
data
to User Entity and persisting it into the database with the help of JPA bulk item writer.
- See Also:
-
Configuration
User
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.batch.core.Step
fetchUserData
(org.springframework.batch.core.repository.JobRepository jobRepository, org.springframework.transaction.PlatformTransactionManager transactionManager, org.springframework.batch.item.ItemWriter<List<User>> userWriter, org.springframework.batch.item.ItemReader<List<UserDTO>> userReader, UserProcessor userProcessor, int chunkSize) User processor bean creates an instance of UserProcessor that processes user data that comes from reader bean.reader
(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String host, String path, int pageSize, int startPage, int endPage) User reader bean is responsible for fetching data from an API and path with pagination.writer
(jakarta.persistence.EntityManagerFactory entityManagerFactory)
-
Constructor Details
-
UserData
public UserData()
-
-
Method Details
-
reader
@Bean(name="userReader") public org.springframework.batch.item.ItemReader<List<UserDTO>> reader(com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Value("${userdata.reader.resource.host}") String host, @Value("${userdata.reader.resource.path}") String path, @Value("${userdata.reader.page.size}") int pageSize, @Value("${userdata.reader.start.page}") int startPage, @Value("${userdata.reader.end.page}") int endPage) User reader bean is responsible for fetching data from an API and path with pagination. It reads data until the predicate meets the criteria. For reading the data from API, it uses RestApiItemReader builder to create an Item reader object.- Parameters:
objectMapper
- ObjectMapper for mapping data to UserDTOhost
- the host where data resides, injected from application propertiespath
- the path where data resides, injected from application propertiespageSize
- the fetch size for each page, injected from application propertiesstartPage
- the start page to read, injected from application propertiesendPage
- the end page, injected from application properties- Returns:
- RestApiItemReader that is an implementation of ItemReader functional interface
- See Also:
-
ItemReader
UserDTO
ObjectMapper
Value
Bean
-
processor
User processor bean creates an instance of UserProcessor that processes user data that comes from reader bean. -
writer
-
fetchUserData
@Bean(name="fetchUserData") public org.springframework.batch.core.Step fetchUserData(org.springframework.batch.core.repository.JobRepository jobRepository, org.springframework.transaction.PlatformTransactionManager transactionManager, org.springframework.batch.item.ItemWriter<List<User>> userWriter, org.springframework.batch.item.ItemReader<List<UserDTO>> userReader, UserProcessor userProcessor, @Value("${userdata.reader.chunk.size}") int chunkSize)
-