我正在尝试从几个属性中填充值,并通过以下代码将所有这些信息存储在文件中。
import java.io.FileWriter;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;
import java.util.List;
import java.lang.Object;
import java.lang.String;
import java.util.ArrayList;
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,First_Name,Last_Name,WorkforceID,Organization,Email");
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");
String email = (String) user.getAttribute("mail");
//Get application attributes for export
String userid="";
String fn = "";
String ln = "";
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("User Name");
fn = (String) l.getAttribute("First Name");
ln = (String) l.getAttribute("Last Name");
List organizations = l.getAttribute("Allscript_Instance");
for (Object organization : organizations)
{
// Output file
out.write(identityName + "," + userid + "," + fn + "," + ln + "," + workforceid + "," + organization + "," + email);
out.newLine();
out.flush();
}
}
}
} }
}
ret="true";
}
//Close file and return
out.close();
return ret;
因此,在编译此代码时,我将获取属性的所有值,但不会获取电子邮件。
out.write("IdentityName,UserName,First_Name,Last_Name,WorkforceID,Organization,Email");
它不断在文件中写入空值。
我无法弄清楚我在哪里犯了错误。有人接受并帮助我。
答案 0 :(得分:0)
我会认为
String email = (String) user.getAttribute("mail");
是null
。也许这可能是其他名称的email
或user.mail
。你能尝试打印属性的名称吗?