Search in sources :

Example 1 with TaskChannel

use of org.motechproject.tasks.annotations.TaskChannel in project motech by motech.

the class TaskAnnotationBeanPostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    if (bean == null) {
        return null;
    }
    final Class<?> targetClass = getTargetClass(bean);
    final TaskChannel taskChannel = targetClass.getAnnotation(TaskChannel.class);
    if (taskChannel != null) {
        LOGGER.debug("The @TaskChannel annotation was found in {}", targetClass.getName());
        doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {

            @Override
            public void doWith(Method method) throws IllegalAccessException {
                Method targetMethod = findMethod(targetClass, method.getName(), method.getParameterTypes());
                if (targetMethod != null) {
                    TaskAction taskAction = targetMethod.getAnnotation(TaskAction.class);
                    if (taskAction != null) {
                        LOGGER.debug("The @TaskAction annotation was found in method: {}", targetMethod.getName());
                        String serviceInterface = getServiceInterface(targetClass);
                        Channel channel = getChannel(taskChannel);
                        addActionTaskEvent(channel, serviceInterface, targetMethod, taskAction);
                    }
                }
            }
        });
    }
    return bean;
}
Also used : TaskChannel(org.motechproject.tasks.annotations.TaskChannel) TaskAction(org.motechproject.tasks.annotations.TaskAction) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskChannel(org.motechproject.tasks.annotations.TaskChannel) ReflectionUtils.findMethod(org.springframework.util.ReflectionUtils.findMethod) Method(java.lang.reflect.Method) ReflectionUtils(org.springframework.util.ReflectionUtils)

Example 2 with TaskChannel

use of org.motechproject.tasks.annotations.TaskChannel in project motech by motech.

the class TaskAnnotationBeanPostProcessor method getChannel.

private Channel getChannel(TaskChannel taskChannel) {
    String displayName = taskChannel.channelName();
    String moduleName = taskChannel.moduleName();
    String moduleVersion = taskChannel.moduleVersion();
    Channel channel = channelService.getChannel(moduleName);
    if (channel == null) {
        LOGGER.debug("Creating new channel: {}  for module: {}", displayName, moduleName);
        channel = new Channel(displayName, moduleName, moduleVersion);
    } else {
        LOGGER.debug("Channel: {}  for module: {} was retrieved", displayName, moduleName);
    }
    return channel;
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskChannel(org.motechproject.tasks.annotations.TaskChannel)

Aggregations

TaskChannel (org.motechproject.tasks.annotations.TaskChannel)2 Channel (org.motechproject.tasks.domain.mds.channel.Channel)2 Method (java.lang.reflect.Method)1 TaskAction (org.motechproject.tasks.annotations.TaskAction)1 ReflectionUtils (org.springframework.util.ReflectionUtils)1 ReflectionUtils.findMethod (org.springframework.util.ReflectionUtils.findMethod)1