public NotebookDTO updateNotebook()

in server/src/main/java/com/epam/indigoeln/core/service/notebook/NotebookService.java [333:407]


    public NotebookDTO updateNotebook(NotebookDTO notebookDTO, String projectId, User user) {
        Lock lock = experimentService.getLock(projectId);
        try {
            lock.lock();
            String fullNotebookId = SequenceIdUtil.buildFullId(projectId, notebookDTO.getId());
            Notebook notebookFromDB = notebookRepository.findById(fullNotebookId).
                    orElseThrow(() -> EntityNotFoundException.createWithNotebookId(notebookDTO.getId()));

            // Check of EntityAccess (User must have "Read Entity" permission in project access list and
            // "Update Entity" permission in notebook access list, or must have CONTENT_EDITOR authority)

            Project project = projectRepository.findByNotebookId(fullNotebookId);
            if (project == null) {
                throw EntityNotFoundException.createWithNotebookChildId(notebookFromDB.getId());
            }

            if (!PermissionUtil.isContentEditor(user) && !PermissionUtil.hasPermissions(user.getId(),
                    project.getAccessList(), UserPermission.READ_ENTITY,
                    notebookFromDB.getAccessList(), UserPermission.UPDATE_ENTITY)) {
                throw OperationDeniedException.createNotebookUpdateOperation(notebookFromDB.getId());
            }

            Notebook notebook = dtoMapper.convertFromDTO(notebookDTO);
            // check of user permissions's correctness in access control list
            PermissionUtil.checkCorrectnessOfAccessList(userService, notebook.getAccessList());

            boolean notebookNameChanged = !notebookFromDB.getName().equals(notebook.getName());
            if (notebookNameChanged) {
                List<String> numbers = BatchComponentUtil.hasBatches(notebookFromDB);
                if (!numbers.isEmpty()) {
                    throw OperationNotAvailableException
                            .createNotebookUpdateNameOperation();
                }
                boolean hasNotOpen = notebookFromDB.getExperiments().stream()
                        .anyMatch(e -> e.getStatus() != ExperimentStatus.OPEN);
                if (hasNotOpen) {
                    throw OperationNotAvailableException
                            .createNotebookUpdateNameOperation();
                }
                notebookFromDB.setName(notebook.getName());
                notebookFromDB.getExperiments().forEach(e -> e.compileExperimentFullName(notebook.getName()));
            }
            notebookFromDB.setDescription(notebook.getDescription());
            notebookFromDB.setVersion(notebook.getVersion());

            Triple<PermissionChanges<Project>, PermissionChanges<Notebook>, List<PermissionChanges<Experiment>>>
                    permissionsChanges = NotebookPermissionHelper
                    .changeNotebookPermissions(project, notebookFromDB, notebook.getAccessList(), user);

            Notebook savedNotebook = saveNotebookAndHandleError(notebookFromDB);

            Set<User> contentEditors = userService.getContentEditors();
            ArrayList<WebSocketUtil.DelayedNotificationRunnable> notifications = new ArrayList<>();

            PermissionChanges<Notebook> notebooksPermissionChanges = permissionsChanges.getMiddle();
            if (notebooksPermissionChanges.hadChanged() || notebookNameChanged) {
                notifications.addAll(
                        updateProjectAndGetNotifications(user, permissionsChanges.getLeft(), contentEditors));

                notifications.addAll(
                        updateExperimentsAndGetNotifications(user, project.getId(), contentEditors,
                                notebooksPermissionChanges, permissionsChanges.getRight(), notebookNameChanged));
            }

            notifications.addAll(
                    getNotebookNotifications(user, project, savedNotebook,
                            contentEditors, notebooksPermissionChanges));

            webSocketUtil.sendAll(notifications);

            return new NotebookDTO(savedNotebook);
        } finally {
            lock.unlock();
        }
    }