use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.
the class DefaultLibraryAliasGenerator method generate.
@Override
public String generate(Library library) throws MisoNamingException, IOException {
if (library.getSample() != null) {
Pattern samplePattern = Pattern.compile("([A-z0-9]+)_S([A-z0-9]+)_(.*)");
Matcher m = samplePattern.matcher(library.getSample().getAlias());
if (m.matches()) {
Collection<Library> siblings = libraryService.listBySampleId(library.getSample().getId());
Set<String> siblingAliases = siblings.stream().map(Library::getAlias).collect(Collectors.toSet());
String alias = null;
long siblingNumber = siblings.stream().filter(sibling -> sibling.getId() != library.getId()).count();
do {
siblingNumber++;
alias = m.group(1) + "_" + "L" + m.group(2) + "-" + siblingNumber + "_" + m.group(3);
} while (siblingAliases.contains(alias));
return alias;
} else {
throw new MisoNamingException("Cannot generate Library alias from supplied sample alias: " + library.getSample().getAlias());
}
} else {
throw new NullPointerException("This alias generation scheme requires the Library to have a parent Sample set.");
}
}
use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.
the class OicrBaseLibraryAliasGenerator method getLibraryTypeAbbreviation.
/**
* @param item the item that an alias is being generated for
* @return the name portion representing the LibraryType
* @throws NullPointerException if item's LibraryType is not set
* @throws MisoNamingException if unable to generate an alias for any other reason
*/
private String getLibraryTypeAbbreviation(R item) throws MisoNamingException {
LibraryType libraryType = getLibraryType(item);
String abbr = libraryType.getAbbreviation();
if (abbr == null) {
throw new MisoNamingException("Cannot generate alias for library type '" + libraryType.getDescription() + "'");
}
return abbr;
}
use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.
the class V2LibraryAliquotAliasGenerator method generate.
@Override
public String generate(LibraryAliquot aliquot) throws MisoNamingException, IOException {
if (!isDetailedLibraryAliquot(aliquot)) {
throw new MisoNamingException("Can only generate an alias for detailed library aliquots");
}
Library library = aliquot.getLibrary();
String partialAlias = library.getAlias() + "-";
int next = siblingNumberGenerator.getFirstAvailableSiblingNumber(LibraryAliquot.class, partialAlias);
String siblingNumber = zeroPad(next, 2);
return partialAlias + siblingNumber;
}
use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException 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.exception.MisoNamingException 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;
}
Aggregations