use of org.aspectj.lang.annotation.Around 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.aspectj.lang.annotation.Around in project AndroidDevMetrics by frogermcs.
the class ActivityLifecycleAnalyzer method logAndExecute.
@Around("onCreateMethod() || onStartMethod() || onResumeMethod()")
public Object logAndExecute(ProceedingJoinPoint joinPoint) throws Throwable {
if (!enabled)
return joinPoint.proceed();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String methodName = signature.getMethod().getName();
final Object result;
if (METHOD_ON_RESUME.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnResume((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnResume((Activity) joinPoint.getTarget());
} else if (METHOD_ON_START.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnStart((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnStart((Activity) joinPoint.getTarget());
} else if (METHOD_ON_CREATE.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnCreate((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnCreate((Activity) joinPoint.getTarget());
} else {
result = null;
}
return result;
}
use of org.aspectj.lang.annotation.Around in project PhotoNoter by yydcdut.
the class PermissionAspect method aroundCheckAndRequestPermission.
@Around("pointcut2CheckAndRequestPermissions(aspectPermission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, AspectPermission aspectPermission) {
if (aspectPermission == null) {
return;
}
IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
int value = aspectPermission.value();
switch(value) {
case PermissionUtils.CODE_CAMERA:
case PermissionUtils.CODE_ADJUST_CAMERA:
{
if (hasPermission4Camera(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getContext() instanceof Activity) {
requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
} else {
YLog.i(TAG, "iPresenter.getContext() instanceof Activity --> false");
}
}
}
break;
case PermissionUtils.CODE_STORAGE:
{
if (hasPermission4Storage(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getContext() instanceof Activity) {
requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
} else {
YLog.i(TAG, "iPresenter.getContext() instanceof Activity --> false");
}
}
}
break;
case PermissionUtils.CODE_LOCATION_AND_CAMERA:
{
if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getContext() instanceof Activity) {
requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
} else {
YLog.i(TAG, "iPresenter.getContext() instanceof Activity --> false");
}
}
}
break;
case PermissionUtils.CODE_AUDIO:
{
if (hasPermission4Audio(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getContext() instanceof Activity) {
requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
} else {
YLog.i(TAG, "iPresenter.getContext() instanceof Activity --> false");
}
}
}
break;
case PermissionUtils.CODE_PHONE_STATE:
{
if (hasPermission4PhoneState(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getContext() instanceof Activity) {
requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
} else {
YLog.i(TAG, "iPresenter.getContext() instanceof Activity --> false");
}
}
}
break;
}
}
use of org.aspectj.lang.annotation.Around in project apollo by ctripcorp.
the class RepositoryAspect method invokeWithCatTransaction.
@Around("anyRepositoryMethod()")
public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
String name = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName();
Transaction catTransaction = Tracer.newTransaction("SQL", name);
try {
Object result = joinPoint.proceed();
catTransaction.setStatus(Transaction.SUCCESS);
return result;
} catch (Throwable ex) {
catTransaction.setStatus(ex);
throw ex;
} finally {
catTransaction.complete();
}
}
use of org.aspectj.lang.annotation.Around in project books by aidanwhiteley.
the class LimitDataVisibilityAspect method limitBookDataImpl.
@Around("limitBookData()")
public Object limitBookDataImpl(ProceedingJoinPoint joinPoint) throws Throwable {
Object retVal = joinPoint.proceed();
Principal principal = getPrincipal(joinPoint);
// Note - we only look at data from the JWT to build the User here - we
// are
// only interested in the users roles and they are in the JWT.
Optional<User> user = authUtils.extractUserFromPrincipal(principal, true);
if (retVal instanceof Book) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("About to call setPermissionsAndContentForUser for {}", joinPoint.getSignature());
}
((Book) retVal).setPermissionsAndContentForUser(user.orElse(null));
} else {
LOGGER.error("Unexpected return type found by aspect");
}
return retVal;
}
Aggregations