/* * Get the index of comment which contains given position. If there's no * matching comment, then return depends on exact parameter: = 0: return -1 * < 0: return index of the comment before the given position > 0: return * index of the comment after the given position */ private int getCommentIndex(int start, int position, int exact) { if (position == 0) { if (this.comments.length > 0 && this.comments[0].getStart() == 0) { return 0; } return -1; } int bottom = start, top = this.comments.length - 1; int i = 0, index = -1; Comment comment = null; while (bottom <= top) { i = bottom + (top - bottom) / 2; comment = this.comments[i]; int commentStart = comment.getStart(); if (position < commentStart) { top = i - 1; } else if (position >= (commentStart + comment.getLength())) { bottom = i + 1; } else { index = i; break; } } if (index < 0 && exact != 0) { comment = this.comments[i]; if (position < comment.getStart()) { return exact < 0 ? i - 1 : i; } else { return exact < 0 ? i : i + 1; } } return index; }
// smartsheet.sheetResources().commentResources().attachmentResources().attachFile(sheetId, // commentId, file,"text/plain"); public void testattachFileComment() throws SmartsheetException, IOException { // create comment to add to discussion Comment comment = new Comment.AddCommentBuilder().setText("This is a test comment").build(); Discussion discussion = new Discussion.CreateDiscussionBuilder() .setTitle("New Discussion") .setComment(comment) .build(); discussion = smartsheet.sheetResources().discussionResources().createDiscussion(sheetId, discussion); // comment = // smartsheet.sheetResources().discussionResources().comments().addComment(sheetId,discussion.getId(), comment); comment = discussion.getComments().get(0); commentId = comment.getId(); discussionId = discussion.getId(); File file1 = new File("src/integration-test/resources/small-text.txt"); // attach file to comment Attachment attachment = smartsheet .sheetResources() .commentResources() .attachmentResources() .attachFile(sheetId, commentId, file1, "text/plain"); testGetAttachmentComment(attachment.getId()); }
private void checkCommentLinks(String url, Comment comment) { Assert.assertNotNull(comment); Assert.assertEquals(0, comment.getId()); RESTServiceDiscovery links = comment.getRest(); Assert.assertNotNull(links); Assert.assertEquals(6, links.size()); // self AtomLink atomLink = links.getLinkForRel("self"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref()); // update atomLink = links.getLinkForRel("update"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref()); // remove atomLink = links.getLinkForRel("remove"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref()); // list atomLink = links.getLinkForRel("list"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comments", atomLink.getHref()); // add atomLink = links.getLinkForRel("add"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comments", atomLink.getHref()); // collection atomLink = links.getLinkForRel("collection"); Assert.assertNotNull(atomLink); Assert.assertEquals(url + "/book/foo/comment-collection", atomLink.getHref()); }
public void loadComments() throws RemoteException { comments = new ArrayList<Comment>(); // if the ticket was created via conversion, sometime past_history is empty (simply because the // source ticket doesn't have any..) // if this occurs, then we can simply ignore this. if (accessor != null) { GetRecordsResult_type0 coms[] = accessor.getComments(sys_id); if (coms != null) { for (GetRecordsResult_type0 com : coms) { Comment entry = new Comment(); entry.content = com.getValue(); entry.name = com.getSys_created_by(); try { entry.time = df.parse(com.getSys_created_on()); } catch (ParseException e) { logger.error( "ServiceNowTicket::loadComments: Couldn't parse date: " + com.getSys_created_on(), e); } // ignore status change only histories.. if (entry.content.length() > 0) { comments.add(entry); } } } else { logger.debug("Failed to load comments - maybe there is none?"); } } }
@Override public boolean equals(Object o) { if (!(o instanceof Comment)) return false; Comment com = (Comment) o; return com.id().equals(id()); }
@Override public void onCommand(CommandSender sender, String[] args, boolean confirmedCmd) throws IllegalArgumentException { final ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); final String reason = Utils.getFinalArg(args, 1); if(target == null){ if(!confirmedCmd && Core.getPlayerIP(args[0]).equals("0.0.0.0")){ mustConfirmCommand(sender, getName() + " " + Joiner.on(' ').join(args), _("operationUnknownPlayer", new String[] {args[0]})); return; } } if(sender instanceof ProxiedPlayer){ checkArgument(PermissionManager.canExecuteAction(Action.WARN , sender, ((ProxiedPlayer)sender).getServer().getInfo().getName()), _("noPerm")); } checkArgument(comment.hasLastcommentCooledDown(args[0]), _("cooldownUnfinished")); comment.insertComment(args[0], reason, Type.WARNING, sender.getName()); if(target != null){ target.sendMessage(__("wasWarnedNotif", new String[] {reason})); } BAT.broadcast(_("warnBroadcast", new String[]{args[0], sender.getName(), reason}), Action.WARN_BROADCAST.getPermission()); return; }
private void dispatchIssueCommentEditedEvent(Comment comment, Map<String, Object> parameters) { IssueEventBundle issueCommentBundle = issueEventBundleFactory.createCommentEditedBundle( comment.getIssue(), comment.getUpdateAuthorApplicationUser(), comment, parameters); issueEventManager.dispatchEvent(issueCommentBundle); dispatchEvent(EventType.ISSUE_COMMENT_EDITED_ID, comment, parameters); }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; itemposition = info.position; if (itemposition > 0) itemposition--; // hay que restar 1 porque la lista tiene un header Comment comment = listaComments.get(itemposition); // Cuando pulsamos nos aparece como tÃtulo la fecha y la hora para saber cual seleccionamos final int MAXLENGHT = 10; String txt = comment.getTxt(); if (txt.length() > MAXLENGHT) { // truncamos por la longitud maxima txt = txt.substring(0, MAXLENGHT) + " ..."; } menu.setHeaderTitle(comment.getUsername() + " : \"" + txt + "\""); byte[] img = comment.getImage(); if (img != null) { ByteArrayInputStream is = new ByteArrayInputStream(img); menu.setHeaderIcon(Drawable.createFromStream(is, "image")); } // si somos supervaca o somos los dueños del mensaje if ((BuildConfig.SUPERAPP) || (comment.getDevid() == Utilidades.getDevId(getActivity()))) { menu.add( FRAGMENT_GROUPID, R.id.action_borrar_comentario, 0, "Borrar comentario"); // podremos borrar } }
/** * Perform the action of the plugin. * * @param document the current document. */ public boolean perform(Document document) throws IOException { // Interact with the user to get the layer tag/ Tag layerTag = getLayerTagFromUser(document); if (layerTag == null) return false; // User cancled. Tag endTag = new Tag(layerTag.getName(), false); // Get the output stream to hold the new document text. PrintWriter out = new PrintWriter(document.getOutput()); // Create a lexical stream to tokenize the old document text. LexicalStream in = new LexicalStream(new SelectedHTMLReader(document.getInput(), out)); for (; ; ) { // Get the next token of the document. Token token = in.next(); if (token == null) break; // Null means we've finished the document. else if (token instanceof Comment) { Comment comment = (Comment) token; if (comment.isSelectionStart()) { out.print(layerTag); } else if (comment.isSelectionEnd()) { out.print(comment); out.print(endTag); continue; // So comment isn't printed twice. } } out.print(token); } out.close(); return true; }
/** Implement MouseListener interface highlight button state */ public void mouseEntered(MouseEvent e) { super.mouseEntered(e); this.setBorder(BorderFactory.createLineBorder(Color.yellow)); Comment comment = workspace.getEnv().getRenderableBlock(getBlockID()).getComment(); comment.setVisible(true); comment.showOnTop(); }
/** Tests that listeners are fired when a comment is rejected. */ public void testListenersFiredWhenCommentRejected() throws Exception { final StringBuffer buf = new StringBuffer("123"); final Comment comment = blogEntry.createComment( "title", "body", "author", "email", "website", "avatar", "127.0.0.1"); blogEntry.addComment(comment); comment.setPending(); service.putBlogEntry(blogEntry); CommentListener listener = new CommentListener() { public void commentAdded(CommentEvent event) {} public void commentRemoved(CommentEvent event) {} public void commentApproved(CommentEvent event) {} public void commentRejected(CommentEvent event) { assertEquals(comment, event.getSource()); buf.reverse(); } }; blog.getEventListenerList().addCommentListener(listener); comment.setRejected(); service.putBlogEntry(blogEntry); assertEquals("321", buf.toString()); }
/** * Insert data. * * @param comment the comment * @return the number of inserted */ public long insertComment(Comment comment) { this.insertComment.bindString(1, comment.getChatterId()); this.insertComment.bindString(2, comment.getCommentId()); this.insertComment.bindString(3, comment.getAuthor()); this.insertComment.bindString(4, comment.getBody()); return this.insertComment.executeInsert(); }
/** * Tests that listeners are not fired when a cloned comment is approved. Why? Because manipulating * comments from a blog entry decorator will generate excess events if not disabled. */ public void testListenersNotFiredWhenCommentApprovedOnClone() { comment.setPending(); comment = (Comment) comment.clone(); CommentListener listener = new CommentListener() { public void commentAdded(CommentEvent event) { fail(); } public void commentRemoved(CommentEvent event) { fail(); } public void commentApproved(CommentEvent event) { fail(); } public void commentRejected(CommentEvent event) { fail(); } }; blog.getEventListenerList().addCommentListener(listener); comment.setApproved(); }
private String postComment( String projectId, String entityId, String text, String name, String email) { if (projectId == null) throw new RuntimeException("projectId == null"); if (Str.isBlank(text)) throw new RuntimeException("Comment is empty."); Project project = projectDao.getById(projectId); AEntity entity = daoService.getById(entityId); Comment comment = commentDao.postComment(entity, "<nowiki>" + text + "</nowiki>", name, email, true); String message = "New comment posted"; if (!Str.isBlank(name)) message += " by " + name; subscriptionService.notifySubscribers(entity, message, project, email); project.updateHomepage(entity, true); String reference = ((ReferenceSupport) entity).getReference(); String label = ((LabelSupport) entity).getLabel(); ProjectEvent event = projectEventDao.postEvent( project, comment.getAuthorName() + " commented on " + reference + " " + label, entity); if (Str.isEmail(email)) subscriptionService.subscribe(email, entity); transactionService.commit(); webApplication.sendToConversationsByProject(project, event); return "<h2>Comment posted</h2><p>Thank you for your comment! It will be visible in a few minutes.</p><p>Back to <strong>" + KunagiUtl.createExternalRelativeHtmlAnchor(entity) + "</strong>.</p>"; }
/** * Delete a comment from a song. * * @param authorId The author of the song. */ public void deleteComment(String authorId, Date date) { for (Comment comment : comments) { if (comment.getAuthor().equals(authorId) && comment.getDate().equals(date)) { comments.remove(comment); return; } } }
/** Tests that the title is set when an owning blog entry is present. */ public void testTitleTakenFromOwningBlogEntryWhenNotSpecified() { BlogEntry entry = new BlogEntry(blog); entry.setTitle("My blog entry title"); comment = entry.createComment(null, "", "", "", "", "", ""); assertEquals("Re: My blog entry title", comment.getTitle()); comment = entry.createComment("", "", "", "", "", "", ""); assertEquals("Re: My blog entry title", comment.getTitle()); }
private void mapComment(JSONObject jsonComment, Comment comment) throws JSONException { comment.setId(jsonComment.getInt("id")); comment.setUsername( jsonComment.getJSONObject("links").getJSONObject("user").getString("title")); comment.setText(jsonComment.getString("text")); comment.setTimestamp(ReviewboardUtil.marshallDate(jsonComment.getString("timestamp"))); }
/** Implement MouseListener interface de-highlight button state */ public void mouseExited(MouseEvent e) { super.mouseExited(e); this.setBorder(BorderFactory.createLineBorder(Color.gray)); Comment comment = workspace.getEnv().getRenderableBlock(getBlockID()).getComment(); if (!isActive()) { comment.setVisible(false); } }
/** Tests that the date can never be null. */ public void testDate() { assertNotNull(comment.getDate()); comment.setDate(new Date()); assertNotNull(comment.getDate()); comment.setDate(null); assertNotNull(comment.getDate()); }
private Comment createComment(int i, UUID targetId) { Comment comment = new Comment(); comment.setTargetId(targetId); comment.setAuthor("Pretentious Douchebag " + i); comment.setContent("This test sucks. 0/5 would not test again."); comment.setImage(bitmap); return comment; }
private void populateGenericValueFromComment(Comment updatedComment, GenericValue commentGV) { ApplicationUser updateAuthor = updatedComment.getUpdateAuthorApplicationUser(); commentGV.setString("updateauthor", updateAuthor == null ? null : updateAuthor.getKey()); commentGV.setString("body", updatedComment.getBody()); commentGV.setString("level", updatedComment.getGroupLevel()); commentGV.set("rolelevel", updatedComment.getRoleLevelId()); commentGV.set( "updated", JiraDateUtils.copyOrCreateTimestampNullsafe(updatedComment.getUpdated())); }
@Override public int parseJson(JSONObject json) { // TODO Auto-generated method stub try { id = json.getString("id"); JSONObject fromObject = json.getJSONObject("from"); from = new From(fromObject.getString("id"), fromObject.getString("name")); createdTime = json.getString("created_time"); JSONObject applicationObject = json.getJSONObject("application"); application = new From(applicationObject.getString("id"), applicationObject.getString("name")); achievement = new Achievement(); JSONObject achiveObject = json.getJSONObject("achivement"); achievement.setId(achiveObject.getString("id")); achievement.setUrl(achiveObject.getString("url")); achievement.setType(achiveObject.getString("type")); achievement.setTitle(achiveObject.getString("title")); likes = new Like(); JSONObject likeObject = json.getJSONObject("likes"); JSONArray likeArray = likeObject.getJSONArray("data"); ArrayList<From> likeList = new ArrayList<From>(likeObject.getInt("count")); for (int i = 0; i < likeObject.getInt("count"); i++) { likeList.add( new From( likeArray.getJSONObject(i).getString("id"), likeArray.getJSONObject(i).getString("name"))); } likes = new Like(likeList, likeObject.getInt("count")); comments = new ArrayList<Comment>(); JSONObject commentObject = json.getJSONObject("comments"); JSONArray commentArray = commentObject.getJSONArray("data"); for (int i = 0; i < commentObject.getInt("count"); i++) { Comment tmp = new Comment(); tmp.setId(commentArray.getJSONObject(i).getString("id")); tmp.setFrom( new From( commentArray.getJSONObject(i).getJSONObject("from").getString("id"), commentArray.getJSONObject(i).getJSONObject("from").getString("name"))); tmp.setMessage(commentArray.getJSONObject(i).getString("message")); tmp.setCreateTime(commentArray.getJSONObject(i).getString("created_time")); comments.add(tmp); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
public Comment addComment(String message, Account currAccount, Task task) { Hibernate.initialize(task.getComments()); Comment comment = new Comment(); comment.setTask(task); comment.setAuthor(currAccount); comment.setDate(new Date()); comment.setMessage(message); wlSrv.addActivityLog(task, message, LogType.COMMENT); return save(comment); }
public static void write(IceInternal.BasicStream __os, java.util.List<Comment> __v) { if (__v == null) { __os.writeSize(0); } else { __os.writeSize(__v.size()); for (Comment __elem : __v) { __elem.__write(__os); } } }
@Override public ChangeItemBean delete(Comment comment) { ChangeItemBean changeItemBean = constructChangeItemBeanForCommentDelete(comment); // TODO: move this into the Store (when it gets created) delegator.removeByAnd( "Action", FieldMap.build("id", comment.getId(), "type", ActionConstants.TYPE_COMMENT)); this.jsonEntityPropertyManager.deleteByEntity( EntityPropertyType.COMMENT_PROPERTY.getDbEntityName(), comment.getId()); return changeItemBean; }
// TODO: the event generation should live in the service // This is mostly here for testing purposes so we do not really need to dispatch the event to know // it was called correctly void dispatchEvent(Long eventTypeId, Comment comment, Map<String, Object> parameters) { issueEventManager.dispatchRedundantEvent( eventTypeId, comment.getIssue(), comment.getUpdateAuthorUser(), comment, null, null, parameters); }
public boolean equalsComment(Comment c) { if (c.getCommenter().equals(commenter)) { if (c.getComment().equals(comment)) { if (c.getDate().equals(date)) { return true; } } } return false; }
protected void onPostExecute(JSONObject json) { int success; String mensaje; int totalcount; try { success = json.getInt(Constantes.JSON_SUCCESS); mensaje = json.getString(Constantes.JSON_MESSAGE); if (success == 1) { // si fue bien totalcount = json.getInt("totalcount"); JSONArray messageList = json.getJSONArray("listmessages"); listaComments.clear(); for (int i = 0; i < messageList.length(); i++) { // se supone que solo tiene que haber uno JSONObject message = messageList.getJSONObject(i); String id = message.getString("id"); String username = message.getString("username"); String txt = message.getString("msg"); String timestamp = message.getString("timestamp"); String cartelBase64 = message.getString("image"); String devid = message.getString("devid"); byte[] image = Base64.decode(cartelBase64, Base64.DEFAULT); Comment comment = new Comment(image, txt, username, timestamp, devid, id); comment.print("comment = "); listaComments.add(comment); } commentsadapter.notifyDataSetChanged(); ///// PONEMOS VISIBILIDAD ADECUADA AL BOTON DE SHOW MORE COMMENTS Toast.makeText(getActivity(), Integer.toString(totalcount), Toast.LENGTH_LONG); if (totalcount > Constantes .NUMBER_MAX_COMMENTS_SHOW) { // si es mayor que el limite maximo que queremos // cargar if (totalcount == listaComments.size()) btnShowMore.setVisibility(View.GONE); // else btnShowMore.setVisibility(View.VISIBLE); } else btnShowMore.setVisibility(View.GONE); ///////////////////////////////////////////////// 7 if (listaComments.size() == 1) { tvCountComments.setText(Integer.toString(messageList.length()) + " comentario"); } else { tvCountComments.setText(Integer.toString(messageList.length()) + " comentarios"); } } else { Toast.makeText(getActivity(), mensaje, Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } }
public SortedSet<Comment> getFilteredComments() { SortedSet<Comment> filteredComments = new TreeSet<Comment>(); for (Comment c : this.comments) { if (!c.getForbidden()) { filteredComments.add(c); } } return filteredComments; }
public Comment getInstance() { if (instance == null) { log.info("create new comment instance"); instance = new Comment(); instance.setAuthor(user); instance.setBlogEntry(blogEntry); } log.info("return comment instance " + instance); return instance; }