1

我需要导出 4 列中的值。3 列的值正在正确填充。我在第 4 列出现问题,即组织列。它是多值列。即:它有多个值。

我试图将组织列的对象转换为字符串,但没有帮助。

请看下面的代码:

    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("Name,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="";

                    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");
                                              List orgList = 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;

这段代码的输出应该是:

例如:姓名、用户名、WorkforceID、组织 abc、abc、123、xy qwe、q01,234、xy

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

4

2 回答 2

1

编辑:

这应该给你你想要的输出:

out.write(identityName+","+userid+","+workforceid+","+Arrays.toString(orgList.toArray());

于 2012-08-01T00:06:26.387 回答
0

您可能希望List orgList在 while 循环之外声明,因为每次创建它并且您正在使用 org 并且我在您的代码中的其他地方没有看到任何 org

于 2012-07-31T22:47:35.393 回答