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