Search in sources :

Example 1 with ValidationResult

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

the class AbstractNamingScheme method generateNameFor.

@Override
public String generateNameFor(Nameable nameable) throws MisoNamingException, IOException {
    if (getNameGenerator() == null)
        throw new UnsupportedOperationException("check hasNameGenerator() to determine availability");
    String name = getNameGenerator().generate(nameable);
    ValidationResult vr = validateName(name);
    if (vr.isValid())
        return name;
    throw new MisoNamingException("failed to generate a valid name: " + vr.getMessage());
}
Also used : ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 2 with ValidationResult

use of uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult 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 3 with ValidationResult

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

the class DefaultExperimentService method create.

@Override
public long create(Experiment experiment) throws IOException {
    loadRunPartitions(experiment);
    experiment.setName(LimsUtils.generateTemporaryName());
    experiment.setInstrumentModel(instrumentModelService.get(experiment.getInstrumentModel().getId()));
    experiment.setLibrary(libraryService.get(experiment.getLibrary().getId()));
    experiment.setStudy(studyService.get(experiment.getStudy().getId()));
    experiment.setChangeDetails(authorizationManager.getCurrentUser());
    experimentStore.save(experiment);
    String name;
    try {
        name = namingSchemeHolder.getPrimary().generateNameFor(experiment);
    } catch (MisoNamingException e) {
        throw new IOException("Cannot save Experiment - failed to generate a valid name", e);
    }
    experiment.setName(name);
    ValidationResult nameValidation = namingSchemeHolder.getPrimary().validateName(experiment.getName());
    if (!nameValidation.isValid()) {
        throw new IOException("Cannot save Experiment - invalid name:" + nameValidation.getMessage());
    }
    return experimentStore.save(experiment);
}
Also used : IOException(java.io.IOException) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 4 with ValidationResult

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

the class DefaultExperimentService method update.

@Override
public long update(Experiment experiment) throws IOException {
    loadRunPartitions(experiment);
    ValidationResult nameValidation = namingSchemeHolder.getPrimary().validateName(experiment.getName());
    if (!nameValidation.isValid()) {
        throw new IOException("Cannot save Experiment - invalid name:" + nameValidation.getMessage());
    }
    Experiment original = experimentStore.get(experiment.getId());
    original.setAccession(experiment.getAccession());
    original.setAlias(experiment.getAlias());
    original.setDescription(experiment.getDescription());
    original.setName(experiment.getName());
    original.setInstrumentModel(instrumentModelService.get(experiment.getInstrumentModel().getId()));
    original.setLibrary(libraryService.get(experiment.getLibrary().getId()));
    original.setStudy(studyService.get(experiment.getStudy().getId()));
    original.setTitle(experiment.getTitle());
    // These have been already reloaded.
    original.setRunPartitions(experiment.getRunPartitions());
    original.getRunPartitions().forEach(rp -> rp.setExperiment(original));
    Set<Kit> kits = new HashSet<>();
    for (Kit k : experiment.getKits()) {
        kits.add(kitService.get(k.getId()));
    }
    original.setKits(kits);
    original.setChangeDetails(authorizationManager.getCurrentUser());
    return experimentStore.save(original);
}
Also used : Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Kit(uk.ac.bbsrc.tgac.miso.core.data.Kit) IOException(java.io.IOException) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult) HashSet(java.util.HashSet)

Aggregations

ValidationResult (uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult)4 IOException (java.io.IOException)2 MisoNamingException (uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Experiment (uk.ac.bbsrc.tgac.miso.core.data.Experiment)1 Kit (uk.ac.bbsrc.tgac.miso.core.data.Kit)1 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)1 SampleNumberPerProject (uk.ac.bbsrc.tgac.miso.core.data.SampleNumberPerProject)1 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)1 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)1 NamingScheme (uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme)1