Search in sources :

Example 1 with SampleTissueProcessingDto

use of uk.ac.bbsrc.tgac.miso.dto.SampleTissueProcessingDto in project miso-lims by miso-lims.

the class SampleRestController method buildHierarchy.

/**
 * Converts the DTO to a Sample, complete with parents. Parent SampleClasses are inferred where necessary
 *
 * @param sampleDto
 * @return
 * @throws IOException
 */
public Sample buildHierarchy(SampleDto sampleDto) throws IOException {
    if (sampleDto instanceof SampleAliquotDto) {
        SampleAliquotDto dto = (SampleAliquotDto) sampleDto;
        dto.setStockClassId(inferIntermediateSampleClassId(dto, dto.getSampleClassId(), SampleAliquot.CATEGORY_NAME, SampleStock.CATEGORY_NAME, true));
        // Some hierarchies have two Aliquot levels
        if (dto.getStockClassId() == null) {
            dto.setParentAliquotClassId(inferIntermediateSampleClassId(dto, dto.getSampleClassId(), SampleAliquot.CATEGORY_NAME, SampleAliquot.CATEGORY_NAME, false));
            Long topAliquotClassId = dto.getParentAliquotClassId() == null ? dto.getSampleClassId() : dto.getParentAliquotClassId();
            dto.setStockClassId(inferIntermediateSampleClassId(dto, topAliquotClassId, SampleAliquot.CATEGORY_NAME, SampleStock.CATEGORY_NAME, false));
        }
        if (dto.getParentId() == null) {
            // infer tissue processing class if necessary
            SampleClass processingClass = sampleClassService.getRequiredTissueProcessingClass(dto.getStockClassId());
            if (processingClass != null) {
                dto.setTissueProcessingClassId(processingClass.getId());
                // infer tissue class
                dto.setParentSampleClassId(inferIntermediateSampleClassId(dto, dto.getTissueProcessingClassId(), SampleTissueProcessing.CATEGORY_NAME, SampleTissue.CATEGORY_NAME, false));
            } else {
                // infer tissue class
                dto.setParentSampleClassId(inferIntermediateSampleClassId(dto, dto.getStockClassId(), SampleStock.CATEGORY_NAME, SampleTissue.CATEGORY_NAME, false));
            }
        }
    } else if (sampleDto instanceof SampleStockDto) {
        // infer tissue processing class if necessary
        SampleStockDto dto = (SampleStockDto) sampleDto;
        SampleClass processingClass = sampleClassService.getRequiredTissueProcessingClass(dto.getSampleClassId());
        if (processingClass != null) {
            dto.setTissueProcessingClassId(processingClass.getId());
            // infer tissue class
            dto.setParentSampleClassId(inferIntermediateSampleClassId(dto, dto.getTissueProcessingClassId(), SampleTissueProcessing.CATEGORY_NAME, SampleTissue.CATEGORY_NAME, false));
        } else {
            // infer tissue class
            dto.setParentSampleClassId(inferIntermediateSampleClassId(dto, dto.getSampleClassId(), SampleStock.CATEGORY_NAME, SampleTissue.CATEGORY_NAME, false));
        }
    } else if (sampleDto instanceof SampleTissueProcessingDto) {
        DetailedSampleDto dto = (DetailedSampleDto) sampleDto;
        Long topProcessingClassId = dto.getSampleClassId();
        if (sampleDto instanceof SampleTissuePieceDto) {
            SampleTissuePieceDto lcmDto = (SampleTissuePieceDto) dto;
            // Some hierarchies have two Tissue Processing levels
            lcmDto.setParentSlideClassId(inferIntermediateSampleClassId(dto, dto.getSampleClassId(), SampleTissueProcessing.CATEGORY_NAME, SampleTissueProcessing.CATEGORY_NAME, true));
            if (lcmDto.getParentSlideClassId() != null) {
                topProcessingClassId = lcmDto.getParentSlideClassId();
            }
        }
        dto.setParentSampleClassId(inferIntermediateSampleClassId(dto, topProcessingClassId, SampleTissueProcessing.CATEGORY_NAME, SampleTissue.CATEGORY_NAME, false));
    }
    return Dtos.to(sampleDto);
}
Also used : DetailedSampleDto(uk.ac.bbsrc.tgac.miso.dto.DetailedSampleDto) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleTissueProcessingDto(uk.ac.bbsrc.tgac.miso.dto.SampleTissueProcessingDto) SampleTissuePieceDto(uk.ac.bbsrc.tgac.miso.dto.SampleTissuePieceDto) SampleAliquotDto(uk.ac.bbsrc.tgac.miso.dto.SampleAliquotDto) SampleStockDto(uk.ac.bbsrc.tgac.miso.dto.SampleStockDto)

Aggregations

SampleClass (uk.ac.bbsrc.tgac.miso.core.data.SampleClass)1 DetailedSampleDto (uk.ac.bbsrc.tgac.miso.dto.DetailedSampleDto)1 SampleAliquotDto (uk.ac.bbsrc.tgac.miso.dto.SampleAliquotDto)1 SampleStockDto (uk.ac.bbsrc.tgac.miso.dto.SampleStockDto)1 SampleTissuePieceDto (uk.ac.bbsrc.tgac.miso.dto.SampleTissuePieceDto)1 SampleTissueProcessingDto (uk.ac.bbsrc.tgac.miso.dto.SampleTissueProcessingDto)1