Search in sources :

Example 1 with DataAccessRequestTimeline

use of org.obiba.mica.access.domain.DataAccessRequestTimeline in project mica2 by obiba.

the class DataAccessRequestResource method archive.

@PUT
@Path("/_archive")
public Response archive(@PathParam("id") String id) {
    if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
        throw new AuthorizationException();
    }
    DataAccessRequest request = dataAccessRequestService.findById(id);
    if (DataAccessEntityStatus.APPROVED.equals(request.getStatus())) {
        DataAccessRequestTimeline timeline = reportNotificationService.getReportsTimeline(request);
        if (!timeline.hasEndDate())
            throw new BadRequestException("Cannot archive: no data access request end date is defined");
        if (new Date().before(timeline.getEndDate()))
            throw new BadRequestException("Cannot archive: data access request end date not reached");
        request.setArchived(true);
        dataAccessRequestService.archive(request, true);
    } else {
        throw new BadRequestException("Cannot archive: data access request must have been approved before being archived");
    }
    return Response.noContent().build();
}
Also used : DataAccessRequestTimeline(org.obiba.mica.access.domain.DataAccessRequestTimeline) AuthorizationException(org.apache.shiro.authz.AuthorizationException) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Date(java.util.Date)

Example 2 with DataAccessRequestTimeline

use of org.obiba.mica.access.domain.DataAccessRequestTimeline in project mica2 by obiba.

the class DataAccessRequestReportNotificationService method getReportsTimeline.

/**
 * Get the declared start and end date from the data access request or its amendments. Add intermediate
 * (yearly) milestone dates.
 *
 * @param dar
 * @return
 */
public DataAccessRequestTimeline getReportsTimeline(DataAccessRequest dar) {
    DataAccessRequestTimeline timeline = new DataAccessRequestTimeline();
    timeline.setStartDate(getStartDate(dar));
    timeline.setEndDate(getEndDate(dar));
    // split time interval between start and end date by year steps
    if (timeline.hasStartDate() && timeline.hasEndDate() && timeline.getStartDate().before(timeline.getEndDate())) {
        LocalDate localStartDate = toLocalDate(timeline.getStartDate());
        LocalDate localEndDate = toLocalDate(timeline.getEndDate()).minus(6, ChronoUnit.MONTHS);
        LocalDate localDate = localStartDate.plus(1, ChronoUnit.YEARS);
        while (localDate.isBefore(localEndDate)) {
            timeline.addIntermediateDate(toDate(localDate));
            localDate = localDate.plus(1, ChronoUnit.YEARS);
        }
    }
    return timeline;
}
Also used : DataAccessRequestTimeline(org.obiba.mica.access.domain.DataAccessRequestTimeline) LocalDate(java.time.LocalDate)

Example 3 with DataAccessRequestTimeline

use of org.obiba.mica.access.domain.DataAccessRequestTimeline 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)

Aggregations

DataAccessRequestTimeline (org.obiba.mica.access.domain.DataAccessRequestTimeline)3 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)2 AuthorizationException (org.apache.shiro.authz.AuthorizationException)1 DataAccessConfig (org.obiba.mica.micaConfig.domain.DataAccessConfig)1 Async (org.springframework.scheduling.annotation.Async)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1