Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < line.size(); i++) {
row.put(header[i], line.get(i));
}
Campaign campaign = new Campaign();
try {
String id = row.get(getText("entity.id.label"));
if (!CommonUtil.isNullOrEmpty(id)) {
campaign.setId(Integer.parseInt(id));
UserUtil.permissionCheck("update_campaign");
} else {
UserUtil.permissionCheck("create_campaign");
}
campaign.setName(CommonUtil.fromNullToEmpty(row
.get(getText("entity.name.label"))));
String statusID = row
.get(getText("entity.status_id.label"));
if (CommonUtil.isNullOrEmpty(statusID)) {
campaign.setStatus(null);
} else {
CampaignStatus status = campaignStatusService
.getEntityById(CampaignStatus.class,
Integer.parseInt(statusID));
campaign.setStatus(status);
}
String typeID = row.get(getText("entity.type_id.label"));
if (CommonUtil.isNullOrEmpty(typeID)) {
campaign.setType(null);
} else {
CampaignType type = campaignTypeService.getEntityById(
CampaignType.class, Integer.parseInt(typeID));
campaign.setType(type);
}
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constant.DATE_EDIT_FORMAT);
String startDateS = row
.get(getText("entity.start_date.label"));
if (startDateS != null) {
Date startDate = dateFormat.parse(startDateS);
campaign.setStart_date(startDate);
} else {
campaign.setStart_date(null);
}
String endDateS = row.get(getText("entity.end_date.label"));
if (startDateS != null) {
Date endDate = dateFormat.parse(endDateS);
campaign.setEnd_date(endDate);
} else {
campaign.setEnd_date(null);
}
String currencyID = row
.get(getText("entity.currency_id.label"));
if (CommonUtil.isNullOrEmpty(currencyID)) {
campaign.setCurrency(null);
} else {
Currency currency = currencyService.getEntityById(
Currency.class, Integer.parseInt(currencyID));
campaign.setCurrency(currency);
}
String impressions = row
.get(getText("campaign.impressions.label"));
if (CommonUtil.isNullOrEmpty(impressions)) {
campaign.setImpressions(0);
} else {
campaign.setImpressions(Double.parseDouble(impressions));
}
String budget = row.get(getText("campaign.budget.label"));
if (CommonUtil.isNullOrEmpty(budget)) {
campaign.setBudget(0);
} else {
campaign.setBudget(Double.parseDouble(budget));
}
String expectedCost = row
.get(getText("campaign.expected_cost.label"));
if (CommonUtil.isNullOrEmpty(expectedCost)) {
campaign.setExpected_cost(0);
} else {
campaign.setExpected_cost(Double
.parseDouble(expectedCost));
}
String actualCost = row
.get(getText("campaign.actual_cost.label "));
if (CommonUtil.isNullOrEmpty(actualCost)) {
campaign.setActual_cost(0);
} else {
campaign.setActual_cost(Double.parseDouble(actualCost));
}
String expectedRevenue = row
.get(getText("campaign.expected_revenue.label"));
if (CommonUtil.isNullOrEmpty(expectedRevenue)) {
campaign.setExpected_revenue(0);
} else {
campaign.setExpected_revenue(Double
.parseDouble(expectedRevenue));
}
String expectedRespone = row
.get(getText("campaign.expected_respone.label"));
if (CommonUtil.isNullOrEmpty(expectedRespone)) {
campaign.setExpected_respone(0);
} else {
campaign.setExpected_respone(Double
.parseDouble(expectedRespone));
}
campaign.setObjective(CommonUtil.fromNullToEmpty(row
.get(getText("campaign.objective.label"))));
campaign.setNotes(CommonUtil.fromNullToEmpty(row
.get(getText("entity.notes.label"))));
String assignedToID = row
.get(getText("entity.assigned_to_id.label"));
if (CommonUtil.isNullOrEmpty(assignedToID)) {
campaign.setAssigned_to(null);
} else {
User assignedTo = userService.getEntityById(User.class,
Integer.parseInt(assignedToID));
campaign.setAssigned_to(assignedTo);
}
baseService.makePersistent(campaign);
successfulNum++;
} catch (Exception e) {
failedNum++;
failedMsg.put(campaign.getName(), e.getMessage());
}
}
this.setFailedMsg(failedMsg);