in server/src/main/java/com/epam/indigoeln/core/service/notebook/NotebookService.java [179:223]
public List<ShortEntityDTO> getNotebooksForExperimentCreation(User user) {
val notebookCollection = mongoTemplate.getCollection(Notebook.COLLECTION_NAME);
val userCollection = mongoTemplate.getCollection(User.COLLECTION_NAME);
val notebooks = new HashMap<Object, Document>();
if (PermissionUtil.isContentEditor(user)) {
notebookCollection
.find()
.forEach(n -> notebooks.put(n.get("_id"), n));
} else {
notebookCollection
.find(new Document()
.append("accessList", new Document()
.append("$elemMatch", new Document()
.append("user.$id", user.getId())
.append("permissions", new Document()
.append("$in", Collections.singletonList(UserPermission.CREATE_SUB_ENTITY))))))
.forEach(n -> notebooks.put(n.get("_id"), n));
}
val userIds = new HashSet<Object>();
notebooks
.values()
.forEach(n -> {
if (n.get("author") != null) {
userIds.add(((DBRef) n.get("author")).getId());
}
if (n.get("lastModifiedBy") != null) {
userIds.add(((DBRef) n.get("lastModifiedBy")).getId());
}
});
val users = new HashMap<Object, Document>();
userCollection
.find(new Document("_id", new Document("$in", userIds)))
.forEach(u -> users.put(u.get("_id"), u));
return notebooks
.values()
.stream()
.map(n -> new ShortEntityDTO(n, users))
.sorted(Comparator.comparing(ShortEntityDTO::getName))
.collect(toList());
}