Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < line.size(); i++) {
row.put(header[i], line.get(i));
}
Opportunity opportunity = new Opportunity();
try {
String id = row.get(getText("entity.id.label"));
if (!CommonUtil.isNullOrEmpty(id)) {
opportunity.setId(Integer.parseInt(id));
}
opportunity.setName(CommonUtil.fromNullToEmpty(row
.get(getText("entity.name.label"))));
String accountID = row
.get(getText("entity.account_id.label"));
if (CommonUtil.isNullOrEmpty(accountID)) {
opportunity.setAccount(null);
} else {
Account account = accountService.getEntityById(
Account.class, Integer.parseInt(accountID));
opportunity.setAccount(account);
}
String currencyID = row
.get(getText("entity.currency_id.label"));
if (CommonUtil.isNullOrEmpty(currencyID)) {
opportunity.setCurrency(null);
} else {
Currency currency = currencyService.getEntityById(
Currency.class, Integer.parseInt(currencyID));
opportunity.setCurrency(currency);
}
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constant.DATE_EDIT_FORMAT);
String expectCloseDateS = row
.get(getText("opportunity.expect_close_date.label"));
if (expectCloseDateS != null) {
Date expectCloseDate = dateFormat
.parse(expectCloseDateS);
opportunity.setExpect_close_date(expectCloseDate);
} else {
opportunity.setExpect_close_date(null);
}
opportunity
.setOpportunity_amount(CommonUtil.fromNullToEmpty(row
.get(getText("opportunity.opportunity_amount.label"))));
String typeID = row.get(getText("entity.type_id.label"));
if (CommonUtil.isNullOrEmpty(typeID)) {
opportunity.setType(null);
} else {
OpportunityType opportunityType = opportunityTypeService
.getEntityById(OpportunityType.class,
Integer.parseInt(typeID));
opportunity.setType(opportunityType);
}
String salesStageID = row
.get(getText("entity.salesStage_id.label"));
if (CommonUtil.isNullOrEmpty(salesStageID)) {
opportunity.setSales_stage(null);
} else {
SalesStage salesStage = salesStageService
.getEntityById(SalesStage.class,
Integer.parseInt(salesStageID));
opportunity.setSales_stage(salesStage);
}
String leadSourceID = row
.get(getText("entity.leadSource_id.label"));
if (CommonUtil.isNullOrEmpty(leadSourceID)) {
opportunity.setLead_source(null);
} else {
LeadSource leadSource = leadSourceService
.getEntityById(LeadSource.class,
Integer.parseInt(leadSourceID));
opportunity.setLead_source(leadSource);
}
String probability = row
.get(getText("opportunity.probability.label"));
if (CommonUtil.isNullOrEmpty(probability)) {
opportunity.setProbability(0);
} else {
opportunity.setProbability(Double
.parseDouble(probability));
}
String campaignID = row
.get(getText("entity.campaign_id.label"));
if (CommonUtil.isNullOrEmpty(campaignID)) {
opportunity.setCampaign(null);
} else {
Campaign campaign = campaignService.getEntityById(
Campaign.class, Integer.parseInt(campaignID));
opportunity.setCampaign(campaign);
}
opportunity.setNext_step(CommonUtil.fromNullToEmpty(row
.get(getText("opportunity.next_step.label"))));
opportunity.setNotes(CommonUtil.fromNullToEmpty(row
.get(getText("entity.notes.label"))));
String assignedToID = row
.get(getText("entity.assigned_to_id.label"));
if (CommonUtil.isNullOrEmpty(assignedToID)) {
opportunity.setAssigned_to(null);
} else {
User assignedTo = userService.getEntityById(User.class,
Integer.parseInt(assignedToID));
opportunity.setAssigned_to(assignedTo);
}
baseService.makePersistent(opportunity);
successfulNum++;
} catch (Exception e) {
failedNum++;
failedMsg.put(opportunity.getName(), e.getMessage());
}
}
this.setFailedMsg(failedMsg);