Posts

Showing posts from July, 2015

UnSubscribe the user from the comment

  Whenever we write comment to the post(Blog or webcontent etc..) , user will automatically subscribe to the comments and also will be receving the email when ever any user update or add the comment.   If user want to subscribe manually, it is timetaking to check each and every post.   so here the following code which helps to unsubscribe the user from the post. Here we are unsubscribing the "Admin" user  posts of  JournalArticle.   String screenName = "Admin"; String className = JournalArticle.class.getName(); User user = null; ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); try { user = UserLocalServiceUtil.getUserByScreenName(themeDisplay.getCompanyId(), screenName); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } if(user!=null) { List<subscription> subscriptionList = null; try { subscriptionL

Knowing the cluster Node in the server

Sometimes we need to know which server node we are accessing in cluster environment. We know that we can execute the "Groovy" and "BeanShell" script in control panel. So place the following code and execute it, you will be knowing which server we are accessing. Note: Before execution make necessary imports ClusterNode clusterNode =ClusterExecutorUtil.getLocalClusterNode(); if (clusterNode != null) { System.out.println("cluster Node is "+clusterNode.getClusterNodeId()); }

Deleting the cookies

Sometimes it is required to delete the cookies, where we need to set the MaxAge to 0. Here we are retrieving the cookies from the request, and setting the maxAge to "0" to the response , so that it will expire the cookies. Cookie[] cookies = request.getCookies(); for(Cookie cookie : cookies){ System.out.println("cookie Name is "+cookie.getName()); cookie.setMaxAge(0); response.addProperty(cookie); }