Posts

Checking weather the user has the role Organization Administrator.

Whenever we are creating the Organization we can assign the user to the Organization also we can assign the Organization role to the User. As of now we have 2 roles. 1.Organization Owner. 2. Organization Administrator. User who created the Organization will have the role "Organization Owner". But we need to manually assign the "Organization Administrator" to the user. In programmatically to check weather user has roles or not here is the code. ThemeDisplay  themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY); try {         Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),RoleConstants.ORGANIZATION_ADMINISTRATOR);  //Get the Role List<UserGroupRole> userGroupList = UserGroupRoleLocalServiceUtil.getUserGroupRoles(themeDisplay.getUserId()); //Getting the Roles of the User for(UserGroupRole userGroupRole :userGroupList) { //Iterating the loop      if...

Checking the Weather user has userdelete Permission or not.

First of all we need the permission checker we can get it from the themedisplay . PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();  boolean deleteStatus  = false; try { Getting the all the Role of the User List<Role> roleList = RoleLocalServiceUtil.getUserRoles(themeDisplay.getUserId());     for(Role role : roleList) { Iterating the all the roles of the user           if(permissionChecker.hasPermission(themeDisplay.getScopeGroupId(), User.class.getName(),                          role.getRoleId(), ActionKeys.DELETE)) {            deleteStatus = true;         System.out.println("roleId"+role.getName());          }     } } catch (SystemException e) {           e.printStackTrace(); }

Ajax Implementation in the Liferay

Creating the Resource URL Liferay's default uses the resource url for ajax requests          <portlet:resourceURL id="addResource" var="addResourceURL">         </portlet:resourceURL> Creating the Ajax function creating the Jquery  ajax function function <portlet:namespace/>getEntries(){                 var url = "${addResourceURL}";                         $.ajax({                                 type : "POST",                                 url : url,                                 dataType : "JSON",                 ...

Assigning and Unassigning user to the userGroup

Assinging users to the userGroups .       UserLocalServiceUtil.addUserGroupUsers(userGroupId, addUserIds); Removing users from the UserGroups.       UserLocalServiceUtil.unsetUserGroupUsers(userGroupId, removeUserIds);

Converting the Hits into the UserList

 By default liferay indexes the content and So when ever we are searching the any content in the liferay, It reterives from the index. Suppose we think we need search the Users which we need to implement programmatically. Liferay has one utility function which search the user and returns in the form of a Hits. Hits hits = UserLocalServiceUtil.search(-,-,-,-,-,-,-,-,-,-,-,); So how can convert the hits into UserList.  Here the code. public List<User> getUserList(Hits hits) throws PortalException, SystemException {   List<Document> documents = hits.toList(); // Converting the Hits into the Documents List<User> userList = new ArrayList<User>();         for (Document document : documents) {                 long userId = GetterUtil.getLong(document.get(Field.USER_ID)); // Getting the Individual User by userId.             ...

Getting the search container checkbox values in the Liferay

In liferay if we see the search container they have the chexkboxes which default liferay creates. So how do we reterive the those checkbox values in the javascript? Here is the code to retrieve the chexkbox values in javascript. Liferay.provide( window, '<portlet:namespace />updateStatus',  // Name of the javascript function . function(cmd) {       var updateStatus = true;        var updateUserIds = Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, "<portlet:namespace />allRowIds");  // Getting the checked checkboxes values , Here "fm" is the form name .       if (!updateUserIds) {            updateStatus = false;       } // Here based on the user click we are displaying the message . else if (cmd == "deActive") {      if (!confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-deac...

Deleting the user and Changing the status : Active and Deactive of the user

Here is the following code to delete the user and change the status of the user In Liferay After deactivating the user then only we can delete the user. It is the below code what liferay is using to delete and update the status of the user.  protected void deleteUsers(ActionRequest actionRequest) throws Exception {              String cmd = ParamUtil.getString(actionRequest, Constants.CMD);              // Getting the List of all the Users              long[] deleteUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteUserIds"), 0L);              // Based on the user status selected we are changing the status              for (long deleteUserId : deleteUserIds) {                        if (cmd.equals(Constants.DEACTIV...