Include measurement system in REST root resource (#1710)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-10-10 20:04:25 +02:00
committed by GitHub
parent 76f51026aa
commit 351fcb1852
2 changed files with 11 additions and 3 deletions
@@ -26,6 +26,7 @@ import javax.ws.rs.core.UriInfo;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.io.rest.RESTConstants;
import org.openhab.core.io.rest.RESTResource;
import org.openhab.core.io.rest.internal.resources.beans.RootBean;
@@ -81,11 +82,14 @@ public class RootResource implements RESTResource {
private final Logger logger = LoggerFactory.getLogger(RootResource.class);
private final JaxrsServiceRuntime runtime;
private final LocaleProvider localeProvider;
private final UnitProvider unitProvider;
@Activate
public RootResource(final @Reference JaxrsServiceRuntime runtime, final @Reference LocaleProvider localeProvider) {
public RootResource(final @Reference JaxrsServiceRuntime runtime, final @Reference LocaleProvider localeProvider,
final @Reference UnitProvider unitProvider) {
this.runtime = runtime;
this.localeProvider = localeProvider;
this.unitProvider = unitProvider;
}
@GET
@@ -98,7 +102,7 @@ public class RootResource implements RESTResource {
final Map<String, String> collectedLinks = new HashMap<>();
final RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
final RootBean bean = new RootBean(localeProvider);
final RootBean bean = new RootBean(localeProvider, unitProvider);
for (final ApplicationDTO applicationDTO : runtimeDTO.applicationDTOs) {
for (final ResourceDTO resourceDTO : applicationDTO.resourceDTOs) {
// We are using the JAX-RS name per convention for the link type.
@@ -18,6 +18,7 @@ import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.OpenHAB;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.io.rest.RESTConstants;
/**
@@ -34,12 +35,15 @@ public class RootBean {
public final String locale;
public final String measurementSystem;
public final RuntimeInfo runtimeInfo = new RuntimeInfo();
public final List<Links> links = new ArrayList<>();
public RootBean(LocaleProvider localeProvider) {
public RootBean(LocaleProvider localeProvider, UnitProvider unitProvider) {
this.locale = localeProvider.getLocale().toString();
this.measurementSystem = unitProvider.getMeasurementSystem().getName();
}
public static class RuntimeInfo {