Search in sources :

Example 1 with NamingScheme

use of uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme in project miso-lims by miso-lims.

the class DefaultPoolService method create.

@Override
public long create(Pool pool) throws IOException {
    if (pool.isDiscarded()) {
        pool.setVolume(BigDecimal.ZERO);
    }
    if (pool.getConcentration() == null) {
        pool.setConcentrationUnits(null);
    }
    if (pool.getVolume() == null) {
        pool.setVolumeUnits(null);
    }
    pool.setName(generateTemporaryName());
    loadPoolElements(pool.getPoolContents(), pool);
    pool.setChangeDetails(authorizationManager.getCurrentUser());
    boxService.throwIfBoxPositionIsFilled(pool);
    validateChange(pool, null);
    poolStore.save(pool);
    try {
        NamingScheme namingScheme = namingSchemeHolder.getPrimary();
        pool.setName(namingScheme.generateNameFor(pool));
        validateNameOrThrow(pool, namingScheme);
    } catch (MisoNamingException e) {
        throw new IOException("Invalid name for pool", e);
    }
    if (autoGenerateIdBarcodes) {
        LimsUtils.generateAndSetIdBarcode(pool);
    }
    long savedId = poolStore.save(pool);
    boxService.updateBoxableLocation(pool);
    return savedId;
}
Also used : NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) IOException(java.io.IOException) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 2 with NamingScheme

use of uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme in project miso-lims by miso-lims.

the class DefaultProjectService method create.

@Override
public long create(Project project) throws IOException {
    saveNewContact(project.getContact());
    loadChildEntities(project);
    validateChange(project, null);
    project.setChangeDetails(authorizationManager.getCurrentUser());
    project.setName(generateTemporaryName());
    projectStore.save(project);
    NamingScheme namingScheme = namingSchemeHolder.get(project.isSecondaryNaming());
    try {
        project.setName(namingScheme.generateNameFor(project));
    } catch (MisoNamingException e) {
        throw new ValidationException(new ValidationError("name", e.getMessage()));
    }
    validateNameOrThrow(project, namingScheme);
    return projectStore.save(project);
}
Also used : ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 3 with NamingScheme

use of uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme in project miso-lims by miso-lims.

the class DefaultProjectService method validateChange.

private void validateChange(Project project, Project beforeChange) throws IOException {
    List<ValidationError> errors = new ArrayList<>();
    NamingScheme namingScheme = namingSchemeHolder.get(project.isSecondaryNaming());
    if (ValidationUtils.isSetAndChanged(Project::getShortName, project, beforeChange)) {
        // assume that if project shortname is required by the naming scheme, it is used for generating sample aliases
        if (beforeChange != null && !namingScheme.nullProjectShortNameAllowed() && hasSamples(beforeChange)) {
            errors.add(new ValidationError("shortName", "Cannot change because there are already samples in the project"));
        }
    }
    if (project.getShortName() == null && detailedSample) {
        errors.add(ValidationError.forRequired("shortName"));
    }
    ValidationResult shortNameValidation = namingScheme.validateProjectShortName(project.getShortName());
    if (!shortNameValidation.isValid()) {
        errors.add(new ValidationError("shortName", shortNameValidation.getMessage()));
    }
    if ((beforeChange == null || (project.getShortName() != null && !project.getShortName().equals(beforeChange.getShortName()))) && (project.getShortName() != null && getProjectByShortName(project.getShortName()) != null)) {
        errors.add(new ValidationError("shortName", "There is already a project with this short name"));
    }
    if ((beforeChange == null || !project.getAlias().equals(beforeChange.getAlias())) && projectStore.getByAlias(project.getAlias()) != null) {
        errors.add(new ValidationError("alias", "There is already a project with this alias"));
    }
    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
}
Also used : SampleNumberPerProject(uk.ac.bbsrc.tgac.miso.core.data.SampleNumberPerProject) Project(uk.ac.bbsrc.tgac.miso.core.data.Project) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) ArrayList(java.util.ArrayList) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult)

Example 4 with NamingScheme

use of uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme in project miso-lims by miso-lims.

the class DefaultRunService method save.

private Run save(Run run) throws IOException {
    try {
        run.setChangeDetails(authorizationManager.getCurrentUser());
        Long id = runDao.save(run);
        Run saved = runDao.get(id);
        // post-save field generation
        boolean needsUpdate = false;
        if (hasTemporaryName(run)) {
            NamingScheme namingScheme = namingSchemeHolder.getPrimary();
            saved.setName(namingScheme.generateNameFor(saved));
            validateNameOrThrow(saved, namingScheme);
            needsUpdate = true;
        }
        if (needsUpdate) {
            runDao.save(saved);
            saved = runDao.get(saved.getId());
        }
        createRunPartitions(run);
        return saved;
    } catch (MisoNamingException e) {
        throw new IllegalArgumentException("Name generator failed to generate a valid name", e);
    } catch (ConstraintViolationException e) {
        // Send the nested root cause message to the user, since it contains the actual error.
        throw new ConstraintViolationException(e.getMessage() + " " + ExceptionUtils.getRootCauseMessage(e), e.getSQLException(), e.getConstraintName());
    }
}
Also used : NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) OxfordNanoporeRun(uk.ac.bbsrc.tgac.miso.core.data.OxfordNanoporeRun) IlluminaRun(uk.ac.bbsrc.tgac.miso.core.data.IlluminaRun) SolidRun(uk.ac.bbsrc.tgac.miso.core.data.SolidRun) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) LS454Run(uk.ac.bbsrc.tgac.miso.core.data.LS454Run) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 5 with NamingScheme

use of uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme in project miso-lims by miso-lims.

the class DefaultLibraryService method validateChange.

private void validateChange(Library library, Library beforeChange, boolean libraryReceipt) throws IOException {
    updateDetailedQcStatusDetails(library, beforeChange, authorizationManager);
    List<ValidationError> errors = new ArrayList<>();
    if (!hasTemporaryAlias(library)) {
        NamingScheme namingScheme = getNamingScheme(library);
        boolean aliasChanged = isChanged(Library::getAlias, library, beforeChange);
        if (aliasChanged) {
            if (isInvalidDuplicate(library, namingScheme)) {
                errors.add(ValidationError.forDuplicate("library", "alias"));
            }
        }
        if (!isDetailedLibrary(library) || !((DetailedLibrary) library).hasNonStandardAlias()) {
            uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult aliasValidation = namingScheme.validateLibraryAlias(library.getAlias());
            if (!aliasValidation.isValid()) {
                if (!aliasChanged && isDetailedLibrary(library)) {
                    ((DetailedLibrary) library).setNonStandardAlias(true);
                } else {
                    throw new ValidationException(new ValidationError("alias", aliasValidation.getMessage()));
                }
            }
        }
        if (!isDetailedLibrary(library) || !((DetailedLibrary) library).hasNonStandardAlias()) {
            uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult aliasValidation = namingScheme.validateLibraryAlias(library.getAlias());
            if (!aliasValidation.isValid()) {
                throw new ValidationException(new ValidationError("alias", aliasValidation.getMessage()));
            }
        }
    }
    validateConcentrationUnits(library.getConcentration(), library.getConcentrationUnits(), errors);
    validateVolume(library.getInitialVolume(), library.getVolume(), errors);
    validateVolumeUnits(library.getVolume(), library.getVolumeUnits(), errors);
    validateBarcodeUniqueness(library, beforeChange, barcodableReferenceService, errors);
    validateUnboxableFields(library, errors);
    validateDetailedQcStatus(library, errors);
    if (isDetailedLibrary(library) && beforeChange != null) {
        validateTargetedSequencing(((DetailedLibrary) library).getLibraryDesignCode(), beforeChange.getLibraryAliquots(), errors);
        validateGroupDescription((DetailedLibrary) library, errors);
    }
    // 2. propagating (not library receipt), and options exist
    if (beforeChange != null) {
        if (beforeChange.getThermalCycler() != null && library.getThermalCycler() == null) {
            addRequiredError(errors, "thermalCyclerId");
        }
        if (beforeChange.getKitLot() != null && library.getKitLot() == null) {
            addRequiredError(errors, "kitLot");
        }
        if (beforeChange.getSop() != null && library.getSop() == null) {
            addRequiredError(errors, "sopId");
        }
    } else if (!libraryReceipt) {
        if (library.getThermalCycler() == null && instrumentService.listByType(InstrumentType.THERMAL_CYCLER).stream().anyMatch(Instrument::isActive)) {
            addRequiredError(errors, "thermalCyclerId");
        }
        if (library.getKitLot() == null) {
            addRequiredError(errors, "kitLot");
        }
        if (library.getSop() == null && sopService.listByCategory(SopCategory.LIBRARY).stream().anyMatch(sop -> !sop.isArchived())) {
            addRequiredError(errors, "sopId");
        }
    }
    if (library.getSpikeIn() != null) {
        if (library.getSpikeInDilutionFactor() == null) {
            errors.add(new ValidationError("spikeInDilutionFactor", "Spike-in dilution factor must be specified"));
        }
        if (library.getSpikeInVolume() == null) {
            errors.add(new ValidationError("spikeInVolume", "Spike-in volume must be specified"));
        }
    }
    validateIndices(library, errors);
    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
}
Also used : ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) ArrayList(java.util.ArrayList) Instrument(uk.ac.bbsrc.tgac.miso.core.data.Instrument) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) TransferLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) DetailedLibrary(uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary) DetailedLibrary(uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary)

Aggregations

NamingScheme (uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme)12 MisoNamingException (uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)8 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)6 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)6 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 DetailedLibrary (uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary)2 Library (uk.ac.bbsrc.tgac.miso.core.data.Library)2 TransferLibrary (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary)2 User (com.eaglegenomics.simlims.core.User)1 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)1 IlluminaRun (uk.ac.bbsrc.tgac.miso.core.data.IlluminaRun)1 Instrument (uk.ac.bbsrc.tgac.miso.core.data.Instrument)1 LS454Run (uk.ac.bbsrc.tgac.miso.core.data.LS454Run)1 OxfordNanoporeRun (uk.ac.bbsrc.tgac.miso.core.data.OxfordNanoporeRun)1 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)1 Run (uk.ac.bbsrc.tgac.miso.core.data.Run)1 Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)1 SampleNumberPerProject (uk.ac.bbsrc.tgac.miso.core.data.SampleNumberPerProject)1