*
*/
public CustomerViewBean buildViewBeanCustomer(final RequestData requestData, final Customer customer) throws Exception {
final HttpServletRequest request = requestData.getRequest();
final Locale locale = requestData.getLocale();
final CustomerViewBean customerViewBean = new CustomerViewBean();
if (customer != null) {
customerViewBean.setCode(customer.getCode());
customerViewBean.setAvatarImg(requestUtil.getCustomerAvatar(request, customer));
customerViewBean.setTitle(referentialDataService.getTitleByLocale(customer.getTitle(), locale));
customerViewBean.setFirstname(customer.getFirstname());
customerViewBean.setLastname(customer.getLastname());
customerViewBean.setEmail(customer.getEmail());
customerViewBean.setLogin(customer.getLogin());
DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
if (customer.getDateCreate() != null) {
customerViewBean.setDateCreate(dateFormat.format(customer.getDateCreate()));
}
if (customer.getDateUpdate() != null) {
customerViewBean.setDateUpdate(dateFormat.format(customer.getDateUpdate()));
}
final Set<CustomerGroup> groups = customer.getGroups();
for (Iterator<CustomerGroup> iteratorGroup = groups.iterator(); iteratorGroup.hasNext();) {
CustomerGroup group = (CustomerGroup) iteratorGroup.next();
String keyCustomerGroup = group.getCode();
String valueCustomerGroup = group.getName();
customerViewBean.getGroups().put(keyCustomerGroup, valueCustomerGroup);
final Set<CustomerRole> roles = group.getRoles();
for (Iterator<CustomerRole> iteratorRole = roles.iterator(); iteratorRole.hasNext();) {
CustomerRole role = (CustomerRole) iteratorRole.next();
String keyCustomerRole = role.getCode();
String valueCustomerRole = role.getName();
customerViewBean.getRoles().put(keyCustomerRole, valueCustomerRole);
final Set<CustomerPermission> permissions = role.getPermissions();
for (Iterator<CustomerPermission> iteratorPermission = permissions.iterator(); iteratorPermission.hasNext();) {
CustomerPermission permission = (CustomerPermission) iteratorPermission.next();
String keyCustomerPermission = permission.getCode();
String valueCustomerPermission = permission.getName();
customerViewBean.getPermissions().put(keyCustomerPermission, valueCustomerPermission);
}
}
}
final Set<CustomerConnectionLog> connectionLogs = customer.getConnectionLogs();
if (connectionLogs != null && Hibernate.isInitialized(connectionLogs) && connectionLogs.size() > 0) {
CustomerConnectionLog customerConnectionLog = connectionLogs.iterator().next();
if (customerConnectionLog.getLoginDate() != null) {
customerViewBean.setLastConnectionDate(dateFormat.format(customerConnectionLog.getLoginDate()));
} else {
customerViewBean.setLastConnectionDate(Constants.NOT_AVAILABLE);
}
}
customerViewBean.setActive(customer.isActive());
final ValueBean customerScreenNameValueBean = new ValueBean();
customerScreenNameValueBean.setKey(getSpecificMessage(ScopeWebMessage.CUSTOMER, "screenname.label", locale));
customerScreenNameValueBean.setValue(customer.getScreenName());
customerViewBean.getCustomerAttributes().put(CustomerViewBean.SCREEN_NAME, customerScreenNameValueBean);
}
return customerViewBean;
}