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 intTEN_DAYS -
Constructor Summary
Constructors Constructor Description SubscriptionServiceImpl(SubscriptionDAO subscriptionDao)Service constructor. -
Method Summary
Modifier and Type Method Description booleanchangeSentNotification(java.lang.String email)This service method changes value sentNotification of Subscription.voidcheckIfSent(java.lang.String customerMail)This method is called only if the client's subscription is expiring and check if the client is already notified.intcheckSubscriptionState(java.lang.String customerMail)This method check the state of a subscription.voidcreateSubscription(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.SubscriptionsearchSubscriptionByEmail(java.lang.String customerMail)This method searches in the database for a customer's subscription, given his email.voidsendEmail(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
-
TEN_DAYS
public static final int TEN_DAYS- See Also:
- Constant Field Values
-
-
Constructor Details
-
SubscriptionServiceImpl
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.IOExceptionThis 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:
createSubscriptionin interfaceSubscriptionService- 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.IOExceptionThis method searches in the database for a customer's subscription, given his email.- Specified by:
searchSubscriptionByEmailin interfaceSubscriptionService- Parameters:
customerMail- customer mail- Returns:
- the Subscription.
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
checkSubscriptionState
public int checkSubscriptionState(java.lang.String customerMail) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionThis method check the state of a subscription.- Specified by:
checkSubscriptionStatein interfaceSubscriptionService- 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.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.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.EmailExceptionThis 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:
checkIfSentin interfaceSubscriptionService- Parameters:
customerMail- the client in session to notify.- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOExceptionorg.apache.commons.mail.EmailException
-
sendEmail
public void sendEmail(java.lang.String customerMail, Subscription subscription) throws org.apache.commons.mail.EmailExceptionSend an email to Client, because his subscription is expiring.- Specified by:
sendEmailin interfaceSubscriptionService- 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.IOExceptionThis service method shows all expiring Subscriptions.- Specified by:
getExpiringSubscriptionsin interfaceSubscriptionService- Returns:
- the list of expiring Subscriptions
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
getExpiredSubscriptions
public java.util.ArrayList<Subscription> getExpiredSubscriptions() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionThis service method shows all expired Subscriptions.- Specified by:
getExpiredSubscriptionsin interfaceSubscriptionService- Returns:
- the list of expired Subscriptions
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
getActiveSubscriptions
public java.util.ArrayList<Subscription> getActiveSubscriptions() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionThis service method shows all active Subscriptions.- Specified by:
getActiveSubscriptionsin interfaceSubscriptionService- Returns:
- the list of active Subscriptions
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
changeSentNotification
public boolean changeSentNotification(java.lang.String email) throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedExceptionDescription copied from interface:SubscriptionServiceThis service method changes value sentNotification of Subscription.- Specified by:
changeSentNotificationin interfaceSubscriptionService- Parameters:
email- of the account- Returns:
- true if the change has taken place, false otherwise.
- Throws:
java.io.IOExceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-