Question on discussion Attribute for a RTC work item using Plain Java API
hi , did anyone extract data from
discussion
field in a RTC work item using Plain JAVA API’s? I created small application which is extracting some fields but could not able to pull the discussion data due to assertion failures. Did anyone try this? Please advise. Thank you.
Exception in thread "main" org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.getValue(WorkItemImpl.java:2877)
at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at com.sun.proxy.$Proxy22.getValue(Unknown Source)
at CiasQrtc.ExpandWorkitems(xxxxxx.java:216)
at CiasQrtc.processUnresolvedResults(xxxxx.java:189)
at CiasQrtc.findPersonalQuery(xxxx.java:128)
at CiasQrtc.main(xxxxx.java:74)
Accepted answer
/** * 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(); }
3 other answers
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); workItem.setHTMLDescription(XMLString.createFromPlainText(fSummary));
Hi Ralph, Thank you for taking some time in responding .
Hi,
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110) ~[org.eclipse.equinox.common_3.6.100.v20120522-1841-6.0.5.jar:na]
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96) ~[org.eclipse.equinox.common_3.6.100.v20120522-1841-6.0.5.jar:na]
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.getValue(WorkItemImpl.java:2883) ~[com.ibm.team.workitem.common_3.2.900.v20170928_1641-6.0.5.jar:na]
at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_232]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_232]
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597) ~[com.ibm.team.repository.common_1.4.4000.v20171031_1821-6.0.5.jar:na]
at com.sun.proxy.$Proxy145.getValue(Unknown Source) ~[na:na]
at com.fake.package.name.RtcWorkItemHelper.fetchPropertiesFromWorkItem(RtcWorkItemHelper.java:115) ~[fria-automation-0.0.1-SNAPSHOT.spring:na]
final List<IAttribute> attributes = workItemClient.findAttributes(projectArea, monitor);
for (final String propertyName : propertyNames) {
for (IAttribute attribute : attributes) {
if (propertyName.equals(attribute.getDisplayName())) {
final Object propertyValue = workItem.getValue(attribute);</pre>
Comments
- Conver this in your own question
-
Just because an attribute is defined for a work item type, it does not necessarily be available on all of these items. You can test with workItem.hasAttribute(attribute)
Hi Ralph,
thanks for quick answer.
I am 100% that i saw on the RTC GUI that the work item on which I'm getting the error has the attribute on which the error is shown.
I'll check if the hasAttribute() method returns 'true' on Monday when I get the access to client's environment.
But, what bothers me is that I obviously can't change that attribute on that work item (because of this error).
Do you have any other guidances?
I'll convert this to my own question on Monday when I'll have additional information.
Thanks for your suggestions.
In the end it turned out that client has two attributes with the same display name, but different id in project area.
Problem was solved with requesting client to enter attribute ids instead of display names.
Good advice. I would consider it a best practice.