How to set a work item's QA Team and Phase Found using RTC Plain Java API?
According to posts in this forum, I should use following code to set QA Team and Phase Found.
IAttribute qaAttribute = workItemClient.findAttribute(projectArea, "qa_team", null);
IAttribute phaseAttribute = workItemClient.findAttribute(projectArea, "howfound", null);
workItem.setValue(IAttribute, Object);
But My Question is:
If I have known the QA Team's name(For example, FVT), and PhaseFound's name(For example, Phase 1), how to get those objects which would be used by workItem.setValue(...)?
Which class and method should I use to get the corresponding objects. I want to know how to write the code as below:
IAttribute foundInAttribute = workItemClient.findAttribute(projectArea, "foundIn", null);
IDeliverable foundIN = workItemClient.findDeliverableByName(projectArea, foundIn,
IDeliverable.SMALL_PROFILE, null);
Of course, other implementation is welcome.
Thanks in advance.
----------------------
These two attributes might be customized attributes:
attributetype: test_team
identifier: qa_team
attributetype: HowFound
identifier: howfound
Accepted answer
3 other answers
private static class WorkItemInitialization extends WorkItemOperation {private String fSummary;private ICategoryHandle fCategory;private IIterationHandle fIteration;HashMap<IAttribute, Object> fAttributes;public WorkItemInitialization(String summary, ICategoryHandle category, IIterationHandle iteration, HashMap attributes) {super("Initializing Work Item");fSummary= summary;fCategory= category;fAttributes = attributes;fIteration = iteration;}@Overrideprotected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {IWorkItem workItem= workingCopy.getWorkItem();workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));workItem.setCategory(fCategory);
workItem.setTarget(fIteration);Iterator keys = fAttributes.keySet().iterator();while(keys.hasNext()){IAttribute key = (IAttribute)keys.next();Object value = fAttributes.get(key);workItem.setValue(key, value);}}}.....
String repositoryURI= "https://xx.ibm.com:8001/jazz/";//String userId= "XXX";String password= "XXX";String projectAreaName= "Lotus Connections";String typeIdentifier= "defect";
String summary = "Post install bvt";String categoryName= "Web/Cross Functional/Automation";//args[6];//filedAgainstString plannedFor = "Main development/Release Backlog/2014 Development";//required by task, defectString foundIn = "Automated BVT";//required by defectString qaTeam = "Functional (FVT)";//required by defectString phaseFound = "Functional (FVT)";//required by defect...IWorkItemType workItemType= workItemClient.findWorkItemType(projectArea, typeIdentifier, null);if (workItemType == null) {System.out.println("Work item type not found.");return false;}....
IAttribute phaseAttribute = workItemClient.findAttribute(projectArea, "howfound", null);Identifier literalID_phase = null;IEnumeration enumeration_phase =workItemClient.resolveEnumeration(phaseAttribute, null);List literals_phase = enumeration_phase.getEnumerationLiterals();for (Iterator iterator = literals.iterator(); iterator.hasNext();) {ILiteral iLiteral = (ILiteral) iterator.next();if (iLiteral.getName().equals(phaseFound)) {literalID_phase = iLiteral.getIdentifier2();System.out.println("You found phase!!");break;}}if(literalID_phase==null){System.out.println("not found phase");return false;}attributes.put(foundInAttribute, foundIN);attributes.put(qaAttribute, literalID);attributes.put(phaseAttribute, literalID_phase);...
WorkItemInitialization operation= new WorkItemInitialization(summary, category, cih, attributes);IWorkItemHandle handle= operation.run(workItemType, null);IWorkItem workItem= auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null);System.out.println("Created work item " + workItem.getId() + ".");