MessageResources resources = getResources(req);
Long userSetId = userImportForm.getUserSetId();
if(userSetId == null){
throw new InputException(resources.getMessage(locale, "smssvc.missingUserSetSelection"));
}
UserSetManager userSetMgm = new UserSetManager(locale,session);
UserSet userSet = userSetMgm.getUserSet(userSetId);
if(userSet == null){
throw new InputException(resources.getMessage(locale, "um.userSetNotFound",userSetId));
}
checkAccessRights(req, userSet.getGroup());
FormFile csvFile = userImportForm.getCsvFile();
if (csvFile != null && csvFile.getFileName() != null && csvFile.getFileName().length() != 0){
try {
InputStream inputStream = csvFile.getInputStream();
UserManager userManager = new UserManager(locale,session);
UserImportResult importResult = userManager.importData(inputStream, userImportForm.getCharacterSet(), userImportForm.getDelimiter(),userSet,
userImportForm.getMergeSelection().equals("userName"),
userImportForm.getMergeSelection().equals("msisdn"),
userImportForm.getMergeSelection().equals("personnelNumber"));
inputStream.close();
req.setAttribute("userImportCounter", importResult.getUsersCreated());
req.setAttribute("userUpdateCounter", importResult.getUsersUpdated());
req.setAttribute("userIgnoreCounter", importResult.getUsersIgnored());
req.setAttribute("userImportErrormessages", importResult.getErrorMessages());
} catch (FileNotFoundException e){
throw new InputException(resources.getMessage(locale, "um.fileNotFound",csvFile.getFileName()),e);
} catch (IOException e) {
throw new InputException(resources.getMessage(locale, "um.couldNotReadFile",csvFile.getFileName()),e);
}
} else {
throw new InputException(resources.getMessage(locale, "um.fileNotFound"));
}
return mapping.findForward("imported");