use of net.solarnetwork.domain.LocalizedServiceInfo in project solarnetwork-central by SolarNetwork.
the class DaoUserEventHookBizTests method availableTopics_multipleProducers_overlapTopic.
@Test
public void availableTopics_multipleProducers_overlapTopic() {
// GIVEN
DatumAppEventProducer producer1 = EasyMock.createMock(DatumAppEventProducer.class);
DatumAppEventProducer producer2 = EasyMock.createMock(DatumAppEventProducer.class);
biz.setDatumEventProducers(asList(producer2, producer1));
String topic = "topic/3";
expect(producer2.getProducedDatumAppEventTopics()).andReturn(singleton(topic));
expect(producer1.getProducedDatumAppEventTopics()).andReturn(singleton(topic));
ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
ms.setBasename("net/solarnetwork/central/user/event/biz/dao/test/test-messages-03");
expect(producer2.getMessageSource()).andReturn(ms);
// WHEN
replayAll(producer1, producer2);
Iterable<LocalizedServiceInfo> itr = biz.availableDatumEventTopics(Locale.ENGLISH);
// THEN
assertThat("Service info iterable returned", itr, notNullValue());
List<LocalizedServiceInfo> infos = StreamSupport.stream(itr.spliterator(), false).collect(toList());
assertThat("Service info count", infos, hasSize(1));
LocalizedServiceInfo info;
info = infos.get(0);
assertThat("Service info ID is topic", info.getId(), equalTo(topic));
assertThat("Service name from i18n bundle", info.getLocalizedName(), equalTo("TOPIC-03-3"));
assertThat("Service description from i18n bundle", info.getLocalizedDescription(), equalTo("DESC-03-3"));
}
use of net.solarnetwork.domain.LocalizedServiceInfo in project solarnetwork-central by SolarNetwork.
the class DaoUserExportBiz method availableAggregationTypes.
@Override
public Iterable<LocalizedServiceInfo> availableAggregationTypes(Locale locale) {
List<LocalizedServiceInfo> results = new ArrayList<>(ScheduleType.values().length);
for (Aggregation type : Aggregation.values()) {
String name = type.toString();
String desc = null;
if (messageSource != null) {
name = messageSource.getMessage("aggregation." + type.name() + ".key", null, name, locale);
desc = messageSource.getMessage("aggregation." + type.name() + ".desc", null, desc, locale);
}
results.add(new BasicLocalizedServiceInfo(String.valueOf(type.getKey()), locale, name, desc, null));
}
return results;
}
use of net.solarnetwork.domain.LocalizedServiceInfo in project solarnetwork-central by SolarNetwork.
the class DaoUserExportBiz method availableScheduleTypes.
@Override
public Iterable<LocalizedServiceInfo> availableScheduleTypes(Locale locale) {
List<LocalizedServiceInfo> results = new ArrayList<>(ScheduleType.values().length);
for (ScheduleType type : ScheduleType.values()) {
if (type == ScheduleType.Adhoc) {
// ad hoc not a supported user export type here
continue;
}
String name = type.toString();
String desc = null;
if (messageSource != null) {
name = messageSource.getMessage("scheduleType." + type.name() + ".key", null, name, locale);
desc = messageSource.getMessage("scheduleType." + type.name() + ".desc", null, desc, locale);
}
results.add(new BasicLocalizedServiceInfo(String.valueOf(type.getKey()), locale, name, desc, null));
}
return results;
}
use of net.solarnetwork.domain.LocalizedServiceInfo in project solarnetwork-central by SolarNetwork.
the class DaoUserExportBiz method availableOutputCompressionTypes.
@Override
public Iterable<LocalizedServiceInfo> availableOutputCompressionTypes(Locale locale) {
List<LocalizedServiceInfo> results = new ArrayList<>(OutputCompressionType.values().length);
for (OutputCompressionType type : OutputCompressionType.values()) {
String name = type.toString();
String desc = null;
if (messageSource != null) {
name = messageSource.getMessage("compressionType." + type.name() + ".key", null, name, locale);
desc = messageSource.getMessage("compressionType." + type.name() + ".desc", null, desc, locale);
}
results.add(new BasicLocalizedServiceInfo(String.valueOf(type.getKey()), locale, name, desc, null));
}
return results;
}
use of net.solarnetwork.domain.LocalizedServiceInfo in project solarnetwork-central by SolarNetwork.
the class DaoUserEventHookBiz method availableDatumEventTopics.
@Override
public Iterable<LocalizedServiceInfo> availableDatumEventTopics(Locale locale) {
List<DatumAppEventProducer> svcs = getDatumEventProducers();
Iterable<DatumAppEventProducer> producers = (svcs != null ? svcs : Collections.emptyList());
List<LocalizedServiceInfo> results = new ArrayList<>(10);
Set<String> handledTopics = new HashSet<>(10);
for (DatumAppEventProducer producer : producers) {
Set<String> topics = producer.getProducedDatumAppEventTopics();
for (String topic : topics) {
// don't add duplicate topics... first come, first serve
if (handledTopics.contains(topic)) {
continue;
}
handledTopics.add(topic);
String name = topic;
String desc = null;
// first look if we have a "standard" i18n message
if (messageSource != null) {
name = messageSource.getMessage("event.topic." + topic + ".title", null, topic, locale);
desc = messageSource.getMessage("event.topic." + topic + ".desc", null, null, locale);
}
if (desc == null) {
MessageSource serviceMessageSource = producer.getMessageSource();
if (serviceMessageSource != null) {
name = serviceMessageSource.getMessage("event.topic." + topic + ".title", null, topic, locale);
desc = serviceMessageSource.getMessage("event.topic." + topic + ".desc", null, null, locale);
}
}
results.add(new BasicLocalizedServiceInfo(topic, locale, name, desc, null));
}
}
Collections.sort(results, LocalizedServiceInfo.SORT_BY_NAME);
return results;
}
Aggregations