Workbook wb = this.createWorkbook();
Sheet sheet = wb.getSheet(wb.getSheetName(0));
String password = config.getDefaultPassword();
if (sheet == null || sheet.getLastRowNum() == -1) {
throw new UserAdminException("The first sheet is empty");
}
int limit = sheet.getLastRowNum();
boolean isDuplicate = false;
for (int i = 1; i < limit+1; i++) {
Row row = sheet.getRow(i);
Cell cell = row.getCell(0);
String userName = cell.getStringCellValue();
if (!userStore.isExistingUser(userName)) {
userStore.addUser(userName, password, null, null, null, true);
} else {
isDuplicate = true;
}
}
if (isDuplicate == true) {
throw new UserAdminException(
"Detected duplicate usernames. Failed to import duplicate users. Non-duplicate user names were successfually imported.");
}
} catch (UserAdminException e) {
throw e;
} catch (Throwable e) {
log.error(e.getMessage(), e);
throw new UserAdminException(e.getMessage(), e);
}
}