code未写在文件中的值 [英] Code is not writing the values in File

查看:141
本文介绍了code未写在文件中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想导出文件。

我的code是如下:

import java.io.FileWriter;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;


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="";
                  String org="";
                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");
                                         sailpoint.tools.xml.PersistentArrayList orgList = (sailpoint.tools.xml.PersistentArrayList) l.getAttribute("Organization");

                                }
                        }
                }                               

                //Output file
                out.write(identityName+","+userid+","+workforceid+","+org);                             
                out.newLine();                                                                          
                out.flush();
        }                       
        ret="true";
}
//Close file and return
out.close();
return ret; 

code正在撰写除了组织列3列中的值。不知道为什么?

Code is writing the value for 3 columns except Organization column. Not sure why?

你能请帮我找出什么是错的code。或者有什么我错过。

Can you pls help me to identify what is wrong with the code. Or what i am missing.

顺便说一句,组织列是多值,即该列可能有多个值。

By the way, Organization column is multivalue i.e. that column might have more than one value.

所以最终的输出应,

IdentityName,  UserName,  WorkforceID,  Organization 
1,             abc,       123,          internal
1,             abc,       123,          external

任何帮助将大大AP preciated。

Any help would be greatly appreciated.

推荐答案

字符串组织=;是空的。看来,你分配价值ORG没有,所以空值被写入文件。

String org=""; is empty. It seems no where you assigned value to org, so empty value is being written to file.

这篇关于code未写在文件中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆