package com.worth.ifs.profiling;

import com.worth.ifs.cache.RestCacheInvalidationAdvisor;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;


@Component
public class ProfilingAdvisor extends AbstractPointcutAdvisor {

    public static final int PROFILING_ORDER = RestCacheInvalidationAdvisor.REST_CACHE_INVALIDATE - 1;

    public ProfilingAdvisor() {
        setOrder(PROFILING_ORDER);
    }

    private static final long serialVersionUID = 1L;

    private final StaticMethodMatcherPointcut pointcut = new
            StaticMethodMatcherPointcut() {
                @Override
                public boolean matches(Method method, Class<?> targetClass) {
                    return method.isAnnotationPresent(ProfileExecution.class);
                }
            };

    @Autowired
    private ProfilingMethodInterceptor interceptor;

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    @Override
    public Advice getAdvice() {
        return this.interceptor;
    }


}

@@ -355,16 +355,124 @@
 owired;%0A
+import org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.core.env.Environment;%0A
 import o
@@ -512,16 +512,16 @@
 ponent;%0A
-
 %0Aimport 
@@ -855,16 +855,147 @@
  = 1L;%0A%0A
+    @Value(%22$%7Bifs.web.profilerEnabled:false%7D%22)%0A    private boolean profilerEnabled;%0A%0A    @Autowired%0A    Environment environment;%0A%0A%0A
     priv
@@ -1221,16 +1221,39 @@
   return
+ isProfilerEnabled() &&
  method.
@@ -1573,10 +1573,89 @@
     %7D%0A%0A%0A
+    public boolean isProfilerEnabled() %7B%0A        return profilerEnabled;%0A    %7D%0A
 %7D%0A

Disable profile by default