Class ProductsService

java.lang.Object
es.kukenan.smartfi.microservice.contracts.service.ProductsService

@Service public class ProductsService extends Object
Products related services.
  • Field Details

    • CORE_BACKOFFICE_ID

      private static final Integer CORE_BACKOFFICE_ID
      Core backoffice identifier.
    • productRepository

      @Autowired private ProductRepository productRepository
      Products DB repository.
    • backofficeSubsystemRepository

      @Autowired private BackofficeSubsystemRepository backofficeSubsystemRepository
      BackofficeSubsystem artificial entity repository.
    • userBackofficeRepository

      @Autowired private UserBackofficeRepository userBackofficeRepository
      User back office DB repository.
    • subsystemRepository

      @Autowired private SubsystemRepository subsystemRepository
      Subsystem DB repository.
    • backofficeClientManager

      @Autowired private BackofficeClientManager backofficeClientManager
      Back office clients manager.
    • dtoObfuscator

      @Autowired private DtoObfuscator dtoObfuscator
      Security util to obfuscate sensible data in DTOs.
    • uuidGenerator

      @Autowired private UuidGenerator uuidGenerator
      Uuid generator component.
    • beanValidatorService

      @Autowired private es.kukenan.smartfi.common.service.validation.BeanValidatorService beanValidatorService
      bean Validator Service.
    • ebContractRepository

      @Autowired private EbContractRepository ebContractRepository
      Eb Contract Repository.
  • Constructor Details

    • ProductsService

      public ProductsService()
  • Method Details

    • createProductSearchRequest

      public static ProductSearchRequest createProductSearchRequest(es.kukenan.smartfi.common.security.WalletAuthentication auth, String productId, Product product)
      Request for product search.
      Parameters:
      auth - Authentication bearer with data sesion.
      productId - unique product identifier.
      product - Product dto.
      Returns:
      Product search request.
    • findProducts

      public List<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto> findProducts(String sessionId, String userId, String userToken, String userIp, String contractId, String byType, Boolean withPostedBalance, String byStatus, String bySignature, String byCurrency, String byService)
      Find products service method. Two different cases are considered:
      • 1. The user has no products registered. We perform a full search through all back office.
      • 2. The user, at least, one product. We perform a search in each subsystem of each back office that has, at lease, one product registered.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer
      userIp - user ip.
      contractId - contract identifier.
      byType - types to filter
      withPostedBalance - flag to filter for posted balance
      byStatus - status to filter
      bySignature - signatures to filter
      byCurrency - currency to filter
      byService - service to filter
      Returns:
      product list.
    • findProducts

      public List<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto> findProducts(String sessionId, String userId, String userToken, String userIp, String contractId, String byType, Boolean withPostedBalance, String byStatus, String bySignature, String byCurrency, String byService, boolean internal)
      Find products service method. Two different cases are considered:
      • 1. The user has no products registered. We perform a full search through all back office.
      • 2. The user, at least, one product. We perform a search in each subsystem of each back office that has, at lease, one product registered.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer
      userIp - user ip.
      contractId - contract identifier
      byType - types to filter
      withPostedBalance - flag to filter for posted balance
      byStatus - status to filter
      bySignature - signatures to filter
      byCurrency - currency to filter
      byService - service to filter
      internal - product internal identificator
      Returns:
      product list.
    • findNewProducts

      public HashMap<String,ArrayList<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto>> findNewProducts(String sessionId, String userId, String userToken, String userIp, String contractId, String byType, Boolean withPostedBalance, String byStatus, String bySignature, String byCurrency, String byService, boolean internal)
      Find products service method. Two different cases are considered:
      • 1. The user has no products registered. We perform a full search through all back office.
      • 2. The user, at least, one product. We perform a search in each subsystem of each back office that has, at lease, one product registered.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer
      userIp - user ip.
      contractId - contract identifier
      byType - types to filter
      withPostedBalance - flag to filter for posted balance
      byStatus - status to filter
      bySignature - signatures to filter
      byCurrency - currency to filter
      byService - service to filter
      internal - product internal identificator
      Returns:
      product list.
    • findProductsForced

      public List<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto> findProductsForced(String userId, String userToken, String userIp, String byType, Boolean withPostedBalance, String byStatus, String bySignature, String byCurrency, boolean internal)
      Find products forced service method.
      • Perform a full search through all back office.
      Parameters:
      userId - user identifier.
      userToken - user bearer.
      userIp - user Ip
      byType - types to filter
      withPostedBalance - flag to filter for posted balance
      byStatus - status to filter
      bySignature - signatures to filter
      byCurrency - currency to filter
      internal - product internal identificator
      Returns:
      product list.
    • verifyingUserProduct

      public Product verifyingUserProduct(String userId, String productId)
      verifying user product.
      Parameters:
      userId - user identifier.
      productId - product identifier.
      Returns:
      product details. If the product is not found, an EntityNotFoundException is thrown.
    • findProduct

      @Cacheable(cacheResolver="cacheResolver", key="#sessionId+\'/api/v1/products/\'+#productId") public es.kukenan.smartfi.microservice.contracts.api.products.ProductDto findProduct(String sessionId, String userId, String userToken, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Find a single product details.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      Returns:
      product details. If the product is not found.
    • createProductWallet

      public es.kukenan.smartfi.microservice.contracts.api.products.ProductDto createProductWallet(String sessionId, String userId, String userToken, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Create a single product.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer.
      auth - authentication, required to extract user bank entity.
      Returns:
      product details. If the product is not found.
    • createProductCard

      public es.kukenan.smartfi.microservice.contracts.api.products.ProductDto createProductCard(String sessionId, String userId, String userToken, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Create a single product.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer.
      auth - authentication, required to extract user bank entity.
      Returns:
      product details. If the product is not found.
    • findProductPosition

      @Cacheable(cacheResolver="cacheResolver", key="#sessionId+\'/api/v1/products/\'+#productId+\'/position\'") public es.kukenan.smartfi.microservice.contracts.api.products.ProductDto findProductPosition(String sessionId, String userId, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth, String userToken)
      Find a single product position.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      userToken - userToken.
      Returns:
      product position. If the product is not found.
    • findRepayments

      @Cacheable(cacheResolver="cacheResolver", key="#sessionId+\'/api/v1/products/\'+#productId+\'/repayments\'", unless="#result.getElements().size() == 0") public es.kukenan.smartfi.microservice.contracts.api.repayment.LoanRepaymentsResponseDto findRepayments(String sessionId, String userId, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth, String userToken, String dateFrom, String dateTo)
      Find Repayments.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      userToken - userToken.
      dateFrom - dateFrom.
      dateTo - dateTo.
      Returns:
      product details. If the product is not found.
    • retrieveBackofficeSubsystems

      private List<BackofficeSubsystems> retrieveBackofficeSubsystems(String userId, String contractId, ProductSearchFilter productSearchFilter)
      Get the subsystems that the customer has in their products.
      Parameters:
      userId - userId.
      contractId - contractId.
      productSearchFilter - productSearchFilter.
      Returns:
      list of BackofficeSubsystems.
    • mergeBackofficeSubsystemsLists

      private void mergeBackofficeSubsystemsLists(List<BackofficeSubsystems> originList, List<BackofficeSubsystems> destinationList)
      Merged two list of Subsystems.
      Parameters:
      originList - originList.
      destinationList - destinationList.
    • prepareBackofficeProductSearch

      private List<ProductsService.BackofficeClientProductSearchContext> prepareBackofficeProductSearch(String userId, List<BackofficeSubsystems> backofficeSubsystemsList)
      Prepare backoffice product search context. That is: find all back office clients in the given list or all of them if the list is empty.
      Parameters:
      userId - user identifier.
      backofficeSubsystemsList - known user backoffice subsystems.
      Returns:
      a list of product search context, one for each back office that must be queried.
    • prepareBackofficeProductSearchContextWithAllSubsystem

      private List<ProductsService.BackofficeClientProductSearchContext> prepareBackofficeProductSearchContextWithAllSubsystem(String userId)
      Prepare backoffice product search context with all Subsystems.
      Parameters:
      userId - user identifier.
      Returns:
      a list of product search context, one for each back office that must be queried.
    • findAndSaveBackofficesNewProducts

      private HashMap<String,ArrayList<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto>> findAndSaveBackofficesNewProducts(String userId, List<ProductsService.BackofficeClientProductSearchContext> clientProductSearchContexts, ProductSearchFilter productSearchFilter, boolean internal, String userToken, String userIp, String contractId)
      Find all the products in the given client product search contexts, and store them in the database.
      Parameters:
      userId - user identifier.
      clientProductSearchContexts - a list of clients to query products from with then proper search context.
      productSearchFilter - the criteria to filter the products.
      internal - to show internal products properties.
      userToken - user bearer.
      userIp - user Ip.
      contractId - session identifier.
      Returns:
      all the products found in the given contexts and stored for the given user with.
    • findAndSaveBackofficesProducts

      private List<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto> findAndSaveBackofficesProducts(String userId, List<ProductsService.BackofficeClientProductSearchContext> clientProductSearchContexts, ProductSearchFilter productSearchFilter, boolean internal, String userToken, String userIp, String contractId)
      Find all the products in the given client product search contexts, and store them in the database.
      Parameters:
      userId - user identifier.
      clientProductSearchContexts - a list of clients to query products from with then proper search context.
      productSearchFilter - the criteria to filter the products.
      internal - to show internal products properties.
      userToken - user bearer.
      userIp - user Ip.
      contractId - session identifier.
      Returns:
      all the products found in the given contexts and stored for the given user with.
    • synchronizeUserProducts

      private void synchronizeUserProducts(String userId, List<ProductDomain> newProducts, UserBackoffice userBackoffice, boolean mustUpdateDatabase, String contractId)
      Synchronize the given product list with the previously existing for the given user and back office.
      Parameters:
      userId - user identifier.
      newProducts - actual known user products in the given back office.
      userBackoffice - back office which products are being synchronized.
      mustUpdateDatabase - flag to update BBDD.
      contractId - contract identifier.
    • filterInvalidProducts

      private List<ProductDomain> filterInvalidProducts(List<ProductDomain> products)
      Filtering valid products.
      Parameters:
      products - products domain.
      Returns:
      list valid products
    • findReceipts

      @Cacheable(cacheResolver="cacheResolver",key="#sessionId+\'/api/v1/products/\'+#productId+\'/receipts\'",condition="#paginationKey == null",unless="#result.getData().size() == 0") @Cacheable(cacheResolver="cacheResolver",key="#sessionId+\'/api/v1/products/\'+#productId+\'/receipts?paginationKey=\'+#paginationKey",condition="#paginationKey != null",unless="#result.getData().size() == 0") public es.kukenan.smartfi.microservice.contracts.api.receipt.ReceiptsResponseDto findReceipts(String sessionId, String userId, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth, String paginationKey, String token)
      Find product receipts.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      paginationKey - pagination Key value.
      token - token.
      Returns:
      product receipts.
    • findProductComposition

      @Cacheable(cacheResolver="cacheResolver", key="#sessionId+\'/api/v1/products/\'+#productId+\'/composition\'") public List<es.kukenan.smartfi.microservice.contracts.api.products.ProductDto> findProductComposition(String sessionId, String userId, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth, String userToken)
      Find a single product composition (products managed by the given product).
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      userToken - user bearer token.
      Returns:
      product composition. If the product is not found.
    • generatePinOperationId

      public int generatePinOperationId(String userId, String bankCode, String panToken, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Retrieve pin operation id.
      Parameters:
      userId - user identifier.
      bankCode - entity code.
      panToken - token.
      auth - authentication info.
      Returns:
      pin operation id.
    • generateCvvOperationId

      public int generateCvvOperationId(String userId, String bankCode, String panToken, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Retrieve cvv card.
      Parameters:
      userId - user identifier.
      bankCode - bankCode.
      panToken - panToken.
      auth - auth.
      Returns:
      cvv
    • saveProduct

      public Product saveProduct(String backofficeUserId, Integer backofficeId, String productId, String productType)
      Save new product.
      Parameters:
      backofficeUserId - core user id.
      backofficeId - back identifier.
      productId - product identifier.
      productType - product type.
      Returns:
      new prodyct saved.
    • generateProductSearchByFilter

      private ProductSearchFilter generateProductSearchByFilter(String byType, Boolean withPostedBalance, String byStatus, String bySignature, String byCurrency, String byService)
      Generate product search filter.
      Parameters:
      byType - types to filter
      withPostedBalance - flag to filter for posted balance
      byStatus - status to filter
      bySignature - signatures to filter
      byCurrency - currency to filter
      byService - service to filter
      Returns:
      generic product search filter or specific search filter.
    • findProductWithAssetsTypes

      public es.kukenan.smartfi.microservice.contracts.api.products.ProductDto findProductWithAssetsTypes(String sessionId, String userId, String userToken, String productId, es.kukenan.smartfi.common.security.WalletAuthentication auth)
      Find a single product details with assets types.
      Parameters:
      sessionId - session identifier.
      userId - user identifier.
      userToken - user bearer.
      productId - product identifier.
      auth - authentication, required to extract user bank entity.
      Returns:
      product details. If the product is not found.