Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

How to Manipulate List to String and print in seperate row

Ads

 
 

Share on Google+Share on Google+

Hardik Modi
How to Manipulate List to String and print in seperate row
0 Answer(s)      5 years ago
Posted in : Java Beginners

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?

Ads
View Answers
Ads









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 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
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
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
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
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
how to print the server time
how to print the server time  how to print the server time in jsp and update time in fix interval
how to print - Java Beginners
how to print  how to print something on console without using... anything on the console. import java.io.*; public class Print{ public static void main(String args[]) { PrintWriter pw = new PrintWriter(System.out, true
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO... static void main(String[] args) { String st="hello...++){ char ch=Character.toUpperCase(st.charAt(i)); String str
How to print this in java?
How to print pattern in Java?  How to print a particular pattern in Java...;  How to print this in java
how to print the server time
how to print the server time  i want to print database time in clintside and update time in every secound without creating connection to database for each time. how can i do
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here
How to print UIButton id
How to print UIButton id  How to get the id of the button in the IOS application? Thanks   Hi, You can use the following code: - (IBAction)btnClicked:(id)sender { UIButton *button = (UIButton *)sender; int
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application... datasource=new JRTableModelDataSource(jTable1.getModel()); String.../AccsBook/Tools" // the jrxml file Map<String,Object>params=new
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application... datasource=new JRTableModelDataSource(jTable1.getModel()); String.../AccsBook/Tools" // the jrxml file Map<String,Object>params=new
How to print the following pattern in java?
How to print the following pattern in java?  How to print... java.io.*; class StringPattern { public static void main(String[] args) throws IOException{ String st="he is going in"; String str
How to display string or character
How to display string or character  how to print character or a word without using array concept
How to design a foot print on the sand, print on the sand, print
How to design a foot print on the sand       You might have seen foot prints on the sand field. Do you think, it can be design in the photoshop, yes I have done here. I have used
how to print JInternal frame component ?
how to print JInternal frame component ?  hello sir, i devalop a swing application .but problem is that how display report & print it. some data prefech from database & keep to jtable but how it is print with table
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...  Hello Sir, I am developing a desktop... to read all the values of particular row at which mouse is clicked. and display
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
How can print integer in method
How can print integer in method   a method call process public process(int jobid,int remain){ } how to print int jobid ,int remain in for loop jobid in proc[0],remain in proc[1],both show in text file how to print proc[0
how to print headings horizontally in jsp
how to print headings horizontally in jsp  In one of my jsp i have used for loop. in every iteration it will fetch value from db and print it on heading section, it prints vertically but my requirement is to print it horizontally
How to print current time in r?
How to print current time in r?  Hi, I am learning and want to print current date and time on console. How to print current time in R Programming? Thanks   Hi, You should use Sys.time() for getting current date
how to search the string arraylist contains database rows?
the row values into string arraylist. now i want to print the common rows existed. how do i do...how to search the string arraylist contains database rows?  i need
how to print of hours and minutes of 8725 seconds
how to print of hours and minutes of 8725 seconds  how to print of hours and minutes of 8725 seconds
how to print all colors using awt
how to print all colors using awt  how to print all colors using awt