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);
}
}
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);
}
}
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;
}
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));
}
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);
}
Aggregations