It's all about the answers!

Ask a question

Question on discussion Attribute for a RTC work item using Plain Java API


premkumar sankaranarayanan (512) | asked Jan 07 '20, 10:06 a.m.

 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


permanent link
Ralph Schoon (61.4k33643) | 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



permanent link
Ralph Schoon (61.4k33643) | 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.

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

 


permanent link
premkumar sankaranarayanan (512) | answered Jan 07 '20, 3:25 p.m.

 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));


permanent link
Dino Jurina (11) | answered Jul 03 '20, 11:30 a.m.
edited Jul 03 '20, 11:31 a.m.

 Hi,


I'm getting almost the same error, using rtc plain java api 6.0.5: 

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]

It happens on one property in one specific project area.
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);

for (final String propertyName : propertyNames) {
for (IAttribute attribute : attributes) {
if (propertyName.equals(attribute.getDisplayName())) {
final Object propertyValue = workItem.getValue(attribute);

</pre>

Comments
Ralph Schoon commented Jul 03 '20, 12:30 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
  1. Conver this in your own question
  2. 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)

Dino Jurina commented Jul 03 '20, 3:18 p.m.

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.


Ralph Schoon commented Jul 06 '20, 4:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

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.


Ralph Schoon commented Jul 06 '20, 8:50 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Good advice. I would consider it a best practice.

Your answer


Register or to post your answer.