use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class SsldDeviceSteps method createAnSsldDevice.
private Ssld createAnSsldDevice(final Map<String, String> settings) {
// Set the required stuff
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
final Ssld ssld = new Ssld(deviceIdentification);
ssld.setPublicKeyPresent(getBoolean(settings, PlatformKeys.KEY_PUBLICKEYPRESENT, PlatformDefaults.DEFAULT_PUBLICKEYPRESENT));
ssld.setHasSchedule(getBoolean(settings, PlatformKeys.KEY_HAS_SCHEDULE, PlatformDefaults.DEFAULT_HASSCHEDULE));
if (settings.containsKey(PlatformKeys.KEY_INTERNALID) || settings.containsKey(PlatformKeys.KEY_EXTERNALID) || settings.containsKey(PlatformKeys.KEY_RELAY_TYPE)) {
final List<DeviceOutputSetting> dosList = new ArrayList<>();
final int internalId = getInteger(settings, PlatformKeys.KEY_INTERNALID, PlatformDefaults.DEFAULT_INTERNALID), externalId = getInteger(settings, PlatformKeys.KEY_EXTERNALID, PlatformDefaults.DEFAULT_EXTERNALID);
final RelayType relayType = getEnum(settings, PlatformKeys.KEY_RELAY_TYPE, RelayType.class, RelayType.LIGHT);
if (relayType != null) {
dosList.add(new DeviceOutputSetting(internalId, externalId, relayType));
ssld.updateOutputSettings(dosList);
}
}
ssld.updateInMaintenance(getBoolean(settings, PlatformKeys.DEVICE_IN_MAINTENANCE, PlatformDefaults.DEVICE_IN_MAINTENANCE));
ssld.setFailedConnectionCount(getInteger(settings, PlatformKeys.KEY_FAILED_CONNECTION_COUNT, PlatformDefaults.DEFAULT_FAILED_CONNECTION_COUNT));
final DateTime lastSuccessfulConnectionTimestamp = getDate(settings, PlatformKeys.KEY_LAST_COMMUNICATION_TIME, DateTime.now());
ssld.setLastSuccessfulConnectionTimestamp(lastSuccessfulConnectionTimestamp.toDate());
if (settings.containsKey(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION)) {
final LightMeasurementDevice lmd = this.lmdRepository.findByDeviceIdentification(settings.get(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION));
ssld.setLightMeasurementDevice(lmd);
}
this.ssldRepository.save(ssld);
// now update the common stuff of the SSLD device.
this.updateDevice(deviceIdentification, settings);
// Return the updated ssld device.
return this.ssldRepository.findByDeviceIdentification(deviceIdentification);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceOutputSettingsSteps method deviceOutputSettingsForLightValues.
@Given("^device output settings for lightvalues$")
public void deviceOutputSettingsForLightValues(final Map<String, String> settings) {
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
final String[] lightValues = getString(settings, PlatformKeys.KEY_LIGHTVALUES, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION).split(PlatformKeys.SEPARATOR_SEMICOLON);
final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, "").split(PlatformKeys.SEPARATOR_SEMICOLON);
final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
for (int i = 0; i < lightValues.length; i++) {
final String[] lightValueParts = lightValues[i].split(PlatformKeys.SEPARATOR_COMMA);
final String[] deviceOutputSettingsPart = deviceOutputSettings[i].split(PlatformKeys.SEPARATOR_COMMA);
final DeviceOutputSetting deviceOutputSettingsForLightValue = new DeviceOutputSetting(Integer.parseInt(deviceOutputSettingsPart[0]), Integer.parseInt(lightValueParts[0]), Enum.valueOf(RelayType.class, deviceOutputSettingsPart[1]), deviceOutputSettingsPart[2]);
outputSettings.add(deviceOutputSettingsForLightValue);
}
this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceOutputSettingsSteps method deviceOutputSettings.
@Given("^device output settings$")
public void deviceOutputSettings(final Map<String, String> settings) {
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, "").split(PlatformKeys.SEPARATOR_SEMICOLON);
final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
for (final String deviceOutputSetting : deviceOutputSettings) {
final String[] deviceOutputSettingsPart = deviceOutputSetting.split(PlatformKeys.SEPARATOR_COMMA);
final DeviceOutputSetting deviceOutputSettingsForLightValue = new DeviceOutputSetting(Integer.parseInt(deviceOutputSettingsPart[0]), Integer.parseInt(deviceOutputSettingsPart[1]), Enum.valueOf(RelayType.class, deviceOutputSettingsPart[2]), deviceOutputSettingsPart[3]);
outputSettings.add(deviceOutputSettingsForLightValue);
}
this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceOutputSettingsSteps method aDeviceOutputSetting.
@Given("^a device output setting$")
public void aDeviceOutputSetting(final Map<String, String> settings) {
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
final DeviceOutputSetting deviceOutputSetting = new DeviceOutputSetting(getInteger(settings, PlatformKeys.KEY_INTERNALID, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_INTERNALID), getInteger(settings, PlatformKeys.KEY_EXTERNALID, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_EXTERNALID), getEnum(settings, PlatformKeys.KEY_RELAY_TYPE, RelayType.class, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_RELAY_TYPE), getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_ALIAS));
outputSettings.add(deviceOutputSetting);
this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleGetStatusResponse.
public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final DomainType allowedDomainType, final CorrelationIds ids, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = deviceResult;
OsgpException osgpException = exception;
DeviceStatusMapped deviceStatusMapped = null;
if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
LOGGER.error("Device Response not ok.", osgpException);
} else {
final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
for (final DeviceOutputSetting dos : deviceOutputSettings) {
dosMap.put(dos.getExternalId(), dos);
}
if (status != null) {
deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
this.updateDeviceRelayOverview(ssld, deviceStatusMapped);
} else {
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "Device was not able to report status", new NoDeviceResponseException());
}
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(deviceStatusMapped).withMessagePriority(messagePriority).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
Aggregations