Sunday 25 September 2016

Get the user roles in programtically :

if we want to get the roles of postlogin add the below code:
------------------------------------------------------------------------
HttpServletRequest request;
HttpServletResponse response;

HttpSession session = request.getSession(false);

User user = PortalUtil.getUser(request);
if(Validator.isNotNull(user)){

List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
Map<String, String> rolesMap = new HashMap<String, String>();
for (Role role : userRoles) {
rolesMap.put(role.getName(), role.getName());
}

}
session.setAttribute("roles", rolesMap);

Get the roels in appropriate portlet:
============================

HashMap<String, String> rolesMap = (HashMap<String, String>) portletSession.getAttribute("roles",
PortletSession.APPLICATION_SCOPE);




Monday 19 September 2016

Expando Values.

Get the custom attribute values or Expando values :
======================================

User user = null;
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
user = themeDisplay.getUser();
long curLoginUserid = user.getUserId();
ExpandoValue expandoMobileNumberValue =  ExpandoValueLocalServiceUtil.getValue(themeDisplay.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "contact-number-mobile", curLoginUserid);
ExpandoValue expandoUserCountryValue =  ExpandoValueLocalServiceUtil.getValue(themeDisplay.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "User Country", curLoginUserid);
String curLoginMobileNumber = expandoMobileNumberValue.getData();
String curLoginUserCountry = " ";
if(Validator.isNotNull(expandoUserCountryValue))
curLoginUserCountry = expandoUserCountryValue.getData();

Update expando values of login user:
============================

ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User loginUser = themeDisplay.getUser();
User user = null;
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
user = themeDisplay.getUser();
long curLoginUserid = user.getUserId();
String updateCompanyName = UpdateForm.getCompanyName();
ExpandoValue expandoValue =  ExpandoValueLocalServiceUtil.getValue(themeDisplay.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "company-name", userId);
expandoValue.setData(updateCompanyName);
ExpandoValueLocalServiceUtil.updateExpandoValue(expandoValue);

User details add and get the programatically.

Add the user details in Programatically.
=============================

ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User user = null;
String emailaddress = ParamUtil.getString(“emailaddress”);
String screenName = ParamUtil. getString(“screenname”);
List<User> users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
for(User user : users) {
    if(emailAddress.equalsIgnoreCase(user.getEmailAddress()) || screenName.equalsIgnoreCase(user.getScreenName())){
            System.out.println(“user is already exists ”);
             }
             else{
             }
         }

               long[] groupIds = {themeDisplay.getLayout().getGroupId()};
               ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), req);
serviceContext.setScopeGroupId(themeDisplay.getLayout().getGroupId());
long[] roleIds = {};
long[] organisationIds = {};
long[] userGroupIds = {};


user =UserLocalServiceUtil.addUser(20199, themeDisplay.getCompanyId(), true, "", "", false, screenNam, emailAddrs,facebookId, "", Locale.ENGLISH, firstName, "", lastNameUsr, 1, 1, true, 10, 10, 1900, "", groupIds, roleIds, organisationIds, userGroupIds, true, serviceContext);


Get the current user login details:

=============================

User user = null;
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
user = themeDisplay.getUser();
long curLoginUserid = user.getUserId();

Update the current user login details:
===========================
String email = UpdateForm.getEmailAddress();
String updateScreenName = UpdateForm.getScreenName();
String updateFstName = UpdateForm.getFisrtName();
String updateLastName = UpdateForm.getLastName();
String updateCompanyName = UpdateForm.getCompanyName();
                             
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User loginUser = themeDisplay.getUser();
loginUser.setEmailAddress(email);
loginUser.setUserId(userId);
loginUser.setFirstName(updateFstName);
loginUser.setLastName(updateLastName);
loginUser.setScreenName(updateScreenName);
UserLocalServiceUtil.updateUser(loginUser);

  Inter Portlet Communication (IPC) in Liferay 7.4 Public Render Parameter IPC: 1) Create a new module project -> SenderPortlet 2) In  Se...