Monday 1 August 2022

 

Inter Portlet Communication (IPC) in Liferay 7.4


Public Render Parameter IPC:

1) Create a new module project -> SenderPortlet

2) In SenderPortlet  add the below property in controller class under component annotation 

    

    "javax.portlet.supported-public-render-parameter=ipcMessage"


3) Based on action, we need to set the parameter in actionResponse object

    @Override

    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)

throws IOException, PortletException {

    String ipcMessage =ParamUtil.getString(actionRequest, "sendingValue");

    actionResponse.setRenderParameter("ipcMessage", ipcMessage);

    }


4) Create a another module project -> RecieverPortlet


5) In RecieverPortlet add the below property in controller class under component annotation

   

     "javax.portlet.supported-public-render-parameter=ipcMessage"


6) get the value sender value into recieverportlet in render or doview method


        @Override

public void render(RenderRequest renderRequest, RenderResponse renderResponse)

throws IOException, PortletException {

String senderValueIs = ParamUtil.getString(renderRequest, "ipcMessage");

renderRequest.setAttribute("reciveValue"senderValueIs);

super.render(renderRequest, renderResponse);

}


7) Deploy the both portlets


8) Add the portlets into a page in liferay portal



Thursday 10 December 2020

Changes are Enabling serviceLocator Calls in Liferay DXP

 Working with FreeMarker Template using to fetch the AssetVocabulary and Categories web content template.

  1.  Remove the restricted variables in Control Panel -> System Settings -> Free Marker
  2. Remove serviceLocator and staticUtils

<#assign AssetCategoryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryLocalService")>
<#assign AssetVocabularyLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetVocabularyLocalService")>
<#assign listVecoblaries = AssetVocabularyLocalService.getGroupVocabularies(themeDisplay.getSiteGroupId())>
<#if listVecoblaries?has_content>
<#list listVecoblaries as vecobulary>
<#assign countoftotal = AssetCategoryLocalService.getVocabularyRootCategoriesCount(vecobulary.getVocabularyId())>
<#assign listVecoblaryCategories = AssetCategoryLocalService.getVocabularyRootCategories(vecobulary.getVocabularyId(), 0, countoftotal , null)>
<#if listVecoblaryCategories?has_content>
<#list listVecoblaryCategories as category>
${category.getName()}
</#list>
</#if>
</#list>
</#if>


Tuesday 10 December 2019

Pre and Post Login Events using blade hook in Liferay DXP

For Post Login Event we need to setup the @Component in class

@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)

For Pre Login Event we need to setup the @Component like this -:

@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)

PreLogin Code

@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)

public class PreLoginHook implements LifecycleAction {

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {

log.info("Call Pre Action" );

}
}



Post Login Code

@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)

public class PostLoginHook implements LifecycleAction {

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {

HttpServletRequest req = lifecycleEvent.getRequest();
PermissionChecker permissionChecker;
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User user = null;
try {​​​​​
user = PortalUtil.getUser(req);
}​​​​​ catch (PortalException e) {​​​​​
e.printStackTrace();
}​​​​​
permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
String PhoneNum = user.getExpandoBridge().getAttribute("PhoneNumber");

}


}

Monday 17 December 2018

Sonar Integration with MAVEN


1) Download the apache-maven-3.3.9 software
2) Download the sonarqube-7.4 software
3) Extract the above two softwares into a one folder
4) Set up a maven path in Environment system variable
        C:\Softwaes\apache-maven-3.2.1\bin
5)  Check the maven path setup or not
       Goto Command Prompt -> mvn -version
6)  Add the below properties in setting.xml file
        Goto   C:\Softwaes\apache-maven-3.2.1\conf\
       1)   Open setting.xml file uncomment the below property under "<pluginGroups>" tag
                         <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
      2) Add the below property under  "<profiles>" tag
             <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://localhost:9000
                </sonar.host.url>
            </properties>
        </profile>
7) Run the sonarqube server
8) Create maven application or go to existing application
1) build the maven application
mvn clean install
2) mvn sonar:sonar
9) Access Sonar url "localhost:9000"
10) Get the report of project status under PROJECTS

        

Wednesday 5 December 2018


How to Inject OSGi custom services in Custom Portlets in Liferay 7



1) Create a service builder portlet by using servicebuilder plugin.
2) Generate the OSGI service.
3) Goto xxx-service portlet under build.gradle file 
The below dependencies are generated.
dependencies {
        compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compileOnly project(":modules:EmployeeApp:EmployeeApp-api")
}
4)  Create a sample Portlet
5) Use the custom services in sample portlet
         Add the below dependencie in sample portlet build.gradle file
        compileOnly project(":modules:EmployeeApp:EmployeeApp-api")
6) Refresh the gradle project

Tuesday 6 February 2018

User Landing page validation based on roles
================================

Portal.properties
==================
login.events.post=com.agco.dealer.hook.events.controller.CustomLoginPostAction

liferay-hooks.xml
=================
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>


package com.agco.dealer.hook.events.controller;

public class CustomLoginPostAction extends Action {


public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

long companyId = themeDisplay.getCompanyId();
        User user = themeDisplay.getUser();
        long userId = user.getUserId();

List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
for(Role role : userRoles) {


  if(role.getName().equalsIgnoreCase("X")){
  response.sendRedirect("/web/test");

}
if(role.getName().equalsIgnoreCase("Y")){
  response.sendRedirect("/web/sample");

}
}



}
}

Wednesday 30 August 2017

Liferay integration with solr 



Configure solr with Tomcat 7 


Step -1 
-  Download Solr from apache website. Here we are using solr 4.*.*.(solr-4.3.1.tgz)

-  Download tomcat from apache website(apache-tomcat-7.0.75.zip).

-  Create a  folder called "solr".

-  Unzip both files on solr folder.(  tar -xvf yourfile.tar)

-  Copy solr<version>.war from <extracted_solr>\dist 
    to <extracted_tomcat>\webapps and rename solr<version>.war to solr.war.

-  Copy all jars in <extracted_solr>\example\lib\ext  to <extracted_tomcat>\lib.
      Change the port to 8006

         <Server port="8005" shutdown="SHUTDOWN">
             Change ajp port to 8008
         <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
-  Change the port to 8983  in server.xml file of tomcat . (in different instance no need for this step)

-  Start the tomcat.
-  Check New folder names solr would be available in webapps.

-  Shutdown the tomcat.

-  Modify web.xml located at <extracted_tomcat>\webapps\solr\WEB-INF
         Uncomment below entry and update the path for solr\home.

      <env-entry>  <env-entry-name>solr/home</env-entry-name>   <env-entry-value>    <extracted_solr>C:/Solr/solr-4.3.1/example/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type></env-entry>

- Start the tomcat and access the below URL.
      http://[IP ADDRESS]:[PORT]/solr or  http://localhost:[PORT]/solr

Step-2:

Setup solr-web plugins in liferay :

*  Download the solr web from liferay market place (Liferay Solr 4 Search Engine.lpkg) .
*  Copy the solr-web war file to deploy folder of liferay-server
*  After solr-web  plugin is deployed in Liferay, stop Liferay Tomcat server.
-  Go to <Liferay>/tomcat-7.0.27/webapps/solr-web/WEB-INF/conf directory.
-  Copy and replace schema.xml file to <extracted_solr>example/solr/collection1/conf directory on         solr server.

* Go to < liferay>/tomcat-7.0.42/webapps/solr4-web/WEB-INF/classes/ 
    Edit solr.properties file to update  with property server.http.url
    And value should be< solr-ip>:8983/solr


* Edit the solrconfig.xml file and update the values as below 
     <extracted_solr>example/solr/collection1/conf directory on Solr Server.
        <autoCommit> 
             <maxTime>10000</maxTime> 
            <openSearcher>true</openSearcher> 
     </autoCommit>

*  Creare the log4j.properties file in C:\Solr\apache-tomcat-7.0.75\lib and add the below properties

    #  Logging level
       log4j.rootLogger=INFO, file, CONSOLE

       log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

   #log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
     log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x \u2013 %m%n

   #- size rotation with log cleanup.
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.MaxFileSize=4MB
    log4j.appender.file.MaxBackupIndex=9

   #- File to log to and log format
    log4j.appender.file.File=C:\\Solr\\apache-tomcat-7.0.75\\logs\\solr.log
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n

    log4j.logger.org.apache.zookeeper=WARN

- After above changes are done, first start the Solr Tomcat Server after start Liferay Tomcat server.
- When Liferay Server starts successfully, follow below steps,
     -> Login with admin user
     -> Go to the Control Panel > Server > Server Administration.
     -> Click on Execute Button beside Reindex all search indexes.

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