Search in sources :

Example 1 with KeyedSettingSpecifier

use of net.solarnetwork.settings.KeyedSettingSpecifier in project solarnetwork-node by SolarNetwork.

the class CASettingsService method getSettingValue.

@Override
public Object getSettingValue(SettingSpecifierProvider provider, SettingSpecifier setting) {
    if (setting instanceof KeyedSettingSpecifier<?>) {
        KeyedSettingSpecifier<?> keyedSetting = (KeyedSettingSpecifier<?>) setting;
        if (keyedSetting.isTransient()) {
            return keyedSetting.getDefaultValue();
        }
        final String providerUID = provider.getSettingUid();
        final String instanceUid = (provider instanceof FactorySettingSpecifierProvider ? ((FactorySettingSpecifierProvider) provider).getFactoryInstanceUID() : null);
        try {
            Configuration conf = getConfiguration(providerUID, instanceUid);
            Dictionary<String, ?> props = conf.getProperties();
            Object val = (props == null ? null : props.get(keyedSetting.getKey()));
            if (val == null) {
                val = keyedSetting.getDefaultValue();
            }
            return val;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InvalidSyntaxException e) {
            throw new RuntimeException(e);
        }
    }
    return null;
}
Also used : Configuration(org.osgi.service.cm.Configuration) FactorySettingSpecifierProvider(net.solarnetwork.settings.FactorySettingSpecifierProvider) BasicFactorySettingSpecifierProvider(net.solarnetwork.settings.support.BasicFactorySettingSpecifierProvider) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier)

Example 2 with KeyedSettingSpecifier

use of net.solarnetwork.settings.KeyedSettingSpecifier in project solarnetwork-node by SolarNetwork.

the class DemandBalancerJob method getSettingSpecifiers.

@Override
public List<SettingSpecifier> getSettingSpecifiers() {
    List<SettingSpecifier> result = new ArrayList<>();
    for (SettingSpecifier spec : demandBalancer.getSettingSpecifiers()) {
        if (spec instanceof KeyedSettingSpecifier<?>) {
            KeyedSettingSpecifier<?> keyedSpec = (KeyedSettingSpecifier<?>) spec;
            result.add(keyedSpec.mappedTo("demandBalancer."));
        } else {
            result.add(spec);
        }
    }
    return result;
}
Also used : SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) ArrayList(java.util.ArrayList) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier)

Example 3 with KeyedSettingSpecifier

use of net.solarnetwork.settings.KeyedSettingSpecifier in project solarnetwork-node by SolarNetwork.

the class CCDatumDataSource method getSettingSpecifiers.

@Override
public List<SettingSpecifier> getSettingSpecifiers() {
    CCDatumDataSource defaults = new CCDatumDataSource();
    List<SettingSpecifier> specs = getDefaultSettingSpecifiers();
    SettingSpecifier energyTag = new BasicToggleSettingSpecifier("tagConsumption", Boolean.valueOf(defaults.isTagConsumption()));
    SettingSpecifier atmosTag = new BasicToggleSettingSpecifier("tagIndoor", Boolean.valueOf(defaults.isTagIndoor()));
    if (specs.size() > 4) {
        specs.add(4, atmosTag);
        specs.add(4, energyTag);
    } else {
        specs.add(energyTag);
        specs.add(atmosTag);
    }
    // remove some we don't want, insert addressSourceMappingValueExample
    for (ListIterator<SettingSpecifier> itr = specs.listIterator(); itr.hasNext(); ) {
        SettingSpecifier spec = itr.next();
        if (spec instanceof KeyedSettingSpecifier<?>) {
            KeyedSettingSpecifier<?> keyedSpec = (KeyedSettingSpecifier<?>) spec;
            if (SPECS_FILTER.contains(keyedSpec.getKey())) {
                itr.remove();
            } else if ("addressSourceMappingValue".equals(keyedSpec.getKey())) {
                StringBuilder buf = new StringBuilder();
                for (CCDatum sample : getKnownAddresses()) {
                    if (buf.length() > 0) {
                        buf.append("<br>\n");
                    }
                    String format = getSourceIdFormat();
                    for (int sensor = 1; sensor <= 3; sensor += 1) {
                        buf.append(String.format(format, sample.getDeviceAddress(), sensor));
                        buf.append(" = Phase").append(sensor).append(", ");
                    }
                    buf.append(sample.getDeviceAddress() + ".T = Temperature");
                }
                if (buf.length() > 0) {
                    itr.add(new BasicTitleSettingSpecifier("addressSourceMappingValueExample", buf.toString(), true));
                }
            }
        }
    }
    return specs;
}
Also used : BasicTitleSettingSpecifier(net.solarnetwork.settings.support.BasicTitleSettingSpecifier) SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) BasicToggleSettingSpecifier(net.solarnetwork.settings.support.BasicToggleSettingSpecifier) BasicToggleSettingSpecifier(net.solarnetwork.settings.support.BasicToggleSettingSpecifier) CCDatum(net.solarnetwork.node.hw.currentcost.CCDatum) BasicTitleSettingSpecifier(net.solarnetwork.settings.support.BasicTitleSettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier)

Example 4 with KeyedSettingSpecifier

use of net.solarnetwork.settings.KeyedSettingSpecifier in project solarnetwork-central by SolarNetwork.

the class BasicCsvDatumImportInputFormatServiceTests method settings.

@Test
public void settings() {
    BasicCsvDatumImportInputFormatService service = new BasicCsvDatumImportInputFormatService();
    List<SettingSpecifier> settings = service.getSettingSpecifiers();
    assertThat("Settings", settings, hasSize(9));
    List<String> keys = settings.stream().filter(s -> s instanceof KeyedSettingSpecifier<?>).map(s -> ((KeyedSettingSpecifier<?>) s).getKey()).collect(Collectors.toList());
    assertThat("Setting keys", keys, contains("headerRowCount", "dateFormat", "nodeIdColumn", "sourceIdColumn", "dateColumnsValue", "instantaneousDataColumn", "accumulatingDataColumn", "statusDataColumn", "tagDataColumn"));
}
Also used : CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) ClassPathResource(org.springframework.core.io.ClassPathResource) GeneralNodeDatum(net.solarnetwork.central.datum.domain.GeneralNodeDatum) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ProgressListener(net.solarnetwork.service.ProgressListener) ImportContext(net.solarnetwork.central.datum.imp.biz.DatumImportInputFormatService.ImportContext) Matchers.nullValue(org.hamcrest.Matchers.nullValue) SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) Matchers.hasSize(org.hamcrest.Matchers.hasSize) CsvDatumImportInputProperties(net.solarnetwork.central.datum.imp.standard.CsvDatumImportInputProperties) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ZoneOffset(java.time.ZoneOffset) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) IOException(java.io.IOException) Test(org.junit.Test) DatumImportValidationException(net.solarnetwork.central.datum.imp.biz.DatumImportValidationException) Instant(java.time.Instant) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) Collectors(java.util.stream.Collectors) BasicInputConfiguration(net.solarnetwork.central.datum.imp.domain.BasicInputConfiguration) DatumImportService(net.solarnetwork.central.datum.imp.biz.DatumImportService) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) DateTimeFormatter(java.time.format.DateTimeFormatter) BasicCsvDatumImportInputFormatService(net.solarnetwork.central.datum.imp.standard.BasicCsvDatumImportInputFormatService) Assert(org.junit.Assert) Collections(java.util.Collections) BasicDatumImportResource(net.solarnetwork.central.datum.imp.support.BasicDatumImportResource) BasicCsvDatumImportInputFormatService(net.solarnetwork.central.datum.imp.standard.BasicCsvDatumImportInputFormatService) SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) Test(org.junit.Test)

Example 5 with KeyedSettingSpecifier

use of net.solarnetwork.settings.KeyedSettingSpecifier in project solarnetwork-central by SolarNetwork.

the class S3DatumExportDestinationServiceTests method settingSpecifiers.

@Test
public void settingSpecifiers() {
    // given
    S3DatumExportDestinationService service = new S3DatumExportDestinationService();
    // when
    List<SettingSpecifier> specs = service.getSettingSpecifiers();
    // then
    assertThat("Setting specs provided", specs, hasSize(5));
    Set<String> keys = specs.stream().filter(s -> s instanceof KeyedSettingSpecifier<?>).map(s -> ((KeyedSettingSpecifier<?>) s).getKey()).collect(Collectors.toSet());
    assertThat("Setting keys", keys, containsInAnyOrder("accessKey", "secretKey", "path", "filenameTemplate", "storageClass"));
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) DatumExportService(net.solarnetwork.central.datum.export.biz.DatumExportService) Matchers.not(org.hamcrest.Matchers.not) LoggerFactory(org.slf4j.LoggerFactory) BasicConfiguration(net.solarnetwork.central.datum.export.domain.BasicConfiguration) Map(java.util.Map) SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) KeyVersion(com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion) Resource(org.springframework.core.io.Resource) BasicDatumExportResource(net.solarnetwork.central.datum.export.domain.BasicDatumExportResource) DeleteObjectsResult(com.amazonaws.services.s3.model.DeleteObjectsResult) S3DatumExportDestinationService(net.solarnetwork.central.datum.export.dest.s3.S3DatumExportDestinationService) Set(java.util.Set) Instant(java.time.Instant) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) DatumExportResource(net.solarnetwork.central.datum.export.domain.DatumExportResource) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) FileCopyUtils(org.springframework.util.FileCopyUtils) AmazonS3URI(com.amazonaws.services.s3.AmazonS3URI) AbstractCentralTest(net.solarnetwork.central.test.AbstractCentralTest) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) LocalDateTime(java.time.LocalDateTime) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) ProgressListener(net.solarnetwork.service.ProgressListener) CsvDatumExportOutputFormatService(net.solarnetwork.central.datum.export.standard.CsvDatumExportOutputFormatService) S3Object(com.amazonaws.services.s3.model.S3Object) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) AmazonS3(com.amazonaws.services.s3.AmazonS3) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) BasicDestinationConfiguration(net.solarnetwork.central.datum.export.domain.BasicDestinationConfiguration) Properties(java.util.Properties) Logger(org.slf4j.Logger) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) IOException(java.io.IOException) Test(org.junit.Test) InputStreamReader(java.io.InputStreamReader) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Collections(java.util.Collections) InputStream(java.io.InputStream) SettingSpecifier(net.solarnetwork.settings.SettingSpecifier) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) S3DatumExportDestinationService(net.solarnetwork.central.datum.export.dest.s3.S3DatumExportDestinationService) KeyedSettingSpecifier(net.solarnetwork.settings.KeyedSettingSpecifier) AbstractCentralTest(net.solarnetwork.central.test.AbstractCentralTest) Test(org.junit.Test)

Aggregations

KeyedSettingSpecifier (net.solarnetwork.settings.KeyedSettingSpecifier)12 SettingSpecifier (net.solarnetwork.settings.SettingSpecifier)11 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 InputStream (java.io.InputStream)2 Instant (java.time.Instant)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Set (java.util.Set)2 ProgressListener (net.solarnetwork.service.ProgressListener)2 GroupSettingSpecifier (net.solarnetwork.settings.GroupSettingSpecifier)2 SettingSpecifierProvider (net.solarnetwork.settings.SettingSpecifierProvider)2 BasicCronExpressionSettingSpecifier (net.solarnetwork.settings.support.BasicCronExpressionSettingSpecifier)2 BasicTextFieldSettingSpecifier (net.solarnetwork.settings.support.BasicTextFieldSettingSpecifier)2 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)2