use of uk.ac.bbsrc.tgac.miso.core.service.ContainerService in project miso-lims by miso-lims.
the class PoolRestController method assignPool.
@PostMapping(value = "/{poolId}/assign", produces = "application/json")
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void assignPool(@PathVariable Long poolId, @RequestBody AssignPoolDto request) throws IOException {
Pool pool = poolId == 0 ? null : poolService.get(poolId);
// Determine if this pool transition is allowed for this experiment. If removing a pool, it strictly isn't. If the new pool contains the
// same library as the experiment, it's fine.
Predicate<Experiment> isTransitionValid = pool == null ? experiment -> false : experiment -> pool.getPoolContents().stream().map(pd -> pd.getAliquot().getLibraryId()).anyMatch(id -> id == experiment.getLibrary().getId());
//
request.getPartitionIds().stream().map(//
WhineyFunction.rethrow(containerService::getPartition)).peek(WhineyConsumer.rethrow(partition -> {
for (RunPosition runPos : partition.getSequencerPartitionContainer().getRunPositions()) {
Run run = runPos.getRun();
// Check that we aren't going to hose any existing experiments through this reassignment
boolean relatedExperimentsOkay = //
experimentService.listAllByRunId(run.getId()).stream().flatMap(//
experiment -> experiment.getRunPartitions().stream()).filter(//
rp -> rp.getRun().getId() == run.getId() && rp.getPartition().getId() == partition.getId()).map(//
RunPartition::getExperiment).allMatch(isTransitionValid);
if (!relatedExperimentsOkay) {
throw new RestException(String.format("%s %d is used in an experiment.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber()), Status.BAD_REQUEST);
}
}
if (pool != null && partition.getSequencerPartitionContainer().getModel().getPlatformType() != pool.getPlatformType()) {
throw new RestException(String.format("%s %d in %s is not compatible with pool %s.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber(), partition.getSequencerPartitionContainer().getIdentificationBarcode(), pool.getName()), Status.BAD_REQUEST);
}
partition.setPool(pool);
if (request.getConcentration() != null) {
partition.setLoadingConcentration(new BigDecimal(request.getConcentration()));
partition.setLoadingConcentrationUnits(request.getUnits());
} else {
partition.setLoadingConcentration(null);
partition.setLoadingConcentrationUnits(null);
}
})).forEach(WhineyConsumer.rethrow(containerService::update));
if (pool != null) {
poolService.update(pool);
}
}
Aggregations