use of com.erudika.scoold.core.Revision in project scoold by Erudika.
the class RevisionsController method get.
@GetMapping("/{postid}")
public String get(@PathVariable String postid, HttpServletRequest req, Model model) {
Post showPost = utils.getParaClient().read(postid);
if (showPost == null) {
return "redirect:" + questionslink;
}
Pager itemcount = utils.getPager("page", req);
List<Revision> revisionslist = showPost.getRevisions(itemcount);
// we need the first revision on the next page for diffing
List<Revision> nextPage = showPost.getRevisions(new Pager(itemcount.getPage() + 1, itemcount.getLimit()));
utils.fetchProfiles(revisionslist);
model.addAttribute("path", "revisions.vm");
model.addAttribute("title", utils.getLang(req).get("revisions.title"));
model.addAttribute("showPost", showPost);
model.addAttribute("itemcount", itemcount);
model.addAttribute("revisionslist", revisionslist);
model.addAttribute("lastOnPage", nextPage.isEmpty() ? null : nextPage.get(0));
return "base";
}
use of com.erudika.scoold.core.Revision in project scoold by Erudika.
the class ApiController method getPostRevisions.
@GetMapping("/posts/{id}/revisions")
public List<Map<String, Object>> getPostRevisions(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Model model = new ExtendedModelMap();
revisionsController.get(id, req, res, model);
Post post = (Post) model.getAttribute("showPost");
if (post == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
return ((List<Revision>) model.getAttribute("revisionslist")).stream().map(r -> {
Map<String, Object> rev = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(r, false));
rev.put("author", r.getAuthor());
return rev;
}).collect(Collectors.toList());
}
use of com.erudika.scoold.core.Revision in project scoold by Erudika.
the class RevisionsController method get.
@GetMapping("/{postid}")
public String get(@PathVariable String postid, HttpServletRequest req, HttpServletResponse res, Model model) {
Post showPost = utils.getParaClient().read(postid);
if (showPost == null) {
return "redirect:" + QUESTIONSLINK;
}
// https://github.com/Erudika/scoold/issues/254
res.setHeader("X-Robots-Tag", "noindex, nofollow");
Profile authUser = utils.getAuthUser(req);
if (!utils.canAccessSpace(authUser, showPost.getSpace())) {
return "redirect:" + QUESTIONSLINK;
}
Pager itemcount = utils.getPager("page", req);
List<Revision> revisionslist = showPost.getRevisions(itemcount);
// we need the first revision on the next page for diffing
List<Revision> nextPage = showPost.getRevisions(new Pager(itemcount.getPage() + 1, itemcount.getLimit()));
utils.fetchProfiles(revisionslist);
model.addAttribute("path", "revisions.vm");
model.addAttribute("title", utils.getLang(req).get("revisions.title"));
model.addAttribute("showPost", showPost);
model.addAttribute("itemcount", itemcount);
model.addAttribute("revisionslist", revisionslist);
model.addAttribute("lastOnPage", nextPage.isEmpty() ? null : nextPage.get(0));
return "base";
}
use of com.erudika.scoold.core.Revision in project scoold by Erudika.
the class ScooldUtils method fetchProfiles.
public void fetchProfiles(List<? extends ParaObject> objects) {
if (objects == null || objects.isEmpty()) {
return;
}
Map<String, String> authorids = new HashMap<String, String>(objects.size());
Map<String, Profile> authors = new HashMap<String, Profile>(objects.size());
for (ParaObject obj : objects) {
if (obj.getCreatorid() != null) {
authorids.put(obj.getId(), obj.getCreatorid());
}
}
List<String> ids = new ArrayList<String>(new HashSet<String>(authorids.values()));
if (ids.isEmpty()) {
return;
}
// read all post authors in batch
for (ParaObject author : pc.readAll(ids)) {
authors.put(author.getId(), (Profile) author);
}
// add system profile
authors.put(API_USER.getId(), API_USER);
// set author object for each post
for (ParaObject obj : objects) {
if (obj instanceof Post) {
((Post) obj).setAuthor(authors.get(authorids.get(obj.getId())));
} else if (obj instanceof Revision) {
((Revision) obj).setAuthor(authors.get(authorids.get(obj.getId())));
}
}
}
Aggregations