0

I am trying to populate the values from couple of attributes and storing all this information in file via below code.

    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;

So while compiling this code, I am getting all the values for the attributes but not for the Email.

out.write("IdentityName,UserName,First_Name,Last_Name,WorkforceID,Organization,Email");

its constantly writing null value in file.

I am not able to figure out where i am making the mistake.any takers and help me out.

4

1 回答 1

0

我会假设

String email = (String) user.getAttribute("mail");

null。也许这将是emailuser.mail其他名称。您可以尝试打印属性的名称吗?

于 2012-08-31T14:22:25.377 回答