private void validateChange(Library library, Library beforeChange) throws IOException { List<ValidationError> errors = new ArrayList<>(); validateConcentrationUnits(library.getConcentration(), library.getConcentrationUnits(), errors); validateVolumeUnits(library.getVolume(), library.getVolumeUnits(), errors); validateBarcodeUniqueness(library, beforeChange, libraryDao::getByBarcode, errors, "library"); validateDistributionFields(library.isDistributed(), library.getDistributionDate(), library.getDistributionRecipient(), library.getBox(), errors); validateUnboxableFields(library.isDiscarded(), library.isDistributed(), library.getBox(), errors); 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")); } } if (!errors.isEmpty()) { throw new ValidationException(errors); } }
@Override public void update(LibraryDilution dilution) throws IOException { LibraryDilution managed = get(dilution.getId()); authorizationManager.throwIfNotWritable(managed); boxService.throwIfBoxPositionIsFilled(dilution); Library library = dilution.getLibrary(); if (library.getVolume() != null) { if (dilution.getVolumeUsed() != null && managed.getVolumeUsed() != null) { library.setVolume(library.getVolume() + managed.getVolumeUsed() - dilution.getVolumeUsed()); } else if (managed.getVolumeUsed() != null) { library.setVolume(library.getVolume() + managed.getVolumeUsed()); } else if (dilution.getVolumeUsed() != null) { library.setVolume(library.getVolume() - dilution.getVolumeUsed()); } } validateChange(dilution, managed); applyChanges(managed, dilution); managed.setChangeDetails(authorizationManager.getCurrentUser()); loadChildEntities(managed); save(managed); libraryService.update(library); boxService.updateBoxableLocation(dilution); }
@Override public Long create(LibraryDilution dilution) throws IOException { loadChildEntities(dilution); dilution.setCreator(authorizationManager.getCurrentUser()); if (dilution.getSecurityProfile() == null) { dilution.inheritPermissions(libraryService.get(dilution.getLibrary().getId())); } authorizationManager.throwIfNotWritable(dilution); boxService.throwIfBoxPositionIsFilled(dilution); if (dilution.getConcentration() == null) { dilution.setConcentrationUnits(null); } if (dilution.getVolume() == null) { dilution.setVolumeUnits(null); } Library library = dilution.getLibrary(); if (dilution.getVolumeUsed() != null && library.getVolume() != null) { library.setVolume(library.getVolume() - dilution.getVolumeUsed()); } dilution.setChangeDetails(authorizationManager.getCurrentUser()); // pre-save field generation dilution.setName(generateTemporaryName()); validateChange(dilution, null); long savedId = save(dilution).getId(); libraryService.update(library); boxService.updateBoxableLocation(dilution); return savedId; }
@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; }