NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public ResponseDTO bulkUpload(File file) {
ResponseDTO response = new ResponseDTO();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
response.setSuccess(true);
response.setStatus("File Saved Successfully");
String row;
while (!(row = reader.readLine()).contains("Title"))
;
List<String> headers = Arrays.asList(row.split(","));
String title, firstName, lastName, email, userName, phone, role, timezone, active, password;
List<String> groupNames;
List<UserDTO> userDTOs = new ArrayList<>();
Pattern emailPattern = Pattern.compile("^(.+)@(.+)$",
Pattern.DOTALL | Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
while ((row = reader.readLine()) != null) {
UserDTO userDTO = new UserDTO();
List<String> user = Arrays.asList(row.split(","));
if (user.size() != headers.size()) {
break;
}
title = user.get(headers.indexOf("Title"));
firstName = user.get(headers.indexOf("First Name"));
lastName = user.get(headers.indexOf("Last Name"));
email = user.get(headers.indexOf("Email"));
phone = user.get(headers.indexOf("Phone"));
userName = user.get(headers.indexOf("User name"));
groupNames = Arrays.asList(user.get(headers.indexOf("User groups")).split(";"));
role = user.get(headers.indexOf("User Role"));
timezone = user.get(headers.indexOf("Time zone"));
password = user.get(headers.indexOf("Password"));
active = user.get(headers.indexOf("User Active (Y/N)"));
if (!StringUtils.isBlank(title)) {
userDTO.setTitle(title);
}
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("FirstName", firstName);
map.put("LastName", lastName);
map.put("UserName", userName);
map.put("Email", email);
map.put("Role", role);
map.put("Active", active);
map.put("Password", password);
for (String Key : map.keySet()) {
if (StringUtils.isBlank(map.get(Key))) {
LOGGER.debug(Key + " is a Mandatory field. Please enter a value.");
response.setSuccess(false);
response.setStatus(Key + " is a Mandatory field. Please enter a value.");
break;
}
}
if (!response.getSuccess())
break;
else {
userDTO.setFirstName(firstName);
userDTO.setLastName(lastName);
userDTO.setPassword(password);
}

if (userManager.checkSaveUser(userDTO.getUserName())) {
LOGGER.debug("User with this name already exists. Please enter a new name.");
response.setSuccess(false);
response.setStatus("User with this name already exists. Please enter a new name.");
break;
}
LinkedHashMap<String, String> mapFormat = new LinkedHashMap<String, String>();
mapFormat.put("Email", email);
mapFormat.put("UserName", userName);
for (String Key : mapFormat.keySet()) {
if (!emailPattern.matcher(mapFormat.get(Key)).matches()) {
LOGGER.debug(Key
+ " format is incorrect. Please enter value in correct format <[email protected]>");

response.setSuccess(false);
response.setStatus(Key
+ " format is incorrect. Please enter value in correct format <[email protected]>");
break;
}
}
if (!response.getSuccess())
break;
else {
userDTO.setEmail(email);
userDTO.setUserName(userName);
}

if (!StringUtils.isBlank(phone) && !(phone = phone.replaceAll("[^0-9]", "")).equals("")) {
userDTO.setPhone(Long.parseLong(phone));
}
List<GroupInfoDTO> groupInfoDTOs = new ArrayList<>();
if (!groupNames.isEmpty() && !StringUtils.isBlank(groupNames.get(0))) {
List<Long> groupIds = userManager.getGroupIdsByNames(groupNames);
if (!groupIds.isEmpty() && groupIds.size() == groupNames.size()) {
groupIds.forEach(id -> {
GroupInfoDTO groupInfoDTO = new GroupInfoDTO();
groupInfoDTO.setPkGroupId(id);
groupInfoDTOs.add(groupInfoDTO);
});
userDTO.setGroupsMappedTo(groupInfoDTOs);
} else {
LOGGER.debug("User group entered doesn’t exist.Please enter a valid user group");
response.setStatus("User group entered doesn’t exist.Please enter a valid user group");
response.setSuccess(false);
break;
}
}
Long roleId;
if ((roleId = userManager.getRoleIdByName(role)) != null) {
RoleDTO roleDTO = new RoleDTO();
roleDTO.setPkRoleId(roleId);
userDTO.setRole(roleDTO);
} else {
LOGGER.debug("User role entered doesn’t exist.Please enter a valid user role.");
response.setStatus("User role entered doesn’t exist.Please enter a valid user role.");
response.setSuccess(false);
break;
}
Long timezoneId;
if (!StringUtils.isBlank(timezone)
&& (timezoneId = userManager.getTimezoneIdByName(timezone)) != null) {
TimezoneDTO timezoneDTO = new TimezoneDTO();
timezoneDTO.setpkTimezoneId(timezoneId);
userDTO.setTimezone(timezoneDTO);
}
if (active.equals("N")) {
userDTO.setActive(0);
} else {
userDTO.setActive(1);
}
userDTOs.add(userDTO);
}

if (response.getSuccess() && !userDTOs.isEmpty()) {
userDTOs.forEach(userDto -> {
ResponseDTO res = saveUser(userDto);
if (!res.getSuccess()) {
response.setSuccess(false);
response.setStatus(res.getStatus());
}
});
}
reader.close();
} catch (FileNotFoundException e) {
LOGGER.error("File Not Found");
} catch (IOException e) {
LOGGER.error("IOException");
}
return response;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.