public ExperimentDTO updateExperiment()

in server/src/main/java/com/epam/indigoeln/core/service/experiment/ExperimentService.java [656:739]


    public ExperimentDTO updateExperiment(String projectId, String notebookId, ExperimentDTO experimentDTO, User user) {
        Lock lock = locks.get(projectId);
        ExperimentDTO result;
        try {
            lock.lock();
            Experiment experimentFromDB = experimentRepository
                    .findById(SequenceIdUtil.buildFullId(projectId, notebookId, experimentDTO.getId())).
                    orElseThrow(() -> EntityNotFoundException.createWithExperimentId(experimentDTO.getId()));

            // Check of EntityAccess (User must have "Read Entity" permission in notebook's access list and
            // "Update Entity" in experiment's access list, or must have CONTENT_EDITOR authority)
            checkAccess(user, experimentFromDB);

            Experiment experimentForSave = dtoMapper.convertFromDTO(experimentDTO);

            //Check experiment version before component's saving
            if (!experimentForSave.getVersion().equals(experimentFromDB.getVersion())) {
                throw ConcurrencyException.createWithExperimentName(experimentFromDB.getName(),
                        new IndigoRuntimeException());
            }

            if (experimentFromDB.getStatus() != ExperimentStatus.OPEN) {
                throw OperationDeniedException.createNotOpenExperimentUpdateOperation(experimentFromDB.getId());
            }

            if (experimentDTO.getTemplate() != null) {
                Template tmpl = new Template();
                tmpl.setTemplateContent(experimentDTO.getTemplate().getTemplateContent());
                experimentForSave.setTemplate(tmpl);
            }


            // check of user permissions's correctness in access control list
            PermissionUtil.checkCorrectnessOfAccessList(userService, experimentForSave.getAccessList());

            experimentFromDB.setTemplate(experimentForSave.getTemplate());
            experimentFromDB.setComments(experimentForSave.getComments());
            experimentFromDB.setStatus(experimentForSave.getStatus());
            experimentFromDB.setDocumentId(experimentForSave.getDocumentId());
            experimentFromDB.setSubmittedBy(experimentForSave.getSubmittedBy());
            experimentFromDB.setVersion(experimentForSave.getVersion());

            experimentFromDB.setComponents(updateComponents(experimentFromDB.getComponents(),
                    experimentForSave.getComponents(), experimentFromDB.getId()));

            // add all users as VIEWER to project and to notebook
            String fullNotebookId = SequenceIdUtil.buildFullId(projectId, notebookId);
            Notebook notebook = notebookRepository.findById(fullNotebookId).
                    orElseThrow(() -> EntityNotFoundException.createWithNotebookId(notebookId));
            Project project = projectRepository.findById(projectId).
                    orElseThrow(() -> EntityNotFoundException.createWithProjectId(projectId));

            Triple<PermissionChanges<Project>, PermissionChanges<Notebook>, PermissionChanges<Experiment>> changes =
                    ExperimentPermissionHelper.changeExperimentPermissions(
                            project, notebook, experimentFromDB, experimentForSave.getAccessList(), user);

            Experiment savedExperiment;
            try {
                savedExperiment = experimentRepository.save(experimentFromDB);
            } catch (OptimisticLockingFailureException e) {
                throw ConcurrencyException.createWithExperimentName(experimentFromDB.getName(), e);
            }

            Set<User> contentEditors = userService.getContentEditors();
            List<WebSocketUtil.DelayedNotificationRunnable> notifications = new ArrayList<>();
            if (changes.getRight().hadChanged()) {
                notifications.addAll(
                        updateProjectAndGetNotifications(user, changes.getLeft(), contentEditors));

                notifications.addAll(
                        updateNotebooksAndSendNotifications(user, project, changes.getMiddle(), contentEditors));
            }
            notifications.addAll(
                    getExperimentNotifications(user, project.getId(),
                            notebook, changes.getRight(), contentEditors));

            webSocketUtil.sendAll(notifications);

            result = new ExperimentDTO(savedExperiment);
        } finally {
            lock.unlock();
        }
        return result;
    }