use of uk.ac.bbsrc.tgac.miso.core.service.BulkQcSaveOperation in project miso-lims by miso-lims.
the class DefaultQualityControlService method startBulkOperation.
private BulkQcSaveOperation startBulkOperation(List<QC> items, ThrowingFunction<QC, QC, IOException> action) throws IOException {
QcTarget qcTarget = qcTypeService.get(items.get(0).getType().getId()).getQcTarget();
BulkQcSaveOperation operation = new BulkQcSaveOperation(qcTarget, items, authorizationManager.getCurrentUser());
// Authentication is tied to the thread, so use this same auth in the new thread
Authentication auth = SecurityContextHolder.getContextHolderStrategy().getContext().getAuthentication();
Thread thread = new Thread(() -> {
SecurityContextHolder.getContextHolderStrategy().getContext().setAuthentication(auth);
try {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
while (operation.hasMore()) {
try {
QC item = operation.getNextItem();
QC saved = action.apply(item);
operation.addSuccess(saved.getId());
} catch (ValidationException e) {
operation.addFailure(e);
status.setRollbackOnly();
} catch (Exception e) {
operation.setFailed(e);
status.setRollbackOnly();
}
}
}
});
} catch (Exception e) {
// Exception during transaction commit
operation.setFailed(e);
}
if (operation.isFailed()) {
Exception exception = operation.getException();
if (!(exception instanceof BulkValidationException)) {
LoggerFactory.getLogger(DefaultQualityControlService.class).error("Bulk save failed", exception);
}
}
operation.setComplete();
});
thread.start();
return operation;
}
Aggregations