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;
}
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;
}
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;
}
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"));
}
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"));
}
Aggregations