Search in sources :

Example 1 with MotechListenerNamedParametersProxy

use of org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy in project motech by motech.

the class EventAnnotationBeanPostProcessor method processAnnotations.

private void processAnnotations(final Object bean, final String beanName) {
    if (bean == null) {
        return;
    }
    // Get declared methods from class without superclass methods.
    for (Method method : bean.getClass().getDeclaredMethods()) {
        Method methodOfOriginalClassIfProxied = ReflectionUtils.findMethod(AopUtils.getTargetClass(bean), method.getName(), method.getParameterTypes());
        if (methodOfOriginalClassIfProxied != null) {
            MotechListener annotation = methodOfOriginalClassIfProxied.getAnnotation(MotechListener.class);
            if (annotation != null) {
                final List<String> subjects = Arrays.asList(annotation.subjects());
                MotechListenerAbstractProxy proxy = null;
                switch(annotation.type()) {
                    case MOTECH_EVENT:
                        proxy = new MotechListenerEventProxy(getFullyQualifiedBeanName(bean.getClass(), beanName), bean, method);
                        break;
                    case NAMED_PARAMETERS:
                        proxy = new MotechListenerNamedParametersProxy(getFullyQualifiedBeanName(bean.getClass(), beanName), bean, method);
                        break;
                    default:
                }
                LOGGER.info(String.format("Registering listener type(%20s) bean: %s, method: %s, for subjects: " + "%s", annotation.type().toString() + ":" + beanName, bean.getClass().getName(), method.toGenericString(), subjects));
                if (eventListenerRegistry != null) {
                    eventListenerRegistry.registerListener(proxy, subjects);
                } else {
                    LOGGER.error("Null eventListenerRegistry.  Unable to register listener");
                }
            }
        }
    }
}
Also used : MotechListenerNamedParametersProxy(org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy) MotechListenerAbstractProxy(org.motechproject.event.listener.annotations.MotechListenerAbstractProxy) MotechListener(org.motechproject.event.listener.annotations.MotechListener) Method(java.lang.reflect.Method) MotechListenerEventProxy(org.motechproject.event.listener.annotations.MotechListenerEventProxy)

Example 2 with MotechListenerNamedParametersProxy

use of org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy in project motech by motech.

the class HandlerPredicatesTest method shouldFoundCorrectObject.

@Test
public void shouldFoundCorrectObject() {
    MotechListenerEventProxy expected = new MotechListenerEventProxy("def", null, null);
    List<MotechListenerAbstractProxy> list = new ArrayList<>();
    list.add(new MotechListenerNamedParametersProxy("abc", null, null));
    list.add(expected);
    list.add(new MotechListenerEventProxy("ghi", null, null));
    MotechListenerAbstractProxy actual = (MotechListenerAbstractProxy) find(list, HandlerPredicates.withServiceName("def"));
    assertTrue(actual instanceof MotechListenerEventProxy);
    assertEquals(expected.getIdentifier(), actual.getIdentifier());
}
Also used : MotechListenerNamedParametersProxy(org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy) MotechListenerAbstractProxy(org.motechproject.event.listener.annotations.MotechListenerAbstractProxy) ArrayList(java.util.ArrayList) MotechListenerEventProxy(org.motechproject.event.listener.annotations.MotechListenerEventProxy) Test(org.junit.Test)

Example 3 with MotechListenerNamedParametersProxy

use of org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy in project motech by motech.

the class HandlerPredicatesTest method shouldNotFoundCorrectObject.

@Test
public void shouldNotFoundCorrectObject() {
    List<MotechListenerAbstractProxy> list = new ArrayList<>();
    list.add(new MotechListenerNamedParametersProxy("abc", null, null));
    list.add(new MotechListenerEventProxy("def", null, null));
    list.add(new MotechListenerEventProxy("ghi", null, null));
    MotechListenerAbstractProxy actual = (MotechListenerAbstractProxy) find(list, HandlerPredicates.withServiceName("abc"));
    assertNull(actual);
}
Also used : MotechListenerNamedParametersProxy(org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy) MotechListenerAbstractProxy(org.motechproject.event.listener.annotations.MotechListenerAbstractProxy) ArrayList(java.util.ArrayList) MotechListenerEventProxy(org.motechproject.event.listener.annotations.MotechListenerEventProxy) Test(org.junit.Test)

Aggregations

MotechListenerAbstractProxy (org.motechproject.event.listener.annotations.MotechListenerAbstractProxy)3 MotechListenerEventProxy (org.motechproject.event.listener.annotations.MotechListenerEventProxy)3 MotechListenerNamedParametersProxy (org.motechproject.event.listener.annotations.MotechListenerNamedParametersProxy)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 MotechListener (org.motechproject.event.listener.annotations.MotechListener)1