Wednesday, December 26, 2012

Template : some important variable in template(.vm)

Hi All,

   Many time we use webcontent OOTB functionality for our solution. for that we also use Structure/Template. here Template is render part of WebContent. so many time developer stuck with how to get value of some important properties like theme-dispaly,scopegroupid,image path, etc. so, here give some instruction for that.

1) to get instance of class (some times we can't get accesss class by serviceLocator.findService())
$portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance()   

2)currentScopegroupid 
    - $getterUtil.getLong($request.get("theme-display").get("scope-group-id"))
    - $request.theme-display.scope-group-id
3) images path in theme
    $request.get("theme-display").path-theme-images
4) themeDispaly
    $request.theme-display
5) globalScopeGroupId
    $groupId

5) find service
 $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")


Enjoy!!!

Wednesday, December 19, 2012

Servidce/Util classes access in template (.vm) file in Liferay

Hi Developers,

Many times you need to access services/util class in template. 

Below is some importance hits for the same.

=> Access services using findService method in Velocity(vm)

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
=>Access util class using  findUtil Method for inbuilt Util of Liferay
#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))
=> some times you also need to access util class which is not have access in template file like StorageEngineUtil. for that you can use below approch..

#set ($util = $portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance()) 


HTH.. :))

Wednesday, December 12, 2012

Audio play in portlet using flowplayer.....



For mp3 audio file play you need below plugin swf & js file.

flowplayer.controls-3.2.14.swf
flowplayer.audio-3.2.10.swf
flowplayer-3.2.15.swf
flowplayer-3.2.6.min.js

and here is the sample code snippet to play mp3 audio file which in document library....

<< script type="text/javascript" src="/video-portlet/js/flowplayer-3.2.6.min.js"></script>

<< a href="http://localhost:8080/documents/10180/f7804b0c-9001-4f59-a7b2-45dcbceae8ca" style="display:block;width:520px;height:330px" id="unsecure">
            </a>
<< script type="text/javascript">
        $f("unsecure", "/video-portlet/flowplayer-3.2.15.swf",
                {
                    plugins: {
                        controls: {
                            fullscreen: true,
                            height: 30,
                            autoHide: false
                        },
                        audio: {
                            url: '/video-portlet/flowplayer.audio-3.2.10.swf'
                        }
                    },
                    clip:  {
                         provider: "audio"
                    }
                }
       
       
            );

        </script>


NOTE: "http://localhost:8080/documents/10180/f7804b0c-9001-4f59-a7b2-45dcbceae8ca" is a document library file url.

Monday, September 24, 2012

Connect to Another Datasource/Database Schema from Portlet with service

Hi Folks,

Many developer/client's need to separate the liferay database table and custom database table. so, here is the solution to maintain this approach. for that we maintain two data source/schema for liferay and custom database. we can achieve this by trying to  following steps -

1) portal-ext.properties

Add two connection properties for maintain two differance database source/schema. for example

###### MySQL Connection#######
## Liferay default database connection
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root

## Your new database connection
jdbc.test.driverClassName=com.mysql.jdbc.Driver
jdbc.test.url=jdbc:mysql://localhost/mytest?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.test.username=root
jdbc.test.password=root

2) ext-spring.xml

    create ext-spring.xml in docroot\WEB-INF\src\META-INF\ of you portlet to connect with other database shema default then liferay. copy the below content and paste in newly created file.
   
<<?xml version="1.0"?>
<<beans
    default-destroy-method="destroy"
    default-init-method="afterPropertiesSet"   
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
>

    <<bean id="testDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <<property name="targetDataSource">
            <<bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
                <<property name="propertyPrefix" value="jdbc.test."/>
            <</bean>
        <</property>
    <</bean>
   
   
    <<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" lazy-init="true">
        <<property name="dataSource" ref="testDataSource" />       
    <</bean>
   

    <<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">       
        <<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
    <</bean>
   
    <<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
        <<property name="dataSource" ref="testDataSource" />
        <<property name="globalRollbackOnParticipationFailure" value="false"/>
        <<property name="sessionFactory" ref="testHibernateSessionFactory" />
    <</bean>

<</beans>

3) service.xml
    create entity with the parameter data-source,session-factory,tx-manager to connect other then default database. for example....
   
    <<entity name="MyTable" local-service="true" remote-service="false" data-source="testDataSource" session-factory="testSessionFactory" tx-manager="testTransactionManager">


4) service.properties

   check the entry of ext-spring.xml in \docroot\WEB-INF\src\service.properties file(some version of liferay have already this entry). if it is not there then append spring.configs properties with the value "WEB-INF/classes/META-INF/ext-spring.xml"
  
  
 At Last......

 After deploying portlet, custom portlet are able to connect with other then default database source/schema .

 NOTE :
 1)This example is  based on Liferay 6.0 and 6.0.29 tomcat bundle. you have to do specific changes in any of file(.xml) if needed based on Liferay version.
 2)While you connect with other then default liferay database source/schema. service-builder can't create automatically table in database. you have to create table manually. then after you can CURD operation for you custom table same as liferay default database.

Thursday, September 6, 2012

Liferay portal connection with various databse

Hi visitor,

here is the list of  different/various database and it's connection properties to connection Liferay portal.

 MySQL

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=


 Oracle

jdbc.default.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.default.url=jdbc:oracle:thin:@localhost:1521:xe
jdbc.default.username=lportal
jdbc.default.password=lportal


DB2

jdbc.default.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.default.url=jdbc:db2://localhost:50000/lportal:deferPrepares=false;fullyMaterializeInputStreams=true;fullyMaterializeLobData=true;progresssiveLocators=2;progressiveStreaming=2;
jdbc.default.username=db2admin
jdbc.default.password=lportal


 Derby

jdbc.default.driverClassName=org.apache.derby.jdbc.EmbeddedDriver
jdbc.default.url=jdbc:derby:lportal
jdbc.default.username=
jdbc.default.password=


 Hypersonic

dbc.default.driverClassName=org.hsqldb.jdbcDriver
dbc.default.url=jdbc:hsqldb:${liferay.home}/data/hsql/lportal
dbc.default.username=sa
dbc.default.password=


 Ingres

jdbc.default.driverClassName=com.ingres.jdbc.IngresDriver
jdbc.default.url=jdbc:ingres://localhost:II7/lportal
jdbc.default.username=
jdbc.default.password=


 P6Spy

jdbc.default.driverClassName=com.p6spy.engine.spy.P6SpyDriver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=


 PostgreSQL

jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://localhost:5432/lportal
jdbc.default.username=sa
jdbc.default.password=


 SQL Server

jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://localhost/lportal
jdbc.default.username=sa
jdbc.default.password=


 Sybase

jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sybase://localhost:5000/lportal
jdbc.default.username=sa
jdbc.default.password=

Sunday, August 5, 2012

Drop all tables from users schemas in Oracle

Many times we need to clear/delete all TABLE from users schema.We can't directly delete all table.it is tedious task to delete table one by one by command. here is short way to do this.

Execute following statement which will create drop query for every table.

SELECT 'DROP TABLE ' || TABLE_NAME || ' CASCADE CONSTRAINTS;' FROM user_tables;

Now, analyze results and copy appropriate statements, paste and execute them against the database.

This is the simple way to delete all tables from user's schema.


This approach can also be used in order to drop all SEQUENCE from user's schema.

SELECT 'DROP SEQUENCE ' || sequence_name || ';' FROM user_sequences;


That's it. enjoy...!!!

Tuesday, July 24, 2012

Use of PortalClassInvoker in Liferay-Portlet...

Some times we need to use portal-impl classes functionality,but we can't access that in our custom portlet. Hence,we require to PortalClassInvoker class.

for example : we need to access PortalLDAPUtil.getLdapServerId()(method for get LDAP ServerId) in our costum portlet and it's there in portal-impl ,so access is the issue. For that , we use PortalClassInvoker.invoke() (This method have many forms) with MethodKey.

Following are steps to use PortalClassInvoker.invoke() method to access utility of portal-impl class PortalLDAPUtil.

1) Initialize MethodKey object.
   
    Syntax : MethodKey portalLDAPUtilMethodKey = new MethodKey("classNameWithPackagePath", "methodName",argClassType1,argClassType2......);
   
    Example : MethodKey portalLDAPUtilMethodKey = new MethodKey("com.liferay.portal.security.ldap.PortalLDAPUtil", "getLdapServerId",Long.class,String.class);
   
2) Use PortalClassInvoker.invoke() to access portal-impl classes using MethodKey.
    Syntax : PortalClassInvoker.invoke(newInstance, methodKey, argumentList);
   
    Example : Long ldapServerId = (Long) PortalClassInvoker.invoke(false, portalLDAPUtilMethodKey, new Object[] {Long.valueOf(themeDisplay.getCompanyId()),screenName});
here screenName is ldap user screenName. i.e. “ketan.savaliya”.

Thursday, July 19, 2012

Deployment/ReDeployment ext in liferay


I assume that you have WAR file ready for deployment and name of ext is abc-ext.war.

1          1.       First of all, shutdown your tomcat if it's already running and delete your work and temp folder.
2          2.       Now go to \tomcat\lib\ext folder , and remove ext-abc-ext-service.jar.
3          3.       Go inside webapps, and remove the abc-ext.
4          4.       Go inside webapps\ROOT\WEB-INF and remove
·         liferay-display-ext.xml
·         ext-abc-ext.xml
·         liferay-portlet-ext.xml
·         portlet-ext.xml,
   5.     Go inside webapps\ROOT\WEB-INF\lib and delete
·         ext-abc-ext-impl.jar,
·         ext-abc-ext-util-bridges.jar,
·         ext-abc-ext-util-java.jar
·         ext-abc-ext-util-taglib.jar.

    Start the tomcat.
    Put WAR file inside hot deploy folder and wait till it expends and give message to reboot your server.
    Restart tomcat and its done.

SVN with eclipse configuration in Windows





To configure svn in eclipse for windows, we need to process below steps...

1) Install svn plugins in eclipse

    Go to : Help Menu->eclipse marketplace...->Popular(tab)
    install below two plugins one after other
        I) Subeclipse
        II)Subversive - SVN Team Provider

2) After that restart eclipse

3) Now go to SVN Repositories window for useing svn repository.

That's it. enjoy :))