in server/src/main/java/com/epam/indigoeln/core/service/dashboard/DashboardService.java [72:154]
public DashboardDTO getDashboard() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("REST request to get dashboard experiments");
}
val dashboardDTO = new DashboardDTO();
// Necessary collections
val projectCollection = mongoTemplate.getCollection(Project.COLLECTION_NAME);
val notebookCollection = mongoTemplate.getCollection(Notebook.COLLECTION_NAME);
val experimentCollection = mongoTemplate.getCollection(Experiment.COLLECTION_NAME);
val componentCollection = mongoTemplate.getCollection(Component.COLLECTION_NAME);
val userCollection = mongoTemplate.getCollection(User.COLLECTION_NAME);
// Current user and date threshold
val user = userService.getUserWithAuthorities();
val zonedThreshold = ZonedDateTime.now()
.minus(dashboardProperties.getThresholdLevel(), dashboardProperties.getThresholdUnit());
val threshold = JSR310DateConverters.ZonedDateTimeToDateConverter.INSTANCE.convert(zonedThreshold);
// Load all necessary entities
val experiments = new HashMap<Object, Document>();
experimentCollection
.find(new Document("$or", Arrays.asList(
new Document("author.$id", user.getId()),
new Document("submittedBy.$id", user.getId()))))
.forEach(e -> experiments.put(e.get("_id"), e));
val notebooks = new HashMap<Object, Document>();
notebookCollection
.find(new Document("experiments.$id", new Document("$in", experiments.keySet())))
.forEach(n -> notebooks.put(n.get("_id"), n));
val projects = new HashMap<Object, Document>();
projectCollection
.find(new Document("notebooks.$id", new Document("$in", notebooks.keySet())))
.forEach(p -> projects.put(p.get("_id"), p));
val componentIds = new HashSet<Object>();
experiments.values().forEach(e -> ((Iterable) e.get("components")).forEach(c -> componentIds.add(((DBRef) c).getId())));
val components = new HashMap<Object, Document>();
componentCollection
.find(new Document()
.append("_id", new Document("$in", componentIds))
.append("$or", Arrays.asList(
new Document("name", "reaction"),
new Document("name", "reactionDetails"),
new Document("name", "conceptDetails"))))
.forEach(c -> components.put(c.get("_id"), c));
val userIds = new HashSet<Object>();
experiments.values()
.forEach(e -> {
if (e.get("author") != null) {
userIds.add(((DBRef) e.get("author")).getId());
}
if (e.get("submittedBy") != null) {
userIds.add(((DBRef) e.get("submittedBy")).getId());
}
});
components.values()
.forEach(c -> {
if (c.get("content") != null && ((Document) c.get("content")).get("coAuthors") != null) {
((Iterable) ((Document) c.get("content")).get("coAuthors")).forEach(userIds::add);
}
});
val users = new HashMap<Object, Document>();
userCollection.find(new Document("_id", new Document("$in", userIds))).forEach(u -> users.put(u.get("_id"), u));
// Fill dashboard
dashboardDTO.setOpenAndCompletedExp(openExperiments(threshold, user, projects, notebooks, experiments, components, users));
dashboardDTO.setWaitingSignatureExp(waitingExperiments(user, projects, notebooks, experiments, components, users));
dashboardDTO.setSubmittedAndSigningExp(submittedExperiments(threshold, user, projects, notebooks, experiments, components, users));
return dashboardDTO;
}