1

我正在尝试使用以下代码导出提要文件:

String appname = "abc";
String path = "//home/exportfile//";
String filename = path + "Uncorrelated_ApplicationExport-" + appname + ".txt";
String ret = "false";

QueryOptions ops = new QueryOptions();
Filter[] filters = new Filter[1];
filters[0] = Filter.eq("application.name", appname);
ops.add(filters);

List props = new ArrayList();
props.add("identity.name");

// Do search
Iterator it = context.search(Link.class, ops, props);

// Build file and export header row
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write("Userid~First_Name~Last_Name~Facility/CBO~Title~Menu");
out.newLine();

// Iterate Search Results
if (it != null)
{
    while (it.hasNext())
    {
        // Get link and create object
        Object[] record = it.next();
        String identityName = (String) record[0];
        Identity user = (Identity) context.getObject(Identity.class, identityName);

        // Get Identity attributes for export
        String workforceid = (String) user.getAttribute("workforceID");

        // Get application attributes for export

        List links = user.getLinks();
        if (links != null)
        {
            Iterator lit = links.iterator();
            while (lit.hasNext())
            {
                Link l = lit.next();
                String lname = l.getApplicationName();
                if (lname.equalsIgnoreCase(appname))
                {
                    if (workforceid == null)
                    {
                        userid = (String) l.getAttribute("Userid");
                        fn = (String) l.getAttribute("First Name");
                        ln = (String) l.getAttribute("Last Name");
                        menu = (String) l.getAttribute("Menu");

                        List fac = l.getAttribute("Facility/CBO");
                        List title = l.getAttribute("Title");

                        for (Object fac1 : fac)
                        {
                            for (Object title1 : title)
                            {
                                // Output file

                                out
                                    .write(userid + "~" + fn + "~" + ln + "~" + fac1 + "~" + title1 + "~"
                                        + menu);
                                out.newLine();
                                out.flush();

                            }
                        }
                    }
                }
            }
        }
    }

    ret = "true";
}
// Close file and return
out.close();
return ret;

当我执行上面的代码时,我收到以下错误:

发生意外错误:java.lang.Exception:sailpoint.tools.GeneralException:BeanShell 脚本错误:源文件:内联评估:import java.io.FileWriter;导入java.io.File;导入 java.io.B 。. . '' : for 语句的集合、数组、映射、迭代器或枚举部分不能为空。:在第 80 行:在文件中:内联评估:``import java.io.FileWriter; 导入java.io.File;导入 java.io.B 。. . '' : for ( 对象 title1 : title ) { BSF info:

我知道在我的提要文件中,标题列中有几条空白记录,因此理想情况下,代码应该在文件中写入除标题列之外的所有内容(如果标题列为空白)。谁能帮我在哪里更改代码?

4

1 回答 1

0
                    List fac = l.getAttribute("Facility/CBO");
                    List title = l.getAttribute("Title");

                    for (Object fac1 : fac)
                    {
                        for (Object title1 : title)

fac 或 title 被设置为 null,然后您尝试对其进行迭代。您应该在执行循环之前引入一些空值检查。

于 2012-09-25T20:24:39.167 回答