Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < line.size(); i++) {
row.put(header[i], line.get(i));
}
CaseInstance caseInstance = new CaseInstance();
try {
String id = row.get(getText("entity.id.label"));
if (!CommonUtil.isNullOrEmpty(id)) {
caseInstance.setId(Integer.parseInt(id));
UserUtil.permissionCheck("update_case");
} else {
UserUtil.permissionCheck("create_case");
}
String priorityID = row
.get(getText("entity.priority_id.label"));
if (CommonUtil.isNullOrEmpty(priorityID)) {
caseInstance.setPriority(null);
} else {
CasePriority priority = casePriorityService
.getEntityById(CasePriority.class,
Integer.parseInt(priorityID));
caseInstance.setPriority(priority);
}
String statusID = row
.get(getText("entity.status_id.label"));
if (CommonUtil.isNullOrEmpty(statusID)) {
caseInstance.setStatus(null);
} else {
CaseStatus status = caseStatusService.getEntityById(
CaseStatus.class, Integer.parseInt(statusID));
caseInstance.setStatus(status);
}
String typeID = row.get(getText("case.type_id.label"));
if (CommonUtil.isNullOrEmpty(typeID)) {
caseInstance.setType(null);
} else {
CaseType type = caseTypeService.getEntityById(
CaseType.class, Integer.parseInt(typeID));
caseInstance.setType(type);
}
String originID = row.get(getText("case.origin_id.label"));
if (CommonUtil.isNullOrEmpty(originID)) {
caseInstance.setOrigin(null);
} else {
CaseOrigin origin = caseOriginService.getEntityById(
CaseOrigin.class, Integer.parseInt(originID));
caseInstance.setOrigin(origin);
}
String reasonID = row.get(getText("case.reason_id.label"));
if (CommonUtil.isNullOrEmpty(reasonID)) {
caseInstance.setReason(null);
} else {
CaseReason reason = caseReasonService.getEntityById(
CaseReason.class, Integer.parseInt(reasonID));
caseInstance.setReason(reason);
}
caseInstance.setSubject(CommonUtil.fromNullToEmpty(row
.get(getText("entity.subject.label"))));
caseInstance.setNotes(CommonUtil.fromNullToEmpty(row
.get(getText("entity.notes.label"))));
caseInstance.setResolution(CommonUtil.fromNullToEmpty(row
.get(getText("case.resolution.label"))));
String assignedToID = row
.get(getText("entity.assigned_to_id.label"));
if (CommonUtil.isNullOrEmpty(assignedToID)) {
caseInstance.setAssigned_to(null);
} else {
User assignedTo = userService.getEntityById(User.class,
Integer.parseInt(assignedToID));
caseInstance.setAssigned_to(assignedTo);
}
baseService.makePersistent(caseInstance);
successfulNum++;
} catch (Exception e) {
failedNum++;
failedMsg.put(String.valueOf(caseInstance.getSubject()),
e.getMessage());
}
}