Search in sources :

Example 6 with DataAccessConfig

use of org.obiba.mica.micaConfig.domain.DataAccessConfig in project mica2 by obiba.

the class DataAccessRequestReportNotificationService method remindDataAccessReports.

@Async
@Scheduled(cron = "${dar.reminder.cron:0 0 0 * * ?}")
public void remindDataAccessReports() {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (!dataAccessConfig.isNotifyFinalReport() && !dataAccessConfig.isNotifyIntermediateReport())
        return;
    int nbOfDaysBeforeReport = dataAccessConfig.getNbOfDaysBeforeReport();
    if (nbOfDaysBeforeReport < 0)
        return;
    LocalDate dateNow = LocalDate.now().minusDays(nbOfDaysBeforeReport);
    for (DataAccessRequest dar : dataAccessRequestService.findByStatus(Lists.newArrayList(DataAccessEntityStatus.APPROVED.name()))) {
        DataAccessRequestTimeline timeline = getReportsTimeline(dar);
        if (timeline.hasEndDate()) {
            LocalDate localEndDate = toLocalDate(timeline.getEndDate());
            if (dataAccessConfig.isNotifyFinalReport() && dateNow.plusDays(nbOfDaysBeforeReport).equals(localEndDate)) {
                // today is the day to notify final report
                remindDataAccessFinalReport(dataAccessConfig, dar, timeline.getEndDate(), nbOfDaysBeforeReport);
            } else if (dataAccessConfig.isNotifyIntermediateReport() && timeline.hasIntermediateDates()) {
                for (Date interDate : timeline.getIntermediateDates()) {
                    if (dateNow.plusDays(nbOfDaysBeforeReport).equals(toLocalDate(interDate))) {
                        remindDataAccessIntermediateReport(dataAccessConfig, dar, interDate, nbOfDaysBeforeReport);
                        break;
                    }
                }
            }
        } else {
            log.warn("No end date found for data access request {}", dar.getId());
        }
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig) DataAccessRequestTimeline(org.obiba.mica.access.domain.DataAccessRequestTimeline) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Scheduled(org.springframework.scheduling.annotation.Scheduled) Async(org.springframework.scheduling.annotation.Async)

Example 7 with DataAccessConfig

use of org.obiba.mica.micaConfig.domain.DataAccessConfig in project mica2 by obiba.

the class DataAccessEntityService method sendConditionallyApprovedEmail.

protected void sendConditionallyApprovedEmail(T request) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (dataAccessConfig.isNotifyConditionallyApproved()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        String prefix = getTemplatePrefix(ctx);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getConditionallyApprovedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), prefix + "ConditionallyApprovedApplicantEmail", ctx, request.getApplicant());
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Example 8 with DataAccessConfig

use of org.obiba.mica.micaConfig.domain.DataAccessConfig in project mica2 by obiba.

the class DataAccessEntityService method sendReviewedNotificationEmail.

protected void sendReviewedNotificationEmail(T request) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (dataAccessConfig.isNotifyReviewed() && dataAccessConfig.isWithReview()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        String prefix = getTemplatePrefix(ctx);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getReviewedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), prefix + "ReviewedApplicantEmail", ctx, request.getApplicant());
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Example 9 with DataAccessConfig

use of org.obiba.mica.micaConfig.domain.DataAccessConfig in project mica2 by obiba.

the class DataAccessEntityService method sendRejectedNotificationEmail.

protected void sendRejectedNotificationEmail(T request) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (dataAccessConfig.isNotifyRejected()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        String prefix = getTemplatePrefix(ctx);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getRejectedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), prefix + "RejectedApplicantEmail", ctx, request.getApplicant());
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Example 10 with DataAccessConfig

use of org.obiba.mica.micaConfig.domain.DataAccessConfig in project mica2 by obiba.

the class DataAccessEntityService method sendApprovedNotificationEmail.

protected void sendApprovedNotificationEmail(T request) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (dataAccessConfig.isNotifyApproved()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        String prefix = getTemplatePrefix(ctx);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getApprovedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), prefix + "ApprovedApplicantEmail", ctx, request.getApplicant());
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Aggregations

DataAccessConfig (org.obiba.mica.micaConfig.domain.DataAccessConfig)15 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)3 List (java.util.List)2 Timed (com.codahale.metrics.annotation.Timed)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 Map (java.util.Map)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 DateTime (org.joda.time.DateTime)1 DataAccessRequestGenerationException (org.obiba.mica.access.DataAccessRequestGenerationException)1 DataAccessRequestTimeline (org.obiba.mica.access.domain.DataAccessRequestTimeline)1 IdentifierGenerator (org.obiba.mica.core.support.IdentifierGenerator)1 DataAccessConfigUpdatedEvent (org.obiba.mica.micaConfig.event.DataAccessConfigUpdatedEvent)1 SubjectAcl (org.obiba.mica.security.domain.SubjectAcl)1 Async (org.springframework.scheduling.annotation.Async)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1