Question on discussion Attribute for a RTC work item using Plain Java API
hi , did anyone extract data from
Exception in thread "main" org.eclipse.core.runtime.AssertionFailedException: assertion failed: |
Accepted answer
Ralph Schoon (63.7k●3●36●48)
| answered Jan 08 '20, 2:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Jan 08 '20, 3:52 a.m.
Sorry, I somehow missed the point.
The Discussion is not a real attribute. It is a collection of (comment) objects. Here how I access it.
/** * Convert the comments data into a string containing all the comments * * @param workItem * @return * @throws TeamRepositoryException */ private String calculateCommentsAsString(IWorkItem workItem) throws TeamRepositoryException { IComments comments = workItem.getComments(); IComment[] theComments = comments.getContents(); List<string> commentText = new ArrayList<string>(theComments.length); int i = 1; for (IComment aComment : theComments) { if (i > 1) { commentText.add("\r"); } commentText.add(i + ". " + getCommentAsString(aComment)); i++; } return StringUtil.listToString(commentText, SEPERATOR_NEWLINE); } </string></string> This is how to get the content of the comment: /* * Get one comment as string * * @param aComment * @return * @throws TeamRepositoryException / private String getCommentAsString(IComment aComment) throws TeamRepositoryException { String creator = calculateContributorAsString(aComment.getCreator()); String creationDate = calculateTimestampAsString(aComment.getCreationDate()); return creator + " - " + creationDate + SEPERATOR_NEWLINE + aComment.getHTMLContent().getPlainText(); } premkumar sankaranarayanan selected this answer as the correct answer
|
3 other answers
Ralph Schoon (63.7k●3●36●48)
| answered Jan 07 '20, 11:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I have been always able to get the description. Since there is no hint which code fails, not able to speculate what goes wrong.
In general I have described the basics here: https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
There is a dedicated API for the description, that can be used as well. https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ shows how to get and set it. It is available for the summary as well.
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); workItem.setHTMLDescription(XMLString.createFromPlainText(fSummary));
there is a getter as well. You should be able to use the IAttribute as well, check what the object type is.
Comments
premkumar sankaranarayanan
commented Jan 07 '20, 3:26 p.m.
could not able to respond you here because of some restrictions. Posted my response below |
Hi Ralph, Thank you for taking some time in responding .
I referred all these items before but could not able to resolve the specific issue am facing.
I'm trying to fetch the Custom Attribute called discussion which is of type html.
I pulled the source code of WorkitemImpl and looked into the method where it is failing. It looks like it is failing at the Assertion where it is checking whether the attribute is present or not and I guess it is failing right exactly there. I'm not quite sure if there would be a list of custom and built-in attributes which can compared to check for fetching the work item attribute to get data.
public Object getValue(IAttribute attribute) {
Assert.isTrue(hasAttribute(attribute));
|
Hi,
I'm getting almost the same error, using rtc plain java api 6.0.5:
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
I'm successfully getting values from other properties in that project area and I'm fetching the value of that same property in another project area created with the same template.
The error pops out on the last line of this block (final Object propertyValue = workItem.getValue(attribute); - is the line 115 where I am getting errors)
And it's very strange because findAttributes() returns the attribute as one of the possible attributes, but workItem.getValue(attribute) throws the exception saying that the attribute is not available on the work item.
Any guidances?
final List<IAttribute> attributes = workItemClient.findAttributes(projectArea, monitor); Comments
Ralph Schoon
commented Jul 03 '20, 12:30 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Dino Jurina
commented Jul 03 '20, 3:18 p.m.
Hi Ralph,
Unless you have more data, I don't have anything. My suggestions are on my blog e.g. https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
You could try using the WCL https://rsjazz.wordpress.com/2019/07/03/work-item-command-line-5-0/ to see if it has the same issue. The WCL also has a lot of example code for reading and updating work items.
Dino Jurina
commented Jul 06 '20, 8:38 a.m.
Thanks for your suggestions.
Good advice. I would consider it a best practice.
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.