Skip to content

Commit

Permalink
Fix countries and connection AddonInfo issues (openhab#3797)
Browse files Browse the repository at this point in the history
Fixes the following:

* connection and countries details missing for some AddonServices
* missing connection getter on AddonInfo
* countries lists has empty String when when countries info is missing

Related to openhab#3795

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored Sep 9, 2023
1 parent daeb367 commit f6435ec
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ private Addon getAddon(Bundle bundle, @Nullable Locale locale) {
if (addonInfo != null) {
// only enrich if this add-on is installed, otherwise wrong data might be added
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription())
.withCountries(addonInfo.getCountries()).withLink(getDefaultDocumentationLink(type, name))
.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
.withLink(getDefaultDocumentationLink(type, name))
.withConfigDescriptionURI(addonInfo.getConfigDescriptionURI());
} else {
addon = addon.withLabel(name).withLink(getDefaultDocumentationLink(type, name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ private Addon fromAddonEntry(AddonEntryDTO addonEntry) {
.withCompatible(compatible).withMaturity(addonEntry.maturity).withProperties(properties)
.withLink(addonEntry.link).withImageLink(addonEntry.imageUrl)
.withConfigDescriptionURI(addonEntry.configDescriptionURI).withLoggerPackages(addonEntry.loggerPackages)
.build();
.withConnection(addonEntry.connection).withCountries(addonEntry.countries).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public class AddonEntryDTO {
public String url = "";
@SerializedName("logger_packages")
public List<String> loggerPackages = List.of();
public String connection = "";
public List<String> countries = List.of();
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public String getDescription() {
return sourceBundle;
}

public @Nullable String getConnection() {
return connection;
}

public List<String> getCountries() {
return countries;
}
Expand Down Expand Up @@ -192,7 +196,7 @@ public Builder withConnection(@Nullable String connection) {
}

public Builder withCountries(@Nullable String countries) {
this.countries = Arrays.asList(Objects.requireNonNullElse(countries, "").split(","));
this.countries = countries == null || countries.isBlank() ? List.of() : Arrays.asList(countries.split(","));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private Addon toAddon(Bundle bundle, AddonInfo addonInfo) {
String uid = ADDON_ID_PREFIX + addonInfo.getUID();
return Addon.create(uid).withId(addonInfo.getId()).withType(addonInfo.getType()).withInstalled(true)
.withVersion(bundle.getVersion().toString()).withLabel(addonInfo.getName())
.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
.withConfigDescriptionURI(addonInfo.getConfigDescriptionURI())
.withDescription(Objects.requireNonNullElse(addonInfo.getDescription(), bundle.getSymbolicName()))
.withContentType(ADDONS_CONTENT_TYPE).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ private Addon getAddon(Feature feature, @Nullable Locale locale) {
if (isInstalled && addonInfo != null) {
// only enrich if this add-on is installed, otherwise wrong data might be added
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription())
.withCountries(addonInfo.getCountries()).withLink(getDefaultDocumentationLink(type, name))
.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
.withLink(getDefaultDocumentationLink(type, name))
.withConfigDescriptionURI(addonInfo.getConfigDescriptionURI());
} else {
addon = addon.withLabel(feature.getDescription()).withLink(getDefaultDocumentationLink(type, name));
Expand Down

0 comments on commit f6435ec

Please sign in to comment.