0

我正在尝试导出文件,但出现以下异常:

发生意外错误:java.lang.Exception:sailpoint.tools.GeneralException:应用程序脚本引发异常:java.lang.ClassCastException:无法将sailpoint.tools.xml.PersistentArrayList 转换为java.lang.String BSF 信息:导出文件- Abc 在行:0 列:columnNo

我的代码如下:

    import java.io.FileWriter;
    import java.io.File;
    import java.io.BufferedWriter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.*;

    String appname = "Abc";
    String path = "//home/exportfile//";
    String filename = path+"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("IdentityName,UserName,WorkforceID,Organization");
    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
                    String userid="";
                      String org="";
                    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))
                                    {
                                              userid = (String) l.getAttribute("User Name");
                                              org= (String) l.getAttribute("Organization");
                                    }
                            }
                    }                               

                    //Output file
                    out.write(identityName+","+userid+","+workforceid+","+org);                             
                    out.newLine();                                                                          
                    out.flush();
            }                       
            ret="true";
    }
    //Close file and return
    out.close();
    return ret;     

在运行上面的代码时,我收到强制转换异常错误:因为组织属性是多值的。即:在该属性中,您可以有多个值。

任何帮助纠正此代码将不胜感激。

4

1 回答 1

1

它说得很清楚,您正在获取一个类型的对象sailpoint.tools.xml.PersistentArrayList并尝试将其转换为字符串。

从你的问题我明白问题出在这里:

org= (String) l.getAttribute("Organization");

因此,您需要将其更改为:

sailpoint.tools.xml.PersistentArrayList orgList = (sailpoint.tools.xml.PersistentArrayList) l.getAttribute("Organization");

然后从该列表中提取正确的值。

于 2012-07-31T13:54:08.973 回答