我为工作项创建了一个Java提供的属性,该属性通过查看来自同一/当前工作项的两个其他属性(枚举)来提供值集,这些属性一起形成java提供的属性将创建的目录路径使用嵌套在该目录中的文件名设置值。如果首次创建工作项,则效果很好但是在修改工作项时,它无法填充集,因此可以选择新值。
我发现它到达这个陈述:
IAttribute currentAttribute =(IAttribute)句柄;
生成异常。它无法转换为IAttribute句柄,因为来自workItem.getCustomAttributes()的返回项在新Wotk项和修改后的工作项之间是不同的。
异常消息是:
com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl与com.ibm.team.workitem.common.model.IAttribute不兼容
我不知道为什么如何获取com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl用于修改工作项和... ... AttributeHandle用于首次创建作品项目
我不知道如何解决这个问题或将其投射到我所需要的IAttribute上。
public class SpecificArtifactType implements IValueSetProvider<String> {
private List<String> list;
public SpecificArtifactType() {
}
@Override
public List<String> getValueSet(IAttribute attribute, IWorkItem workItem,
IWorkItemCommon workItemCommon, IConfiguration configuration,
IProgressMonitor monitor) throws TeamRepositoryException {
String idValue= "";
String deliverableArtifactTypeValue= "";
List<IAttributeHandle> customAttributeHandles= workItem.getCustomAttributes();
/*
* THE DELIVERABLE ARTIFACT AND ID VALUES ARE BOTH USED TO BUILD
* THE DIRECTORY PATH WHICH THIS ATTRIBUTE WILL USE TO POPULATE
* ITS VALUE SET WITH THE ARTIFACTS LOCATED AT THAT LOCATION.
*/
for (IAttributeHandle handle: customAttributeHandles)
{
IAttribute currentAttribute= (IAttribute) handle;
if (currentAttribute.getDisplayName()
.equals(ICustomAttributeDefinitions.ID))
{
idValue= getValue(currentAttribute, monitor, workItemCommon, workItem);
}
else if (currentAttribute.getDisplayName()
.equals(ICustomAttributeDefinitions.DELIVERABLE_ARTIFACT_TYPE))
{
deliverableArtifactTypeValue= getValue(currentAttribute, monitor, workItemCommon, workItem);
}
}
// BUILD THE DIRECTORY PATH
String directory = ICustomAttributeDefinitions.STREAM_ROOT_DIRECTORY
+deliverableArtifactTypeValue +"\\"+ idValue;
File folderPath = new File(directory);
/*
* NEED A VALID PATH TO CONTINUE AND ALSO PREVENT TRYING TO
* LIST CHILD ITEMS IF IT'S A FILE.
*/
if (folderPath.exists() && folderPath.isDirectory())
{
if (folderPath.list().length == 0)
{
directoryEmpty();
return list;
}
list= new ArrayList<String>();
for (String name: folderPath.list())
list.add(name);
}
else invalidDirectoryPath();
return list;
}
/*
* CONVERT VALUE FROM MODEL IDENTIFIER (EG ID.literal.l01) TO ACTUAL VALUE
*/
private String getValue(IAttribute attribute,
IProgressMonitor monitor,
IWorkItemCommon workItemCommon,
IWorkItem workItem) throws TeamRepositoryException
{
IEnumeration<? extends ILiteral> enumeration= workItemCommon
.resolveEnumeration(attribute, monitor);
String value= "";
List<? extends ILiteral> literals= enumeration.getEnumerationLiterals();
for (Iterator<? extends ILiteral> iterator= literals.iterator(); iterator.hasNext(); )
{
ILiteral iLiteral= (ILiteral) iterator.next();
if (iLiteral.getIdentifier2().equals(workItem.getValue(attribute)))
{
value= iLiteral.getName().toString();
break;
}
}
return value;
}
private void directoryEmpty(){
list= new ArrayList<String>(1);
list.add(ICustomAttributeDefinitions.DIRECTORY_EMPTY);
}
private void invalidDirectoryPath()
{
list= new ArrayList<String>(1);
list.add(ICustomAttributeDefinitions.INVALID_DIRECTORY_PATH);
}
}
答案 0 :(得分:1)
这个问题可能有三种解决方案:
1)当你创建workItem并保存workItem实例然后它的状态发生了变化,所以现在当你调用workItem.getCustomAttributes()时,它不会返回所需的结果所以你需要添加这个之前的行:
IWorkItem workItem = (IWorkItem) getWorkItemServer()
.getAuditableCommon()
.resolveAuditable(savedWorkItem, IWorkItem.FULL_PROFILE, null);
您可以轻松地针对此服务器代码获取客户端代码,这将获得保存的workItem状态
2)您可以在将instanceof
转换为IAttribute
IAttribute
来防止发生此异常
3)按照标识符获取IAttribute
,然后通过以下方式获取WorkItemUIWorkingCopy uiWorkingCopy = (WorkItemUIWorkingCopy)
workingCopy.getAdapter(IWorkItemUIWorkingCopy.class);
IAttribute attribute =
uiWorkingCopy.getResolvedWorkItem().findAttribute(fAttribute.getIdentifier());
:
SELECT *
FROM [Schema].[SomeFullTextIndexedView] t
INNER JOIN CONTAINSTABLE([Schema].[SomeFullTextIndexedView], ColumnToSearch, '"*bla*" OR "*di*" OR "*bladi*"') c
ON t.ID = c.[KEY]
ORDER BY [RANK] DESC
希望它能帮到你