Friday, July 31, 2015

Liferay : Deployable template and structure

Liferay uses template and structure for major built in portlets. It gives us freedom to design and mange the content of the site(Webcontent , DDL - Dynamic data list  , ADT - Application Display template , Page template, Site Template). These portlet are very useful when designing the quick sites. Hot deploy able feature make it cool.

Major problem what we are facing is on the side of migration. There are LAR import / export features are available by default. But when you need to be make automatically in all the environment. That's were the deploy able template and structures serves us good features.

Required dependencies :

1) Enable markeplace in your local liferay from the control panel
2) Go the liferay.com marketplace and purchase the resource-importer. (Its free)
Note : Choose EE / CE for your own environment
3) Deploy the lpkg of the resource-importer in local liferay

Create plugin project:

1) Creating portlet plugin project
2) Replace this below content in top of the liferay-plugin-package.properties file
-------------------------------------------------------------------------
name=
required-deployment-contexts=\
    resources-importer-web
resources-importer-developer-mode-enabled=true
module-incremental-version=1
-------------------------------------------------------------------------
Note : name should be empty, so that this portlet will not be listed in the available apps.

3) Remove display-name in the portlet.xml
4) Create a folder called template-importer in the project src folder. where you always create package and java class file.
5) Copy your templates in the respective folders. Refere the github project shared in the bottom of this post.
6) Deploy the portlet
7) Test your templates from the control pannel

Refer the template file this project repository location, or use this as sample project.
Source code:
liferay/sample-templates-importer-portlet

Friday, July 17, 2015

Java 8 : Method reference

This post more deep into demonstrate about Method reference.  This code is contains following three functional features of Method reference.
  • Reference to constructor (1)
  • Reference to Static method (2)
  • Reference to Instance Method of particular object (3)
Note : The color codes refers with numbers are used in the comments. to make notes clear

I would not say this program is self explanatory. Comments are provided in the major three lines.
Explanation goes here,

Reference to Instance Method of particular object (3)
The "MyComparator" class have override method and instance method too. Collection sort functionality expect compactor object to process the provided list input. So, Created "MyComparator" class instance and supplied to the sort functionality.

Reference to Static method (2)
As like instance method we can call the static methods in the reference. "doPrint" also has the static method reference. This method contain collection forEach also time being skip this content now. It will be covered in later posts.

Reference to constructor (1)
Constructor also calling in the lambda expression way. In case of multiple constructor available, the smarty will recognize by the suitable parameter. 

Hint : Try to execute the below code, play with it, change something. then you will surely understand the concept. Method reference major concept are covered in a single program. It is useful for reference while doing other task.
----------------------------------------------- Java 8------------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ComparatorMethodReference {
List<String> l;
public ComparatorMethodReference(List<String> l) {
this.l=l;
}
public static void main(String[] args) {
List<String> l = new ArrayList<String>();

l.add("Banana");
l.add("Apple");
l.add("Mango");

Func fun=ComparatorMethodReference::new; // (1) Reference by constructor
ComparatorMethodReference comp=fun.loadList(l);
comp.doJava8Sort();
}

public static void doPrint(List<String> l) {
l.forEach(System.out::println); // (2) Reference to Static method
System.out.println(); // For Empty line
}

public void doJava8Sort() {
MyComparator comparator=new MyComparator();
Collections.sort(l,comparator);
doPrint(l);
Collections.sort(l,comparator::myReverse); // (3) Reference to Instance Method of particular object
doPrint(l);
}
}
class MyComparator implements Comparator<String> {
@Override
public int compare(String st1, String st2) {
return st1.compareTo(st2);
}
public int myReverse(String st1,String st2)
{
return st2.compareTo(st1);
}
}

@FunctionalInterface
interface Func {
ComparatorMethodReference loadList(List<String> l);
}

Java 8 : Lambda expression

Lambda expression is a key point to achieve functional programming. It facilitate to make your code more concise. Java developer aware of anonymous class. Now taste the anonymous methods. This can be created using lambda expressions.
-------------------------------------------------------Java 8--------------------------------------------------------
package com.ran;

@FunctionalInterface
interface ExpressionHolder {
int eval(int a,int b);
}
public class LamdaExpressionInJava8 {
//Functional interface
public static void main(String[] args) {
ExpressionHolder addExpression=(a1,a2)-> a1 + a2;
System.out.println(addExpression.eval(1, 2));
}
}
-----------------------------------------------------------------------------------------------------------------------
From the above code the high lighted portion is sample for lambda expression.
Here ExpressionHolder is a interface which has apply method in it. Int the case of  traditional way of java development would go with implementation class for ExpressionHolder or anonumous class. Here the complete implementation has covered in the lambda expression. This is inline implementation of the functional interface.

Method parameters --> functional body

For comparison purpose I have given the java 7 code also with the sample model. This code may help to understand the lambda expression in best.
Anonumous class implemenation of ExpressionHolder has been exhibited here.
----------------------------------------------------Java 7----------------------------------------------------
package com.ran.java7;

interface ExpressionHolder {
int apply(int a,int b);
}
public class LamdaExpressionInJava7 {
//Functional interface
public static void main(String[] args) {
ExpressionHolder addExpression=new ExpressionHolder() {
@Override
public int apply(int a, int b) {
return a+b;
}
};
System.out.println(addExpression.apply(1, 2));
}
}
----------------------------------------------------------------------------------------------------------------

Wednesday, July 15, 2015

Does Java 8 support multiple inheritance

This thought were brought in my mind , after reading the default method / defender method concept.
     The default method is useful, when situation comes to introduce new method or functionality in the existing interface.
     In the previous version of java, new method can not be pushed in the already delivered interface. Because It leads to rework on all the implementation classes. Default Method will have there own default implementation on the interface. So , it stop us from the re implementation.

     Every one aware of that , Java does not support multiple inheritance directly. As developer we cooked this design with help of interface. So, multiple interface can be implemented in one class. Interface had stopped the presence of diamond problem.

     Situation has changed now. You can have implementation in the interface using default method. So, if we have more than one interface implemented in a single class , what will happen?

You can prioritize the calling order of the interface. It could be more text based explanation, will see code here.

package com.ran;
interface Car{
default void engine(){ System.out.println("Car Engine implemenation");
}
}
interface Boat{
default void engine(){
System.out.println("Boat Engine implemenation");
}
}
public class JamesBondSuperCar implements Car,Boat {
public void engine() { Car.super.engine();
Boat.super.engine();
} public static void main(String[] args) {
JamesBondSuperCar bond=new JamesBondSuperCar();
bond.engine();
}
}
The above code is self explanatory for JamesBondSuperCar. It has mixed of the boad and car functionality to drive the special effect on screen. Ya.! It helped here too.

Tuesday, July 14, 2015

Java 8 : New Features

Bored with Java, May be you have not tired Java 8. Some of you might installed the java 8 , as like another common version update.It has a major feature release.

It is not again the simple "latest version available to download" notification. This is a great version to get java developer be boosted. Yes come and site in the edge of the seat. I am not going to screen the all feature here. But I will listing the features shot and sweet  with new teams that you may not come across.
If you are curious to know in deep , ask google yourself.

A java developer must know these following Terms,

Lambda Expressions
       Single-Abstract-method interfaces == functional interfaces (aka SAM Interfaces)
       Defender Methods == Default Methods

Method references
       Static method
       Constructor
       Instance Method of Arbitrary object
       Instance Method of particular object

Annotations
       Repeating Annotations
       Type Annotations

Type inference
       Better Type inference than java 7. But no types were added.

Reflection
       Obtain the names of the parameters of methods or constructors,

Collections
      Streams API - (Reactive programming to process collection in parallel or sequential)

JavaScript Engine
      Nashorn - A JAVA based engine to execute JavaScript code

Links

Official Java 8 features page
Default-methods-defender-methods-in-java-8

Thursday, July 9, 2015

Liferay Site Administrator Role customization


Site Admin roles and privileges

In Nutshell liferay has very good RAP system. Aka Roles and privileges. There are so many use cases been talking about the liferay roles and permission. Here I am gonna add one. which related to the Site Admin roles and customizing some sort of privileges for that roles. In General there are three "Site roles " are available. 

Site Administrator - Who have all the permission to with posts, pages, document library and other stuffs. Except one thing that , he can't assign another member as Site Admin as same this user holds.

Site Owner : This Role have all the privilege of what site admin have and one step ahead of him. He can assign any user as Site admin.

Think in this scenario, A role that contain only privilege to access user management of their own site.
Here I am going to share the steps and screenshot to solve this problem in liferay.

Environment : 
Liferay 6.2 CE GA3

1) Role creation

Role Name : SiteUserAdmin

Steps to create Role

a) Goto Control panel
Liferay portal → Admin ( Dockbar menu ) → Control panel

b) Roles (Under user section)

c) Add Site Role




d) Save Role

Save the form after Adding the role name , title and description. Refer below screen shot.




2) Define permission for Site Admin role
Permissions (Resource Permissions ) :
  • Assign Members
  • Assign User Roles
  • Go to Site Administration
Steps to assign permission :
a) Goto Site user Admin role → Action → Define Permission





b) Define Permission (Tab) → Site Administration (Left side tree panel )→ Users → Site Membership


c) Check and enable the following permission on the Resource Permission section
   Assign Members , Assign User Roles , Go to Site Administration



d) Click and save the configuration changes.


3) Assign User to Site User Admin Role For Sports Site
Follow the below steps to assign users to “ Site User Admin” role for Sports Site.

  a) Goto “Sports” site
            Liferay portal → Admin ( Dockbar menu ) → Control panel → Site
  b) Users (Left side panel) → Site Memberships


                                           

 c) Add site roles to users



 d) Search for “siteuseradmin”


e) Go to site user admin by clicking on the title column
(Prior to this step make sure user has already created and assigned to the “Sports” site)
Available tab → search for user → select the user → click on “Update Associate”



4) Test the Role
  Test the “ site admin role “ by login the thorough the assigned user.



Access the “Sports” site,
Admin ought to have only the users menu under site Administration section.


5) Goto Site Administration by Clicking on the Users under the Admin menu. Site user admin role have only permission to access the "Add members " and "Add Site Roles to". Here logged in user can manage the members and roles for the Sports site.



Monday, June 22, 2015

Git repository branch merge

When you try to merge two branches, It does not require any PullRequest to do the task. Internal repository code merge can be done using local .

Even we can do the pull request using one the repository console link. But I may be end up with the conflict error. Be conscious on what you gonna do. You may not get option to resolve it on the online editor.

Need to know how to do, You have to follow this steps.

1) Go to  repository location
2) Project1<REL-2.0.X> $ git pull
3) Project1<REL-2.0.X> $ git merge REL-1.7.X  
4) Destination <-- Source

Source is 2.0 and destination 1.7 (Don't be confused with this repository versions).
Finally you will get the all source code changes on 1.7 version will be available on the 2.0.

If you done some mistake during this merge, follow this to revert.
(Get the merge commit version)

git revert -m 1 26a0837
git push
(Note :  1 is first parent, and 26a0837 is commit id.)


Thursday, April 23, 2015

intellij idea tips

If you are getting transformation from eclipse to idea user.
You may encounter this difficulties to find some of the project settings.

I will list out them here,

Enable project auto-import of sbt project

   File --> settings --> (search for) SBT --> Enable auto import
[On the rigth side main pannel check the auto import]

Some nice tips to talk with google

He understand keywords, But I some point they evolved with some more good features.
Let try this link,
http://www.google.com/insidesearch/tipstricks/all.html
[If is it not working working don't blame me]

Some of the finest ways that I would like are follows,

Search with in the site
       ticket site:redbus.com

Search by filetype
          filetype:ppt

Find from phrase
        "Use quote to search"

To avoid some word in search Use - sign
         salsa recipe -tomatoes 

Find related page or url
        related: www.webupd8.com

Get definition
      definition : computer
    
Note : Google ignore punctuation, Don't waste your time there

there are more please find your self


Wednesday, April 22, 2015

MongoDB NoSql

Key points to know about MongoDB
  • It's a NoSQL database - In another way it is no RDBMS
  • MongoDB does not use SQL as a query language , It uses java script syntactical way to query the db.It is not fully ACID-compliant
  • Data stores as documents, into buckets
  • Collection is the term to identify the buckets
  • A document is a set of data , That Stored as BSON format (Binary JSON) 
  • Client feed the JSON input and db engine translate them as BSON.
  • The process of data retrieval will transform the BSON to JSON. 
  • The manipulation of a document can be very easy. 
  • Fetched documents are ready to use on the web layer. 
  • Queries are in JSON style.
  • Forming query is like taking with your friend with java notation. 
  •     db.tablea.find()  /* How easy know */ 
  • [Note: Don't care about complex query now. Just park the thought and continue reading. Because we have option]


  • You have media files to store , go and get GridFS. 
  • The actual strength is , highly scalable, massive performance, No need to maintain document structure (I love it).

Merging two sorted arrays - Big O (n+m) time complexity

 Problem :  Merge the two sorted arrays. Edge case :  Array can empty Arrays can be in different size let getMaxLength = ( input1 , input...