Search in sources :

Example 1 with TransferNotification

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"));
        }
    }
}
Also used : TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 2 with TransferNotification

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);
    }
}
Also used : ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 3 with TransferNotification

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);
    }
}
Also used : TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) EmailException(org.apache.commons.mail.EmailException) Date(java.util.Date)

Example 4 with TransferNotification

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);
    }
}
Also used : TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) EmailException(org.apache.commons.mail.EmailException) Date(java.util.Date)

Example 5 with TransferNotification

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);
}
Also used : User(com.eaglegenomics.simlims.core.User) TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) Transfer(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer) NotFoundException(org.springframework.security.acls.model.NotFoundException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

TransferNotification (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification)13 Date (java.util.Date)4 Test (org.junit.Test)3 AbstractHibernateSaveDaoTest (uk.ac.bbsrc.tgac.miso.AbstractHibernateSaveDaoTest)3 Transfer (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer)3 EmailException (org.apache.commons.mail.EmailException)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)2 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)1 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)1 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)1 User (com.eaglegenomics.simlims.core.User)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NotFoundException (org.springframework.security.acls.model.NotFoundException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 Contact (uk.ac.bbsrc.tgac.miso.core.data.impl.Contact)1 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)1 Dtos (uk.ac.bbsrc.tgac.miso.dto.Dtos)1 OrderAliquotDto (uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto)1