需求中需要从choiceList中去的数据,找了一些代码但是因为缺少UserContextUtils.pushSubject(userSession.getSubject());一直报错,后来经过伟东的帮忙解决了。
下面是该过程的代码,应为需要的数据形式 不同所以代码里经过了一些修饰,核心代码为红色标记。
public String getSystemNames(UserSession userSession){
try{
UserContextUtils.pushSubject(userSession.getSubject());
return choiceListUtil.getSystemNames(userSession.getObjectStore());
}catch(Exception e){
logger.error("choiceList cannot be get due to the reason:" + e.getMessage());
return "";
}finally{
UserContextUtils.popSubject();
}
}
/**
* @Title: getSystemNames
* @Description: 查询CE中系统名称
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
public String getSystemNames(ObjectStore objectStore){
String systemNames = "<item label=\"信息系统名称\">";
try {
ChoiceList fetchInstance = Factory.ChoiceList.fetchInstance(objectStore, new Id(ConfigUtils.getIsChoiceListId()), null);
com.filenet.api.collection.ChoiceList choices = fetchInstance.get_ChoiceValues();
systemNames = cycleChoiceList(systemNames, choices);
} catch (Exception e) {
e.printStackTrace();
}
systemNames += "</item>";
//System.out.println(systemNames);
return systemNames;
}
//ChoiceList
@SuppressWarnings("rawtypes")
private String cycleChoiceList(String systemNames, com.filenet.api.collection.ChoiceList choices) {
try {
Iterator iter = choices.iterator();
while(iter.hasNext()){
Choice choice = (Choice) iter.next();
systemNames += "\n";
systemNames += " <item label=\""+ choice.get_Name() +"\">";
if(choice.get_ChoiceType() == com.filenet.api.constants.ChoiceType.MIDNODE_STRING) {
com.filenet.api.collection.ChoiceList clist = choice.get_ChoiceValues();
systemNames = cycleChoiceList(systemNames, clist);
}
systemNames += "</item>";
}
} catch (Exception e) {
e.printStackTrace();
}
systemNames += "\n";
return systemNames;
}
另外ConfigUtils.getIsChoiceListId()是从FCM中的choicelist的properties中查看的相应的choiceList的ID值。