Search in sources :

Example 1 with MethodArgHolder

use of org.mifos.rest.approval.domain.MethodArgHolder in project head by mifos.

the class AspectJRESTApprovalInterceptor method profile.

@Around("restMethods() && requestMapping() && excludeAPI() && exludeRestfulServices()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    Signature signature = pjp.getStaticPart().getSignature();
    LOG.debug(this.getClass().getSimpleName() + " staring");
    // FIXME : somehow autowiring is not working
    if (approvalService == null) {
        approvalService = ApplicationContextProvider.getBean(ApprovalService.class);
    }
    if (configurationServiceFacade == null) {
        configurationServiceFacade = ApplicationContextProvider.getBean(ConfigurationServiceFacade.class);
    }
    if (parameterNameDiscoverer == null) {
        parameterNameDiscoverer = ApplicationContextProvider.getBean(ParameterNameDiscoverer.class);
    }
    if (!RESTConfigKey.isApprovalRequired(configurationServiceFacade)) {
        LOG.debug(pjp.getSignature() + " skip approval");
        return pjp.proceed();
    }
    if (signature instanceof MethodSignature) {
        MethodSignature ms = (MethodSignature) signature;
        Method m = ms.getMethod();
        RequestMapping mapping = m.getAnnotation(RequestMapping.class);
        if (isReadOnly(mapping)) {
            LOG.debug(m.getName() + " is read only, hence returning control");
            return pjp.proceed();
        }
        Class<?> methodClassType = m.getDeclaringClass();
        if (!methodClassType.getSimpleName().endsWith("RESTController")) {
            LOG.debug(m.getName() + " is not from REST controller, hence returning control");
            return pjp.proceed();
        }
        Object[] argValues = pjp.getArgs();
        Class<?>[] argTypes = m.getParameterTypes();
        String methodName = m.getName();
        String[] names = parameterNameDiscoverer.getParameterNames(m);
        MethodArgHolder args = new MethodArgHolder(argTypes, argValues, names);
        ApprovalMethod method = new ApprovalMethod(methodName, methodClassType, args);
        approvalService.create(method);
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer) ApprovalService(org.mifos.rest.approval.service.ApprovalService) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Method(java.lang.reflect.Method) ConfigurationServiceFacade(org.mifos.config.servicefacade.ConfigurationServiceFacade) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Around(org.aspectj.lang.annotation.Around)

Example 2 with MethodArgHolder

use of org.mifos.rest.approval.domain.MethodArgHolder in project head by mifos.

the class ApprovalServiceTest method createApprovalMethod.

private void createApprovalMethod() throws Exception {
    Class[] c = new Class[1];
    c[0] = String.class;
    MethodArgHolder args = new MethodArgHolder(c, new Object[1], new String[1]);
    ApprovalMethod am = new ApprovalMethod("updateCall", StubRESTController.class, args);
    try {
        approvalService.create(am);
        fail("should have thrown interrupt exception");
    } catch (RESTCallInterruptException e) {
    }
}
Also used : RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) BeforeClass(org.junit.BeforeClass)

Example 3 with MethodArgHolder

use of org.mifos.rest.approval.domain.MethodArgHolder in project head by mifos.

the class ApprovalServiceTest method createFailureApprovalMethod.

private void createFailureApprovalMethod() throws Exception {
    Class[] c = new Class[1];
    c[0] = String.class;
    MethodArgHolder args = new MethodArgHolder(c, new Object[1], new String[1]);
    ApprovalMethod am = new ApprovalMethod("failCall", StubRESTController.class, args);
    try {
        approvalService.create(am);
        fail("should have thrown interrupt exception");
    } catch (RESTCallInterruptException e) {
    }
}
Also used : RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) BeforeClass(org.junit.BeforeClass)

Example 4 with MethodArgHolder

use of org.mifos.rest.approval.domain.MethodArgHolder in project head by mifos.

the class ApprovalMethodInvocationHandler method process.

@Override
public Object process(MethodInvocation invocation) throws Throwable {
    LOG.debug(this.getClass().getSimpleName() + " staring");
    // FIXME : somehow autowiring is not working
    if (approvalService == null) {
        approvalService = ApplicationContextProvider.getBean(ApprovalService.class);
    }
    if (configurationServiceFacade == null) {
        configurationServiceFacade = ApplicationContextProvider.getBean(ConfigurationServiceFacade.class);
    }
    if (!RESTConfigKey.isApprovalRequired(configurationServiceFacade)) {
        LOG.debug(invocation + " skip approval");
        return invocation.proceed();
    }
    Method m = invocation.getMethod();
    RequestMapping mapping = m.getAnnotation(RequestMapping.class);
    if (isReadOnly(mapping)) {
        LOG.debug(m.getName() + " is read only, hence returning control");
        return invocation.proceed();
    }
    Class<?> methodClassType = m.getDeclaringClass();
    if (!methodClassType.getSimpleName().endsWith("RESTController")) {
        LOG.debug(m.getName() + " is not from REST controller, hence returning control");
        return invocation.proceed();
    }
    if (methodClassType.equals(ApprovalRESTController.class)) {
        LOG.debug(m.getName() + " is from Approval REST controller, hence returning control");
        return invocation.proceed();
    }
    Object[] argValues = invocation.getArguments();
    Class<?>[] argTypes = m.getParameterTypes();
    String methodName = m.getName();
    String[] names = parameterNameDiscoverer.getParameterNames(m);
    MethodArgHolder args = new MethodArgHolder(argTypes, argValues, names);
    ApprovalMethod method = new ApprovalMethod(methodName, methodClassType, args);
    approvalService.create(method);
    return invocation.proceed();
}
Also used : ApprovalService(org.mifos.rest.approval.service.ApprovalService) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Method(java.lang.reflect.Method) ConfigurationServiceFacade(org.mifos.config.servicefacade.ConfigurationServiceFacade) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod)

Aggregations

ApprovalMethod (org.mifos.rest.approval.domain.ApprovalMethod)4 MethodArgHolder (org.mifos.rest.approval.domain.MethodArgHolder)4 Method (java.lang.reflect.Method)2 BeforeClass (org.junit.BeforeClass)2 ConfigurationServiceFacade (org.mifos.config.servicefacade.ConfigurationServiceFacade)2 ApprovalService (org.mifos.rest.approval.service.ApprovalService)2 RESTCallInterruptException (org.mifos.rest.approval.service.RESTCallInterruptException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 Signature (org.aspectj.lang.Signature)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 ParameterNameDiscoverer (org.springframework.core.ParameterNameDiscoverer)1