Search in sources :

Example 1 with QC

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QC 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;
}
Also used : ContainerQC(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC) LibraryQC(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC) QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) SampleQC(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC) PoolQC(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) BulkValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.BulkValidationException) Authentication(org.springframework.security.core.Authentication) QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) TransactionStatus(org.springframework.transaction.TransactionStatus) BulkValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.BulkValidationException) BulkQcSaveOperation(uk.ac.bbsrc.tgac.miso.core.service.BulkQcSaveOperation) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) BulkValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.BulkValidationException) IOException(java.io.IOException)

Example 2 with QC

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QC in project miso-lims by miso-lims.

the class Dtos method to.

public static QC to(@Nonnull QcDto dto) {
    QC to;
    switch(dto.getQcTarget()) {
        case "Library":
            LibraryQC newLibraryQc = new LibraryQC();
            Library ownerLibrary = new LibraryImpl();
            ownerLibrary.setId(dto.getEntityId());
            newLibraryQc.setLibrary(ownerLibrary);
            to = newLibraryQc;
            break;
        case "Sample":
            SampleQC newSampleQc = new SampleQC();
            Sample ownerSample = new SampleImpl();
            ownerSample.setId(dto.getEntityId());
            newSampleQc.setSample(ownerSample);
            to = newSampleQc;
            break;
        case "Pool":
            PoolQC newPoolQc = new PoolQC();
            Pool ownerPool = new PoolImpl();
            ownerPool.setId(dto.getEntityId());
            newPoolQc.setPool(ownerPool);
            to = newPoolQc;
            break;
        case "Container":
            ContainerQC newContainerQc = new ContainerQC();
            SequencerPartitionContainer ownerContainer = new SequencerPartitionContainerImpl();
            ownerContainer.setId(dto.getEntityId());
            newContainerQc.setContainer(ownerContainer);
            to = newContainerQc;
            break;
        case "Requisition":
            RequisitionQC newRequisitionQc = new RequisitionQC();
            Requisition ownerRequisition = new Requisition();
            ownerRequisition.setId(dto.getEntityId());
            newRequisitionQc.setRequisition(ownerRequisition);
            to = newRequisitionQc;
            break;
        default:
            throw new IllegalArgumentException("No such QC target: " + dto.getQcTarget());
    }
    if (dto.getId() != null) {
        to.setId(dto.getId());
    }
    to.setDate(parseDate(dto.getDate()));
    setBigDecimal(to::setResults, dto.getResults());
    setObject(to::setType, QcType::new, dto.getQcTypeId());
    to.setDescription(dto.getDescription());
    setObject(to::setInstrument, InstrumentImpl::new, dto.getInstrumentId());
    setObject(to::setKit, KitDescriptor::new, dto.getKitDescriptorId());
    setString(to::setKitLot, dto.getKitLot());
    addQcControlRuns(dto.getControls(), to, QcTarget.valueOf(dto.getQcTarget()));
    return to;
}
Also used : SequencerPartitionContainer(uk.ac.bbsrc.tgac.miso.core.data.SequencerPartitionContainer) InstrumentImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.InstrumentImpl) ParentSample(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentSample) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) WorksetSample(uk.ac.bbsrc.tgac.miso.core.data.impl.workset.WorksetSample) GrandparentSample(uk.ac.bbsrc.tgac.miso.core.data.impl.view.GrandparentSample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) SampleQC(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC) RequisitionQC(uk.ac.bbsrc.tgac.miso.core.data.qc.RequisitionQC) LibraryQC(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC) PoolImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolImpl) LibraryQC(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC) PoolQC(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC) QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) SampleQC(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC) ContainerQC(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC) RequisitionQC(uk.ac.bbsrc.tgac.miso.core.data.qc.RequisitionQC) KitDescriptor(uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor) LibraryImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryImpl) DetailedLibraryImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedLibraryImpl) SequencerPartitionContainerImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SequencerPartitionContainerImpl) TransferPool(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferPool) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) InstrumentStatusPositionRunPool(uk.ac.bbsrc.tgac.miso.core.data.impl.view.instrumentstatus.InstrumentStatusPositionRunPool) ContainerQC(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC) TransferLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary) ParentLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentLibrary) DetailedLibrary(uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary) WorksetLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.workset.WorksetLibrary) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) IonTorrentRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IonTorrentRunDto) QcHierarchyNodeDto(uk.ac.bbsrc.tgac.miso.dto.dashi.QcHierarchyNodeDto) RunPositionDto(uk.ac.bbsrc.tgac.miso.dto.run.RunPositionDto) PacBioRunDto(uk.ac.bbsrc.tgac.miso.dto.run.PacBioRunDto) Ls454RunDto(uk.ac.bbsrc.tgac.miso.dto.run.Ls454RunDto) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) OxfordNanoporeRunDto(uk.ac.bbsrc.tgac.miso.dto.run.OxfordNanoporeRunDto) IlluminaRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IlluminaRunDto) NotificationDto(ca.on.oicr.gsi.runscanner.dto.NotificationDto) OxfordNanoporeNotificationDto(ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) SolidRunDto(uk.ac.bbsrc.tgac.miso.dto.run.SolidRunDto) OrderAliquotDto(uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto) PoolQC(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC) Requisition(uk.ac.bbsrc.tgac.miso.core.data.impl.Requisition) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) DetailedSampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedSampleImpl) QcType(uk.ac.bbsrc.tgac.miso.core.data.type.QcType)

Example 3 with QC

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QC in project miso-lims by miso-lims.

the class AsyncOperationManager method startAsyncBulkQcUpdate.

public <T, R extends Identifiable> ObjectNode startAsyncBulkQcUpdate(List<QcDto> dtos) throws IOException {
    final QcTarget qcTarget = getQcTarget(dtos.get(0).getQcTarget());
    List<QC> items = validateBulkUpdate("QC", dtos, Dtos::to, id -> qualityControlService.get(qcTarget, id));
    BulkSaveOperation<QC> operation = qualityControlService.startBulkUpdate(items);
    String uuid = addAsyncOperation(operation);
    return makeRunningProgress(uuid, operation);
}
Also used : QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget)

Example 4 with QC

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QC in project miso-lims by miso-lims.

the class DefaultQualityControlService method saveControlRuns.

private void saveControlRuns(long savedId, QC from, QcTargetStore handler) throws IOException {
    QC to = get(from.getEntity().getQcTarget(), from.getId());
    List<QcControlRun> toDelete = new ArrayList<>();
    for (QcControlRun toControl : to.getControls()) {
        if (!toControl.isSaved()) {
            // newly created QC
            continue;
        }
        QcControlRun fromControl = from.getControls().stream().filter(fc -> fc.getId() == toControl.getId()).findFirst().orElse(null);
        if (fromControl == null) {
            toDelete.add(toControl);
        } else {
            toControl.setControl(fromControl.getControl());
            toControl.setLot(fromControl.getLot());
            toControl.setQcPassed(fromControl.isQcPassed());
            handler.updateControlRun(toControl);
        }
    }
    for (QcControlRun control : toDelete) {
        handler.deleteControlRun(control);
    }
    for (QcControlRun fromControl : from.getControls()) {
        if (!fromControl.isSaved()) {
            switch(to.getType().getQcTarget()) {
                case Container:
                    ((ContainerQcControlRun) fromControl).setQc((ContainerQC) to);
                    break;
                case Library:
                    ((LibraryQcControlRun) fromControl).setQc((LibraryQC) to);
                    break;
                case Pool:
                    ((PoolQcControlRun) fromControl).setQc((PoolQC) to);
                    break;
                case Sample:
                    ((SampleQcControlRun) fromControl).setQc((SampleQC) to);
                    break;
                default:
                    throw new IllegalArgumentException("Unhandled QC target: " + to.getType().getQcTarget());
            }
            handler.createControlRun(fromControl);
        }
    }
}
Also used : ContainerQC(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC) LibraryQC(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC) QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) SampleQC(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC) PoolQC(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC) PoolQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQcControlRun) SampleQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQcControlRun) QcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControlRun) PoolQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQcControlRun) LibraryQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQcControlRun) ContainerQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQcControlRun) SampleQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQcControlRun) ArrayList(java.util.ArrayList) LibraryQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQcControlRun) ContainerQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQcControlRun)

Example 5 with QC

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QC in project miso-lims by miso-lims.

the class DefaultQualityControlService method update.

@Override
public QC update(QC qc) throws IOException {
    loadChildEntities(qc);
    QcTargetStore handler = getHandler(qc.getType().getQcTarget());
    QualityControlEntity entity = handler.getEntity(qc.getEntity().getId());
    User user = authorizationManager.getCurrentUser();
    QC managed = handler.get(qc.getId());
    if (managed.getType().getId() != qc.getType().getId()) {
        throw new IllegalArgumentException("QC type has changed");
    }
    validateChange(qc, managed);
    applyChanges(managed, qc);
    entity.setChangeDetails(user);
    changeLoggableStore.update(entity);
    handler.save(managed);
    saveControlRuns(managed.getId(), qc, handler);
    return managed;
}
Also used : ContainerQC(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC) LibraryQC(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC) QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) SampleQC(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC) PoolQC(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC) User(com.eaglegenomics.simlims.core.User) QualityControlEntity(uk.ac.bbsrc.tgac.miso.core.data.qc.QualityControlEntity) QcTargetStore(uk.ac.bbsrc.tgac.miso.persistence.QcTargetStore)

Aggregations

QC (uk.ac.bbsrc.tgac.miso.core.data.qc.QC)8 ContainerQC (uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC)4 LibraryQC (uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC)4 PoolQC (uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC)4 QcTarget (uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget)4 SampleQC (uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)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 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Stream (java.util.stream.Stream)1 Authentication (org.springframework.security.core.Authentication)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1