@Override public void update(Library library) throws IOException { Library managed = get(library.getId()); managed.setChangeDetails(authorizationManager.getCurrentUser()); List<Index> originalIndices = new ArrayList<>(managed.getIndices()); authorizationManager.throwIfNotWritable(managed); maybeRemoveFromBox(library); boxService.throwIfBoxPositionIsFilled(library); boolean validateAliasUniqueness = !managed.getAlias().equals(library.getAlias()); validateChange(library, managed); applyChanges(managed, library); loadChildEntities(managed); makeChangeLogForIndices(originalIndices, managed.getIndices(), managed); save(managed, validateAliasUniqueness); boxService.updateBoxableLocation(library); }
@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; }