class ContextualPreferenceManager {

    public ContextualPreference search(final List<String> preferences,
                                       final ContextualPreferenceExternalResource resource) {
        if (resource == null) {
            return search(preferences);
        }
        validateNames(preferences);
        validateResource(resource);
        Assert.isTrue(resource.getLevel() == ContextualPreferenceLevel.TOOL, messageHelper.getMessage(
                MessageConstants.ERROR_SEARCH_CONTEXTUAL_PREFERENCE_EXTERNAL_RESOURCE_LEVEL_INVALID));
        return contextualPreferenceHandler.search(preferences, resources(resource))
                .orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage(
                        MessageConstants.ERROR_CONTEXTUAL_PREFERENCE_NOT_FOUND, preferences, resource)));
    }

}