mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Fix community marketplace discourse parsing (#5376)
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
This commit is contained in:
+4
-5
@@ -27,7 +27,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -188,8 +187,8 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||
}
|
||||
|
||||
List<DiscourseUser> users = pages.stream().flatMap(p -> Stream.of(p.users)).toList();
|
||||
pages.stream().flatMap(p -> Stream.of(p.topicList.topics))
|
||||
.filter(t -> showUnpublished || List.of(t.tags).contains(PUBLISHED_TAG))
|
||||
pages.stream().flatMap(p -> Stream.of(p.topicList.topics)).filter(t -> showUnpublished
|
||||
|| (t.tags != null && Arrays.stream(t.tags).anyMatch(tag -> PUBLISHED_TAG.equals(tag.name))))
|
||||
.map(t -> Optional.ofNullable(convertTopicItemToAddon(t, users)))
|
||||
.forEach(a -> a.ifPresent(addons::add));
|
||||
} catch (Exception e) {
|
||||
@@ -290,7 +289,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||
*/
|
||||
private @Nullable Addon convertTopicItemToAddon(DiscourseTopicItem topic, List<DiscourseUser> users) {
|
||||
try {
|
||||
List<String> tags = Arrays.asList(Objects.requireNonNullElse(topic.tags, new String[0]));
|
||||
List<String> tags = topic.tags == null ? List.of() : Arrays.stream(topic.tags).map(t -> t.name).toList();
|
||||
|
||||
String uid = ADDON_ID_PREFIX + topic.id.toString();
|
||||
AddonType addonType = getAddonType(topic.categoryId, tags);
|
||||
@@ -376,7 +375,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||
*/
|
||||
private Addon convertTopicToAddon(DiscourseTopicResponseDTO topic) {
|
||||
String uid = ADDON_ID_PREFIX + topic.id.toString();
|
||||
List<String> tags = Arrays.asList(Objects.requireNonNullElse(topic.tags, new String[0]));
|
||||
List<String> tags = topic.tags == null ? List.of() : Arrays.stream(topic.tags).map(t -> t.name).toList();
|
||||
|
||||
AddonType addonType = getAddonType(topic.categoryId, tags);
|
||||
String type = (addonType != null) ? addonType.getId() : "";
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ public class DiscourseCategoryResponseDTO {
|
||||
public Integer id;
|
||||
public String title;
|
||||
public String slug;
|
||||
public String[] tags;
|
||||
public TagDTO[] tags;
|
||||
@SerializedName("posts_count")
|
||||
public Integer postsCount;
|
||||
@SerializedName("image_url")
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class DiscourseTopicResponseDTO {
|
||||
public Integer likeCount;
|
||||
public Integer views;
|
||||
|
||||
public String[] tags;
|
||||
public TagDTO[] tags;
|
||||
@SerializedName("category_id")
|
||||
public Integer categoryId;
|
||||
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2026 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.addon.marketplace.internal.community.model;
|
||||
|
||||
/**
|
||||
* A DTO class mapped to the Discourse tag object.
|
||||
*
|
||||
* @author Ravi Nadahar - Initial contribution
|
||||
*/
|
||||
public class TagDTO {
|
||||
public Integer id;
|
||||
public String name;
|
||||
public String slug;
|
||||
}
|
||||
Reference in New Issue
Block a user