UserUtil.permissionCheck("view_account");
String fileName = getText("entity.account.label") + ".csv";
fileName = new String(fileName.getBytes(), "ISO8859-1");
File file = new File(fileName);
ICsvMapWriter writer = new CsvMapWriter(new FileWriter(file),
CsvPreference.EXCEL_PREFERENCE);
try {
final String[] header = new String[] { getText("entity.id.label"),
getText("entity.name.label"),
getText("entity.account_level_id.label"),
getText("entity.account_level_name.label"),
getText("entity.currency_id.label"),
getText("entity.currency_name.label"),
getText("entity.capital_id.label"),
getText("entity.capital_name.label"),
getText("entity.annual_revenue_id.label"),
getText("entity.annual_revenue_name.label"),
getText("entity.company_size_id.label"),
getText("entity.company_size_name.label"),
getText("entity.account_type_id.label"),
getText("entity.account_type_name.label"),
getText("entity.industry_id.label"),
getText("entity.industry_name.label"),
getText("entity.email.label"),
getText("entity.office_phone.label"),
getText("entity.website.label"),
getText("entity.fax.label"),
getText("entity.billing_street.label"),
getText("entity.billing_city.label"),
getText("entity.billing_state.label"),
getText("entity.billing_postal_code.label"),
getText("entity.billing_country.label"),
getText("entity.shipping_street.label"),
getText("entity.shipping_city.label"),
getText("entity.shipping_state.label"),
getText("entity.shipping_postal_code.label"),
getText("entity.shipping_country.label"),
getText("entity.account_nature_id.label"),
getText("entity.account_nature_name.label"),
getText("entity.legal_representative.label"),
getText("entity.business_scope.label"),
getText("entity.create_date.label"),
getText("entity.credit.label"),
getText("entity.reputation.label"),
getText("entity.market_position.label"),
getText("entity.development_potential.label"),
getText("entity.operational_characteristics.label"),
getText("entity.operational_direction.label"),
getText("account.sic_code.label"),
getText("account.ticket_symbol.label"),
getText("account.manager_id.label"),
getText("account.manager_name.label"),
getText("entity.assigned_to_id.label"),
getText("entity.assigned_to_name.label") };
writer.writeHeader(header);
if (!isTemplate) {
String[] ids = seleteIDs.split(",");
for (int i = 0; i < ids.length; i++) {
String id = ids[i];
Account account = baseService.getEntityById(Account.class,
Integer.parseInt(id));
final HashMap<String, ? super Object> data1 = new HashMap<String, Object>();
data1.put(header[0], account.getId());
data1.put(header[1],
CommonUtil.fromNullToEmpty(account.getName()));
AccountLevel accountLevel = account.getAccount_level();
if (accountLevel != null) {
data1.put(header[2], accountLevel.getId());
} else {
data1.put(header[2], "");
}
data1.put(header[3],
CommonUtil.getOptionLabel(accountLevel));
if (account.getCurrency() != null) {
data1.put(header[4], account.getCurrency().getId());
data1.put(header[5], account.getCurrency().getName());
} else {
data1.put(header[4], "");
data1.put(header[5], "");
}
Capital capital = account.getCapital();
if (capital != null) {
data1.put(header[6], capital.getId());
} else {
data1.put(header[6], "");
}
data1.put(header[7], CommonUtil.getOptionLabel(capital));
AnnualRevenue annualRevenue = account.getAnnual_revenue();
if (annualRevenue != null) {
data1.put(header[8], annualRevenue.getId());
} else {
data1.put(header[8], "");
}
data1.put(header[9],
CommonUtil.getOptionLabel(annualRevenue));
CompanySize companySize = account.getCompany_size();
if (companySize != null) {
data1.put(header[10], companySize.getId());
} else {
data1.put(header[10], "");
}
data1.put(header[11],
CommonUtil.getOptionLabel(companySize));
AccountType accountType = account.getAccount_type();
if (accountType != null) {
data1.put(header[12], accountType.getId());
} else {
data1.put(header[12], "");
}
data1.put(header[13],
CommonUtil.getOptionLabel(accountType));
Industry industry = account.getIndustry();
if (industry != null) {
data1.put(header[14], industry.getId());
} else {
data1.put(header[14], "");
}
data1.put(header[15], CommonUtil.getOptionLabel(industry));
data1.put(header[16],
CommonUtil.fromNullToEmpty(account.getEmail()));
data1.put(header[17], CommonUtil.fromNullToEmpty(account
.getOffice_phone()));
data1.put(header[18],
CommonUtil.fromNullToEmpty(account.getWebsite()));
data1.put(header[19],
CommonUtil.fromNullToEmpty(account.getFax()));
data1.put(header[20], CommonUtil.fromNullToEmpty(account
.getBill_street()));
data1.put(header[21],
CommonUtil.fromNullToEmpty(account.getBill_city()));
data1.put(header[22],
CommonUtil.fromNullToEmpty(account.getBill_state()));
data1.put(header[23], CommonUtil.fromNullToEmpty(account
.getBill_postal_code()));
data1.put(header[24], CommonUtil.fromNullToEmpty(account
.getBill_country()));
data1.put(header[25], CommonUtil.fromNullToEmpty(account
.getShip_street()));
data1.put(header[26],
CommonUtil.fromNullToEmpty(account.getShip_city()));
data1.put(header[27],
CommonUtil.fromNullToEmpty(account.getShip_state()));
data1.put(header[28], CommonUtil.fromNullToEmpty(account
.getShip_postal_code()));
data1.put(header[29], CommonUtil.fromNullToEmpty(account
.getShip_country()));
AccountNature accountNature = account.getAccount_nature();
if (accountNature != null) {
data1.put(header[30], accountNature.getId());
} else {
data1.put(header[30], "");
}
data1.put(header[31],
CommonUtil.getOptionLabel(accountNature));
data1.put(header[32], CommonUtil.fromNullToEmpty(account
.getLegal_representative()));
data1.put(header[33], CommonUtil.fromNullToEmpty(account
.getBusiness_scope()));
Date createDate = account.getCreate_date();
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constant.DATE_EDIT_FORMAT);
if (createDate != null) {
data1.put(header[34], dateFormat.format(createDate));
} else {
data1.put(header[34], "");
}
data1.put(header[35],
CommonUtil.fromNullToEmpty(account.getCredit()));
data1.put(header[36],
CommonUtil.fromNullToEmpty(account.getReputation()));
data1.put(header[37], CommonUtil.fromNullToEmpty(account
.getMarket_position()));
data1.put(header[38], CommonUtil.fromNullToEmpty(account
.getDevelopment_potential()));
data1.put(header[39], CommonUtil.fromNullToEmpty(account
.getOperational_characteristics()));
data1.put(header[40], CommonUtil.fromNullToEmpty(account
.getOperational_direction()));
data1.put(header[41],
CommonUtil.fromNullToEmpty(account.getSic_code()));
data1.put(header[42], CommonUtil.fromNullToEmpty(account
.getTicket_symbol()));
if (account.getManager() != null) {
data1.put(header[43], account.getManager().getId());
data1.put(header[44], account.getManager().getName());
} else {
data1.put(header[43], "");
data1.put(header[44], "");
}
if (account.getAssigned_to() != null) {
data1.put(header[45], account.getAssigned_to().getId());
data1.put(header[46], account.getAssigned_to()
.getName());
} else {
data1.put(header[45], "");
data1.put(header[46], "");
}
writer.write(data1, header);
}
}
} catch (Exception e) {
throw e;
} finally {
writer.close();
}
InputStream in = new FileInputStream(file);
this.setFileName(fileName);
return in;