use of com.vsct.vboard.models.Pin in project vboard by voyages-sncf-technologies.
the class CommentsController method removeComment.
@RequestMapping(value = "", method = RequestMethod.DELETE)
@ResponseBody
@Valid
public Comment removeComment(@RequestParam(value = "id") String id) {
Comment comment;
try {
comment = this.commentDAO.findById(id);
if (comment != null) {
// Check if the user can update this comment (or throw an exception)
permission.ensureUserHasRightsToAlterPin(comment.getAuthor());
this.commentDAO.delete(comment);
String pinId = comment.getPinId();
Pin pin = this.pinDAO.findByPinId(pinId);
if (pin != null) {
pin.decreaseCommentsNumber();
this.pinDAO.save(pin);
}
// Decrease the number of comments for the given pin in elasticsearch
this.elsClient.removeComment(pinId);
this.logger.debug("deleteComment: id={}", id);
// Update the stats
this.gamification.updateStats(permission.getSessionUserWithSyncFromDB());
} else {
throw new VBoardException("Comment does not exist or already deleted");
}
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return comment;
}
use of com.vsct.vboard.models.Pin in project vboard by voyages-sncf-technologies.
the class LabelsController method getAllFromPins.
// Return all labels still on any pins
@RequestMapping(value = "/throughPins", method = RequestMethod.GET)
@ResponseBody
@Valid
public Set<Label> getAllFromPins() {
Set<Label> labels = new HashSet<>();
Iterable<Pin> pins = this.pinDAO.findAll();
pins.forEach(p -> {
if (!isBlank(p.getLabels())) {
List<String> pinLabels = p.getLabelsAsList();
pinLabels.forEach(l -> {
labels.add(new Label(l));
this.labelDAO.save(new Label(l));
});
}
});
return labels;
}
use of com.vsct.vboard.models.Pin in project vboard by voyages-sncf-technologies.
the class RssController method getFeedInRss.
@RequestMapping(value = "/rss", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
public ModelAndView getFeedInRss(@RequestParam(value = "text", required = false) String text, @RequestParam(value = "labels", required = false) String labels) {
final String from = DateTimeFormat.forPattern("YYYY-MM-dd").print(DateTime.now().minusDays(7));
final List<Pin> pins = elsClient.searchPins(text, labels, from, 0);
final ModelAndView mav = new ModelAndView();
mav.setView(new RssViewer(publicHostname));
mav.addObject("feedContent", pins);
return mav;
}
use of com.vsct.vboard.models.Pin in project vboard by voyages-sncf-technologies.
the class ElasticSearchClient method jsonMapToPin.
private Pin jsonMapToPin(HashMap jsonMap) {
final Pin pin = new Pin((String) jsonMap.get("pin_id"), (String) jsonMap.get("pin_title"), (String) jsonMap.get("href_url"), // ElasticSearch or jsonMap seems to integrate doubles by default whereas the parameter is an int
jsonMap.get("likes") != null ? ((Double) jsonMap.get("likes")).intValue() : 0, (String) jsonMap.get("img_type"), (String) jsonMap.get("labels"), (String) jsonMap.get("indexable_text_content"), (String) jsonMap.get("author"), (String) jsonMap.get("post_date_utc"), jsonMap.get("comments_number") != null ? ((Double) jsonMap.get("comments_number")).intValue() : 0);
ValidatorUtils.validate(pin);
return pin;
}
use of com.vsct.vboard.models.Pin in project vboard by voyages-sncf-technologies.
the class CommentControllerTest method deleteComment.
@Test
public void deleteComment() {
User.getEmailFromString(Mockito.anyString());
this.pinDAO.save(new Pin("0", "title", "", 0, "", "", "content", "auth", new DateTime().toString(), 1));
Comment comment = new Comment("id", "0", "auth", "comment", new DateTime().toString());
Assert.assertFalse(this.commentDAO.findAll().iterator().hasNext());
this.commentDAO.save(comment);
Assert.assertTrue(this.commentDAO.findAll().iterator().hasNext());
this.commentsController.removeComment("id");
Assert.assertFalse(this.commentDAO.findAll().iterator().hasNext());
Assert.assertEquals(0, this.pinDAO.findByPinId("0").getCommentsNumber());
this.pinDAO.delete("0");
comment = new Comment("id", "0", "auth", "comment", new DateTime().toString());
Assert.assertFalse(this.commentDAO.findAll().iterator().hasNext());
this.commentDAO.save(comment);
Assert.assertTrue(this.commentDAO.findAll().iterator().hasNext());
this.commentsController.removeComment("id");
Assert.assertFalse(this.commentDAO.findAll().iterator().hasNext());
Assert.assertNull(this.pinDAO.findByPinId("0"));
this.pinDAO.save(new Pin("0", "title", "", 1, "", "", "content", "auth", new DateTime()));
this.commentDAO.save(comment);
Assert.assertTrue(this.commentDAO.findAll().iterator().hasNext());
ArrayList<Pin> pins = new ArrayList<>();
pins.add(this.pinDAO.findByPinId("0"));
Mockito.doReturn(pins).when(elsClient).searchPinsById("0");
this.pinsController.deletePinFromId("0");
Assert.assertFalse(this.commentDAO.findAll().iterator().hasNext());
}
Aggregations