Class UserData

java.lang.Object
com.ecom.winners.configurations.UserData

@Configuration public class UserData extends Object
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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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, int chunkSize)
     
    User processor bean creates an instance of UserProcessor that processes user data that comes from reader bean.
    org.springframework.batch.item.ItemReader<List<UserDTO>>
    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.
    org.springframework.batch.item.ItemWriter<List<User>>
    writer (jakarta.persistence.EntityManagerFactory entityManagerFactory)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 UserDTO
      host - the host where data resides, injected from application properties
      path - the path where data resides, injected from application properties
      pageSize - the fetch size for each page, injected from application properties
      startPage - the start page to read, injected from application properties
      endPage - 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

      @Bean(name="userProcessor") public UserProcessor processor()
      User processor bean creates an instance of UserProcessor that processes user data that comes from reader bean.
      Returns:
      UserProcessor maps a list of UserDTO to a list of User entities.
      See Also:
    • writer

      @Bean(name="userWriter") public org.springframework.batch.item.ItemWriter<List<User>> writer (jakarta.persistence.EntityManagerFactory entityManagerFactory)
    • 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)