Cannot set custom attribute value (of type Enumeration) using rtc client libraries

StackOverflow https://stackoverflow.com/questions/23564098

  •  18-07-2023
  •  | 
  •  

문제

I'm trying to write a Java tool to set a custom attribute on a jazz work item.
The custom attribute has following definition:

Name: Phase Found
Type: HowFound (Enumeration)
ID: howfound`

Literals for HowFound:

Name: Automation
Name: Testing

This is the Java code which tries to set the custom attribute's value.
Note: log.info("Phase found: workitem has attribute"); is printed, so I know it finds the attribute, just cannot set value.

public class WorkItemInitialization extends WorkItemOperation {

    private static Logger log = Logger.getLogger(WorkItemInitialization.class.getName());

    public WorkItemInitialization(ICategoryHandle filedAgainst) {
        super("Initializing Work Item");
    }

    protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {

        log.info("Executing work item changes.");
        IWorkItem workItem = workingCopy.getWorkItem();

        IWorkItemClient workItemClient = (IWorkItemClient) Main.repo.getClientLibrary(IWorkItemClient.class);
        IAttribute phaseFound = workItemClient.findAttribute(Main.projectAreaRTC, "howfound", monitor);
        if (workItem.hasCustomAttribute(phaseFound)){
            log.info("Phase found: workitem has attribute");

            IEnumeration<? extends ILiteral> myEnumeration = workItemClient.resolveEnumeration(phaseFound, monitor);
            ILiteral targetLiteral = null;

            for(ILiteral literal : myEnumeration.getEnumerationLiterals()) {

                if(literal.getName().equals("Automation")) {

                    targetLiteral = literal;
                }
            }
            workItem.setValue(phaseFound, targetLiteral);
        }
    }
}

This is the error I get when running:

Exception in thread "main" java.lang.ClassCastException: com.ibm.team.workitem.common.internal.model.ConfigurationItem incompatible with com.ibm.team.workitem.common.model.Identifier
    at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2945)
도움이 되었습니까?

해결책

this was very helpful
http://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/

private static Identifier getLiteralEqualsString(String name, IAttributeHandle ia) throws TeamRepositoryException {
    IWorkItemClient workItemClient = (IWorkItemClient) teamrepository.getClientLibrary(IWorkItemClient.class);

    Identifier literalID = null;
    IEnumeration enumeration = workItemClient.resolveEnumeration(ia, null); // or IWorkitemCommon
    List literals = enumeration.getEnumerationLiterals();
    for (Iterator iterator = literals.iterator(); iterator.hasNext();) {
        ILiteral iLiteral = (ILiteral) iterator.next();
        if (iLiteral.getName().equals(name)) {
            literalID = iLiteral.getIdentifier2();
            break;
        }
    }
    return literalID;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top