Tuesday, 12 November 2013

How can I get a list of all the implementations of an interface programmatically in Java?


Polymorphism



Polymorphism

When one action is performed by different ways i.e. known as polymorphism. For example: to convense the customer differently, to draw something e.g. shape or rectangle etc.
In java, we use method overloading and method overriding to achieve polymorphism.
Another example can be to speak something e.g. cat speaks meaw, dog barks woof etc.

Saturday, 9 November 2013

How to know from where a Class was loaded in Java

import java.security.ProtectionDomain;
import java.io.*;
public class CodeLoc
{
    public void codeLoc()
    {
        ProtectionDomain protectionDomain = getClass().getProtectionDomain();
        File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());
        System.out.println("--------codeLoc="+codeLoc);
    }
    public static void main(String []args)
    {
        CodeLoc cl=new CodeLoc();
        cl.codeLoc();
    }
}

Sunday, 3 November 2013

Apply liferay search indexer to custom portlets

Please follow the steps given below if you want , Your custom portlets data to be search by Liferay search portlet.

1.Create custom indexer class that extends BaseIndexer.

2.Make custom class indexer entry in liferay-portlet.xml for example,just beneath <icon> tag.

3.Write codes mentioned below in xxxabcLocalServiceImpl class methods ,for example add,delete .

Indexer indexer = IndexerRegistryUtil.getIndexer(xxxabc.class);

for add and update method

indexer.reindex(object of class);

for delete method you should write like

indexer.delete(object of class);

4.Now deploy your portlet and goto Liferay Portal.

5.Add search portlet to page.

6.Click on search portlet configuration.

7.Click on advance button.

8.Add your model name as already entered there, for example BlogsEntry,DLFileEntry.

Wednesday, 23 October 2013

Liferay use custom data source instead of liferay default data source via spring-ext.xml updation

Please find the below sample code liferay to use our custom data source. Add/update spring-ext.xml file with below code:



<bean id="testDataSourceTarget" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName">
<value>jdbc/test</value>
</property>
</bean>
<bean id="testDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
<property name="targetDataSource">
<ref bean="testDataSourceTarget" />
</property>
</bean>
<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
<property name="dataSource" ref="testDataSource" />
<property name="sessionFactoryClassLoader" ref="portletClassLoader" />
<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
</bean>
<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="testDataSource" />
</bean>
<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="dataSource">
<ref bean="testDataSource" />
</property>
<property name="sessionFactory">
<ref bean="testHibernateSessionFactory" />
</property>
</bean>

Monday, 16 September 2013

Rebuild SOLR indexes in Alfresco 4.x

Steps to rebuild SOLR indexes:

1) Stop the Server.

2) Remove two folders named “index” and “spellchecker” in “ALFRESCO/alf_data/solr/workspace/SpacesStore/” path.

3) Remove two folders named “index” and “spellchecker” in “ALFRESCO/alf_data/solr/archive/SpacesStore/” path.

4) Start the Server.

By default, the SOLR indexes are stored in
“ALFRESCO/alf_data/solr/workspace/SpacesStore/” path for workspace-SpacesStore and “ALFRESCO/alf_data/solr/archive/SpacesStore/” path for archive-SpacesStore.

Each store has its own index directory defined by property ${data.dir.root}/${data.dir.store} in solrcore.properties file.

To change the index location for both stores, edit the
solrcore.properties file:
  • SOLR/workspace-SpacesStore/conf/solrcore.properties
  • SOLR/archive-SpacesStore/conf/solrcore.properties

Set the data.dir.root property to the location where the SOLR indexes will be stored. You can also set the same value for the both stores, and the stores will create the sub-directories.

Eg:
1)  For workspace-SpaceStore, edit SOLR/workspace-SpacesStore/conf/solrcore.properties file
data.dir.root=/mnt/data-store/solr-indexes
data.dir.store=workspace/SpacesStore

2) For archive-SpaceStore, edit SOLR/archive-SpacesStore/conf/solrcore.properties
data.dir.root=/mnt/data-store/solr-indexes
data.dir.store=archive/SpacesStore

NOTE: The index.recovery.mode=FULL property is not used by SOLR Engine.

Saturday, 29 June 2013

To avoid resubmit of liferay action url

Problem: Click on an actionURL and action is successfully completed and page gets displayed on the browser. Click on refresh button again the same action gets called and performs the action again.
Resolution: set a tag value in liferay-portlet.xml
<action-url-redirect>true</action-url-redirect>
by default the value of this tag is false.
Note: it’s not a substitute to open another jsp page after completing the action.