Release Notes / Version 10.2104
Table Of Contents
In order to mature our experimental translation API, we had to refactor
com.coremedia.translate.TranslatablePredicate
. Instead of implementing
isTranslatable(CapPropertyDescriptor):boolean
you now need to implement
isTranslatable(List<CapPropertyDescriptor>):boolean
.
The change makes the implementation of
com.coremedia.translate.TranslatablePredicate
straightforward and less error-prone (caused by the slightly different semantics of the existing old methods).
In addition to that, we also eased adding more predicates to decide upon the translatable state of a property descriptor.
Instead of having to adapt the bean named
translatablePredicate
in
TranslatablePredicateConfiguration
, you can now
just add additional predicates to your Spring context. All existing predicates will be ORed to decide, if a property descriptor
is considered translatable or not. A positive decision of any predicate cannot be vetoed.
If for any reason, you need a veto-algorithm, you still need to override the bean
translatablePredicate
.
Upgrade:
The upgrade path differs for API usages and API implementations.
API Usages:
If you used
isTranslatable(CapPropertyDescriptor):boolean
only, your code most likely does not need to be adapted at all. A compatible API still exists and will exist in future versions. Note though, that the compatible method
isTranslatable(CapPropertyDescriptor...):boolean
will only return
true
, if the last element of the list shall be considered translatable. Prior to this change the old method
isTranslatable(CapPropertyDescriptor):boolean
was documented, that it shall return
true
, if nested properties (for Structs)
may
exist, which are translatable.
API Implementations:
As API implementor you will experience, that your project won't compile. This is because the interface now requires implementing
isTranslatable(List):boolean
.
A compatible replacement for
isTranslatable(CapPropertyDescriptor):boolean
will just check for the first element of the list to be translatable. You may use the new method
TranslatablePredicate.testFirst(Predicate, List):boolean
as mentioned below for lambdas.
If you want to widen your implementation for Struct use-cases the following approach is suggested:
Rename your implementation of
isTranslatable(CapPropertyDescriptor):boolean
toisDescriptorTranslatable(CapPropertyDescriptor):boolean
and make it private.Implement
isTranslatable(List):boolean
as follows:
@Override public boolean isTranslatable(List<? extends CapPropertyDescriptor> descriptors) { return descriptors.stream().anyMatch(this::isDescriptorTranslatable); }
Special Note on Lambdas:
If you used a lambda to implement
TranslatablePredicate
you will get an error as the input argument changed from
CapPropertyDescriptor
to
List<CapPropertyDescriptor
. A sufficient change would be to get the first element of the list and continue to check that element. The possible
NoSuchElementException
is acceptable, as it is an error, if an empty list is passed to the predicate.
As alternative, a convenience API exists, which is meant to ease your upgrade process. Instead of:
TranslatablePredicate tp = d -> "xml".equals(d.getName());
you may change this to:
TranslatablePredicate tp = ds -> TranslatablePredicate.testFirst( d -> "xml".equals(d.getName()), ds );
(CMS-16402)