Search in sources :

Example 6 with QcControl

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

the class DefaultQcTypeService method validateChange.

private void validateChange(QcType qcType, QcType beforeChange) throws IOException {
    List<ValidationError> errors = new ArrayList<>();
    if (beforeChange != null) {
        long usage = qcTypeStore.getUsage(beforeChange);
        if (usage > 1L) {
            if (isChanged(QcType::getInstrumentModel, qcType, beforeChange)) {
                errors.add(new ValidationError("instrumentModelId", "Cannot change because there are already QCs of this type"));
            }
            if (!qcType.getKitDescriptors().isEmpty() && beforeChange.getKitDescriptors().isEmpty()) {
                errors.add(new ValidationError("kitDescriptors", "Cannot add kits because there are already QCs of this type"));
            }
            if (!qcType.getControls().isEmpty() && beforeChange.getControls().isEmpty()) {
                errors.add(new ValidationError("controls", "Cannot add controls because there are already QCs of this type"));
            }
        }
        Set<QcControl> toDelete = getControlsToDelete(qcType, beforeChange);
        for (QcControl control : toDelete) {
            long controlUsage = qcTypeStore.getControlUsage(control);
            if (controlUsage > 0L) {
                throw new ValidationException(String.format("Cannot remove control '%s' because it is used in %d %s", control.getAlias(), controlUsage, Pluralizer.qcs(controlUsage)));
            }
        }
        Set<KitDescriptor> kitsToRemove = beforeChange.getKitDescriptors().stream().filter(beforeKit -> qcType.getKitDescriptors().stream().anyMatch(kit -> kit.getId() == beforeKit.getId())).collect(Collectors.toSet());
        for (KitDescriptor kit : kitsToRemove) {
            long kitUsage = qcTypeStore.getKitUsage(qcType, kit);
            if (kitUsage > 0L) {
                errors.add(new ValidationError("kitDescriptors", String.format("Cannot remove kit '%s' because it is used in %d %s", kit.getName(), kitUsage, Pluralizer.qcs(kitUsage))));
            }
        }
    }
    if (!qcType.isArchived()) {
        List<QcType> dupes = qcTypeStore.listByNameAndTarget(qcType.getName(), qcType.getQcTarget());
        if (dupes.stream().anyMatch(dupe -> dupe.getId() != qcType.getId() && !dupe.isArchived())) {
            errors.add(new ValidationError("name", String.format("There is already a non-archived %s QC type with this name", qcType.getQcTarget().getLabel())));
        }
    }
    for (KitDescriptor kit : qcType.getKitDescriptors()) {
        if (kit.getKitType() != KitType.QC) {
            errors.add(new ValidationError("kitDescriptorId", "Must be a QC kit"));
        }
    }
    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
}
Also used : QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) AuthorizationManager(uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager) KitDescriptorService(uk.ac.bbsrc.tgac.miso.core.service.KitDescriptorService) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) KitType(uk.ac.bbsrc.tgac.miso.core.data.type.KitType) Service(org.springframework.stereotype.Service) LimsUtils(uk.ac.bbsrc.tgac.miso.core.util.LimsUtils) Pluralizer(uk.ac.bbsrc.tgac.miso.core.util.Pluralizer) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) KitDescriptor(uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationResult) QcType(uk.ac.bbsrc.tgac.miso.core.data.type.QcType) QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) Set(java.util.Set) DeletionStore(uk.ac.bbsrc.tgac.miso.core.store.DeletionStore) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) QcTypeService(uk.ac.bbsrc.tgac.miso.core.service.QcTypeService) List(java.util.List) InstrumentModelService(uk.ac.bbsrc.tgac.miso.core.service.InstrumentModelService) ValidationUtils(uk.ac.bbsrc.tgac.miso.service.impl.ValidationUtils) QualityControlTypeStore(uk.ac.bbsrc.tgac.miso.persistence.QualityControlTypeStore) Transactional(org.springframework.transaction.annotation.Transactional) KitDescriptor(uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) ArrayList(java.util.ArrayList) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) QcType(uk.ac.bbsrc.tgac.miso.core.data.type.QcType)

Example 7 with QcControl

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

the class Dtos method addQcControlRuns.

private static void addQcControlRuns(@Nonnull Collection<QcControlRunDto> list, QC qc, QcTarget qcTarget) {
    if (list == null) {
        return;
    }
    for (QcControlRunDto from : list) {
        QcControlRun to = null;
        switch(qcTarget) {
            case Container:
                ContainerQcControlRun containerQcControlRun = new ContainerQcControlRun();
                containerQcControlRun.setQc((ContainerQC) qc);
                ((ContainerQC) qc).getControls().add(containerQcControlRun);
                to = containerQcControlRun;
                break;
            case Library:
                LibraryQcControlRun libraryQcControlRun = new LibraryQcControlRun();
                libraryQcControlRun.setQc((LibraryQC) qc);
                ((LibraryQC) qc).getControls().add(libraryQcControlRun);
                to = libraryQcControlRun;
                break;
            case Pool:
                PoolQcControlRun poolQcControlRun = new PoolQcControlRun();
                poolQcControlRun.setQc((PoolQC) qc);
                ((PoolQC) qc).getControls().add(poolQcControlRun);
                to = poolQcControlRun;
                break;
            case Run:
                throw new IllegalArgumentException("Unhandled QC target: Run");
            case Sample:
                SampleQcControlRun sampleQcControlRun = new SampleQcControlRun();
                sampleQcControlRun.setQc((SampleQC) qc);
                ((SampleQC) qc).getControls().add(sampleQcControlRun);
                to = sampleQcControlRun;
                break;
            default:
                throw new IllegalArgumentException("Unhandled QC target: " + qcTarget == null ? "null" : qcTarget.getLabel());
        }
        setLong(to::setId, from.getId(), false);
        setObject(to::setControl, QcControl::new, from.getControlId());
        setString(to::setLot, from.getLot());
        setBoolean(to::setQcPassed, from.getQcPassed(), false);
    }
}
Also used : QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) PoolQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQcControlRun) QcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControlRun) LibraryQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQcControlRun) SampleQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQcControlRun) PoolQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQcControlRun) ContainerQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQcControlRun) SampleQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQcControlRun) LibraryQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQcControlRun) 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) ContainerQcControlRun(uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQcControlRun)

Example 8 with QcControl

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

the class Dtos method to.

private static QcControl to(@Nonnull QcControlDto from) {
    QcControl to = new QcControl();
    setLong(to::setId, from.getId(), false);
    setString(to::setAlias, from.getAlias());
    return to;
}
Also used : QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) 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)

Example 9 with QcControl

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

the class HibernateQcTypeDaoIT method testGetControlUsage.

@Test
public void testGetControlUsage() throws Exception {
    QcControl control = (QcControl) currentSession().get(QcControl.class, 1L);
    assertNotNull(control);
    assertEquals(2L, dao.getControlUsage(control));
}
Also used : QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Example 10 with QcControl

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

the class HibernateQcTypeDaoIT method testDeleteControl.

@Test
public void testDeleteControl() throws Exception {
    QcControl control = (QcControl) currentSession().get(QcControl.class, 3L);
    assertNotNull(control);
    dao.deleteControl(control);
    clearSession();
    QcControl deleted = (QcControl) currentSession().get(QcControl.class, 3L);
    assertNull(deleted);
}
Also used : QcControl(uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Aggregations

QcControl (uk.ac.bbsrc.tgac.miso.core.data.qc.QcControl)10 Test (org.junit.Test)5 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)4 QcType (uk.ac.bbsrc.tgac.miso.core.data.type.QcType)3 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)2 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)2 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)2 HashSet (java.util.HashSet)2 KitDescriptor (uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor)2 QcControlRun (uk.ac.bbsrc.tgac.miso.core.data.qc.QcControlRun)2 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)2 OrderAliquotDto (uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto)2 QcHierarchyNodeDto (uk.ac.bbsrc.tgac.miso.dto.dashi.QcHierarchyNodeDto)2 IlluminaRunDto (uk.ac.bbsrc.tgac.miso.dto.run.IlluminaRunDto)2 IonTorrentRunDto (uk.ac.bbsrc.tgac.miso.dto.run.IonTorrentRunDto)2 Ls454RunDto (uk.ac.bbsrc.tgac.miso.dto.run.Ls454RunDto)2 OxfordNanoporeRunDto (uk.ac.bbsrc.tgac.miso.dto.run.OxfordNanoporeRunDto)2 PacBioRunDto (uk.ac.bbsrc.tgac.miso.dto.run.PacBioRunDto)2 RunDto (uk.ac.bbsrc.tgac.miso.dto.run.RunDto)2 RunPositionDto (uk.ac.bbsrc.tgac.miso.dto.run.RunPositionDto)2