public static String nullifyStringIfBlank(String s) { return (isStringBlankOrNull(s) ? null : s); }
public static String makeLocationLabel(boolean discarded, String locationBarcode, String boxAlias, String position, String boxLocationBarcode) { if (discarded) { return "EMPTY"; } else if (boxAlias != null && position != null) { return (isStringEmptyOrNull(locationBarcode) ? "" : locationBarcode + ", ") + boxAlias + " - " + position + (isStringEmptyOrNull(boxLocationBarcode) ? "" : " (" + boxLocationBarcode + ")"); } else if (locationBarcode != null) { return locationBarcode; } else { return "Unknown"; } }
private static SampleTissueProcessingDto asTissueProcessingSampleDto(@Nonnull SampleTissueProcessing from) { from = deproxify(from); if (isSampleSlide(from)) { return asSlideSampleDto((SampleSlide) from); } else if (isLcmTubeSample(from)) { return asLCMTubeSampleDto((SampleLCMTube) from); } else if (isProcessingSingleCellSample(from)) { return asSingleCellSampleDto((SampleSingleCell) from); } else { return new SampleTissueProcessingDto(); } }
public static boolean isTissueSample(Sample sample) { if (!isDetailedSample(sample)) return false; return sample instanceof SampleTissue || safeCategoryCheck(sample, SampleTissue.CATEGORY_NAME); }
public static Date parseDateTime(String dateString) { if (isStringEmptyOrNull(dateString)) { return null; } try { return getDateTimeFormat().parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Invalid datetime string"); } }
public static Date parseDate(String dateString) { if (isStringEmptyOrNull(dateString)) { return null; } try { return getDateFormat().parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Invalid date string"); } }
target.setConcentrationUnits(target.getConcentration() == null ? null : source.getConcentrationUnits()); target.setLocationBarcode(source.getLocationBarcode()); target.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(source.getIdentificationBarcode())); target.setDistributed(source.isDistributed()); target.setDistributionDate(source.getDistributionDate()); if (isDetailedSample(target)) { DetailedSample dTarget = (DetailedSample) target; DetailedSample dSource = (DetailedSample) source; dTarget.setDetailedQcStatusNote(nullifyStringIfBlank(dSource.getDetailedQcStatusNote())); dTarget.setQcPassed(dSource.getQcPassed()); dTarget.setSubproject(dSource.getSubproject()); if (isIdentitySample(target)) { applyIdentityChanges((SampleIdentity) target, (SampleIdentity) source); } else if (isTissueSample(target)) { applyTissueChanges((SampleTissue) target, (SampleTissue) source); } else if (isTissueProcessingSample(target)) { applyTissueProcessingChanges((SampleTissueProcessing) target, (SampleTissueProcessing) source); } else if (isAliquotSample(target)) { applyAliquotChanges((SampleAliquot) target, (SampleAliquot) source); } else if (isStockSample(target)) { applyStockChanges((SampleStock) target, (SampleStock) source);
@Override public String generate(Sample sample) throws MisoNamingException, IOException { if (!LimsUtils.isDetailedSample(sample)) { throw new IllegalArgumentException("Can only generate an alias for detailed samples"); } DetailedSample detailed = (DetailedSample) sample; if (isIdentitySample(detailed)) { return generateIdentityAlias((SampleIdentity) detailed); } for (DetailedSample parent = detailed.getParent(); parent != null; parent = parent.getParent()) { if (isAliquotSample(parent)) { return addSiblingTag(parent.getAlias(), detailed); } if (isTissueSample(parent)) { if (isTissueSample(detailed)) { // tissues parented to tissues return generateTissueAlias((SampleTissue) detailed, LimsUtils.getParent(SampleIdentity.class, parent)); } else { return addSiblingTag(parent.getAlias(), detailed); } } if (isIdentitySample(parent)) { if (!isTissueSample(detailed)) throw new IllegalArgumentException("Missing parent tissue"); return generateTissueAlias((SampleTissue) detailed, (SampleIdentity) parent); } } throw new IllegalStateException("Unexpected conditions for alias generation"); }
private static DetailedSampleDto asDetailedSampleDto(@Nonnull DetailedSample from) { DetailedSampleDto dto = null; if (isIdentitySample(from)) { dto = asIdentitySampleDto((SampleIdentity) from); } else if (isTissueSample(from)) { dto = asTissueSampleDto((SampleTissue) from); } else if (isTissueProcessingSample(from)) { dto = asTissueProcessingSampleDto((SampleTissueProcessing) from); } else if (isAliquotSample(from)) { dto = asAliquotSampleDto((SampleAliquot) from); } else if (isStockSample(from)) { dto = asStockSampleDto((SampleStock) from); } else { dto.setSynthetic(from.isSynthetic()); dto.setCreationDate(from.getCreationDate() == null ? "" : formatDate(from.getCreationDate())); dto.setNonStandardAlias(from.hasNonStandardAlias()); if (from.getDetailedQcStatus() != null) {
sample.setProject(projectStore.get(sample.getProject().getId())); if (isDetailedSample(sample)) { DetailedSample sai = (DetailedSample) sample; if (sai.getSampleClass() != null && sai.getSampleClass().getId() != null) { sai.setSubproject(subProjectDao.getSubproject(sai.getSubproject().getId())); if (isTissueProcessingSample(sai) && sai instanceof SampleSlide) { Stain originalStain = ((SampleSlide) sai).getStain(); Stain stain; if (isAliquotSample(sai)) { SampleAliquot sa = (SampleAliquot) sai; if (sa.getSamplePurpose() != null && sa.getSamplePurpose().getId() != SubprojectImpl.UNSAVED_ID) { if (isTissueSample(sai)) { SampleTissue st = (SampleTissue) sai; if (st.getTissueMaterial() != null && st.getTissueMaterial().getId() != TissueMaterialImpl.UNSAVED_ID) {
private Library save(Library library, boolean validateAliasUniqueness) throws IOException { try { if (!hasTemporaryAlias(library)) { validateAliasOrThrow(library); if (hasTemporaryName(library)) { managed.setName(namingScheme.generateNameFor(managed)); validateNameOrThrow(managed, namingScheme); needsUpdate = true; if (hasTemporaryAlias(library)) { String generatedAlias = namingScheme.generateLibraryAlias(managed); managed.setAlias(generatedAlias); if (isDetailedLibrary(managed)) { if (autoGenerateIdBarcodes && isStringEmptyOrNull(managed.getIdentificationBarcode())) { generateAndSetIdBarcode(managed); needsUpdate = true;
if (!hasTemporaryAlias(sample)) { validateAlias(sample); if (hasTemporaryName(sample)) { created.setName(namingScheme.generateNameFor(created)); validateNameOrThrow(created, namingScheme); needsUpdate = true; if (hasTemporaryAlias(sample)) { String generatedAlias = namingScheme.generateSampleAlias(created); created.setAlias(generatedAlias); if (isDetailedSample(created)) { if (autoGenerateIdBarcodes && isStringEmptyOrNull(created.getIdentificationBarcode())) { generateAndSetIdBarcode(created); needsUpdate = true;
boxService.throwIfBoxPositionIsFilled(sample); sample.setChangeDetails(authorizationManager.getCurrentUser()); if (isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (!isIdentitySample(sample)) { try { setIdentity(detailed); if (!isIdentitySample(detailed.getParent())) { detailed.setParent(findOrCreateParent(detailed)); sample.setName(generateTemporaryName()); if (isStringEmptyOrNull(sample.getAlias()) && namingScheme.hasSampleAliasGenerator()) { sample.setAlias(generateTemporaryName());
to.setSampleClass(sampleClass); to.setGroupId(nullifyStringIfBlank(from.getGroupId())); to.setGroupDescription(nullifyStringIfBlank(from.getGroupDescription())); to.setSynthetic(from.getSynthetic()); if (from.getSubprojectId() != null) { to.setSubproject(subproject); to.setCreationDate(LimsUtils.isStringEmptyOrNull(from.getCreationDate()) ? null : parseDate(from.getCreationDate())); if (from.getIdentityId() != null) { to.setIdentityId(from.getIdentityId()); if (!LimsUtils.isStringEmptyOrNull(from.getExternalNames()) && to.getParent() != null) { SampleIdentity identity = LimsUtils.getParent(SampleIdentity.class, to); if (identity == null) { throw new IllegalStateException("Missing Identity at root of hierarchy");
private void validateParentOrThrow(Library library) { if (!isDetailedLibrary(library)) return; if (!isAliquotSample(library.getSample())) { String sc = null; if (isDetailedSample(library.getSample())) { DetailedSample sample = (DetailedSample) library.getSample(); sc = sample.getSampleClass() == null ? "not set" : sample.getSampleClass().getAlias(); } else { sc = "Plain Sample"; } throw new IllegalArgumentException(String.format("Sample Class '%s' is not a valid parent for Libraries. Must be an aliquot", sc)); } }
public static boolean isStockSingleCellSample(Sample sample) { if (!isDetailedSample(sample)) return false; return sample instanceof SampleStockSingleCell; }
private static <S extends DetailedSample, T> Function<Sample, T> detailedSample(Class<S> clazz, Function<S, T> function, T defaultValue) { return s -> { if (clazz.isInstance(s)) { return function.apply(clazz.cast(s)); } if (LimsUtils.isDetailedSample(s)) { S parent = LimsUtils.getParent(clazz, (DetailedSample) s); if (parent != null) { return function.apply(parent); } } return defaultValue; }; }
to.setAccession(nullifyStringIfBlank(from.getAccession())); to.setName(from.getName()); to.setDescription(nullifyStringIfBlank(from.getDescription())); to.setIdentificationBarcode(nullifyStringIfBlank(from.getIdentificationBarcode())); to.setLocationBarcode(nullifyStringIfBlank(from.getLocationBarcode())); to.setSampleType(from.getSampleType()); to.setReceivedDate(parseDate(from.getReceivedDate())); to.setQcPassed(from.getQcPassed()); to.setScientificName(from.getScientificName()); to.setAlias(from.getAlias()); to.setDescription(from.getDescription()); to.setVolume(isStringEmptyOrNull(from.getVolume()) ? null : Double.valueOf(from.getVolume())); to.setVolumeUnits(from.getVolumeUnits()); to.setConcentration(isStringEmptyOrNull(from.getConcentration()) ? null : Double.valueOf(from.getConcentration())); to.setConcentrationUnits(from.getConcentrationUnits()); to.setDiscarded(from.isDiscarded()); to.setDistributionDate(parseDate(from.getDistributionDate())); to.setDistributionRecipient(from.getDistributionRecipient()); return to;
public static ConsentLevel getIdentityConsentLevel(DetailedSample sample) { SampleIdentity identity = null; if (isIdentitySample(sample)) { identity = (SampleIdentity) sample; } else { identity = LimsUtils.getParent(SampleIdentity.class, sample); } if (identity != null && identity.getConsentLevel() != null) { return identity.getConsentLevel(); } return null; }
private LibraryDilution save(LibraryDilution dilution) throws IOException { validateTargetedSequencing(dilution); dilution.setLastModifier(authorizationManager.getCurrentUser()); try { Long newId = dilutionDao.save(dilution); LibraryDilution managed = dilutionDao.get(newId); // post-save field generation boolean needsUpdate = false; if (hasTemporaryName(dilution)) { managed.setName(namingScheme.generateNameFor(managed)); validateNameOrThrow(managed, namingScheme); needsUpdate = true; } if (autoGenerateIdBarcodes && isStringEmptyOrNull(managed.getIdentificationBarcode())) { // if !autoGenerateIdBarcodes then the identificationBarcode is set by the user generateAndSetIdBarcode(managed); needsUpdate = true; } if (needsUpdate) dilutionDao.save(managed); return managed; } catch (MisoNamingException e) { throw new IllegalArgumentException("Name generator failed to generate valid name for library"); } 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()); } }