Problem when creating a new defect in rtc
Hello,
I am ussing Java Plain Client Libr. I want to create a new defect from a simple java app.
I am ussing a class that extends WorkItemOperation.
and the code for my exectute method is:
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem= workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
workItem.setCreator(teamRepository.loggedInContributor());
workItem.setOwner(teamRepository.loggedInContributor());
IAuditableClient client= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
List<IAttribute> customAttribs = client.resolveAuditables(workItem.getCustomAttributes(), IAttribute.FULL_PROFILE, null);
for (IAttribute ia : customAttribs) {
System.out.println( " attribute name:" + ia.getDisplayName()+" default value "+ia.getDefaultValue(client, workItem, null));
workItem.setValue(ia,ia.getDefaultValue(client, workItem, null) );
System.out.println(" the new attribute value = "+workItem.getValue(ia)+" the value is set = "+workItem.isAttributeSet(ia));
if(ia.getDisplayName().contains("ODC Trigger"))
{
workItem.setValue(ia,existingItemCustomAtt.get(1).getValue(client, workItem, null));
}
if(ia.getDisplayName().contains("ODC Activity"))
{
workItem.setValue(ia,existingItemCustomAtt.get(2).getValue(client, workItem, null));
}
if(ia.getDisplayName().contains("ODC Impact"))
{
workItem.setValue(ia,existingItemCustomAtt.get(0).getValue(client, workItem, null));
}
}
workingCopy.save(null);
}
}
In the existingItemCustomAtt list I have put values from another defect for the 3 custom attributes.
The work item does not get saved. Do you know why?
The same code but used for creating a task works... I guess that the problem are the custom attributes for ODC information when creating a defect.
Thanks
5 answers
Like I've said, if I try to create a task, the task is created. But if I try to create a defect ( String typeIdentifier= "task";) it gives me:
Name: Save Work Item
ID: com.ibm.team.workitem.operation.workItemSave
Severity: ERROR
Name: Required Properties
ID: com.ibm.team.workitem.advisor.requiredProperties
Severity: ERROR
Summary: Attribute 'ODC Trigger' not set
Description: The 'ODC Trigger' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Summary: Attribute 'ODC Impact' not set
Description: The 'ODC Impact' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Summary: Attribute 'ODC Activity' not set
Description: The 'ODC Activity' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Name: Required Approvals
ID: com.ibm.team.workitem.advisor.requiredApprovals
Severity: OK
Name: Dynamic Required Attributes
ID: com.ibm.team.workitem.advisor.requiredAttributes
Severity: OK
Name: Attribute Validation
ID: com.ibm.team.workitem.advisor.validation
Severity: OK
Name: SPoRT Duplicate Work Item Check
ID: com.ibm.sport.rtc.process.service.operationAdvisors.duplicateWorkItemCheck
Severity: OK
1. I never use workingCopy.save() in such an operation. The operation handles that outside. Try to remove that statement.
2. I use code like the below to make sure the attribute actually exists on the element (especially for modify). i have seen a bunch of people using the display name instead of the ID and fetching the wrong attribute, that actually was not defined or used for a type, in which case you just get issue. Otherwise, I can't tell. Kind of hard to debug on my end, missing the schema and the complete code.
IAttribute customString = workItemClient.findAttribute(fProjectArea,
fCustomStringAttributeID, null);
if(null!=customString){
if(workItem.hasCustomAttribute(customString))
workItem.setValue(customString, fCustomString);
}
2. I use code like the below to make sure the attribute actually exists on the element (especially for modify). i have seen a bunch of people using the display name instead of the ID and fetching the wrong attribute, that actually was not defined or used for a type, in which case you just get issue. Otherwise, I can't tell. Kind of hard to debug on my end, missing the schema and the complete code.
IAttribute customString = workItemClient.findAttribute(fProjectArea,
fCustomStringAttributeID, null);
if(null!=customString){
if(workItem.hasCustomAttribute(customString))
workItem.setValue(customString, fCustomString);
}
I've changed my execute code into
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem= workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
workItem.setCreator(teamRepository.loggedInContributor());
workItem.setOwner(teamRepository.loggedInContributor());
workItem.setDuration(10000);
IAuditableClient client= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
List<IAttribute> customAttribs = client.resolveAuditables(workItem.getCustomAttributes(), IAttribute.FULL_PROFILE, null);
IAttribute customString = workItemClient.findAttribute(projectArea,
"ODC_Defect_Target", null);
if(null!=customString){
if(workItem.hasCustomAttribute(customString))
{
workItem.setValue(customString, customString.getDefaultValue(client, workItem, null));
System.out.println("Is set ="+workItem.isAttributeSet(customString));
}
}
IAttribute acttring = workItemClient.findAttribute(projectArea,
"ODC_Activity", null);
if(null!=acttring){
if(workItem.hasCustomAttribute(acttring))
{
workItem.setValue(acttring, acttring.getDefaultValue(client, workItem, null));
System.out.println("Is set ="+workItem.isAttributeSet(acttring));
}
}
IAttribute impactString = workItemClient.findAttribute(projectArea,
"ODC_Impact", null);
if(null!=impactString){
if(workItem.hasCustomAttribute(impactString))
{
workItem.setValue(impactString, impactString.getDefaultValue(client, workItem, null));
System.out.println("Is set ="+workItem.isAttributeSet(impactString));
}
}
}
but the same problem.
com.ibm.team.process.common.advice.TeamOperationCanceledException: 'Save Work Item' failed. Preconditions have not been met: The 'ODC Trigger' attribute needs to be set (work item <05:26:54>).
Name: Save Work Item
ID: com.ibm.team.workitem.operation.workItemSave
Severity: ERROR
Name: Required Properties
ID: com.ibm.team.workitem.advisor.requiredProperties
Severity: ERROR
Summary: Attribute 'ODC Trigger' not set
Description: The 'ODC Trigger' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Summary: Attribute 'ODC Impact' not set
Description: The 'ODC Impact' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Summary: Attribute 'ODC Activity' not set
Description: The 'ODC Activity' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Name: Required Approvals
ID: com.ibm.team.workitem.advisor.requiredApprovals
Severity: OK
Name: Dynamic Required Attributes
ID: com.ibm.team.workitem.advisor.requiredAttributes
Severity: OK
Name: Attribute Validation
ID: com.ibm.team.workitem.advisor.validation
Severity: OK
Name: SPoRT Duplicate Work Item Check
ID: com.ibm.sport.rtc.process.service.operationAdvisors.duplicateWorkItemCheck
Severity: OK
In debug mode the code goes into all of the three setValue lines and at "Is set" it prints true in all of the three cases.
Since this morning I'm working on this issue and I honestly don;t know what to do to it anymore.
If you debug this in Eclipse (see https://jazz.net/library/article/807 how to set this up), does the code find the attributes? If you don't want to debug, consider to put in System.out.println() statement and getValue() to understand if the code actually is called..
Comments
showing 5 of 7
show 2 more comments