Search in sources :

Example 1 with Email

use of org.hisp.dhis.email.Email in project dhis2-core by dhis2.

the class MetadataSyncPostProcessor method sendSuccessMailToAdmin.

public void sendSuccessMailToAdmin(MetadataSyncSummary metadataSyncSummary) {
    ImportReport importReport = metadataSyncSummary.getImportReport();
    StringBuilder text = new StringBuilder("Successful Import Report for the scheduler run for Metadata synchronization \n\n").append("Imported Version Details \n ").append("Version Name: " + metadataSyncSummary.getMetadataVersion().getName() + "\n").append("Version Type: " + metadataSyncSummary.getMetadataVersion().getType() + "\n");
    Map<Class<?>, TypeReport> typeReportMap = importReport.getTypeReportMap();
    if (typeReportMap != null && typeReportMap.entrySet().size() == 0) {
        text.append("New Version created. It does not have any metadata changes. \n");
    } else if (typeReportMap != null) {
        text.append("Imported Object Details: \n");
        for (Map.Entry<Class<?>, TypeReport> typeReportEntry : typeReportMap.entrySet()) {
            if (typeReportEntry != null) {
                Class<?> key = typeReportEntry.getKey();
                TypeReport value = typeReportEntry.getValue();
                Stats stats = value.getStats();
                text.append("Metadata Object Type: ").append(key).append("\n").append("Stats: \n").append("total: " + stats.getTotal() + "\n");
                if (stats.getCreated() > 0) {
                    text.append(" created: " + stats.getCreated() + "\n");
                }
                if (stats.getUpdated() > 0) {
                    text.append(" updated: " + stats.getUpdated() + "\n");
                }
                if (stats.getIgnored() > 0) {
                    text.append(" ignored: " + stats.getIgnored() + "\n");
                }
            }
        }
        text.append("\n\n");
    }
    if (text.length() > 0) {
        log.info("Success mail will be sent with the following message: " + text);
        emailService.sendSystemEmail(new Email("Success Notification: Metadata Synchronization", text.toString()));
    }
}
Also used : Email(org.hisp.dhis.email.Email) TypeReport(org.hisp.dhis.feedback.TypeReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Stats(org.hisp.dhis.feedback.Stats)

Example 2 with Email

use of org.hisp.dhis.email.Email in project dhis2-core by dhis2.

the class MetadataSyncPostProcessor method sendFailureMailToAdmin.

public void sendFailureMailToAdmin(MetadataRetryContext retryContext) {
    StringBuilder text = new StringBuilder("Following Exceptions were encountered while the scheduler run for metadata sync \n\n");
    for (String name : MetadataSyncTask.keys) {
        Object value = retryContext.getRetryContext().getAttribute(name);
        if (value != null) {
            text.append("ERROR_CATEGORY ").append(": ").append(name).append("\n ERROR_VALUE : ").append(value).append("\n\n");
        }
    }
    Object report = retryContext.getRetryContext().getAttribute(MetadataSyncTask.METADATA_SYNC_REPORT);
    if (report != null) {
        String reportString = (String) report;
        text.append(MetadataSyncTask.METADATA_SYNC_REPORT).append("\n ").append(reportString);
    } else {
        if (retryContext.getRetryContext().getLastThrowable() != null) {
            text.append(retryContext.getRetryContext().getLastThrowable().getMessage());
        }
    }
    if (text.length() > 0) {
        log.info("Failure mail will be sent with the following message: " + text);
        emailService.sendSystemEmail(new Email("Action Required: MetadataSync Failed Notification", text.toString()));
    }
}
Also used : Email(org.hisp.dhis.email.Email)

Example 3 with Email

use of org.hisp.dhis.email.Email in project dhis2-core by dhis2.

the class DefaultMessageService method sendSystemMessage.

@Override
public int sendSystemMessage(String subject, String text) {
    UserGroup userGroup = configurationService.getConfiguration().getFeedbackRecipients();
    Set<User> users = Sets.newHashSet();
    if (userGroup != null && userGroup.getMembers().size() > 0) {
        users.addAll(userGroup.getMembers());
    }
    emailService.sendSystemEmail(new Email(subject, text));
    return sendMessage(subject, text, null, users, null, MessageType.SYSTEM, false);
}
Also used : Email(org.hisp.dhis.email.Email)

Aggregations

Email (org.hisp.dhis.email.Email)3 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)1 Stats (org.hisp.dhis.feedback.Stats)1 TypeReport (org.hisp.dhis.feedback.TypeReport)1