in server/src/main/java/com/epam/indigoeln/core/service/experiment/ExperimentService.java [164:232]
public List<ExperimentTreeNodeDTO> getAllExperimentTreeNodes(String projectId, String notebookId, User user) {
val notebookCollection = mongoTemplate.getCollection(Notebook.COLLECTION_NAME);
val experimentCollection = mongoTemplate.getCollection(Experiment.COLLECTION_NAME);
val userCollection = mongoTemplate.getCollection(User.COLLECTION_NAME);
val notebook = notebookCollection
.find(new Document().append("_id", SequenceIdUtil.buildFullId(projectId, notebookId))).first();
if (notebook == null) {
throw EntityNotFoundException.createWithNotebookId(notebookId);
}
if (notebook.get("experiments") instanceof Iterable) {
val experimentIds = new ArrayList<String>();
((Iterable) notebook.get("experiments"))
.forEach(e -> experimentIds.add(String.valueOf(((DBRef) e).getId())));
val experiments = new ArrayList<Document>();
experimentCollection.find(new Document()
.append("_id", new Document().append("$in", experimentIds))).forEach(experiments::add);
Map<Object, Object> experimentsWithUsers = getExperimentsWithUsers(experiments, userCollection);
Map<Object, List<Object>> experimentsWithComponents =
getExperimentsWithComponents(experiments);
if (user != null) {
val notebookAccessList = new HashSet<UserPermission>();
((Iterable) notebook.get("accessList"))
.forEach(a -> notebookAccessList.add(new UserPermission((Document) a)));
if (!PermissionUtil.hasEditorAuthorityOrPermissions(user, notebookAccessList,
UserPermission.READ_ENTITY)) {
throw OperationDeniedException
.createNotebookSubEntitiesReadOperation(String.valueOf(notebook.get("_id")));
}
experiments.removeIf(experiment -> {
val experimentAccessList = new HashSet<UserPermission>();
((Iterable) experiment.get("accessList"))
.forEach(a -> experimentAccessList.add(new UserPermission((Document) a)));
return !PermissionUtil.hasUser(experimentAccessList, user);
});
}
List<ExperimentTreeNodeDTO> result = experiments.stream()
.map(ExperimentTreeNodeDTO::new)
.collect(Collectors.toList());
result.forEach(e -> {
Optional userObject = (Optional) experimentsWithUsers.get(e.getFullId());
Document userBasicDBObject = null;
if ((userObject).isPresent()) {
userBasicDBObject = (Document) userObject.get();
}
val components = experimentsWithComponents.get(e.getFullId());
setValuesForExperimentTreeNodeDTO(e, userBasicDBObject, components);
});
result = result.stream().sorted(TreeNodeDTO.NAME_COMPARATOR).collect(Collectors.toList());
return result;
}
return Collections.emptyList();
}