in server/src/main/java/com/epam/indigoeln/core/service/project/ProjectService.java [185:229]
public List<ShortEntityDTO> getProjectsForNotebookCreation(User user) {
val projectCollection = mongoTemplate.getCollection(Project.COLLECTION_NAME);
val userCollection = mongoTemplate.getCollection(User.COLLECTION_NAME);
val projects = new HashMap<Object, Document>();
if (PermissionUtil.isContentEditor(user)) {
projectCollection
.find()
.forEach(p -> projects.put(p.get("_id"), p));
} else {
projectCollection
.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(p -> projects.put(p.get("_id"), p));
}
val userIds = new HashSet<Object>();
projects
.values()
.forEach(p -> {
if (p.get("author") != null) {
userIds.add(((DBRef) p.get("author")).getId());
}
if (p.get("lastModifiedBy") != null) {
userIds.add(((DBRef) p.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 projects
.values()
.stream()
.map(p -> new ShortEntityDTO(p, users))
.sorted(Comparator.comparing(ShortEntityDTO::getName))
.collect(Collectors.toList());
}