Search in sources :

Example 1 with QcTarget

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget 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 QcTarget

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget 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 3 with QcTarget

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

the class QcController method editBulkFrom.

@PostMapping("/bulk/editFrom/{qcTarget}")
public ModelAndView editBulkFrom(@PathVariable("qcTarget") String qcTargetLabel, @RequestParam Map<String, String> form, ModelMap model) throws IOException {
    QcTarget qcTarget = getQcTarget(qcTargetLabel);
    String entityIds = getStringInput("entityIds", form, true);
    int addControls = getIntegerInput("addControls", form, true);
    return new BulkQcEditTable(qcTarget, qcService, instrumentService, addControls).display(entityIds, model);
}
Also used : QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) BulkQcEditTable(uk.ac.bbsrc.tgac.miso.webapp.util.BulkQcEditTable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with QcTarget

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

the class QcController method addBulk.

@PostMapping("/bulk/addFrom/{qcTarget}")
public ModelAndView addBulk(@PathVariable("qcTarget") String qcTargetLabel, @RequestParam Map<String, String> form, ModelMap model) throws IOException {
    QcTarget qcTarget = getQcTarget(qcTargetLabel);
    String entityIds = getStringInput("entityIds", form, true);
    int copies = getIntegerInput("copies", form, true);
    int controls = getIntegerInput("controls", form, true);
    return new BulkQcAddTable(qcTarget, qcService, instrumentService, copies, controls).display(entityIds, model);
}
Also used : QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) BulkQcAddTable(uk.ac.bbsrc.tgac.miso.webapp.util.BulkQcAddTable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with QcTarget

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

the class HibernateQcTypeDaoIT method testListByNameAndTarget.

@Test
public void testListByNameAndTarget() throws Exception {
    String name = "QuBit";
    QcTarget target = QcTarget.Library;
    List<QcType> qcTypes = dao.listByNameAndTarget(name, target);
    assertNotNull(qcTypes);
    assertEquals(1, qcTypes.size());
    assertEquals(name, qcTypes.get(0).getName());
    assertEquals(target, qcTypes.get(0).getQcTarget());
}
Also used : QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) QcType(uk.ac.bbsrc.tgac.miso.core.data.type.QcType) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Aggregations

QcTarget (uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 QC (uk.ac.bbsrc.tgac.miso.core.data.qc.QC)4 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 Authentication (org.springframework.security.core.Authentication)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)1 ContainerQC (uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC)1 LibraryQC (uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC)1 PoolQC (uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC)1 SampleQC (uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC)1 QcType (uk.ac.bbsrc.tgac.miso.core.data.type.QcType)1