无法使用rtc客户端库设置自定义属性值(类型为Enumeration)

时间:2014-05-09 11:59:36

标签: java rtc

我正在尝试编写一个Java工具来为爵士乐工作项设置自定义属性 自定义属性具有以下定义:

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

HowFound的文字:

Name: Automation
Name: Testing

这是尝试设置自定义属性值的Java代码 注意:打印log.info("Phase found: workitem has attribute");,因此我知道它找到了属性,只是无法设置值。

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

这是我在运行时遇到的错误:

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)

1 个答案:

答案 0 :(得分:1)

这非常有帮助 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;
}