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());
}
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);
}
}
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);
}
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);
}
Aggregations