Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < line.size(); i++) {
row.put(header[i], line.get(i));
}
Task task = new Task();
try {
String id = row.get(getText("entity.id.label"));
if (!CommonUtil.isNullOrEmpty(id)) {
task.setId(Integer.parseInt(id));
}
task.setSubject(CommonUtil.fromNullToEmpty(row
.get(getText("entity.subject.label"))));
String statusID = row
.get(getText("entity.status_id.label"));
if (CommonUtil.isNullOrEmpty(statusID)) {
task.setStatus(null);
} else {
TaskStatus status = taskStatusService.getEntityById(
TaskStatus.class, Integer.parseInt(statusID));
task.setStatus(status);
}
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constant.DATE_TIME_FORMAT);
String startDateS = row
.get(getText("entity.start_date.label"));
if (startDateS != null) {
Date startDate = dateFormat.parse(startDateS);
task.setStart_date(startDate);
} else {
task.setStart_date(null);
}
String dueDateS = row.get(getText("task.due_date.label"));
if (dueDateS != null) {
Date dueDate = dateFormat.parse(dueDateS);
task.setDue_date(dueDate);
} else {
task.setDue_date(null);
}
task.setRelated_object(CommonUtil.fromNullToEmpty(row
.get(getText("entity.related_object.label"))));
String relatedRecord = row
.get(getText("entity.related_record_id.label"));
if (CommonUtil.isNullOrEmpty(relatedRecord)) {
task.setRelated_record(0);
} else {
task.setRelated_record(Integer.parseInt(relatedRecord));
}
String contactID = row
.get(getText("entity.contact_id.label"));
if (CommonUtil.isNullOrEmpty(contactID)) {
task.setContact(null);
} else {
Contact contact = contactService.getEntityById(
Contact.class, Integer.parseInt(contactID));
task.setContact(contact);
}
String priorityID = row
.get(getText("entity.priority_id.label"));
if (CommonUtil.isNullOrEmpty(priorityID)) {
task.setPriority(null);
} else {
TaskPriority priority = taskPriorityService
.getEntityById(TaskPriority.class,
Integer.parseInt(priorityID));
task.setPriority(priority);
}
task.setDescription(CommonUtil.fromNullToEmpty(row
.get(getText("entity.description.label"))));
task.setNotes(CommonUtil.fromNullToEmpty(row
.get(getText("entity.notes.label"))));
String assignedToID = row
.get(getText("entity.assigned_to_id.label"));
if (CommonUtil.isNullOrEmpty(assignedToID)) {
task.setAssigned_to(null);
} else {
User assignedTo = userService.getEntityById(User.class,
Integer.parseInt(assignedToID));
task.setAssigned_to(assignedTo);
}
baseService.makePersistent(task);
successfulNum++;
} catch (Exception e) {
failedNum++;
failedMsg.put(task.getSubject(), e.getMessage());
}
}
this.setFailedMsg(failedMsg);