Search in sources :

Example 1 with LocalizedServiceInfo

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"));
}
Also used : DatumAppEventProducer(net.solarnetwork.central.datum.biz.DatumAppEventProducer) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) LocalizedServiceInfo(net.solarnetwork.domain.LocalizedServiceInfo) Test(org.junit.Test)

Example 2 with LocalizedServiceInfo

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;
}
Also used : Aggregation(net.solarnetwork.central.domain.Aggregation) ArrayList(java.util.ArrayList) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo) LocalizedServiceInfo(net.solarnetwork.domain.LocalizedServiceInfo) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo)

Example 3 with LocalizedServiceInfo

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;
}
Also used : ScheduleType(net.solarnetwork.central.datum.export.domain.ScheduleType) ArrayList(java.util.ArrayList) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo) LocalizedServiceInfo(net.solarnetwork.domain.LocalizedServiceInfo) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo)

Example 4 with LocalizedServiceInfo

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;
}
Also used : OutputCompressionType(net.solarnetwork.central.datum.export.domain.OutputCompressionType) ArrayList(java.util.ArrayList) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo) LocalizedServiceInfo(net.solarnetwork.domain.LocalizedServiceInfo) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo)

Example 5 with LocalizedServiceInfo

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;
}
Also used : DatumAppEventProducer(net.solarnetwork.central.datum.biz.DatumAppEventProducer) ArrayList(java.util.ArrayList) MessageSource(org.springframework.context.MessageSource) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo) BasicLocalizedServiceInfo(net.solarnetwork.domain.BasicLocalizedServiceInfo) LocalizedServiceInfo(net.solarnetwork.domain.LocalizedServiceInfo) HashSet(java.util.HashSet)

Aggregations

LocalizedServiceInfo (net.solarnetwork.domain.LocalizedServiceInfo)10 ArrayList (java.util.ArrayList)5 DatumAppEventProducer (net.solarnetwork.central.datum.biz.DatumAppEventProducer)5 BasicLocalizedServiceInfo (net.solarnetwork.domain.BasicLocalizedServiceInfo)5 Test (org.junit.Test)4 Aggregation (net.solarnetwork.central.domain.Aggregation)2 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)2 HashSet (java.util.HashSet)1 OutputCompressionType (net.solarnetwork.central.datum.export.domain.OutputCompressionType)1 ScheduleType (net.solarnetwork.central.datum.export.domain.ScheduleType)1 DatumImportInputFormatService (net.solarnetwork.central.datum.imp.biz.DatumImportInputFormatService)1 MessageSource (org.springframework.context.MessageSource)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1