use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class SsldDeviceSteps method aSwitchingEventRelayStatus.
@Given("^a switching event relay status$")
@Transactional("txMgrCore")
public void aSwitchingEventRelayStatus(final Map<String, String> settings) {
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, PlatformDefaults.DEVICE_OUTPUT_SETTINGS).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
final String[] relayStatuses = getString(settings, PlatformKeys.RELAY_STATUSES, PlatformDefaults.RELAY_STATUSES).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
final List<DeviceOutputSetting> dosList = new ArrayList<>();
for (final String dos : deviceOutputSettings) {
final String[] deviceOutputSetting = dos.split(PlatformKeys.SEPARATOR_COMMA);
dosList.add(new DeviceOutputSetting(Integer.parseInt(deviceOutputSetting[0]), Integer.parseInt(deviceOutputSetting[1]), RelayType.valueOf(deviceOutputSetting[2]), deviceOutputSetting[3]));
}
ssld.updateOutputSettings(dosList);
for (final String rs : relayStatuses) {
final String[] relayStatus = rs.split(PlatformKeys.SEPARATOR_COMMA);
final int index = Integer.parseInt(relayStatus[0]);
final boolean lastSwitchingEventState = Boolean.parseBoolean(relayStatus[1]);
final Date lastSwitchingEventTime = getDateTime2(relayStatus[2], DateTime.now()).toDate();
final RelayStatus currentRelayStatus = ssld.getRelayStatusByIndex(index);
if (currentRelayStatus == null) {
this.relayStatusRepository.save(new RelayStatus.Builder(ssld, index).withLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime).build());
} else {
currentRelayStatus.updateLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime);
this.relayStatusRepository.save(currentRelayStatus);
}
}
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceConfigurationSteps method aDeviceOutputSetting.
@Given("^a device configuration$")
public void aDeviceOutputSetting(final Map<String, String> settings) throws Throwable {
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);
device.updateOutputSettings(outputSettings);
this.ssldRepository.save(device);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceConfigurationSteps method deviceOutputSettingsForLightValues.
@Given("^device configuration for lightvalues$")
public void deviceOutputSettingsForLightValues(final Map<String, String> settings) throws Throwable {
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);
}
device.updateOutputSettings(outputSettings);
this.ssldRepository.save(device);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceOutputSettingsSteps method saveDeviceOutputSettingsAndRelayStatuses.
private void saveDeviceOutputSettingsAndRelayStatuses(final List<DeviceOutputSetting> deviceOutputSettings, final Ssld device) {
device.updateOutputSettings(deviceOutputSettings);
this.ssldRepository.save(device);
// Create a dummy relay status for each device output setting
for (final DeviceOutputSetting deviceOutputSetting : deviceOutputSettings) {
final RelayStatus relayStatus = new RelayStatus.Builder(device, deviceOutputSetting.getExternalId()).withLastSwitchingEventState(false, new Date()).build();
this.relayStatusRepository.save(relayStatus);
}
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method handleGetConfigurationResponse.
public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
Configuration configuration = null;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
this.replaceEmptyOutputSettings(configurationDto, outputSettings);
configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
// TARIFF_REVERSED will be changed to the correct RelayType.
for (final DeviceOutputSetting dos : outputSettings) {
if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
rm.changeRelayType(RelayType.TARIFF_REVERSED);
}
}
}
}
} catch (final Exception e) {
LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
Aggregations