use of org.apache.airavata.credential.store.store.impl.CredentialReaderImpl 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);
}
}
Aggregations