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();
}
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) {
}
}
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) {
}
}
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();
}
Aggregations