如何在 FileNet P8 中获取 属性 数据类型
How to get the property data type in FileNet P8
在 FileNet P8 中,我需要使用 JAVA API 获取自定义 class 的 属性 的数据类型。有什么办法可以做到吗?
这应该让您了解需要做什么:
//SymbolicName of the property we will search for.
String strSearchName = PropertyNames.DATE_LAST_MODIFIED;
//Document (or other object) that we will use to get classDescription.
Document document = (Document) arg0;
PropertyDescription objPropDesc = null;
PropertyDescriptionList pdl = document.get_ClassDescription().get_PropertyDescriptions();
Iterator<?> iter = pdl.iterator();
while (iter.hasNext())
{
objPropDesc = (PropertyDescription) iter.next();
// Get SymbolicName property from the property cache
String strPropDescSymbolicName = objPropDesc.get_SymbolicName();
if (strPropDescSymbolicName.equalsIgnoreCase(strSearchName))
{
// PropertyDescription object found
System.out.println("Property description selected: " + strPropDescSymbolicName);
System.out.println(objPropDesc);
TypeID type = objPropDesc.get_DataType();
System.out.println(type.toString());
break;
}
}
想法是:
- 取一个对象(在本例中为文档)。
- 获取其 Class 说明。
- 从 Class 描述中获取 属性 描述的列表。
- 遍历 属性 描述,直到找到您要查找的描述。
- 从 属性 描述中获取 TypeId。
- TypeId 包含您需要知道 属性 的类型的信息。
我从这里借用了代码:Working with Properties
你也应该熟悉这个:Properties
编辑以添加不同的方法:
在创建文档的情况下,我们需要能够获取到ClassDescription对象。这意味着我们将需要执行额外的往返。
// Get the ClassDescription
String strSymbolicName = "myClassName";
ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(myObjStore, strSymbolicName, null);
// find the PropertyDescription
PropertyDescription pds = null;
PropertyDescriptionList pdl = objClassDesc.get_PropertyDescriptions();
Iterator<?> itr = pdl.iterator();
while(itr.hasNext()){
pds = (PropertyDescription) itr.next();
System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString());
}
// You can now use it in a loop of several documents if you wish.
...
也看看这里:Working With Classes
Christopher Powell 的回答是正确的,但有一件事它没有涵盖(取决于所讨论的习俗 class 的定义)。将此视为“最佳实践”或只是从 Christopher 提到的 URL 借用的代码的扩展。
FileNet P8 class 层次结构允许继承 属性 定义。简单示例:可以搜索对象存储的 'Document' class - 这是 class 层次结构的根 class,并使用一些 属性搜索 sql 中的子class。将 Subclass1 想象成 Document 的直接子class。 Subclass1 有一个 属性 Property1。即使 Document 在其 class 描述中没有此 属性,在具有 Property1='somevalue' 的 Document 中搜索也会 return Subclass1 的对象(如果'somevalue').
匹配
然而,
objClassDesc.get_PropertyDescriptions();
不会 return 属性 子 class 的描述,因此您可能会遇到 API_PROPERTY_NOT_IN_CACHE 错误。
如果您遇到这种情况,为了给您一个好的起点,请查看以下代码:
PropertyDescriptionList ownProps = objClassDesc.get_PropertyDescriptions();
PropertyDescriptionList subclassProps = null;
if (objClassDesc.get_HasProperSubclassProperties()) {
logger.debug("Document class '"+documentClassname+"' supports 'include descendant properties' queries, including descendant properties.");
subclassProps = objClassDesc.get_ProperSubclassPropertyDescriptions();
}
List<PropertyDescription> result = mergePropertyDescriptionLists(ownProps, subclassProps);
如果您需要合并这两个列表,最好使用 PropertyDescription 对象列表而不是 PropertyDescriptionList:服务器 return 编辑的是 read-only.
@SuppressWarnings("unchecked")
protected List<PropertyDescription> mergePropertyDescriptionLists(PropertyDescriptionList list1, PropertyDescriptionList list2) throws Exception {
try {
@SuppressWarnings("unchecked")
List<PropertyDescription> mergedList = new ArrayList<PropertyDescription>();
if (list1 != null && (list1.size() > 0)) {
mergedList.addAll(list1);
}
if (list2 != null && (list2.size() > 0)) {
mergedList.addAll(list2);
}
return mergedList;
} catch (Throwable t) {
throw new Exception("Failed to merge property description lists.", t);
}
}
在 FileNet P8 中,我需要使用 JAVA API 获取自定义 class 的 属性 的数据类型。有什么办法可以做到吗?
这应该让您了解需要做什么:
//SymbolicName of the property we will search for.
String strSearchName = PropertyNames.DATE_LAST_MODIFIED;
//Document (or other object) that we will use to get classDescription.
Document document = (Document) arg0;
PropertyDescription objPropDesc = null;
PropertyDescriptionList pdl = document.get_ClassDescription().get_PropertyDescriptions();
Iterator<?> iter = pdl.iterator();
while (iter.hasNext())
{
objPropDesc = (PropertyDescription) iter.next();
// Get SymbolicName property from the property cache
String strPropDescSymbolicName = objPropDesc.get_SymbolicName();
if (strPropDescSymbolicName.equalsIgnoreCase(strSearchName))
{
// PropertyDescription object found
System.out.println("Property description selected: " + strPropDescSymbolicName);
System.out.println(objPropDesc);
TypeID type = objPropDesc.get_DataType();
System.out.println(type.toString());
break;
}
}
想法是:
- 取一个对象(在本例中为文档)。
- 获取其 Class 说明。
- 从 Class 描述中获取 属性 描述的列表。
- 遍历 属性 描述,直到找到您要查找的描述。
- 从 属性 描述中获取 TypeId。
- TypeId 包含您需要知道 属性 的类型的信息。
我从这里借用了代码:Working with Properties
你也应该熟悉这个:Properties
编辑以添加不同的方法:
在创建文档的情况下,我们需要能够获取到ClassDescription对象。这意味着我们将需要执行额外的往返。
// Get the ClassDescription
String strSymbolicName = "myClassName";
ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(myObjStore, strSymbolicName, null);
// find the PropertyDescription
PropertyDescription pds = null;
PropertyDescriptionList pdl = objClassDesc.get_PropertyDescriptions();
Iterator<?> itr = pdl.iterator();
while(itr.hasNext()){
pds = (PropertyDescription) itr.next();
System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString());
}
// You can now use it in a loop of several documents if you wish.
...
也看看这里:Working With Classes
Christopher Powell 的回答是正确的,但有一件事它没有涵盖(取决于所讨论的习俗 class 的定义)。将此视为“最佳实践”或只是从 Christopher 提到的 URL 借用的代码的扩展。
FileNet P8 class 层次结构允许继承 属性 定义。简单示例:可以搜索对象存储的 'Document' class - 这是 class 层次结构的根 class,并使用一些 属性搜索 sql 中的子class。将 Subclass1 想象成 Document 的直接子class。 Subclass1 有一个 属性 Property1。即使 Document 在其 class 描述中没有此 属性,在具有 Property1='somevalue' 的 Document 中搜索也会 return Subclass1 的对象(如果'somevalue').
匹配然而,
objClassDesc.get_PropertyDescriptions();
不会 return 属性 子 class 的描述,因此您可能会遇到 API_PROPERTY_NOT_IN_CACHE 错误。 如果您遇到这种情况,为了给您一个好的起点,请查看以下代码:
PropertyDescriptionList ownProps = objClassDesc.get_PropertyDescriptions();
PropertyDescriptionList subclassProps = null;
if (objClassDesc.get_HasProperSubclassProperties()) {
logger.debug("Document class '"+documentClassname+"' supports 'include descendant properties' queries, including descendant properties.");
subclassProps = objClassDesc.get_ProperSubclassPropertyDescriptions();
}
List<PropertyDescription> result = mergePropertyDescriptionLists(ownProps, subclassProps);
如果您需要合并这两个列表,最好使用 PropertyDescription 对象列表而不是 PropertyDescriptionList:服务器 return 编辑的是 read-only.
@SuppressWarnings("unchecked")
protected List<PropertyDescription> mergePropertyDescriptionLists(PropertyDescriptionList list1, PropertyDescriptionList list2) throws Exception {
try {
@SuppressWarnings("unchecked")
List<PropertyDescription> mergedList = new ArrayList<PropertyDescription>();
if (list1 != null && (list1.size() > 0)) {
mergedList.addAll(list1);
}
if (list2 != null && (list2.size() > 0)) {
mergedList.addAll(list2);
}
return mergedList;
} catch (Throwable t) {
throw new Exception("Failed to merge property description lists.", t);
}
}