public Object docLike(@FormParam("docRef") String docRef) throws Exception {
// Get document
CoreSession session = ctx.getCoreSession();
DocumentModel docToLike = session.getDocument(new IdRef(docRef));
// Get Like Services
LikeService likeService = Framework.getLocalService(LikeService.class);
// Get user name
String userName = ctx.getPrincipal().getName();
if (likeService.hasUserLiked(userName, docToLike)) {
likeService.dislike(userName, docToLike);
} else {
likeService.like(userName, docToLike);
}
return Response.ok(
getView("bricks/document_like").arg("doc", docToLike)).header(
"docRef", docRef).build();
}