Skip to content

Commit

Permalink
[Marketplace] Add option to include unpublished entries (openhab#2488)
Browse files Browse the repository at this point in the history
Add a config parameter to bypass the filtering of Dicourse topics
to include those which don't have the "published" tag.

Set the API key parameter as advanced (irrelevant to most users).

Signed-off-by: Yannick Schaus <[email protected]>
  • Loading branch information
ghys authored Sep 16, 2021
1 parent 41a535b commit 0ef477e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class CommunityMarketplaceAddonService implements AddonService {
// constants for the configuration properties
static final String CONFIG_URI = "system:marketplace";
static final String CONFIG_API_KEY = "apiKey";
static final String CONFIG_SHOW_UNPUBLISHED_ENTRIES_KEY = "showUnpublished";

private final Logger logger = LoggerFactory.getLogger(CommunityMarketplaceAddonService.class);

Expand Down Expand Up @@ -102,6 +103,7 @@ public class CommunityMarketplaceAddonService implements AddonService {
private final Set<MarketplaceAddonHandler> addonHandlers = new HashSet<>();
private EventPublisher eventPublisher;
private String apiKey = null;
private boolean showUnpublished = false;

@Activate
protected void activate(Map<String, Object> config) {
Expand All @@ -118,6 +120,9 @@ protected void activate(Map<String, Object> config) {
void modified(@Nullable Map<String, Object> config) {
if (config != null) {
this.apiKey = (String) config.get(CONFIG_API_KEY);
Object showUnpublishedConfigValue = config.get(CONFIG_SHOW_UNPUBLISHED_ENTRIES_KEY);
this.showUnpublished = showUnpublishedConfigValue != null
&& "true".equals(showUnpublishedConfigValue.toString());
}
}

Expand Down Expand Up @@ -182,7 +187,7 @@ public List<Addon> getAddons(Locale locale) {

List<DiscourseUser> users = pages.stream().flatMap(p -> Stream.of(p.users)).collect(Collectors.toList());
return pages.stream().flatMap(p -> Stream.of(p.topic_list.topics))
.filter(t -> Arrays.asList(t.tags).contains(PUBLISHED_TAG))
.filter(t -> showUnpublished || Arrays.asList(t.tags).contains(PUBLISHED_TAG))
.map(t -> convertTopicItemToAddon(t, users)).collect(Collectors.toList());
} catch (Exception e) {
logger.error("Unable to retrieve marketplace add-ons", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
https://openhab.org/schemas/config-description-1.0.0.xsd">

<config-description uri="system:marketplace">
<parameter name="showUnpublished" type="boolean">
<label>Show Unpublished Entries</label>
<default>false</default>
<description>Include entries which have not been tagged as published. Warning: this may include entries that are not
ready and might not work or harm your installation. Enable at your own risk, for testing purposes only.</description>
</parameter>
<parameter name="apiKey" type="text">
<advanced>true</advanced>
<label>API Key for community.openhab.org</label>
<description>Specify the API key to use on the community forum (for staff and curators - this allows for instance to
see content which is not yet reviewed or otherwise hidden from the general public). Leave blank if you don't have
Expand Down

0 comments on commit 0ef477e

Please sign in to comment.