use of uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification in project miso-lims by miso-lims.
the class DefaultTransferNotificationService method collectValidationErrors.
@Override
protected void collectValidationErrors(TransferNotification object, TransferNotification beforeChange, List<ValidationError> errors) throws IOException {
if (beforeChange == null) {
List<TransferNotification> others = transferNotificationStore.listByTransfer(object.getTransfer());
TransferNotification other = others.stream().filter(x -> x.getRecipientEmail().equals(object.getRecipientEmail()) && x.getSendSuccess() == null).findFirst().orElse(null);
if (other != null) {
errors.add(new ValidationError("recipientEmail", "A notification is already being sent to this address"));
}
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification in project miso-lims by miso-lims.
the class DefaultTransferNotificationService method bulkDelete.
@Override
public void bulkDelete(Collection<TransferNotification> notifications, boolean force) throws IOException {
for (TransferNotification notification : notifications) {
TransferNotification managed = transferNotificationStore.get(notification.getId());
authorizationManager.throwIfNonAdminOrMatchingOwner(managed.getCreator());
if (!force && managed.getSentTime() != null) {
throw new ValidationException(new ValidationError("Cannot delete a notification after it has already been sent"));
}
transferNotificationStore.delete(managed);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification in project miso-lims by miso-lims.
the class NotificationManager method sendPendingFailureNotifications.
private void sendPendingFailureNotifications() throws IOException {
List<TransferNotification> pendingFailures = transferNotificationService.listFailurePending(getCurrentAllowance());
for (TransferNotification pending : pendingFailures) {
pending.setFailureSentTime(new Date());
try {
sendFailedNotification(pending);
} catch (EmailException e) {
log.warn("Failed to send notification failure email", e);
smtpFailed.inc();
}
transferNotificationService.update(pending);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification in project miso-lims by miso-lims.
the class NotificationManager method sendPendingTransferNotifications.
private void sendPendingTransferNotifications() throws IOException {
List<TransferNotification> pendingNotifications = transferNotificationService.listPending(smtpHoldMinutes, getCurrentAllowance());
for (TransferNotification pending : pendingNotifications) {
pending.setSentTime(new Date());
try {
sendTransferNotification(pending);
pending.setSendSuccess(true);
} catch (EmailException e) {
log.warn("Failed to send email", e);
smtpFailed.inc();
pending.setSendSuccess(false);
}
transferNotificationService.update(pending);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification in project miso-lims by miso-lims.
the class TransferController method edit.
@GetMapping("/{id}")
public ModelAndView edit(@PathVariable long id, ModelMap model) throws IOException, EmailException {
Transfer transfer = transferService.get(id);
if (transfer == null) {
throw new NotFoundException("No transfer found for ID: " + id);
}
model.put("title", "Transfer " + id);
User user = authorizationManager.getCurrentUser();
// allow editing receipt if user is admin or recipient
boolean editReceipt = user.isAdmin() || (transfer.getRecipientGroup() != null && userHasGroup(user, transfer.getRecipientGroup()));
// allow editing send if user is admin, sender, or recipient of external -> internal transfer
boolean editSend = user.isAdmin() || (transfer.getSenderGroup() != null && userHasGroup(user, transfer.getSenderGroup())) || (editReceipt && transfer.getSenderGroup() == null);
List<TransferNotification> notifications = transferNotificationService.listByTransferId(id);
ObjectMapper mapper = new ObjectMapper();
model.put("notifications", mapper.writeValueAsString(notifications.stream().map(Dtos::asDto).collect(Collectors.toList())));
return setupForm(transfer, PageMode.EDIT, editSend, editReceipt, model);
}
Aggregations