属性模板,顾名思义为创建属性的模板。这是FileNet创建类中属性的一大利器。当我们在FileNet中创建自定义的Class时,就能够通过属性模板选择定义好的属性,大大的提高了开发效率。
在FEM下管理属性模板是比较容易了,这里我们不再阐述,下面以API展示的形式说明属性模板的创建。
/**
* 创建属性模板
* @param os ObjectStore
* @param dataType
属性类型(0:二进制,1:布尔值...)
* @param cardinality
属性值列表(0:单值;1:List;2:枚举)
* @param symbolicName
文档类型
* @param displayNameMap
显示名称
* @return
*/
public static PropertyTemplate createPropertyTemplate(ObjectStore os, int dataType, int cardinality, String symbolicName, Map<String, String> displayNameMap) {
PropertyTemplate prop = null;
switch (dataType) {
case TypeID.BINARY_AS_INT:
prop = Factory.PropertyTemplateBinary.createInstance(os);
break;
case TypeID.BOOLEAN_AS_INT:
prop = Factory.PropertyTemplateBoolean.createInstance(os);
break;
case TypeID.DATE_AS_INT:
prop = Factory.PropertyTemplateDateTime.createInstance(os);
break;
case TypeID.DOUBLE_AS_INT:
prop = Factory.PropertyTemplateFloat64.createInstance(os);
break;
case TypeID.GUID_AS_INT:
prop = Factory.PropertyTemplateId.createInstance(os);
break;
case TypeID.LONG_AS_INT:
prop = Factory.PropertyTemplateInteger32.createInstance(os);
break;
case TypeID.OBJECT_AS_INT:
prop = Factory.PropertyTemplateObject.createInstance(os);
break;
case TypeID.STRING_AS_INT:
prop = Factory.PropertyTemplateString.createInstance(os);
break;
default:
prop = Factory.PropertyTemplateObject.createInstance(os);
}
switch (cardinality) {
case Cardinality.SINGLE_AS_INT:
prop.set_Cardinality(Cardinality.SINGLE);
break;
case Cardinality.LIST_AS_INT:
prop.set_Cardinality(Cardinality.LIST);
break;
case Cardinality.ENUM_AS_INT:
prop.set_Cardinality(Cardinality.ENUM);
break;
default:
prop.set_Cardinality(Cardinality.SINGLE);
}
prop.set_SymbolicName(symbolicName);
prop.set_DisplayNames(Factory.LocalizedString.createList());
Set<String> keySet = displayNameMap.keySet();
for (String key : keySet) {
LocalizedString displayName = Factory.LocalizedString.createInstance();
displayName.set_LocaleName(key);
displayName.set_LocalizedText(displayNameMap.get(key));
prop.get_DisplayNames().add(displayName);
}
prop.save(RefreshMode.REFRESH);
return prop;
}
/**
* 删除属性模板
* @param os
ObjectStore
* @param propTemplateId 属性模板Id
*/
public static void deletePropertyTemplate(ObjectStore os, Id propTemplateId) {
PropertyTemplate prop = Factory.PropertyTemplate.fetchInstance(os, propTemplateId, null);
prop.delete();
prop.save(RefreshMode.REFRESH);
}
//查找属性模板
public static PropertyTemplate fetchPropertyTemplate(ObjectStore os, String id) {
PropertyTemplate propertyTemplate = Factory.PropertyTemplate.fetchInstance(os, new Id(id), null);
return propertyTemplate;
}
//根据文档类型查找属性模板
public static List<PropertyTemplate> fetchPropertyTemplates(ObjectStore os, String symbolicName) {
SearchScope searchScope = new SearchScope(os);
String sql =
"SELECT p." + PropertyNames.THIS + ",P." + PropertyNames.ID + ",P." + PropertyNames.SYMBOLIC_NAME + ",P." + PropertyNames.DISPLAY_NAMES + ",P."
+ PropertyNames.DATA_TYPE + ",P." + PropertyNames.CARDINALITY + ",P." + PropertyNames.CHOICE_LIST + ",P." + PropertyNames.DISPLAY_NAME + ",P."
+ PropertyNames.PROPERTY_DISPLAY_CATEGORY + " FROM " + ClassNames.PROPERTY_TEMPLATE + " p WHERE p." + PropertyNames.SYMBOLIC_NAME + "='"
+ symbolicName + "'";
SearchSQL searchSQL = new SearchSQL(sql);
IndependentObjectSet objects = searchScope.fetchObjects(searchSQL, null, null, true);
List<PropertyTemplate> propTemplates = new ArrayList<PropertyTemplate>();
for (PropertyTemplate propTemplate : EngineCollectionUtils.c(objects, PropertyTemplate.class)) {
propTemplates.add(propTemplate);
}
System.out.println("Search SQL:" + sql);
return propTemplates;
}
//更新属性模板
public static PropertyTemplate updateDisplayNamesOfPropertyTemplate(PropertyTemplate propertyTemplate, Map<String, String> displayNameMap, boolean save) {
LocalizedStringList displayNames = propertyTemplate.get_DisplayNames();
ObjectStoreUtil.updateDisplayNames(displayNames, displayNameMap);
if (save)
propertyTemplate.save(RefreshMode.REFRESH);
return propertyTemplate;
}