Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Separate ChannelGroupType infrastructure from ChannelType #6072

Merged
merged 10 commits into from
Aug 20, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.eclipse.smarthome.core.thing.type.BridgeType
import org.eclipse.smarthome.core.thing.type.ChannelDefinition
import org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition
import org.eclipse.smarthome.core.thing.type.ChannelGroupType
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID
import org.eclipse.smarthome.core.thing.type.ChannelType
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider
Expand Down Expand Up @@ -239,11 +240,14 @@ class ThingFactoryTest extends OSGiTest{
getChannelTypes: { channelTypes },
getChannelType: { ChannelTypeUID uid, Locale locale ->
channelTypes.find { it.UID == uid }
},
}
] as ChannelTypeProvider)

registerService([
getChannelGroupTypes: { channelGroupTypes },
getChannelGroupType: { ChannelGroupTypeUID uid, Locale locale ->
channelGroupTypes.find { it.UID == uid }
},
] as ChannelTypeProvider)
] as ChannelGroupTypeProvider)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
Expand Down Expand Up @@ -159,12 +160,13 @@ public void setup() throws URISyntaxException {
when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
when(channelTypeProvider.getChannelType(any(), any()))
.thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
registerService(channelTypeProvider);

when(channelTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
when(channelTypeProvider.getChannelGroupType(any(), any()))
ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
when(channelGroupTypeProvider.getChannelGroupType(any(), any()))
.thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));

registerService(channelTypeProvider);
registerService(channelGroupTypeProvider);

managedItemProvider.add(new StringItem(ITEM_GENERIC));
managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import org.eclipse.smarthome.core.thing.link.ItemChannelLink;
import org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
Expand Down Expand Up @@ -144,16 +142,6 @@ public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale)
}
return null;
}

@Override
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
return null;
}

@Override
public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
return Collections.emptySet();
}
});

registerService(new DynamicStateDescriptionProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.core.thing.type.ThingType;
Expand All @@ -41,7 +42,7 @@ public class ChannelTypesI18nTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "ChannelTypesI18nTest.bundle";

private ChannelTypeProvider channelTypeProvider;
private ChannelTypeProvider channelGroupTypeProvider;
private ChannelGroupTypeProvider channelGroupTypeProvider;
private ThingTypeProvider thingTypeProvider;

@Before
Expand All @@ -51,7 +52,7 @@ public void setUp() {
serviceReference -> "core.xml.channels".equals(serviceReference.getProperty("esh.scope")));

assertThat(channelTypeProvider, is(notNullValue()));
channelGroupTypeProvider = getService(ChannelTypeProvider.class,
channelGroupTypeProvider = getService(ChannelGroupTypeProvider.class,
serviceReference -> "core.xml.channelGroups".equals(serviceReference.getProperty("esh.scope")));

assertThat(channelGroupTypeProvider, is(notNullValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;

import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
Expand All @@ -38,15 +39,15 @@ public class ChannelTypesTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "ChannelTypesTest.bundle";

private ChannelTypeProvider channelTypeProvider;
private ChannelTypeProvider channelGroupTypeProvider;
private ChannelGroupTypeProvider channelGroupTypeProvider;

@Before
public void setUp() {
// get ONLY the XMLChannelTypeProvider
channelTypeProvider = getService(ChannelTypeProvider.class,
serviceReference -> "core.xml.channels".equals(serviceReference.getProperty("esh.scope")));
assertThat(channelTypeProvider, is(notNullValue()));
channelGroupTypeProvider = getService(ChannelTypeProvider.class,
channelGroupTypeProvider = getService(ChannelGroupTypeProvider.class,
serviceReference -> "core.xml.channelGroups".equals(serviceReference.getProperty("esh.scope")));
assertThat(channelGroupTypeProvider, is(notNullValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
Expand All @@ -42,6 +43,7 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {

private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
private ChannelGroupTypeRegistry channelGroupTypeRegistry;

@Before
public void setUp() {
Expand All @@ -50,6 +52,9 @@ public void setUp() {

channelTypeRegistry = getService(ChannelTypeRegistry.class);
assertThat(channelTypeRegistry, is(notNullValue()));

channelGroupTypeRegistry = getService(ChannelGroupTypeRegistry.class);
assertThat(channelGroupTypeRegistry, is(notNullValue()));
}

@After
Expand All @@ -61,7 +66,7 @@ public void tearDown() throws Exception {
public void systemChannelsInChannelGroupsShouldLoadAndUnload() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
int initialNumberOfChannelTypes = channelTypeRegistry.getChannelTypes().size();
int initialNumberOfChannelGroupTypes = channelTypeRegistry.getChannelGroupTypes().size();
int initialNumberOfChannelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes().size();

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
Expand All @@ -70,15 +75,15 @@ public void systemChannelsInChannelGroupsShouldLoadAndUnload() throws Exception
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
assertThat(channelTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes + 1));
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes + 1));

// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));

assertThat(thingTypeProvider.getThingTypes(null).size(), is(initialNumberOfThingTypes));
assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes));
assertThat(channelTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));

}

Expand All @@ -94,7 +99,7 @@ public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDe

assertThat(thingTypes.size(), is(1));

List<ChannelGroupType> channelGroupTypes = channelTypeRegistry.getChannelGroupTypes();
List<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();

ChannelGroupType channelGroup = channelGroupTypes.stream()
.filter(it -> it.getUID().equals(new ChannelGroupTypeUID("SystemChannelsInChannelGroups:channelGroup")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
Expand All @@ -38,6 +39,7 @@ public class ThingTypeI18nTest extends JavaOSGiTest {

private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
private ChannelGroupTypeRegistry channelGroupTypeRegistry;

@Before
public void setUp() {
Expand All @@ -46,6 +48,9 @@ public void setUp() {

channelTypeRegistry = getService(ChannelTypeRegistry.class);
assertNotNull(channelTypeRegistry);

channelGroupTypeRegistry = getService(ChannelGroupTypeRegistry.class);
assertNotNull(channelGroupTypeRegistry);
}

@After
Expand Down Expand Up @@ -87,7 +92,7 @@ public void channelGroupTypeShouldBeLocalized() throws Exception {
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);

ChannelGroupType channelGroupType = channelTypeRegistry
ChannelGroupType channelGroupType = channelGroupTypeRegistry
.getChannelGroupType(weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
assertNotNull(channelGroupType);

Expand Down Expand Up @@ -147,7 +152,7 @@ public void channelsInGroupTypeShouldBeLocalized() throws Exception {
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);

ChannelGroupType forecastTodayChannelGroupType = channelTypeRegistry
ChannelGroupType forecastTodayChannelGroupType = channelGroupTypeRegistry
.getChannelGroupType(forecastTodayChannelGroupDefinition.getTypeUID(), Locale.GERMAN);
assertNotNull(forecastTodayChannelGroupType);
assertEquals(3, forecastTodayChannelGroupType.getChannelDefinitions().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,22 @@
* @author Michael Grammling - Initial Contribution
* @author Ivan Iliev - Added support for system wide channel types
*
* @see ThingTypeXmlProviderFactory
*/
public class ThingTypeXmlProvider implements XmlDocumentProvider<List<?>> {

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

private Bundle bundle;
private AbstractXmlConfigDescriptionProvider configDescriptionProvider;
private XmlThingTypeProvider thingTypeProvider;
private final Bundle bundle;
private final AbstractXmlConfigDescriptionProvider configDescriptionProvider;
private final XmlThingTypeProvider thingTypeProvider;

// temporary cache
private List<ThingTypeXmlResult> thingTypeRefs;
private List<ChannelGroupTypeXmlResult> channelGroupTypeRefs;
private List<ChannelTypeXmlResult> channelTypeRefs;
private final List<ThingTypeXmlResult> thingTypeRefs;
private final List<ChannelGroupTypeXmlResult> channelGroupTypeRefs;
private final List<ChannelTypeXmlResult> channelTypeRefs;

private XmlChannelTypeProvider channelTypeProvider;
private XmlChannelGroupTypeProvider channelGroupTypeProvider;
private final XmlChannelTypeProvider channelTypeProvider;
private final XmlChannelGroupTypeProvider channelGroupTypeProvider;

public ThingTypeXmlProvider(Bundle bundle, AbstractXmlConfigDescriptionProvider configDescriptionProvider,
XmlThingTypeProvider thingTypeProvider, XmlChannelTypeProvider channelTypeProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
package org.eclipse.smarthome.core.thing.xml.internal;

import java.util.Collection;
import java.util.Collections;
import java.util.Locale;

import org.eclipse.smarthome.config.xml.AbstractXmlBasedProvider;
import org.eclipse.smarthome.core.thing.UID;
import org.eclipse.smarthome.core.thing.i18n.ChannelGroupTypeI18nLocalizationService;
import org.eclipse.smarthome.core.thing.i18n.ThingTypeI18nLocalizationService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not needed anymore.

import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
import org.osgi.framework.Bundle;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand All @@ -36,9 +34,9 @@
*/
@Component(immediate = true, property = { "esh.scope=core.xml.channelGroups" })
public class XmlChannelGroupTypeProvider extends AbstractXmlBasedProvider<UID, ChannelGroupType>
implements ChannelTypeProvider {
implements ChannelGroupTypeProvider {

private ThingTypeI18nLocalizationService thingTypeI18nLocalizationService;
private ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService;

@Override
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
Expand All @@ -51,32 +49,23 @@ public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
}

@Reference
public void setThingTypeI18nLocalizationService(
final ThingTypeI18nLocalizationService thingTypeI18nLocalizationService) {
this.thingTypeI18nLocalizationService = thingTypeI18nLocalizationService;
public void setChannelGroupTypeI18nLocalizationService(
final ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService) {
this.channelGroupTypeI18nLocalizationService = channelGroupTypeI18nLocalizationService;
}

public void unsetThingTypeI18nLocalizationService(
final ThingTypeI18nLocalizationService thingTypeI18nLocalizationService) {
this.thingTypeI18nLocalizationService = null;
public void unsetChannelGroupTypeI18nLocalizationService(
final ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService) {
this.channelGroupTypeI18nLocalizationService = null;
}

@Override
protected ChannelGroupType localize(Bundle bundle, ChannelGroupType channelGroupType, Locale locale) {
if (thingTypeI18nLocalizationService == null) {
if (channelGroupTypeI18nLocalizationService == null) {
return null;
}
return thingTypeI18nLocalizationService.createLocalizedChannelGroupType(bundle, channelGroupType, locale);
}

@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
return Collections.emptyList();
}

@Override
public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
return null;
return channelGroupTypeI18nLocalizationService.createLocalizedChannelGroupType(bundle, channelGroupType,
locale);
}

}
Loading