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.


Sunday, May 18, 2014

Seam

At the heart of Seam is the contextual component model.
(1) Seam is a factory that constructs objects according to component definitions.
(2) After creation, each object is stored in the container under one of several contexts (i.e. variable scopes) with varying lifetimes, making the objects contextual and capable of holding state (i.e.stateful).
(3) Seam promotes the interaction of these stateful objects across contexts, assembling them together

Monday, March 24, 2014

Python

Python is a dynamic, strongly typed, object oriented, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax.
  1. Python is dynamically typed: it means that you don't declare a type (e.g. 'integer') for a variable name, and then assign something of that type (and only that type). Instead, you have variable names, and you bind them to entities whose type stays with the entity itself. a = 5 makes the variable name a to refer to the integer 5. Later, a = "hello" makes the variable name a to refer to a string containing "hello". Static typed languages would have you declare int a and then a = 5, but assigning a = "hello" would have been a compile time error. On one hand, this makes everything more unpredictable (you don't know what a refers to). On the other hand, it makes very easy to achieve some results a static typed languages makes very difficult.
  2. Python is strongly typed. It means that if a = "5" (the string whose value is '5') will remain a string, and never coerced to a number if the context requires so. Every type conversion in python must be done explicitly. This is different from, for example, Perl or Javascript, where you have weak typing, and can write things like "hello" + 5 to get "hello5".
  3. Python is object oriented, with class-based inheritance. Everything is an object (including classes, functions, modules, etc), in the sense that they can be passed around as arguments, have methods and attributes, and so on.
  4. Python is multipurpose: it is not specialised to a specific target of users (like R for statistics, or PHP for web programming). It is extended through modules and libraries, that hook very easily into the C programming language.
  5. Python enforces correct indentation of the code by making the indentation part of the syntax. There are no control braces in Python. Blocks of code are identified by the level of indentation. Although a big turn off for many programmers not used to this, it is precious as it gives a very uniform style and results in code that is visually pleasant to read.
  6. The code is compiled into byte code and then executed in a virtual machine. This means that precompiled code is portable between platforms.

Sunday, February 16, 2014

Differences between Interface and Abstract Class

  1. Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.
  2. Variables declared in a Java interface is by default final. An  abstract class may contain non-final variables.
  3. Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
  4. Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
  5. An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
  6. A Java class can implement multiple interfaces but it can extend only one abstract class.
  7. Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
  8. In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.