* @throws Exception
*
*/
public UserViewBean buildViewBeanUser(final RequestData requestData, final User user) throws Exception {
final HttpServletRequest request = requestData.getRequest();
final UserViewBean userViewBean = new UserViewBean();
userViewBean.setId(user.getId());
userViewBean.setCode(user.getCode());
userViewBean.setLogin(user.getLogin());
userViewBean.setFirstname(user.getFirstname());
userViewBean.setLastname(user.getLastname());
userViewBean.setEmail(user.getEmail());
userViewBean.setPassword(user.getPassword());
userViewBean.setActive(user.isActive());
userViewBean.setAddress1(user.getAddress1());
userViewBean.setAddress2(user.getAddress2());
userViewBean.setAddressAdditionalInformation(user.getAddressAdditionalInformation());
userViewBean.setPostalCode(user.getPostalCode());
userViewBean.setCity(user.getCity());
userViewBean.setStateCode(user.getStateCode());
userViewBean.setAreaCode(user.getAreaCode());
userViewBean.setCountryCode(user.getCountryCode());
DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
if (user.getDateCreate() != null) {
userViewBean.setDateCreate(dateFormat.format(user.getDateCreate()));
} else {
userViewBean.setDateCreate(Constants.NOT_AVAILABLE);
}
if (user.getDateUpdate() != null) {
userViewBean.setDateUpdate(dateFormat.format(user.getDateUpdate()));
} else {
userViewBean.setDateUpdate(Constants.NOT_AVAILABLE);
}
final Set<UserGroup> groups = user.getGroups();
for (Iterator<UserGroup> iteratorGroup = groups.iterator(); iteratorGroup.hasNext();) {
UserGroup group = (UserGroup) iteratorGroup.next();
String keyUserGroup = group.getCode();
String valueUserGroup = group.getName();
userViewBean.getGroups().put(keyUserGroup, valueUserGroup);
final Set<UserRole> roles = group.getRoles();
for (Iterator<UserRole> iteratorRole = roles.iterator(); iteratorRole.hasNext();) {
UserRole role = (UserRole) iteratorRole.next();
String keyUserRole = role.getCode();
String valueUserRole = role.getName();
userViewBean.getRoles().put(keyUserRole, valueUserRole);
final Set<UserPermission> permissions = role.getPermissions();
for (Iterator<UserPermission> iteratorPermission = permissions.iterator(); iteratorPermission.hasNext();) {
UserPermission permission = (UserPermission) iteratorPermission.next();
String keyUserPermission = permission.getCode();
String valueUserPermission = permission.getName();
userViewBean.getPermissions().put(keyUserPermission, valueUserPermission);
}
}
}
final Set<UserConnectionLog> connectionLogs = user.getConnectionLogs();
for (Iterator<UserConnectionLog> iteratorUserConnectionLog = connectionLogs.iterator(); iteratorUserConnectionLog.hasNext();) {
UserConnectionLog connectionLog = (UserConnectionLog) iteratorUserConnectionLog.next();
UserConnectionLogValueBean userConnectionLogValueBean = new UserConnectionLogValueBean();
userConnectionLogValueBean.setDate(dateFormat.format(connectionLog.getLoginDate()));
userConnectionLogValueBean.setHost(Constants.NOT_AVAILABLE);
if (StringUtils.isNotEmpty(connectionLog.getHost())) {
userConnectionLogValueBean.setHost(connectionLog.getHost());
}
userConnectionLogValueBean.setPublicAddress(Constants.NOT_AVAILABLE);
if (StringUtils.isNotEmpty(connectionLog.getPublicAddress())) {
userConnectionLogValueBean.setPublicAddress(connectionLog.getPublicAddress());
}
userConnectionLogValueBean.setPrivateAddress(Constants.NOT_AVAILABLE);
if (StringUtils.isNotEmpty(connectionLog.getPrivateAddress())) {
userConnectionLogValueBean.setPublicAddress(connectionLog.getPrivateAddress());
}
userViewBean.getUserConnectionLogs().add(userConnectionLogValueBean);
}
final List<String> excludedPatterns = new ArrayList<String>();
excludedPatterns.add("form");
userViewBean.setBackUrl(requestUtil.getLastRequestUrl(request, excludedPatterns));
userViewBean.setUserDetailsUrl(backofficeUrlService.generateUrl(BoUrls.USER_DETAILS, requestData, user));
userViewBean.setUserEditUrl(backofficeUrlService.generateUrl(BoUrls.USER_EDIT, requestData, user));
userViewBean.setPersonalDetailsUrl(backofficeUrlService.generateUrl(BoUrls.PERSONAL_DETAILS, requestData, user));
userViewBean.setPersonalEditUrl(backofficeUrlService.generateUrl(BoUrls.PERSONAL_EDIT, requestData, user));
return userViewBean;
}