Search in sources :

Example 1 with EmailNotificationMessage

use of org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage in project airavata by apache.

the class NotifierBootstrap method run.

@Override
public void run() {
    if (!enabled)
        return;
    // retrieve OA4MP credentials
    try {
        CredentialReader credentialReader = new CredentialReaderImpl(this.dbUtil);
        List<Credential> credentials = credentialReader.getAllCredentials();
        for (Credential credential : credentials) {
            if (credential instanceof CertificateCredential) {
                CertificateCredential certificateCredential = (CertificateCredential) credential;
                Date date = Utility.convertStringToDate(certificateCredential.getNotAfter());
                // gap is 1 days
                date.setDate(date.getDate() + 1);
                Date currentDate = new Date();
                if (currentDate.after(date)) {
                    // Send an email
                    CommunityUser communityUser = certificateCredential.getCommunityUser();
                    String body = String.format(MESSAGE, communityUser.getUserName(), certificateCredential.getNotAfter());
                    String subject = String.format(SUBJECT, communityUser.getUserName());
                    NotificationMessage notificationMessage = new EmailNotificationMessage(subject, communityUser.getUserEmail(), body);
                    this.credentialStoreNotifier.notifyMessage(notificationMessage);
                }
            }
        }
    } catch (ApplicationSettingsException e) {
        log.error("Error configuring email senders.", e);
    } catch (CredentialStoreException e) {
        log.error("Error sending emails about credential expiring.", e);
    } catch (ParseException e) {
        log.error("Error parsing date time when sending emails", e);
    }
}
Also used : EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)1 Credential (org.apache.airavata.credential.store.credential.Credential)1 CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)1 EmailNotificationMessage (org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage)1 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)1 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)1 CredentialReaderImpl (org.apache.airavata.credential.store.store.impl.CredentialReaderImpl)1