0

我正在尝试导出文件。

我的代码如下:

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");
                                         sailpoint.tools.xml.PersistentArrayList orgList = (sailpoint.tools.xml.PersistentArrayList) 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; 

代码正在写入除组织列之外的 3 列的值。不知道为什么?

你能帮我找出代码有什么问题吗?或者我错过了什么。

顺便说一句,组织列是多值的,即该列可能有多个值。

所以最终的输出应该是,

IdentityName,  UserName,  WorkforceID,  Organization 
1,             abc,       123,          internal
1,             abc,       123,          external

任何帮助将不胜感激。

4

2 回答 2

1

字符串 org=""; 是空的。您似乎没有为 org 分配值,因此正在将空值写入文件。

于 2012-07-31T14:30:29.813 回答
0

你定义org=""了它会写一个空字符串。

你会得到一个组织列表:

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

该对象可能具有获取所需值的方法,因此您可以执行以下操作:

org = orgList.getOrganization();

当然这只是一个例子,因为我不知道对象的确切结构,使用 IDE 你可以探索这个对象的不同方法并找出你需要的东西。

于 2012-07-31T14:42:59.440 回答