Tuesday, June 24, 2014

To check the existence of session before doing any operation in Struts 2 application, we can use interceptor. For implementation of this, we will have to follow some easy steps:

Step 1: Make an interceptor class as below:

public class LoginInterceptor extends AbstractInterceptor {
      @Override
       public String intercept(final ActionInvocation invocation) throws Exception {
        Map session = ActionContext.getContext().getSession();

        UserVo userVo = (UserVo) session.get(Constant.LOGGEDIN_USER_KEY);
        String userLoggedin="";
        if(userVo!=null){
            userLoggedin = userVo.getUsername();

        }
        Object action = invocation.getAction();
        // user is not logged in yet
        if(userLoggedin == null||userLoggedin.equals("")){      

            // Pages that require the user to be logged in - user not logged in yet
            if (!(action instanceof BaseAction)) {
                 return "loginRedirect";
            }      
        }
        // user is logged in
        else{
             return invocation.invoke();
        }
        return invocation.invoke();
    }
}


Step 2: In struts.xml configuration file, add in the package of

 
<interceptors> <interceptor name='login' class='com.dbbl.mbs.portal.auth.LoginInterceptor'> 
 </interceptor> <interceptor-stack name='loginStack'> 
 <interceptor-ref name='login'>
</interceptor-ref> 
<interceptor-ref name='defaultStack'>
</interceptor-ref> 
</interceptor-stack> 
</interceptors> 
<default-interceptor-ref name=&quot;loginStack&quot; /> 
 <global-results> 
<result name=&quot;loginRedirect&quot; type=&quot;redirect&quot;>/login.jsp</result> 
</global-results>


That's the start of the epic.

Sunday, June 22, 2014

To get conditional Sum in BI reporting

In some cases, we need to get the sum of values of a column depending on the values of other column in BI reporting.

For that case, we can do that in a simple way of one line of code as:

<? sum(current-group()/LCY_BAL[../IS_LEAF='Y']) ?> 

In the above code we have get the sum of LCY_BAL field group wise. And the condition for this sum has been implemented in [../IS_LEAF='Y'] . This condition will filter the sum according to the case it supports.