0

I have java classes like this :

@Data
public class Lead {
    private A a;
    ...
}

@Data
public class A {
    private B b;
    private String c;
    private List<Integer> d;
}

@Data 
public class B {
    private String e;
    private String f;
}

I have a mapper method with annotation like this :

@FieldPermissionAnnotation("a")
public A fetchA(//Some DB Entities) {
    A a = new A();
    ...
    a.setB(fetchB());
    ...
    a.setC(fetchC());
    ...
    a.setD(fetchD());
}

My FieldPermissionAspect fetches the permission-field mapping from db for a user and sets field to null if user does not have permission for given field.

I get a list of string field hierarchy like this :

["a-b-e", "a-b-f", "a-c", "a-d"]

I want to set b, c, d to null using @Around around their respective setters inside the fetchA() method. Is it feasible using AspectJ and spring? How do I access the setters for b, c, d inside the fetchA() method?

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Welcome to SO. Please learn how to ask questions by reading what an [MCVE](https://stackoverflow.com/help/mcve) is. You have aspect questions but don't share any aspect code and only fragments of your target classes. So other people who like to help you have to guess. – kriegaex Jan 03 '20 at 02:44

1 Answers1

1

I want to set b, c, d to null using @Around around their respective setters inside the fetchA() method. Is it feasible using AspectJ and spring? How do I access the setters for b, c, d inside the fetchA() method?

As I said in my comment, your question is unclear and I have to guess what you want to do because there is no aspect code. My assumption is that you want to intercept setter methods if (and only if) they are being called from inside a certain other method. I.e. you need a control-flow-dependent pointcut like cflow() or cflowbelow(). According to the Spring manual these pointcuts are not supported by Spring AOP, but you can configure Spring to use full AspectJ with LTW (load-time weaving) instead.

For more details I suggest you show me yours (MCVE, ideally on GitHub with Maven build), then I show you mine (concrete solution).

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Hi kriegaex, I read your previous answers and learned about cflow. When I tried running the application it showed an error mentioned here https://stackoverflow.com/questions/59575549/aspectj-ltw-not-getting-configured-with-spring-in-tomcat . Can you please look into it? Also thanks for your time. :) – Lakshya Yadav Jan 03 '20 at 08:56
  • What was unclear about the term [MCVE](https://stackoverflow.com/help/mcve)? – kriegaex Jan 04 '20 at 04:19