All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flips.advice.FlipFeatureAdvice Maven / Gradle / Ivy

Go to download

Flips Core framework, provides all the flip annotations, conditions and different advices

There is a newer version: 1.1
Show newest version
package org.flips.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.flips.exception.FeatureNotEnabledException;
import org.flips.store.FlipAnnotationsStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
public class FlipFeatureAdvice {

    private FlipAnnotationsStore flipAnnotationsStore;

    @Autowired
    public FlipFeatureAdvice(@Lazy FlipAnnotationsStore flipAnnotationsStore) {
        this.flipAnnotationsStore = flipAnnotationsStore;
    }

    @Pointcut("execution(@(@org.flips.annotation.FlipOnOff *) * *(..)) && !@annotation(org.flips.annotation.FlipBean)")
    private void featureToInspectPointcut(){}

    @Before("featureToInspectPointcut()")
    public void inspectFlips(JoinPoint joinPoint) throws Throwable {
        MethodSignature signature   = (MethodSignature) joinPoint.getSignature();
        Method method               = signature.getMethod();

        this.ensureFeatureIsEnabled(method);
    }

    private void ensureFeatureIsEnabled(Method method) {
        boolean featureEnabled = flipAnnotationsStore.isFeatureEnabled(method);
        if ( !featureEnabled )
            throw new FeatureNotEnabledException("Feature not enabled, identified by method " + method, method);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy