Search in sources :

Example 1 with ContainerService

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);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestParam(org.springframework.web.bind.annotation.RequestParam) LibraryAliquotSpreadSheets(uk.ac.bbsrc.tgac.miso.core.data.spreadsheet.LibraryAliquotSpreadSheets) SampleTissueProcessing(uk.ac.bbsrc.tgac.miso.core.data.SampleTissueProcessing) PoolSpreadSheets(uk.ac.bbsrc.tgac.miso.core.data.spreadsheet.PoolSpreadSheets) PaginationFilter(uk.ac.bbsrc.tgac.miso.core.util.PaginationFilter) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) DataTablesResponseDto(uk.ac.bbsrc.tgac.miso.dto.DataTablesResponseDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) SequencingOrderSummaryViewService(uk.ac.bbsrc.tgac.miso.core.service.SequencingOrderSummaryViewService) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) BigDecimal(java.math.BigDecimal) PutMapping(org.springframework.web.bind.annotation.PutMapping) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Map(java.util.Map) ListPoolView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListPoolView) PostMapping(org.springframework.web.bind.annotation.PostMapping) ListLibraryAliquotViewService(uk.ac.bbsrc.tgac.miso.core.service.ListLibraryAliquotViewService) SampleService(uk.ac.bbsrc.tgac.miso.core.service.SampleService) SequencingOrderCompletionDto(uk.ac.bbsrc.tgac.miso.dto.SequencingOrderCompletionDto) PoolDto(uk.ac.bbsrc.tgac.miso.dto.PoolDto) AdvancedSearchParser(uk.ac.bbsrc.tgac.miso.webapp.controller.component.AdvancedSearchParser) PoolPickerEntry(uk.ac.bbsrc.tgac.miso.webapp.util.PoolPickerResponse.PoolPickerEntry) Predicate(java.util.function.Predicate) ListLibraryAliquotView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListLibraryAliquotView) Collection(java.util.Collection) ListPoolViewService(uk.ac.bbsrc.tgac.miso.core.service.ListPoolViewService) Collectors(java.util.stream.Collectors) IndexChecker(uk.ac.bbsrc.tgac.miso.core.util.IndexChecker) StandardCharsets(java.nio.charset.StandardCharsets) LibraryDto(uk.ac.bbsrc.tgac.miso.dto.LibraryDto) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) MisoWebUtils(uk.ac.bbsrc.tgac.miso.webapp.util.MisoWebUtils) Stream(java.util.stream.Stream) SequencingParametersService(uk.ac.bbsrc.tgac.miso.core.service.SequencingParametersService) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock) PoolService(uk.ac.bbsrc.tgac.miso.core.service.PoolService) RunService(uk.ac.bbsrc.tgac.miso.core.service.RunService) Entry(java.util.Map.Entry) LibraryAliquotDto(uk.ac.bbsrc.tgac.miso.dto.LibraryAliquotDto) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) PoolPickerResponse(uk.ac.bbsrc.tgac.miso.webapp.util.PoolPickerResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LibraryAliquotService(uk.ac.bbsrc.tgac.miso.core.service.LibraryAliquotService) ArrayList(java.util.ArrayList) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) LibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryAliquot) HttpServletRequest(javax.servlet.http.HttpServletRequest) SampleDto(uk.ac.bbsrc.tgac.miso.dto.SampleDto) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) ContainerService(uk.ac.bbsrc.tgac.miso.core.service.ContainerService) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) Status(javax.ws.rs.core.Response.Status) SampleAliquot(uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot) SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) ConcentrationUnit(uk.ac.bbsrc.tgac.miso.core.data.ConcentrationUnit) LibraryService(uk.ac.bbsrc.tgac.miso.core.service.LibraryService) WhineyFunction(uk.ac.bbsrc.tgac.miso.core.util.WhineyFunction) HttpServletResponse(javax.servlet.http.HttpServletResponse) SpreadsheetRequest(uk.ac.bbsrc.tgac.miso.dto.SpreadsheetRequest) IOException(java.io.IOException) SequencingParameters(uk.ac.bbsrc.tgac.miso.core.data.SequencingParameters) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) WhineyConsumer(uk.ac.bbsrc.tgac.miso.core.util.WhineyConsumer) Consumer(java.util.function.Consumer) HttpStatus(org.springframework.http.HttpStatus) RunPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition) ExperimentService(uk.ac.bbsrc.tgac.miso.core.service.ExperimentService) PlatformType(uk.ac.bbsrc.tgac.miso.core.data.type.PlatformType) PaginatedDataSource(uk.ac.bbsrc.tgac.miso.core.util.PaginatedDataSource) IlluminaExperiment(uk.ac.bbsrc.tgac.miso.core.util.IlluminaExperiment) AsyncOperationManager(uk.ac.bbsrc.tgac.miso.webapp.controller.component.AsyncOperationManager) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) RunPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) IlluminaExperiment(uk.ac.bbsrc.tgac.miso.core.util.IlluminaExperiment) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) BigDecimal(java.math.BigDecimal) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Status (javax.ws.rs.core.Response.Status)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpStatus (org.springframework.http.HttpStatus)1