Search in sources :

Example 1 with ApprovalService

use of org.mifos.rest.approval.service.ApprovalService 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 ApprovalService

use of org.mifos.rest.approval.service.ApprovalService 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

Method (java.lang.reflect.Method)2 ConfigurationServiceFacade (org.mifos.config.servicefacade.ConfigurationServiceFacade)2 ApprovalMethod (org.mifos.rest.approval.domain.ApprovalMethod)2 MethodArgHolder (org.mifos.rest.approval.domain.MethodArgHolder)2 ApprovalService (org.mifos.rest.approval.service.ApprovalService)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