private void updateProperties(WidgetComment source, JpaWidgetComment converted, String widgetId) { converted.setEntityId(source.getId() == null ? null : Long.parseLong(source.getId())); converted.setCreatedDate(source.getCreatedDate()); converted.setLastModifiedDate(source.getLastModifiedDate()); converted.setText(source.getText()); converted.setUserId(source.getUserId()); converted.setWidgetId(widgetId); } }
@RequestMapping(method = RequestMethod.POST, value = "/{widgetId}/comments") public void createWidgetComment(@PathVariable String widgetId, @RequestParam String text, HttpServletResponse response) { WidgetComment widgetComment = new WidgetCommentImpl(); widgetComment.setUserId(userService.getAuthenticatedUser().getId()); widgetComment.setText(text); widgetComment.setCreatedDate(new Date()); widgetComment.setLastModifiedDate(new Date()); widgetService.createWidgetComment(widgetId, widgetComment); response.setStatus(HttpStatus.NO_CONTENT.value()); }
private boolean isWidgetCommentOwner(Authentication authentication, WidgetComment widgetComment, List<WidgetComment> trustedPageContainer, boolean trustedDomainObject) { WidgetComment trustedWidgetComment = null; if (trustedDomainObject) { trustedWidgetComment = widgetComment; } else { trustedWidgetComment = getTrustedWidgetComment(widgetComment.getId(), trustedPageContainer); } return isWidgetCommentOwnerById(authentication, trustedWidgetComment.getUserId()); }
@Override public void deleteWidgetComment(String widgetId, WidgetComment comment) { // widgetId ignored in JPA manager.remove(comment instanceof JpaWidgetComment ? comment : getCommentById(widgetId, comment.getId())); }
private JpaWidgetComment createEntity(WidgetComment source, String widgetId) { JpaWidgetComment converted = null; if (source != null) { converted = source.getId() == null ? new JpaWidgetComment() : manager.find(JpaWidgetComment.class, Long.parseLong(source.getId())); if (converted == null) { converted = new JpaWidgetComment(); } updateProperties(source, converted, widgetId); } return converted; }
@RequestMapping(method = RequestMethod.POST, value = "/{widgetId}/comments/{widgetCommentId}") public void updateWidgetComment(@PathVariable String widgetId, @PathVariable String widgetCommentId, @RequestParam String text, HttpServletResponse response) { WidgetComment widgetComment = widgetService.getWidgetComment(widgetId, widgetCommentId); if (widgetComment == null) { widgetComment = new WidgetCommentImpl(); widgetComment.setUserId(userService.getAuthenticatedUser().getId()); widgetComment.setCreatedDate(new Date()); widgetComment.setLastModifiedDate(new Date()); widgetComment.setText(text); widgetService.createWidgetComment(widgetId, widgetComment); } else { widgetComment.setText(text); widgetService.updateWidgetComment(widgetId, widgetComment); } response.setStatus(HttpStatus.NO_CONTENT.value()); }