It's all about the answers!

Ask a question

Not able to set the value take from the local database to store in the Description field after saving the workitem. (Follow up action Participant)


Manjunath Badiger (3219) | asked Jan 04 '18, 12:25 p.m.
edited Jan 05 '18, 10:39 a.m.

Hello,

I had stored the value from the local database to String attribute declared as below ;-  
  
public String test;

And stored the value fetched from the database like this :-

test = rs.getString("test");

And then created the string which stores the value taken from the database

final String test1 = test; 

And tried to set the value  as shown below. 
workingCopy.setHTMLDescription(XMLString.createFromPlainText(test1)); 

After saving the workitem it does not store the value in the description field. Is there any other method to implement this??

Hello,

Please find below code, this is the issue which I had mentioned above.

package part;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.foundation.common.text.XMLString;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.runtime.IOperationParticipant;
import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.common.internal.SaveParameter;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;


public class AbstractService extends  com.ibm.team.repository.service.AbstractService implements
IOperationParticipant {
private static final String Recursion = "MyPluginUniqueKey";
private static Set<String> bypass = new HashSet<String> (new ArrayList<String>(Arrays.asList(Recursion)));
private static String TEST_CASE_ID = new String();
private static String MINT_ISSUE_ID = new String();

public String ftest;
public AbstractService() {
// TODO Auto-generated constructor stub
}

@SuppressWarnings("restriction")
@Override
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.
                getConnection("jdbc:oracle:thin:@localhost:1521:test"
                    ,"admin","admin123");
            Statement stmt = con.createStatement();
            System.out.println("Created DB Connection....");
            
            String query = "SELECT * FROM RMDV_MINT_ISSUE_DETAILS";
            PreparedStatement pst = con.prepareStatement(query);
            
            ResultSet rs = pst.executeQuery();
            
            while(rs.next())
            {
            
            TEST_CASE_ID = rs.getString("TEST_CASE_ID");
            MINT_ISSUE_ID = rs.getString("MINT_ISSUE_ID");
            
            System.out.format("%s, %s\n", TEST_CASE_ID, MINT_ISSUE_ID);
            
            
            }
            
            pst.close();
             
          } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        
    Object obj = operation.getOperationData();
    SaveParameter save = (SaveParameter)obj;
    
    IAuditable au = save.getNewState();
    
    if((save.getAdditionalSaveParameters()== null)|| (save.getAdditionalSaveParameters()!=null)&& (!save.getAdditionalSaveParameters().contains(this.Recursion)))
    {
    
    final String name = MINT_ISSUE_ID;
   
    ftest = name;
  
    if(au instanceof IWorkItem)
    {
   
    IWorkItem work = (IWorkItem)au;
    IWorkItemServer serverWI = getService(com.ibm.team.workitem.service.IWorkItemServer.class);
    IWorkItem workingCopy = (IWorkItem) serverWI.findWorkItemById(work.getId(), IWorkItem.FULL_PROFILE,null).getWorkingCopy();
    workingCopy.getTags2().add("Hello World RTC Extension");
      
    workingCopy.setHTMLDescription(XMLString.createFromPlainText(ftest));
    serverWI.saveWorkItem3(workingCopy, null, null, this.bypass);
   
    }
    
    }

}

}

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Jan 05 '18, 10:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

My suggestion would to look into some existing examples and check how they do it. One that might be helpful is https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/

Otherwise there is not any information in your question that would hint at any possible issue.

Manjunath Badiger selected this answer as the correct answer

Comments
Manjunath Badiger commented Jan 05 '18, 10:47 a.m.

Hello Sir,


Please check the code, which I had mentioned in the above question. The issue is I am not able to store the database value in the description field all other things works fine, but when I try to set the database value in the description it does not work at all.
What would be the problem??


1
Ralph Schoon commented Jan 05 '18, 11:11 a.m. | edited Jan 05 '18, 11:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I have looked at the code that was available at that time. Anyway, I am not inclined to debug your code. There is no error message or anything, so I stay with my suggestion to look into working examples and try to figure out what is going wrong, or you debug what happens. 

This, the findWorkItemById(), does absolutely not make any sense by the way:

    IWorkItem workingCopy = (IWorkItem) serverWI.findWorkItemById(work.getId(), IWorkItem.FULL_PROFILE,null).getWorkingCopy();
    workingCopy.getTags2().add("Hello World RTC Extension");

workingCopy.setHTMLDescription(XMLString.createFromPlainText(ftest));
serverWI.saveWorkItem3(workingCopy, null, null, this.bypass);

You already have the work item and I would again suggest to look into the example I gave, how that example gets the working copy for the current work item.

Finally, you usually get the data you need after deciding if you have to do something, so accessing the other database would be something you do last, when the information is needed.


Manjunath Badiger commented Jan 05 '18, 11:21 a.m.

Thank you Sir.


That is what there is no error or anything, but still It does not work, if I tried to set the database value after saving the workitem.


1
Ralph Schoon commented Jan 05 '18, 12:38 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

No reason to "sir" me. Look at the example code.

I think the way you get the workingcopy might be the issue. Again, look at the example and read the blog.

I would remove or comment out the database code for the time being and just print the date or append something to the description, just to reduce complexity until you can change the attribute.

A common issue is that


Manjunath Badiger commented Jan 06 '18, 1:02 a.m.

 OK, Thank you once again.


Manjunath Badiger commented Jan 08 '18, 2:51 a.m.

Hello Ralph,


In the example provided by you, there you taken Attribute ID as hard coded. Is this Attribute ID is same as the Attribute ID which we get under :-  Process Configuration -> Project Configuration ->Configuration Data ->Work Items->Types and Attributes->Attributes->Edit section where each attribute has specific id. Are these both same or different.


1
Ralph Schoon commented Jan 08 '18, 3:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I explained in https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ which ways there are to access the attributes. Depending on which attribute there are more than one way to gt the attribute ID and to get attributes.

Unfortunately the one you describe in your comment - using the project area admin in the RTC Eclipse client does not provide you with a correct ID. The id's exposed for non custom (internal) attributed there are for a different purpose and don't work for getting the IAttribute.  The easiest way to find the ID, if it is not available in the IWorkItem interface is to look into the Web project area administration UI.

For the description, you can use the available getters and setters.


Manjunath Badiger commented Jan 08 '18, 4:15 a.m. | edited Jan 08 '18, 4:17 a.m.

Thank you, Ralph.


This will help me a lot!

showing 5 of 8 show 3 more comments

Your answer


Register or to post 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.