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();
}
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;
}
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());
}
}
}
Aggregations