Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to Manipulate List to String and print in seperate row
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Hardik Modi
How to Manipulate List to String and print in seperate row
0 Answer(s)      2 years and 5 months 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?


Advertisement
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 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 <
Advertisements
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
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
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
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
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
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 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 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 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 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 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
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 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 update checkbox list in database
how to update checkbox list in database  Issues: i am using different checkboxs for getting role then all role list store in one string array i want... ) EditRole.java file 1) Role_Id = request.getParameter("RoleId"); String[] role
how to set value of dropdown list
the value from a link to a dropdown list. I want to set the dropdown list selected according to link. CODE: print(" Blockquote <% String hr...how to set value of dropdown list  Hello Sir, I'd solved the earlier
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 display string or character
How to display string or character  how to print character or a word without using array concept
using getText(String aTextName, List args) - Struts
using getText(String aTextName, List args)   What should my pacakge.properties (Message.properties) should have ? basically i am trying to use ActionSupport.getText(String aTextName, List args) I want something like "you
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
Print
Print  In system.out.println,what meant ln..?   System: It is a class made available by Java to let you manipulate various operating system... into the stream and, as opposed to print() method, gets you to the new line after the text
How to delete the row from the Database by using servlet
How to delete the row from the Database by using servlet  Dear Sir... 25 users details are there. I am given 6th (some n th row)user details true... JdbcUpdateServlet extends HttpServlet { String name,pas,cde; String un,up,co
 

 

 

DMCA.com