You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2019/05/10 12:01:00 UTC

[jira] [Resolved] (SLING-8272) ConfigurationBuilder: Add method to check for the existence of the config

     [ https://issues.apache.org/jira/browse/SLING-8272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Konrad Windszus resolved SLING-8272.
------------------------------------
    Resolution: Fixed

Both PRs are merged now (after several review rounds):
API: https://github.com/apache/sling-org-apache-sling-caconfig-api/commit/ec4daac117f61d4f8aeeac291a494a5388224a19
Impl: https://github.com/apache/sling-org-apache-sling-caconfig-impl/commit/fd730a3cdf80128046d8c1dde26afb721d1517e0

> ConfigurationBuilder: Add method to check for the existence of the config
> -------------------------------------------------------------------------
>
>                 Key: SLING-8272
>                 URL: https://issues.apache.org/jira/browse/SLING-8272
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: Context-Aware Configuration API 1.1.2, Context-Aware Configuration Impl 1.4.14
>            Reporter: Konrad Windszus
>            Assignee: Konrad Windszus
>            Priority: Major
>             Fix For: Context-Aware Configuration API 1.1.4, Context-Aware Configuration Impl 1.4.18
>
>          Time Spent: 4h 50m
>  Remaining Estimate: 0h
>
> Sometimes it is desirable to check if a Context Aware Configuration is there at all via the high level API. Both methods {{as}} and {{asCollection}} will never return null, as they will always consider the default values. All other methods require to set at least a name.
> So to simply check if a CAC content resource is existing for a certain annotation class (defining a Context Aware Configuration) the following code is necessary:
> {code}
> ConfigurationBuilder builder = contentResource.adaptTo(ConfigurationBuilder.class);
> builder.name(<derive name from annotation type>).valueMap().isEmpty();
> {code}
> As there is no method exported to derive the name from an annotation type this would require additional custom code.
> I propose to add a simple 
> {code}
> boolean has(@NotNull java.lang.Class<T> clazz)
> {code}
> which is only then supposed to return {{true}} in case there is an underlying CAC content resource which can be adapted to the given class.
> Compare also with https://www.mail-archive.com/dev@sling.apache.org/msg83617.html.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)