How to Manipulate List to String and print in seperate row

How to Manipulate List to String and print in seperate row

I am trying to export the 4 columns with the below code.the last column organization is a List.

        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="";

                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 organizations = l.getAttribute("Organization");

                                          StringBuilder sb = new StringBuilder();
                                          String listItemsSeparator = ","; 

                                                                                        for (Object organization : organizations)
                                                                                                                {
                                                                                                                        sb.append(organization.toString());
                                                                                                                        sb.append(listItemsSeparator);
                                                                                                                }

                                                                                                                org = sb.toString().trim();

                                }
                        }
                }                   

                //Output file
                out.write(identityName+","+userid+","+workforceid+","+org);                             
                out.newLine();                                                                          
                out.flush();
        }

                 ret="true";
}

//Close file and return
out.close();
return ret;

the output of the above code will be.for ex:

IdentityName,UserName,WorkforceID,Organization

dthomas,dthomas001,12345,Finance,HR

How do i get the output in below fashion

IdentityName,UserName,WorkforceID,Organization

dthomas,dthomas001,12345,Finance

dthomas,dthomas001,12345,HR

what and where i need to change the code?

View Answers









Related Tutorials/Questions & Answers:
How to Manipulate List to String and print in seperate row
How to Manipulate List to String and print in seperate row  I am... is a List. String appname = "abc"; String path = "//home/exportfile... String userid=""; List links = user.getLinks
how to print String as pattern ?
how to print String as pattern ?  i have a one String name ="rajesh" i want to print pattern like r * ra ** raj raje rajes rajesh please help me
Advertisements
how to make seperate view count for each row while clicking view button
how to make seperate view count for each row while clicking view button  I am getting problem with view count when i click view button the seperate count should be happen for each row here is my code ** Tabledata.jsp <
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
How to print list of files in client system
How to print list of files in client system  have some list of files in server.i just want to print that files in client machine with out opening the file.i give the option for user like printall.if user click printall prints
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.
PLEASE Help me write a Java program which will store, manipulate, and print... will store, manipulate, and print student registration information. As part... in the java.util package (d) The field Courses is a set of no more than five (5) string values
ModuleNotFoundError: No module named 'list_print'
'list_print' How to remove the ModuleNotFoundError: No module named 'list...ModuleNotFoundError: No module named 'list_print'  Hi, My Python... have to install padas library. You can install list_print python
ModuleNotFoundError: No module named 'print_list'
'print_list' How to remove the ModuleNotFoundError: No module named 'print_list' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'print_list'  Hi, My Python
ModuleNotFoundError: No module named 'print_list'
'print_list' How to remove the ModuleNotFoundError: No module named 'print_list' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'print_list'  Hi, My Python
ModuleNotFoundError: No module named 'this_is_to_print_list'
: No module named 'this_is_to_print_list' How to remove the ModuleNotFoundError: No module named 'this_is_to_print_list' error? Thanks   Hi...ModuleNotFoundError: No module named 'this_is_to_print_list'  Hi
how to call list objects as string into my sql query?
how to call list objects as string into my sql query?  how to call list data as string into my sql query so that i can retrieve all values from database? List has data retrieved from xml(using xmlSAXparser
ModuleNotFoundError: No module named 'def_print_list'
named 'def_print_list' How to remove the ModuleNotFoundError: No module named 'def_print_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'def_print_list'  Hi, My
ModuleNotFoundError: No module named 'li_print_list'
'li_print_list' How to remove the ModuleNotFoundError: No module named 'li_print_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'li_print_list'  Hi, My
ModuleNotFoundError: No module named 'list_meta_print'
named 'list_meta_print' How to remove the ModuleNotFoundError: No module named 'list_meta_print' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'list_meta_print'  Hi, My
ModuleNotFoundError: No module named 'list_print_bds'
named 'list_print_bds' How to remove the ModuleNotFoundError: No module named 'list_print_bds' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'list_print_bds'  Hi, My
ModuleNotFoundError: No module named 'lsp_print_list'
named 'lsp_print_list' How to remove the ModuleNotFoundError: No module named 'lsp_print_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'lsp_print_list'  Hi, My
ModuleNotFoundError: No module named 'lsp_print_list'
named 'lsp_print_list' How to remove the ModuleNotFoundError: No module named 'lsp_print_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'lsp_print_list'  Hi, My
ModuleNotFoundError: No module named 'lsp_print_list'
named 'lsp_print_list' How to remove the ModuleNotFoundError: No module named 'lsp_print_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'lsp_print_list'  Hi, My
ModuleNotFoundError: No module named 'Mark_print_nested_list'
: No module named 'Mark_print_nested_list' How to remove the ModuleNotFoundError: No module named 'Mark_print_nested_list' error? Thanks   Hi...ModuleNotFoundError: No module named 'Mark_print_nested_list'  Hi
ModuleNotFoundError: No module named 'michaeljy_print_list'
: No module named 'michaeljy_print_list' How to remove the ModuleNotFoundError: No module named 'michaeljy_print_list' error? Thanks   Hi...ModuleNotFoundError: No module named 'michaeljy_print_list'  Hi
ModuleNotFoundError: No module named 'nester_list_print'
named 'nester_list_print' How to remove the ModuleNotFoundError: No module named 'nester_list_print' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'nester_list_print'  Hi, My
ModuleNotFoundError: No module named 'nest-list-print'
named 'nest-list-print' How to remove the ModuleNotFoundError: No module named 'nest-list-print' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'nest-list-print'  Hi, My
ModuleNotFoundError: No module named 'nest-list-print'
named 'nest-list-print' How to remove the ModuleNotFoundError: No module named 'nest-list-print' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'nest-list-print'  Hi, My
ModuleNotFoundError: No module named 'print_list_harkennb'
named 'print_list_harkennb' How to remove the ModuleNotFoundError: No module named 'print_list_harkennb' error? Thanks   Hi...ModuleNotFoundError: No module named 'print_list_harkennb'  Hi, My
ModuleNotFoundError: No module named 'print_list_items'
named 'print_list_items' How to remove the ModuleNotFoundError: No module named 'print_list_items' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_items'  Hi, My
ModuleNotFoundError: No module named 'print_list_kangyu'
named 'print_list_kangyu' How to remove the ModuleNotFoundError: No module named 'print_list_kangyu' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_kangyu'  Hi, My
ModuleNotFoundError: No module named 'print-list-luca'
named 'print-list-luca' How to remove the ModuleNotFoundError: No module named 'print-list-luca' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print-list-luca'  Hi, My
ModuleNotFoundError: No module named 'print_list_module'
named 'print_list_module' How to remove the ModuleNotFoundError: No module named 'print_list_module' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_module'  Hi, My
ModuleNotFoundError: No module named 'print_lol_list'
named 'print_lol_list' How to remove the ModuleNotFoundError: No module named 'print_lol_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_lol_list'  Hi, My
ModuleNotFoundError: No module named 'print_list_bogus'
named 'print_list_bogus' How to remove the ModuleNotFoundError: No module named 'print_list_bogus' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_bogus'  Hi, My
ModuleNotFoundError: No module named 'print_list_brasse'
named 'print_list_brasse' How to remove the ModuleNotFoundError: No module named 'print_list_brasse' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_brasse'  Hi, My
ModuleNotFoundError: No module named 'print_list_harkennb'
named 'print_list_harkennb' How to remove the ModuleNotFoundError: No module named 'print_list_harkennb' error? Thanks   Hi...ModuleNotFoundError: No module named 'print_list_harkennb'  Hi, My
ModuleNotFoundError: No module named 'print_list_items'
named 'print_list_items' How to remove the ModuleNotFoundError: No module named 'print_list_items' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_items'  Hi, My
ModuleNotFoundError: No module named 'print_list_kangyu'
named 'print_list_kangyu' How to remove the ModuleNotFoundError: No module named 'print_list_kangyu' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_kangyu'  Hi, My
ModuleNotFoundError: No module named 'print-list-luca'
named 'print-list-luca' How to remove the ModuleNotFoundError: No module named 'print-list-luca' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print-list-luca'  Hi, My
ModuleNotFoundError: No module named 'print_list_module'
named 'print_list_module' How to remove the ModuleNotFoundError: No module named 'print_list_module' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_module'  Hi, My
ModuleNotFoundError: No module named 'print_list_nester'
named 'print_list_nester' How to remove the ModuleNotFoundError: No module named 'print_list_nester' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_list_nester'  Hi, My
ModuleNotFoundError: No module named 'print-list-nestler'
named 'print-list-nestler' How to remove the ModuleNotFoundError: No module named 'print-list-nestler' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print-list-nestler'  Hi, My
ModuleNotFoundError: No module named 'print_list_recursively'
: No module named 'print_list_recursively' How to remove the ModuleNotFoundError: No module named 'print_list_recursively' error? Thanks   Hi...ModuleNotFoundError: No module named 'print_list_recursively'  Hi
ModuleNotFoundError: No module named 'print_list_tab'
named 'print_list_tab' How to remove the ModuleNotFoundError: No module named 'print_list_tab' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_list_tab'  Hi, My
ModuleNotFoundError: No module named 'print_list_test'
named 'print_list_test' How to remove the ModuleNotFoundError: No module named 'print_list_test' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_list_test'  Hi, My
ModuleNotFoundError: No module named 'print_list_wu'
'print_list_wu' How to remove the ModuleNotFoundError: No module named 'print_list_wu' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_list_wu'  Hi, My
ModuleNotFoundError: No module named 'print_list_yl'
'print_list_yl' How to remove the ModuleNotFoundError: No module named 'print_list_yl' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_list_yl'  Hi, My
ModuleNotFoundError: No module named 'print_lol_list'
named 'print_lol_list' How to remove the ModuleNotFoundError: No module named 'print_lol_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_lol_list'  Hi, My
ModuleNotFoundError: No module named 'print_luo_List'
named 'print_luo_List' How to remove the ModuleNotFoundError: No module named 'print_luo_List' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_luo_List'  Hi, My
ModuleNotFoundError: No module named 'print_nested_list'
named 'print_nested_list' How to remove the ModuleNotFoundError: No module named 'print_nested_list' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_nested_list'  Hi, My
ModuleNotFoundError: No module named 'print_nester_list'
named 'print_nester_list' How to remove the ModuleNotFoundError: No module named 'print_nester_list' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'print_nester_list'  Hi, My
ModuleNotFoundError: No module named 'print_nest_list'
named 'print_nest_list' How to remove the ModuleNotFoundError: No module named 'print_nest_list' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'print_nest_list'  Hi, My

Ads