Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < line.size(); i++) {
row.put(header[i], line.get(i));
}
Lead lead = new Lead();
try {
String id = row.get(getText("entity.id.label"));
if (!CommonUtil.isNullOrEmpty(id)) {
lead.setId(Integer.parseInt(id));
}
String salutationID = row
.get(getText("entity.salutation_id.label"));
if (CommonUtil.isNullOrEmpty(salutationID)) {
lead.setSalutation(null);
} else {
Salutation salutation = salutationService
.getEntityById(Salutation.class,
Integer.parseInt(salutationID));
lead.setSalutation(salutation);
}
lead.setFirst_name(CommonUtil.fromNullToEmpty(row
.get(getText("entity.first_name.label"))));
lead.setLast_name(CommonUtil.fromNullToEmpty(row
.get(getText("entity.last_name.label"))));
lead.setOffice_phone(CommonUtil.fromNullToEmpty(row
.get(getText("entity.office_phone.label"))));
lead.setCompany(CommonUtil.fromNullToEmpty(row
.get(getText("entity.company.label"))));
lead.setTitle(CommonUtil.fromNullToEmpty(row
.get(getText("entity.title.label"))));
lead.setMobile(CommonUtil.fromNullToEmpty(row
.get(getText("entity.mobile.label"))));
lead.setDepartment(CommonUtil.fromNullToEmpty(row
.get(getText("entity.department.label"))));
lead.setFax(CommonUtil.fromNullToEmpty(row
.get(getText("entity.fax.label"))));
String accountID = row
.get(getText("entity.account_id.label"));
if (CommonUtil.isNullOrEmpty(accountID)) {
lead.setAccount(null);
} else {
Account account = accountService.getEntityById(
Account.class, Integer.parseInt(accountID));
lead.setAccount(account);
}
lead.setPrimary_street(CommonUtil.fromNullToEmpty(row
.get(getText("entity.primary_street.label"))));
lead.setPrimary_city(CommonUtil.fromNullToEmpty(row
.get(getText("entity.primary_city.label"))));
lead.setPrimary_state(CommonUtil.fromNullToEmpty(row
.get(getText("entity.primary_state.label"))));
lead.setPrimary_postal_code(CommonUtil.fromNullToEmpty(row
.get(getText("entity.primary_postal_code.label"))));
lead.setPrimary_country(CommonUtil.fromNullToEmpty(row
.get(getText("entity.primary_country.label"))));
lead.setOther_street(CommonUtil.fromNullToEmpty(row
.get(getText("entity.other_street.label"))));
lead.setOther_city(CommonUtil.fromNullToEmpty(row
.get(getText("entity.other_city.label"))));
lead.setOther_state(CommonUtil.fromNullToEmpty(row
.get(getText("entity.other_state.label"))));
lead.setOther_postal_code(CommonUtil.fromNullToEmpty(row
.get(getText("entity.other_postal_code.label"))));
lead.setOther_country(CommonUtil.fromNullToEmpty(row
.get(getText("entity.other_country.label"))));
lead.setEmail(CommonUtil.fromNullToEmpty(row
.get(getText("entity.email.label"))));
lead.setNotes(CommonUtil.fromNullToEmpty(row
.get(getText("entity.notes.label"))));
String statusID = row
.get(getText("entity.status_id.label"));
if (CommonUtil.isNullOrEmpty(statusID)) {
lead.setStatus(null);
} else {
LeadStatus leadStatus = leadStatusService
.getEntityById(LeadStatus.class,
Integer.parseInt(statusID));
lead.setStatus(leadStatus);
}
lead.setStatus_description(CommonUtil.fromNullToEmpty(row
.get(getText("lead.status_description.label"))));
String leadSourceID = row
.get(getText("entity.leadSource_id.label"));
if (CommonUtil.isNullOrEmpty(leadSourceID)) {
lead.setLead_source(null);
} else {
LeadSource leadSource = leadSourceService
.getEntityById(LeadSource.class,
Integer.parseInt(leadSourceID));
lead.setLead_source(leadSource);
}
lead.setLead_source_description(CommonUtil.fromNullToEmpty(row
.get(getText("lead.lead_source_description.label"))));
lead.setOpportunity_amount(CommonUtil.fromNullToEmpty(row
.get(getText("lead.opportunity_amount.label"))));
lead.setReferred_by(CommonUtil.fromNullToEmpty(row
.get(getText("lead.referred_by.label"))));
String campaignID = row
.get(getText("entity.campaign_id.label"));
if (CommonUtil.isNullOrEmpty(campaignID)) {
lead.setCampaign(null);
} else {
Campaign campaign = campaignService.getEntityById(
Campaign.class, Integer.parseInt(campaignID));
lead.setCampaign(campaign);
}
String doNotCall = row
.get(getText("entity.not_call.label"));
if (CommonUtil.isNullOrEmpty(doNotCall)) {
lead.setNot_call(false);
} else {
lead.setNot_call(Boolean.parseBoolean(doNotCall));
}
String assignedToID = row
.get(getText("entity.assigned_to_id.label"));
if (CommonUtil.isNullOrEmpty(assignedToID)) {
lead.setAssigned_to(null);
} else {
User assignedTo = userService.getEntityById(User.class,
Integer.parseInt(assignedToID));
lead.setAssigned_to(assignedTo);
}
baseService.makePersistent(lead);
successfulNum++;
} catch (Exception e) {
failedNum++;
String firstName = CommonUtil.fromNullToEmpty(lead
.getFirst_name());
String lastName = CommonUtil.fromNullToEmpty(lead
.getLast_name());
failedMsg.put(firstName + " " + lastName, e.getMessage());
}
}