Class SubscriptionServiceImpl

java.lang.Object
it.unisa.c03.myPersonalTrainer.subscription.service.SubscriptionServiceImpl
All Implemented Interfaces:
SubscriptionService

public class SubscriptionServiceImpl
extends java.lang.Object
implements SubscriptionService
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int TEN_DAYS  
  • Constructor Summary

    Constructors
    Constructor Description
    SubscriptionServiceImpl​(SubscriptionDAO subscriptionDao)
    Service constructor.
  • Method Summary

    Modifier and Type Method Description
    boolean changeSentNotification​(java.lang.String email)
    This service method changes value sentNotification of Subscription.
    void checkIfSent​(java.lang.String customerMail)
    This method is called only if the client's subscription is expiring and check if the client is already notified.
    int checkSubscriptionState​(java.lang.String customerMail)
    This method check the state of a subscription.
    void createSubscription​(java.lang.String customerMail)
    This service method register the subscription for a customer.
    java.util.ArrayList<Subscription> getActiveSubscriptions()
    This service method shows all active Subscriptions.
    java.util.ArrayList<Subscription> getExpiredSubscriptions()
    This service method shows all expired Subscriptions.
    java.util.ArrayList<Subscription> getExpiringSubscriptions()
    This service method shows all expiring Subscriptions.
    Subscription searchSubscriptionByEmail​(java.lang.String customerMail)
    This method searches in the database for a customer's subscription, given his email.
    void sendEmail​(java.lang.String customerMail, Subscription subscription)
    Send an email to Client, because his subscription is expiring.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • SubscriptionServiceImpl

      public SubscriptionServiceImpl​(SubscriptionDAO subscriptionDao)
      Service constructor.
      Parameters:
      subscriptionDao - is required, because is the DAO that all the service methods will call.
  • Method Details

    • createSubscription

      public void createSubscription​(java.lang.String customerMail) throws java.io.IOException
      This service method register the subscription for a customer. It only needs the customer email. Then it sets a standard price and the expiration date, obtained by adding an extra month to the registration date.
      Specified by:
      createSubscription in interface SubscriptionService
      Parameters:
      customerMail - the customer mail
      Throws:
      java.io.IOException
    • searchSubscriptionByEmail

      public Subscription searchSubscriptionByEmail​(java.lang.String customerMail) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This method searches in the database for a customer's subscription, given his email.
      Specified by:
      searchSubscriptionByEmail in interface SubscriptionService
      Parameters:
      customerMail - customer mail
      Returns:
      the Subscription.
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • checkSubscriptionState

      public int checkSubscriptionState​(java.lang.String customerMail) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This method check the state of a subscription.
      Specified by:
      checkSubscriptionState in interface SubscriptionService
      Parameters:
      customerMail - the mail of the subscription owner
      Returns:
      1 if the subscription is valid, 0 if subscription expiring, -1 for expired subscription.
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • checkIfSent

      public void checkIfSent​(java.lang.String customerMail) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException, org.apache.commons.mail.EmailException
      This method is called only if the client's subscription is expiring and check if the client is already notified. if it has not been sent, this method send an email to the customer that his subscription is expiring
      Specified by:
      checkIfSent in interface SubscriptionService
      Parameters:
      customerMail - the client in session to notify.
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
      org.apache.commons.mail.EmailException
    • sendEmail

      public void sendEmail​(java.lang.String customerMail, Subscription subscription) throws org.apache.commons.mail.EmailException
      Send an email to Client, because his subscription is expiring.
      Specified by:
      sendEmail in interface SubscriptionService
      Parameters:
      customerMail - Account of user to send email.
      subscription - Account subscription.
      Throws:
      org.apache.commons.mail.EmailException
    • getExpiringSubscriptions

      public java.util.ArrayList<Subscription> getExpiringSubscriptions() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This service method shows all expiring Subscriptions.
      Specified by:
      getExpiringSubscriptions in interface SubscriptionService
      Returns:
      the list of expiring Subscriptions
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • getExpiredSubscriptions

      public java.util.ArrayList<Subscription> getExpiredSubscriptions() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This service method shows all expired Subscriptions.
      Specified by:
      getExpiredSubscriptions in interface SubscriptionService
      Returns:
      the list of expired Subscriptions
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • getActiveSubscriptions

      public java.util.ArrayList<Subscription> getActiveSubscriptions() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This service method shows all active Subscriptions.
      Specified by:
      getActiveSubscriptions in interface SubscriptionService
      Returns:
      the list of active Subscriptions
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • changeSentNotification

      public boolean changeSentNotification​(java.lang.String email) throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
      Description copied from interface: SubscriptionService
      This service method changes value sentNotification of Subscription.
      Specified by:
      changeSentNotification in interface SubscriptionService
      Parameters:
      email - of the account
      Returns:
      true if the change has taken place, false otherwise.
      Throws:
      java.io.IOException
      java.util.concurrent.ExecutionException
      java.lang.InterruptedException