private static SampleDto copySampleFields(@Nonnull Sample from, @Nonnull SampleDto dto, boolean includeBoxPositions) { dto.setId(from.getId()); dto.setName(from.getName()); dto.setDescription(from.getDescription()); dto.setUpdatedById(from.getLastModifier().getUserId()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setLocationBarcode(from.getLocationBarcode()); dto.setLocationLabel(BoxUtils.makeLocationLabel(from)); if (from.getBox() != null) { dto.setBox(asDto(from.getBox(), includeBoxPositions)); dto.setBoxPosition(from.getBoxPosition()); dto.setSampleType(from.getSampleType()); dto.setReceivedDate(from.getReceivedDate() == null ? null : formatDate(from.getReceivedDate())); if (from.getQcPassed() != null) { dto.setQcPassed(from.getQcPassed()); dto.setAlias(from.getAlias()); dto.setProjectId(from.getProject().getId()); dto.setScientificName(from.getScientificName()); dto.setTaxonIdentifier(from.getTaxonIdentifier()); if (from.getVolume() != null) { dto.setVolume(from.getVolume().toString()); dto.setVolumeUnits(from.getVolumeUnits()); if (from.getConcentration() != null) { dto.setConcentration(from.getConcentration().toString()); dto.setConcentrationUnits(from.getConcentrationUnits()); dto.setDiscarded(from.isDiscarded());
public static SampleDto asDto(@Nonnull Sample from, boolean includeBoxPositions) { SampleDto dto = null; if (isDetailedSample(from)) { dto = asDetailedSampleDto((DetailedSample) from); } else { dto = new SampleDto(); } copySampleFields(from, dto, includeBoxPositions); dto.setAccession(from.getAccession()); if (from.getQCs() != null && !from.getQCs().isEmpty()) { dto.setQcs(asQcDtos(from.getQCs())); } return dto; }
private void maybeRemoveFromBox(Sample sample) { if (sample.isDiscarded() || sample.isDistributed()) { sample.setBoxPosition(null); } }
private void validateChange(Sample sample, Sample beforeChange) throws IOException { List<ValidationError> errors = new ArrayList<>(); validateConcentrationUnits(sample.getConcentration(), sample.getConcentrationUnits(), errors); validateVolumeUnits(sample.getVolume(), sample.getVolumeUnits(), errors); validateBarcodeUniqueness(sample, beforeChange, sampleStore::getByBarcode, errors, "sample"); validateDistributionFields(sample.isDistributed(), sample.getDistributionDate(), sample.getDistributionRecipient(), sample.getBox(), errors); validateUnboxableFields(sample.isDiscarded(), sample.isDistributed(), sample.getBox(), errors); if (taxonLookupEnabled && (beforeChange == null || !sample.getScientificName().equals(beforeChange.getScientificName())) && (sample.getScientificName() == null || TaxonomyUtils.checkScientificNameAtNCBI(sample.getScientificName()) == null)) { errors.add(new ValidationError("scientificName", "This scientific name is not of a known taxonomy")); } if (!errors.isEmpty()) { throw new ValidationException(errors); } }
target.setDescription(source.getDescription()); target.setSampleType(source.getSampleType()); target.setReceivedDate(source.getReceivedDate()); target.setScientificName(source.getScientificName()); target.setTaxonIdentifier(source.getTaxonIdentifier()); target.setAlias(source.getAlias()); target.setDescription(source.getDescription()); target.setDiscarded(source.isDiscarded()); if (target.isDiscarded()) { target.setVolume(0.0); } else { target.setVolume(source.getVolume()); target.setVolumeUnits(target.getVolume() == null ? null : source.getVolumeUnits()); target.setConcentration(source.getConcentration()); 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()); target.setDistributionRecipient(source.getDistributionRecipient()); if (target.isDistributed()) { target.setLocationBarcode("SENT TO: " + target.getDistributionRecipient()); target.setVolume(0.0); } else { target.setLocationBarcode(source.getLocationBarcode()); target.setQcPassed(source.getQcPassed());
if (from.getId() != null) to.setId(from.getId()); 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.setTaxonIdentifier(from.getTaxonIdentifier()); 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()); if (from.getProjectId() != null) { to.setProject(new ProjectImpl()); to.getProject().setId(from.getProjectId()); to.setBoxPosition((SampleBoxPosition) makeBoxablePosition(from, (SampleImpl) to)); to.setDistributed(from.isDistributed()); to.setDistributionDate(parseDate(from.getDistributionDate())); to.setDistributionRecipient(from.getDistributionRecipient()); return to;
authorizationManager.throwIfNotWritable(sample); boxService.throwIfBoxPositionIsFilled(sample); sample.setChangeDetails(authorizationManager.getCurrentUser()); if (isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (isUniqueExternalNameWithinProjectRequired() && isExternalNameDuplicatedInProject(sample)) { throw new IllegalArgumentException("Sample with external name '" + ((SampleIdentity) sample).getExternalName() + "' already exists in project " + sample.getProject().getShortName()); sample.inheritPermissions(sample.getProject()); sample.setName(generateTemporaryName()); if (isStringEmptyOrNull(sample.getAlias()) && namingScheme.hasSampleAliasGenerator()) { sample.setAlias(generateTemporaryName()); if (sample.getConcentration() == null) { sample.setConcentrationUnits(null); if (sample.getVolume() == null) { sample.setVolumeUnits(null); long savedId = save(sample, true).getId(); boxService.updateBoxableLocation(sample); return savedId;
v.setSampleAccession(sam.getAccession()); v.setSampleAlias(sam.getAlias()); v.setSampleDescription(sam.getDescription()); v.setSampleId(sam.getId()); v.setSampleName(sam.getName()); v.setSampleType(sam.getSampleType()); Project proj = sam.getProject(); if (proj != null) { v.setProjectAlias(proj.getAlias());
dto.setParentSampleId(from.getSample().getId()); dto.setParentSampleAlias(from.getSample().getAlias()); dto.setParentSampleProjectId(from.getSample().getProject().getId()); if (from.getSample() instanceof DetailedSample) { dto.setParentSampleClassId(((DetailedSample) from.getSample()).getSampleClass().getId()); if (from.getSample().getBox() != null) { dto.setSampleBoxPositionLabel(BoxUtils.makeBoxPositionLabel(from.getSample().getBox().getAlias(), from.getSample().getBoxPosition()));
@Override protected void populate(Element xml, Sample sample) { xml.setAttribute("alias", sample.getAlias()); xml.setAttribute("center_name", centreName); Element sampleTitle = xml.getOwnerDocument().createElementNS(null, "TITLE"); sampleTitle.setTextContent(sample.getAlias()); xml.appendChild(sampleTitle); Element sampleName = xml.getOwnerDocument().createElementNS(null, "SAMPLE_NAME"); Element sampleScientificName = xml.getOwnerDocument().createElementNS(null, "SCIENTIFIC_NAME"); sampleScientificName.setTextContent(sample.getScientificName()); sampleName.appendChild(sampleScientificName); // 2/11/2011 Antony Colles moved IF !=null statement, to help produce valid submission XML. Element sampleTaxonIdentifier = xml.getOwnerDocument().createElementNS(null, "TAXON_ID"); if (!isStringEmptyOrNull(sample.getTaxonIdentifier())) { sampleTaxonIdentifier.setTextContent(sample.getTaxonIdentifier()); } else { sampleTaxonIdentifier.setTextContent("000001"); } sampleName.appendChild(sampleTaxonIdentifier); xml.appendChild(sampleName); Element sampleDescription = xml.getOwnerDocument().createElementNS(null, "DESCRIPTION"); sampleDescription.setTextContent(sample.getDescription()); xml.appendChild(sampleDescription); }
private static ArraySampleDto asArraySampleDto(String position, @Nonnull Sample sample) { ArraySampleDto dto = new ArraySampleDto(); dto.setCoordinates(position); dto.setId(sample.getId()); dto.setAlias(sample.getAlias()); dto.setName(sample.getName()); dto.setIdentificationBarcode(sample.getIdentificationBarcode()); return dto; }
if (!isUniqueExternalNameWithinProjectRequired()) return; Collection<SampleIdentity> matches = getIdentitiesByExternalNameOrAliasAndProject(newExternalName, sample.getProject().getId(), true); if (!matches.isEmpty()) { for (SampleIdentity match : matches) { if (match.getId() != sample.getId()) { Set<String> matchExtNames = SampleIdentityImpl.getSetFromString(match.getExternalName()); Set<String> newExtNames = SampleIdentityImpl.getSetFromString(newExternalName);
Long newId = sample.getId(); if (!hasTemporaryAlias(sample)) { validateAlias(sample); created.setName(namingScheme.generateNameFor(created)); validateNameOrThrow(created, namingScheme); needsUpdate = true; created.setAlias(generatedAlias); if (isDetailedSample(created)) { if (autoGenerateIdBarcodes && isStringEmptyOrNull(created.getIdentificationBarcode())) {
@Override public Long getId() { return sample.getId(); }
@Override public void beforeDelete(Sample object) throws IOException { List<Workset> worksets = worksetService.listBySample(object.getId()); for (Workset workset : worksets) { workset.getSamples().removeIf(sam -> sam.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
qc.setResults(qcStep.getQCValue()); Collection<SampleQC> qcs = sample.getQCs(); qcs.add(qc); sample.setQCs(qcs); BoxPosition stockBp = new BoxPosition(stockBox, stockBoxPositionStep.getPosition(), sample.getEntityType(), sample.getId()); stockBox.getBoxPositions().put(stockBoxPositionStep.getPosition(), stockBp);
sampleDescriptor.setAttribute("refname", experiment.getLibrary().getSample().getAlias()); sampleDescriptor.setAttribute("refcenter", centreName); if (!isStringEmptyOrNull(experiment.getLibrary().getSample().getAccession())) { sampleDescriptor.setAttribute("accession", experiment.getLibrary().getSample().getAccession()); librarySource.setTextContent(experiment.getLibrary().getSample().getSampleType()); libraryDescriptor.appendChild(librarySource);
@Override public void update(Sample sample) throws IOException { Sample managed = get(sample.getId()); managed.setChangeDetails(authorizationManager.getCurrentUser()); boolean validateAliasUniqueness = !managed.getAlias().equals(sample.getAlias()); authorizationManager.throwIfNotWritable(managed); maybeRemoveFromBox(sample); boxService.throwIfBoxPositionIsFilled(sample); validateChange(sample, managed); applyChanges(managed, sample); loadChildEntities(managed); if (isDetailedSample(managed)) { DetailedSample detailedUpdated = (DetailedSample) managed; if (detailedUpdated.getParent() != null) { detailedUpdated.setParent((DetailedSample) get(detailedUpdated.getParent().getId())); validateHierarchy(detailedUpdated); } } save(managed, validateAliasUniqueness); boxService.updateBoxableLocation(sample); }
@Override public Long create(Library library) throws IOException { if (library.getSample() != null && library.getSample().getId() == Sample.UNSAVED_ID) { Long sampleId = sampleService.create(library.getSample()); library.getSample().setId(sampleId); } loadChildEntities(library); boxService.throwIfBoxPositionIsFilled(library); library.setChangeDetails(authorizationManager.getCurrentUser()); if (library.getSecurityProfile() == null) { library.inheritPermissions(sampleService.get(library.getSample().getId())); } authorizationManager.throwIfNotWritable(library); validateParentOrThrow(library); // pre-save field generation library.setName(generateTemporaryName()); if (isStringEmptyOrNull(library.getAlias()) && namingScheme.hasLibraryAliasGenerator()) { library.setAlias(generateTemporaryName()); } if (library.getConcentration() == null) { library.setConcentrationUnits(null); } if (library.getVolume() == null) { library.setVolumeUnits(null); } validateChange(library, null); long savedId = save(library, true).getId(); boxService.updateBoxableLocation(library); return savedId; }