Class AbstractDomainEventService

java.lang.Object
es.kukenan.smartfi.microservice.communication.service.messaging.AbstractDomainEventService
Direct Known Subclasses:
FirmEventService, NotificationCreatedEventService, NotificationService, NotificationSettingService, OnboardingDomainEventService, SecurityGatewayEventService, TransferSuccessfulService, UserContractDocumentEventService, UserPasswordResetEventService

public class AbstractDomainEventService extends Object
This abstract class owns the logic that is in common for all domain events processing. It should be extended by any domain event handling service.
  • Field Details

    • CAT_DESTINATION_PREFIX

      public static final String CAT_DESTINATION_PREFIX
      Some notifications configured to be send - as destination - to the CAT may be required in a context that a real user does not exist - at least yet -. This will be the case when we receive an Event with the next prefix in the userId. Due to the database model - that requires the user in the event to exist - if we do not handle this special case message delivering will fail.
      See Also:
    • CAT_USER

      public static final String CAT_USER
      The CAT user identifier prefix. THe company ID must be added as suffix.
      See Also:
    • CAT_LANG

      public static final String CAT_LANG
      The language to use when searching templates for messages destined to CAT virtual user.
      See Also:
    • companyRepository

      @Autowired private CompanyRepository companyRepository
      Spring repository with the methods to access the Company database table.
    • eventRepository

      @Autowired private EventRepository eventRepository
      Spring repository with the methods to access the Event database table.
    • usersRepository

      @Autowired private UsersRepository usersRepository
      Spring repository with the methods to access the User database table.
    • messagesRepository

      @Autowired private MessagesRepository messagesRepository
      Spring repository with the methods to access the Event database table.
    • notificationService

      @Autowired protected NotificationSenderService notificationService
      Common notifications service.
  • Constructor Details

    • AbstractDomainEventService

      public AbstractDomainEventService()
  • Method Details

    • handleGenericNotificationEvent

      protected void handleGenericNotificationEvent(es.kukenan.smartfi.events.common.AbstractEvent event, Map<String,Object> variables)
      Send the messages corresponding to the given onboarding event.
      Parameters:
      event - the event.
      variables - additional variables that the mail template will be able to use. This argument is mandatory and must be modifiable.
    • handleGenericNotificationEvent

      protected void handleGenericNotificationEvent(es.kukenan.smartfi.events.common.AbstractEvent event, Map<String,Object> variables, Boolean ignorePrimaryChannel)
      Send the messages corresponding to the given onboarding event.
      Parameters:
      event - the event.
      variables - additional variables that the mail template will be able to use. This argument is mandatory and must be modifiable.
      ignorePrimaryChannel - indicates if the primary channel should be ignored.
    • toMessageSpecialProperties

      public List<MessagesRequest.MessageSpecialProperties> toMessageSpecialProperties(List<Message> messages, Boolean ignorePrimaryChannel)
      Create a MessageSpecialProperties list from Message list.
      Parameters:
      messages - list
      ignorePrimaryChannel - indicates if the primary channel should be ignored for the message
      Returns:
      MessageSpecialProperties list
    • findMessages

      protected List<Message> findMessages(String eventTypeName, Company company)
      Finds the messages for a given event type id.
      Parameters:
      eventTypeName - the event type identifier.
      company - the company the message must been have designed for.
      Returns:
      the user found. InvalidCallException if the event type is not registered or user is found.
    • findUser

      private User findUser(es.kukenan.smartfi.events.common.AbstractEvent event)
      Finds a user affected by the event.
      Parameters:
      event - the event.
      Returns:
      the user found. UnexpectedException if there is no user information or the user does not exist.
    • createVirtualUserForCatDestination

      protected User createVirtualUserForCatDestination(int companyId)
      Create a user with the information in the event. The ID will be set to match the virtual CAT user so notifications will be able to be stored.
      Parameters:
      companyId - the user company, must be consistent.
      Returns:
      a virtual user.
    • findRealUser

      protected User findRealUser(String userId, int companyId)
      Find a user.
      Parameters:
      userId - the user id, required and the user must exist.
      companyId - the user company, must be consistent.
      Returns:
      the user found. UnexpectedException if the user does not exist or does not belong to the given company.
    • findRealUserFromOnboarding

      protected User findRealUserFromOnboarding(String userId)
      Find a user.
      Parameters:
      userId - the user id, required and the user must exist.
      Returns:
      the user found. UnexpectedException if the user does not exist or does not belong to the given company.
    • eventTypeDescriptor

      protected String eventTypeDescriptor(es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Get the full event descriptor used to search the related messages.
      Parameters:
      event - the domain event.
      Returns:
      the full event type descriptor.