katharsis-project / katharsis-framework

Katharsis adds powerful layer for RESTful endpoints providing implementenation of JSON:API standard
http://katharsis.io
Apache License 2.0
135 stars 65 forks source link

katharsis-3-0-2-upgrade-issue-with-custom-annotation #434

Closed omprak05 closed 7 years ago

omprak05 commented 7 years ago

We are upgrading katharsis to latest version 3.0.2.In older version in resource repository we were using @JsonApiSave to save our resource.Also we were using an around aspect based our own custom annotation (Spring AOP based custom annotation to control resource permissions).Our costom annotation is called before Save operation as around advise. ` @JsonApiResourceRepository(MyResource.class) @MycustomannotationController ((resourceType = "myresouces")) @Component @NoArgsConstructor public class TestService {

@JsonApiSave @mycustomAnnotationMethod(action = mycustomAnnotationMethod.MycustomAnnotation.SAVE) public MyResource save(@Valid Portfolio portfolio) {

return myrepository.save(MyResource);

} ` In latest version upgrade we are extending ResourceRepositoryBase

But issue is that our our custom around annotations are not called when we are extending base katharsis class (ResourceRepositoryBase)

I was wondering if we need to do something so our custom annotations are called in extended child class from katharsis base class `@Component @MycustomannotationController((resourceType = "myresouces")) public class MyresourceRepository extends ResourceRepositoryBase<MyResource, String> {

@Override
@MyCustomAnnotationMethod(action = MyCustomAnnotationMethod.MyCustomAnnotationAction.SAVE)
public <S extends MyResource> S save(S myResource) {

    return myMongoRepository.save(myResource);
}`
chb0github commented 7 years ago

Using a child class is almost certainly the issue. The annotation must use @inherited and maybe other tricks. The annotation is actual lost during compilation. Instead of an aspect pointcut you might want to try using execute expression. It's not subject to such issues

On Fri, Jun 9, 2017, 9:00 AM omprak05 notifications@github.com wrote:

We are upgrading katharsis to latest version 3.0.2.In older version in resource repository we were using @jsonapisave to save our resource.Also we were using an around aspect based our own custom annotation (Spring AOP based custom annotation to control resource permissions).Our costom annotation is called before Save operation as around advise. ` @jsonapiresourcerepository(MyResource.class) @mycustomannotationcontroller ((resourceType = "myresouces")) @component https://github.com/component @NoArgsConstructor https://github.com/noargsconstructor public class TestService {

@jsonapisave @mycustomannotationmethod(action = mycustomAnnotationMethod.MycustomAnnotation.SAVE) public MyResource save(@Valid https://github.com/valid Portfolio portfolio) {

return myrepository.save(MyResource);

} ` In latest version upgrade we are extending ResourceRepositoryBase

But issue is that our our custom around annotations are not called when we are extending base katharsis class (ResourceRepositoryBase)

I was wondering if we need to do something so our custom annotations are called in extended child class from katharsis base class `@component https://github.com/component @mycustomannotationcontroller((resourceType = "myresouces")) public class MyresourceRepository extends ResourceRepositoryBase<MyResource, String> {

@Override @MyCustomAnnotationMethod(action = MyCustomAnnotationMethod.MyCustomAnnotationAction.SAVE) public S save(S myResource) {

return myMongoRepository.save(myResource);

}`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/katharsis-project/katharsis-framework/issues/434, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaI0Jl2GTYYvZlG4tqYJgYHn7qmt1_Aks5sCWwggaJpZM4N1iuB .

hibaymj commented 7 years ago

The combination @Inherited and @Retention(value=RUNTIME) should allow your custom annotation to function, however I doubt it will work the way you anticipate because Annotations are not directly applied to child classes which your point cut will rely on.

There are other ways, like package hierarchy and method wildcards to apply to all public save method calls within the com.foo.app.service package.

hibaymj commented 7 years ago

I think I understand what you are getting at, but I want to make sure we have a testable artifact to debug against. Can you put together a minimal example and PR in the order you are attempting to use it? Ideally with POM so we know the full dependency tree.

omprak05 commented 7 years ago

Well we were able to resolve this.we were using save() method in old version of katharsis .It worked as soon as I used create () for first time resource creation and save() for update and worked like charm. Also adding @EnableAspectJAutoProxy(proxyTargetClass = true) to spring boot class also helped to resolve other upgrade issue when you have custom annotation in your repository classes ` @Override @MyCustomAnnotationMethod(action = MyCustomAnnotationMethod.MyCustomAnnotationAction.SAVE) public S create(@Valid S myResource) {

return myMongoRepository.save(myResource);

}`

chb0github commented 7 years ago

Thanks for the insight.