Search in sources :

Example 1 with InjectDomainFact

use of org.jaffa.soa.services.configdomain.InjectDomainFact in project jaffa-framework by jaffa-projects.

the class SOAEventHandler method injectDomainFacts.

private void injectDomainFacts(UOW uow, ServiceRulesInterceptor interceptor, SOAEventQueueMessage message) throws FrameworkException, ApplicationExceptions {
    SoaEventInfo soaEventInfo = ConfigurationService.getInstance().getSoaEventInfo(message.getEventName());
    if (soaEventInfo != null) {
        for (InjectDomainFact injectDomainFact : soaEventInfo.getInjectDomainFact()) {
            Object[] domainKeyValues = new Object[injectDomainFact.getDomainKey().size() + 1];
            try {
                // Create an array of key-fields to be used for retrieving the domain object
                // NOTE: If support for non-String key-fields is needed, the following logic can be further enhanced
                // to take the datatype of each parameter into consideration when creating the domainKeyValues array
                domainKeyValues[0] = uow;
                int counter = 0;
                for (String domainKeyName : injectDomainFact.getDomainKey()) {
                    if (domainKeyName.length() > PREFIX_PARAMS.length() && domainKeyName.startsWith(PREFIX_PARAMS)) {
                        domainKeyName = domainKeyName.substring(domainKeyName.length());
                    }
                    domainKeyValues[++counter] = message.getHeaderParam(domainKeyName) != null ? message.getHeaderParam(domainKeyName).getValue() : null;
                }
                // Invoke the findByPK method to obtain the domain object
                Object domainObject = findDomainObject(injectDomainFact.getDomainClass(), domainKeyValues);
                if (domainObject != null)
                    interceptor.addFact(domainObject);
                else {
                    if (log.isDebugEnabled())
                        log.debug("Instance of domain class " + injectDomainFact.getDomainClass() + " not found with the arguments " + Arrays.toString(domainKeyValues));
                }
            } catch (Exception e) {
                throw ExceptionHelper.throwAFR(e);
            } finally {
                domainKeyValues = null;
            }
        }
    }
}
Also used : InjectDomainFact(org.jaffa.soa.services.configdomain.InjectDomainFact) SoaEventInfo(org.jaffa.soa.services.configdomain.SoaEventInfo) FrameworkException(org.jaffa.exceptions.FrameworkException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 InjectDomainFact (org.jaffa.soa.services.configdomain.InjectDomainFact)1 SoaEventInfo (org.jaffa.soa.services.configdomain.SoaEventInfo)1