podam icon indicating copy to clipboard operation
podam copied to clipboard

Enable defining ArributeStrategy that will be applicable for all annotation classes implementing the same interface

Open zonkeydonkey opened this issue 6 years ago • 13 comments

Podam allows to set custom AttributeStrategies for specific, explicitly mentioned annotation types:

val factory = PodamFactoryImpl()                                                            
(factory.strategy as RandomDataProviderStrategy).addOrReplaceAttributeStrategy(MyCustomAnnotation::class.java, MyCustomAttributeStrategy())

but it is not possible to define "fallback" strategy that will be used for all annotations that implement the same base interface (for example in Kotlin every annotation class implements kotlin.Annotation):

(factory.strategy as RandomDataProviderStrategy).addOrReplaceAttributeStrategy(Annotation::class.java, MyCustomAttributeStrategy())

All above examples are written in Kotlin.

zonkeydonkey avatar Jun 25 '20 15:06 zonkeydonkey

Hi,

Thank you for the contribution. I will look into it. We definitely need a test for this.

Thanks, Daniil

daivanov avatar Jul 05 '20 06:07 daivanov

@daivanov in the test for this issue you are assuming that when strategy for generic Annotation class is defined, the number of calls of that strategy is equal to 0. Is it only for the test to pass before this PR gets merged or is it some internal requirement for Podam you wish to preserve?

zonkeydonkey avatar Jul 15 '20 15:07 zonkeydonkey

This is just a placeholder test, which I made to succeed otherwise Travis will be failing and everybody will be unhappy. The idea was that @Version and @Basic will be triggering generic AnnotationStrategy, which doesn't happen at the moment.

Thanks, Daniil

daivanov avatar Jul 16 '20 23:07 daivanov

And it looks like the whole enterprise has failed because each field has multiple annotations and at least one of them is supported by Podam :)

Thanks, Daniil

daivanov avatar Jul 16 '20 23:07 daivanov

I think I need to investigate your branch more thoroughly.

Thanks, Daniil

daivanov avatar Jul 23 '20 22:07 daivanov

What do you think about the latest changes?

Thanks, Daniil

daivanov avatar Jul 26 '20 22:07 daivanov

Hi, I agree with all your changes. Thanks for applying them, could you release a new version of Podam? Thanks, Sylwia

zonkeydonkey avatar Jul 27 '20 12:07 zonkeydonkey

Ok, thank you. Fixed in Podam 7.2.4

Thanks, Daniil

daivanov avatar Jul 27 '20 19:07 daivanov

It's already there, but will be visible in Maven UI, when they will synchronize everything https://repo1.maven.org/maven2/uk/co/jemos/podam/podam/7.2.4.RELEASE/

Thanks, Daniil

daivanov avatar Jul 27 '20 19:07 daivanov

https://mvnrepository.com/artifact/uk.co.jemos.podam/podam :man_shrugging:

daivanov avatar Jul 27 '20 22:07 daivanov

@daivanov could you reopen the issue? I have noticed that the logging still needs to be conformed to the changes that have been done for this issue, example: supposing you have your custom validation annotation and you did not registered an attribute strategy for this annotation itself, but you registered a fallback strategy for Annotation class (the interface for all annotation classes), Podam still logs: Please, register AttributeStratergy for custom constraint (...) Better would be to log the above message when no strategy for certain annotation can be applied (neither strategy for the annotation nor for Annotation class) and when fallback strategy can be applied, then log some message in this manner: "A strategy for $annotation was not found, $baseClassOfAnnotation strategy was used."

zonkeydonkey avatar Aug 04 '20 11:08 zonkeydonkey

True, the warning is logged too early.

Thanks, Daniil

daivanov avatar Aug 05 '20 15:08 daivanov

Sorry for a delay. Not it's merged.

Thanks, Daniil

daivanov avatar Aug 16 '20 09:08 daivanov