use of uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition in project miso-lims by miso-lims.
the class DefaultQcStatusService method findPartitionInRun.
private Partition findPartitionInRun(Run run, long partitionId) {
Partition partition = run.getRunPositions().stream().map(RunPosition::getContainer).flatMap(x -> x.getPartitions().stream()).filter(x -> x.getId() == partitionId).findFirst().orElse(null);
throwIfNull("Partition", partition);
return partition;
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition in project miso-lims by miso-lims.
the class DefaultRunService method validateChanges.
private void validateChanges(Run before, Run changed) throws IOException {
ValidationUtils.updateQcDetails(changed, before, Run::getQcPassed, Run::getQcUser, Run::setQcUser, authorizationManager, Run::getQcDate, Run::setQcDate);
if (isChanged(Run::getQcPassed, changed, before)) {
changed.setDataReview(null);
}
ValidationUtils.updateQcDetails(changed, before, Run::getDataReview, Run::getDataReviewer, Run::setDataReviewer, authorizationManager, Run::getDataReviewDate, Run::setDataReviewDate);
List<ValidationError> errors = new ArrayList<>();
if (!changed.getHealth().isDone()) {
changed.setCompletionDate(null);
} else if (changed.getCompletionDate() == null) {
errors.add(new ValidationError("completionDate", "Completion date must be provided for finished run"));
}
if (before != null) {
if (before.getCompletionDate() != null && changed.getCompletionDate() != null && !changed.getCompletionDate().equals(before.getCompletionDate()) && !authorizationManager.isAdminUser()) {
errors.add(new ValidationError("completionDate", "Only admin may change completion date"));
}
if (before.getStartDate() != null && changed.getStartDate() != null && !changed.getStartDate().equals(before.getStartDate()) && !authorizationManager.isAdminUser()) {
errors.add(new ValidationError("completionDate", "Only admin may change start date"));
}
}
if (isSetAndChanged(Run::getAlias, changed, before) && getRunByAlias(changed.getAlias()) != null) {
errors.add(new ValidationError("alias", "A different run with this alias already exists. Run alias must be unique."));
}
InstrumentModel platform = changed.getSequencer().getInstrumentModel();
for (RunPosition position : changed.getRunPositions()) {
if (position.getPosition() != null && !platform.getPositions().contains(position.getPosition())) {
errors.add(new ValidationError(String.format("Platform %s does not have a position %s", platform.getAlias(), position.getPosition())));
}
}
if (changed.getSequencingKit() != null && changed.getSequencingKit().getKitType() != KitType.SEQUENCING) {
errors.add(new ValidationError("sequencingKitId", "Must be a sequencing kit"));
}
if (changed.getSequencingKitLot() != null && changed.getSequencingKit() == null) {
errors.add(new ValidationError("sequencingKitLot", "Sequencing kit not specified"));
}
if (isSetAndChanged(Run::getDataReview, changed, before) && changed.getQcPassed() == null) {
errors.add(new ValidationError("dataReview", "Cannot set data review before QC status"));
}
ValidationUtils.validateQcUser(changed.getQcPassed(), changed.getQcUser(), errors);
ValidationUtils.validateQcUser(changed.getDataReview(), changed.getDataReviewer(), errors, "data review", "Data reviewer");
User user = authorizationManager.getCurrentUser();
if (((before == null && changed.getDataReview() != null) || (before != null && isChanged(Run::getDataReview, changed, before))) && !user.isRunReviewer() && !user.isAdmin()) {
errors.add(new ValidationError("dataReview", "You are not authorized to make this change"));
}
if (changed.getSequencerPartitionContainers() != null) {
if (changed.getSequencerPartitionContainers().size() > changed.getSequencer().getInstrumentModel().getNumContainers()) {
errors.add(new ValidationError(String.format("Cannot have more than %d containers", changed.getSequencer().getInstrumentModel().getNumContainers())));
}
for (SequencerPartitionContainer container : changed.getSequencerPartitionContainers()) {
if (changed.getSequencer().getInstrumentModel().getContainerModels().stream().noneMatch(model -> model.getId() == container.getModel().getId())) {
errors.add(new ValidationError(String.format("Container '%s' is not valid for instrument '%s'", container.getIdentificationBarcode(), changed.getSequencer().getInstrumentModel().getAlias())));
}
}
}
if (!errors.isEmpty()) {
throw new ValidationException(errors);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition in project miso-lims by miso-lims.
the class DefaultRunService method updateContainerFromNotification.
private boolean updateContainerFromNotification(final Run target, User user, SequencingContainerModel containerModel, String containerSerialNumber, final GetLaneContents getLaneContents, String positionName) throws IOException {
if (LimsUtils.isStringBlankOrNull(containerSerialNumber)) {
return false;
}
final Collection<SequencerPartitionContainer> containers = containerService.listByBarcode(containerSerialNumber);
int laneCount = containerModel.getPartitionCount();
InstrumentPosition position = null;
if (!isStringEmptyOrNull(positionName)) {
position = target.getSequencer().getInstrumentModel().getPositions().stream().filter(pos -> positionName.equals(pos.getAlias())).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Unknown position '%s' for platform '%s'", positionName, target.getSequencer().getInstrumentModel().getAlias())));
}
switch(containers.size()) {
case 0:
SequencerPartitionContainer newContainer = containerModel.getPlatformType().createContainer();
newContainer.setModel(containerModel);
newContainer.setCreator(user);
newContainer.setIdentificationBarcode(containerSerialNumber);
newContainer.setPartitionLimit(laneCount);
newContainer.setPartitions(IntStream.range(0, laneCount).mapToObj(i -> new PartitionImpl(newContainer, i + 1)).collect(Collectors.toList()));
updatePartitionContents(getLaneContents, newContainer);
RunPosition newRunPos = new RunPosition();
newRunPos.setRun(target);
newRunPos.setContainer(newContainer);
newRunPos.setPosition(position);
target.getRunPositions().clear();
target.getRunPositions().add(newRunPos);
return true;
case 1:
SequencerPartitionContainer container = containers.iterator().next();
boolean isMutated = false;
if (container.getPartitions().size() != laneCount) {
throw new IllegalArgumentException(String.format("The container %s has %d partitions, but %d were detected by the scanner.", containerSerialNumber, container.getPartitions().size(), laneCount));
}
// only update container model from fallback to non-fallback
if (container.getModel().isFallback() && !containerModel.isFallback() && container.getModel().getId() != containerModel.getId()) {
container.setModel(containerModel);
isMutated = true;
}
if (target.getSequencerPartitionContainers().stream().noneMatch(c -> c.getId() == container.getId())) {
target.addSequencerPartitionContainer(container, position);
updatePartitionContents(getLaneContents, container);
isMutated = true;
}
return isMutated;
default:
throw new IllegalArgumentException("Multiple containers with same identifier: " + containerSerialNumber);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition in project miso-lims by miso-lims.
the class Run method addSequencerPartitionContainer.
public void addSequencerPartitionContainer(SequencerPartitionContainer f, InstrumentPosition position) {
RunPosition rp = new RunPosition();
rp.setRun(this);
rp.setContainer(f);
rp.setPosition(position);
getRunPositions().add(rp);
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition in project miso-lims by miso-lims.
the class DefaultContainerService method validateChange.
private void validateChange(SequencerPartitionContainer container, SequencerPartitionContainer beforeChange) throws IOException {
if (container.getModel().getPartitionCount() != container.getPartitions().size()) {
// this is not user-correctable, so should not be reported as a validation error
throw new IllegalArgumentException("Number of partitions does not match container model specifications");
}
List<ValidationError> errors = new ArrayList<>();
if (LimsUtils.isStringBlankOrNull(container.getIdentificationBarcode())) {
errors.add(new ValidationError("identificationBarcode", "Required"));
}
ValidationUtils.validateBarcodeUniqueness(container, beforeChange, barcodableReferenceService, errors);
if (container.getClusteringKit() != null && container.getClusteringKit().getKitType() != KitType.CLUSTERING) {
errors.add(new ValidationError("clusteringKitId", "Must be a clustering kit"));
}
if (container.getClusteringKitLot() != null && container.getClusteringKit() == null) {
errors.add(new ValidationError("clusteringKitLot", "Clustering kit not specified"));
}
if (container.getMultiplexingKit() != null && container.getMultiplexingKit().getKitType() != KitType.MULTIPLEXING) {
errors.add(new ValidationError("MultiplexingKitId", "Must be a multiplexing kit"));
}
if (container.getMultiplexingKitLot() != null && container.getMultiplexingKit() == null) {
errors.add(new ValidationError("MultiplexingKitLot", "Multiplexing kit not specified"));
}
if (beforeChange != null && ValidationUtils.isSetAndChanged(SequencerPartitionContainer::getModel, container, beforeChange)) {
SequencingContainerModel before = beforeChange.getModel();
SequencingContainerModel after = container.getModel();
if (after.getPlatformType() != before.getPlatformType()) {
errors.add(new ValidationError("model.id", String.format("Can only be changed to a model of the same platform (%s)", before.getPlatformType().getKey())));
} else if (after.getPartitionCount() != before.getPartitionCount()) {
errors.add(new ValidationError("model.id", String.format("Can only be changed to a model with the same number of partitions (%d)", before.getPartitionCount())));
}
if (beforeChange.getRunPositions() != null) {
Set<InstrumentModel> requiredInstrumentModels = beforeChange.getRunPositions().stream().map(RunPosition::getRun).map(Run::getSequencer).map(Instrument::getInstrumentModel).collect(Collectors.toSet());
if (requiredInstrumentModels.stream().anyMatch(required -> after.getInstrumentModels().stream().map(InstrumentModel::getId).noneMatch(id -> id == required.getId()))) {
errors.add(new ValidationError("model.id", String.format("Can only change to a model compatible with the linked runs' instrument models (%s)", LimsUtils.joinWithConjunction(requiredInstrumentModels.stream().map(InstrumentModel::getAlias).collect(Collectors.toSet()), "and"))));
}
}
}
if (!errors.isEmpty()) {
throw new ValidationException(errors);
}
}
Aggregations