Skip to content

Open Infinity Core Documentation V1.2.X.RELEASE

Ilkka Leinonen edited this page Oct 16, 2013 · 2 revisions

Open Infinity Core - 1.2.X.RELEASE

Open Infinity Core framework is a solution accelerator providing best practices patterns and tactics to overcome cross-cutting concerns like audit trail, logging, standardized and localized exception hierarchy, validation, security and quality.

Package Explanation
org.openinfinity.core.annotation Package includes platform specific annotations. Annotations are used as an metadata for aspects.
org.openinfinity.core.aspect Package includes platform specific aspects removing boilerplate code and providing better quality through reusability.
org.openinfinity.core.exception Package includes platform specific exception mechanism. Exceptions have three layerd mechanism to provide information about the application state. Exception level has also been defined.
org.openinfinity.core.util Package includes platform specific utilities and helper classes.
org.openinfinity.core.validation Package includes platform specific security validation modules.
org.openinfinity.core.spring Package includes Spring framework specific helper classes.

org.openinfinity.core.annotation

The package includes the following functionality.

AuditTrail

This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.AuditTrailAspect -aspect when defined. Annotation can be defined in the method level.

@AudiTrail
public SomeObject someMethod(AnotherObject anotherObject() {...}

@AuditTrail(
    isUsernameEnabled=true,
    isRolesEnabled=false,
    isTimeStampEnabled=true, 
    value={"auto/tire/screw","personId"}, 
    argumentStrategy=CUSTOM
)
public SomeObject someMethod(AnotherObject anotherObject() {...}

Log

This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.LogAspect-aspect when defined. Annotation can be defined in the method level.

@Log
public SomeObject someMethod(AnotherObject anotherObject() {...}

@Log(level=LogLevel.INFO)
public SomeObject someMethod(AnotherObject anotherObject() {...}

@Log(
    value={"auto/tire/screw","personId"}, 
    argumentStrategy=CUSTOM
    level=LogLevel.INFO
)
public SomeObject someMethod(AnotherObject anotherObject() {...}
  

NotScript

Field validator for validating XSS attacks.

@NotScript
private String someField;

@NotScript(allowedInputPattern=Person.SSN_XSS)
private String someField;

org.openinfinity.core.aspect

The package includes the following functionality.

AuditTrailAspect

Class is responsible for creating audit trail information. Audit trail storage system can be defined through Log4j property files (JDBCAppender, FileAppender, JMSAppender etc).

<context:component-scan base-package=“org.openinfinity.core"> 

<aop:aspectj-autoproxy>
      <aop:include name="auditTrailAspect“ />
</aop:aspectj-autoproxy>

<bean 
    id="auditTrailAspect" 
    class=“org.openinfinity.core.aspect.AuditTrailAspect" />

ExceptionTranslationAspect

Aspect for handling controller and service level exception translation. Service level exceptions should always be instance of org.openinfinity.core.exception.ApplicationException,org.openinfinity.core.exception.SystemException or org.openinfinity.core.exception.BusinessViolationException. Unknown exceptions will be translated to org.openinfinity.core.exception.SystemException.

<context:component-scan base-package=“org.openinfinity.core"> 

<aop:aspectj-autoproxy>
      <aop:include name=“exceptionTranslatorAspect"/>
</aop:aspectj-autoproxy>

<bean 
    id="exceptionTranslatorAspect"    
    class="org.openinfinity.core.aspect.ExceptionTranslatorAspect” />

LogAspect

This class is responsible of the logging. All the incoming parameters will be logged (based on toString() method). Logging storage system can be defined through Log4j property files (JDBCAppender, FileAppender, JMSAppender etc).

<context:component-scan base-package=“org.openinfinity.core"> 

<aop:aspectj-autoproxy>
      <aop:include name=“logAspect"/>
</aop:aspectj-autoproxy>

<bean 
    id="logAspect" 
    class="org.openinfinity.core.aspect.LogAspect" />

org.openinfinity.core.crypto

The package includes the following functionality.

CryptoSupport

This object supports encryption and decryption of the entity fields. It handles the base 64 encoding and decoding of java.util.String fields.

CryptoSupport example usage for encryption:

@Autowired 
CryptoSupport cryptoSupport;

public SomeObject someMethod(Object plainArgument) {
      byte[] plainBytes = IOUtil.getBytes(plainArgument);
      byte[] encryptedBytes = cryptoSupport.encrypt(plainBytes);
}

public SomeObject someMethod(Object argument) {
      byte[] plainBytes = IOUtil.getBytes(field.get(object));
      String encryptedBase64Presentation = cryptoSupport.encryptAndReturnBase64Presentation(plainBytes, "ISO-8859-1");
}

CryptoSupport example usage for decryption:

@Autowired 
CryptoSupport cryptoSupport;

public SomeObject someMethod(Object encryptedArgument) {
      byte[] plainBytes = IOUtil.getBytes(argument);
      byte[] encryptedBytes = cryptoSupport.encrypt(plainBytes);
}

public SomeObject someMethod(Object encryptedArgument) {
     	byte[] encryptedBytes = IOUtil.getBytes(field.get(encryptedArgument));
	String decryptedBase64Presentation = cryptoSupport.decryptAndReturnBase64Presentation(encryptedBytes, "ISO-8859-1");
}

Context configuration:

<context:component-scan base-package=“org.openinfinity.core"> 

<bean id ="cryptoSupport" class="org.openinfinity.core.crypto.CryptoSupport">
	<constructor-arg name="rsaPublicKeyPath" value="${rsa.public.key.path}"/>
	<constructor-arg name="rsaPrivateKeyPath" value="${rsa.private.key.path}"/>
</bean>

org.openinfinity.core.exception

The package includes the following functionality.

BusinessViolationException

Business violation exception is thrown when business rule fails. This kind of behaviour has a fatal impact for the business. Exception is derived from org.openinfinity.core.exception.AbstractCoreException.

Service interface mapped to error properties:

private static final UNIQUE_EXCEPTION = ”bve.exception.not.found”;

Service implementation using localized properties:

if (product.isNotFound()) {
    BusinessViolationException bve = new BusinessViolationException
    (
        ”Product not found”,      
        ExceptionLevel.ERROR,
        UNIQUE_EXCEPTION
    ); 
    throw bve;
} 

or simply using core utilities:

if (product.isNotFound()) { 
    ExceptionUtil.throwBusinessViolationException(
        ”Product not found”, 
        ExceptionLevel.ERROR, 
    UNIQUE_EXCEPTION);
}

SystemException

This class holds information about the system errors.This exception will be thrown when system level exception occurs (connection failure etc). Exception is derived from org.openinfinity.core.exception.AbstractCoreException.

private static final UNIQUE_EXCEPTION = ”se.exception.cf”;
if (connection.isInFailureState()) {
   SystemException se = new SystemException
   (
       ”Connection failure occurred”,
       ExceptionLevel.WARNING,
       UNIQUE_EXCEPTION
   ); 
   throw se;
}

or:

if (product.isNotFound()) { 
       ExceptionUtil.throwSystemException
       (
           ”Connection failure occurred”,
            ExceptionLevel.WARNING,
            UNIQUE_EXCEPTION
       );
}

ApplicationException

This class holds information about application error. This exception should be thrown when application (use cases) specific problems occurs. Exception is derived from org.openinfinity.core.exception.AbstractCoreException.

if (product.ifContainsIllegalInformation()) {    
   ExceptionUtil.throwApplicationException
   (
      ”Product contains illegal information”,   
      ExceptionLevel.INFORMATIVE, 
      UNIQUE_EXCEPTION
   );
}

org.openinfinity.core.util

The package includes the following functionality.

AspectUtil

Utility for handling aspect specific features.

Log logAnnotation = AspectUtil.getAnnotation(joinPoint, Log.class);

CollectionUtil

CollectionUtil enables element callbacks on java.util.Collection and java.util.Map interfaces unifying their API usage.

Collection<String> expected = new ArrayList<String>();
expected.add("foo");
expected.add("bar");

CollectionElementUtil.iterate(expected, new CollectionElementCallback<String>() {
	public void callback(String callbackObject) {
		System.out.println(callbackObject);	
	}			
});

Map<String, String> expected = new HashMap<String, String>();	
expected.put("foo","me1");
expected.put("bar", "me2");

CollectionElementUtil.iterate(expected, new MapElementCallback<String, String>() {
        public void callback(String key, String value) {
	         System.out.println(key + ":" + value);	
	}			
});

ExceptionUtil

Exception utility class which offers basic methods for exception throwing and stack trace resolving.

String stackTrace = ExceptionUtil.getStackTraceString(throwable);

or:

ExceptionUtil.throwBusinessViolationException(cause);

IOUtil

Utility for handling stream, reader and writer objects.

IOUtil.copyStream(inputStream, outputStream);
IOUtil.getBytes(object);
IOUtil.closeReader(reader);
IOUtil.closeWriter(writer);
IOUtil.closeStream(stream);

StringUtil

Helper class for handling Strings.

@Override
Public String toString() {
    StringUtil.toString(this);
}

JdbcPropertyPlaceholderConfigurer

Utility for key-value properties from JDBC datasource.

<import resource=“classpath:datasource-definitions.xml"/>

<bean class=” org.openinfinity.core.aspect.JdbcPropertyPlaceholderConfigurer">
    <constructor-arg ref=”dataSource” />
    <property name="locations">
        <list>
            <value>
               classpath:/META-INF/properties/logging.properties
            </value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>