Search in sources :

Example 6 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class ConfigurationManagementService method updateDeviceOutputSettings.

private void updateDeviceOutputSettings(final Device device, final Configuration configuration) {
    // Check if device output settings can/should be updated
    if (device == null || configuration == null || configuration.getRelayConfiguration() == null) {
        // Nothing to update
        return;
    }
    if (configuration.getRelayConfiguration().getRelayMap() == null || configuration.getRelayConfiguration().getRelayMap().isEmpty()) {
        // Nothing to update
        return;
    }
    final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
    for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
        outputSettings.add(new DeviceOutputSetting(rm.getAddress(), rm.getIndex(), rm.getRelayType(), rm.getAlias()));
    }
    final Ssld ssld = this.findSsldForDevice(device);
    ssld.updateOutputSettings(outputSettings);
    this.ssldRepository.save(ssld);
}
Also used : ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 7 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class SsldConverter method convertFrom.

@Override
public Ssld convertFrom(final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device source, final Type<Ssld> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final Ssld destination = this.helper.initEntity(source);
    final List<org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
    for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting deviceOutputSetting : source.getOutputSettings()) {
        final org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting(deviceOutputSetting.getInternalId(), deviceOutputSetting.getExternalId(), deviceOutputSetting.getRelayType() == null ? null : org.opensmartgridplatform.domain.core.valueobjects.RelayType.valueOf(deviceOutputSetting.getRelayType().name()), deviceOutputSetting.getAlias());
        deviceOutputSettings.add(newDeviceOutputSetting);
    }
    destination.updateOutputSettings(deviceOutputSettings);
    if (source.isPublicKeyPresent() != null) {
        destination.setPublicKeyPresent(source.isPublicKeyPresent());
    }
    if (source.isHasSchedule() != null) {
        destination.setHasSchedule(source.isHasSchedule());
    }
    if (source.isActivated() != null) {
        destination.setActivated(source.isActivated());
    }
    if (source.getDeviceLifecycleStatus() != null) {
        destination.setDeviceLifecycleStatus(DeviceLifecycleStatus.valueOf(source.getDeviceLifecycleStatus().name()));
    }
    // clearing the existing Eans to prevent duplication
    destination.setEans(new ArrayList<Ean>());
    for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean ean : source.getEans()) {
        final Ean newEan = new Ean(destination, ean.getCode(), ean.getDescription());
        destination.getEans().add(newEan);
    }
    return destination;
}
Also used : ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 8 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class EventNotificationMessageService method handleSwitchDeviceEvents.

private void handleSwitchDeviceEvents(final Device device, final List<Event> switchDeviceEvents) throws UnknownEntityException {
    LOGGER.info("handleSwitchDeviceEvents() called for device: {} with lightSwitchingEvents.size(): {}", device.getDeviceIdentification(), switchDeviceEvents.size());
    if (switchDeviceEvents.isEmpty()) {
        return;
    }
    // Determine light and tariff relays for SSLD.
    final Ssld ssld = this.eventNotificationHelperService.findSsld(device.getId());
    final Set<Integer> indexesLightRelays = new TreeSet<>();
    final Set<Integer> indexesTariffRelays = new TreeSet<>();
    for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
        if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
            indexesLightRelays.add(deviceOutputSetting.getExternalId());
        }
        if (deviceOutputSetting.getOutputType().equals(RelayType.TARIFF) || deviceOutputSetting.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
            indexesTariffRelays.add(deviceOutputSetting.getExternalId());
        }
    }
    this.printRelayIndexes(indexesLightRelays, indexesTariffRelays, device.getDeviceIdentification());
    final Map<Integer, RelayStatus> lastRelayStatusPerIndex = new TreeMap<>();
    for (final Event lightSwitchingEvent : switchDeviceEvents) {
        final Integer index = lightSwitchingEvent.getIndex();
        if (index == 0) {
            this.handleLightSwitchingEventForIndex0(indexesLightRelays, device, lightSwitchingEvent, lastRelayStatusPerIndex);
        } else {
            this.createRelayStatus(device, lightSwitchingEvent, index, lastRelayStatusPerIndex);
        }
    }
    this.printRelayStatuses(lastRelayStatusPerIndex, device.getDeviceIdentification());
    if (!lastRelayStatusPerIndex.isEmpty()) {
        LOGGER.info("calling ssld.updateSwitchingEventRelayStatuses() for device: {} with lastRelayStatusPerIndex.size(): {}", ssld.getDeviceIdentification(), lastRelayStatusPerIndex.size());
        ssld.updateSwitchingEventRelayStatuses(lastRelayStatusPerIndex);
        this.eventNotificationHelperService.saveSsld(ssld);
        this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), ssld.getDeviceIdentification(), null);
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) TreeSet(java.util.TreeSet) Event(org.opensmartgridplatform.domain.core.entities.Event) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) TreeMap(java.util.TreeMap) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 9 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class EventNotificationMessageService method handleSwitchingEvent.

private void handleSwitchingEvent(final String deviceIdentification, final Date dateTime, final EventType eventType, final int index) throws UnknownEntityException {
    final Ssld ssld = this.eventNotificationHelperService.findSsld(deviceIdentification);
    // index.
    if (index == 0) {
        for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
            if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
                this.updateRelayStatusForEvent(deviceOutputSetting.getExternalId(), ssld, dateTime, eventType);
            }
        }
    } else {
        this.updateRelayStatusForEvent(index, ssld, dateTime, eventType);
    }
    this.eventNotificationHelperService.saveSsld(ssld);
    this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), deviceIdentification, null);
}
Also used : DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 10 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class DeviceInstallationService method handleSsld.

private void handleSsld(final String deviceIdentification, final DeviceStatus status, final GetStatusResponse response) {
    // Find device and output settings.
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
    final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
    // Create map with external relay number as key set.
    final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
    for (final DeviceOutputSetting dos : deviceOutputSettings) {
        dosMap.put(dos.getExternalId(), dos);
    }
    if (status != null) {
        // Map the DeviceStatus for SSLD.
        final DeviceStatusMapped deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, DomainType.TARIFF_SWITCHING), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, DomainType.PUBLIC_LIGHTING), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
        deviceStatusMapped.setBootLoaderVersion(status.getBootLoaderVersion());
        deviceStatusMapped.setCurrentConfigurationBackUsed(status.getCurrentConfigurationBackUsed());
        deviceStatusMapped.setCurrentIp(status.getCurrentIp());
        deviceStatusMapped.setCurrentTime(status.getCurrentTime());
        deviceStatusMapped.setDcOutputVoltageCurrent(status.getDcOutputVoltageCurrent());
        deviceStatusMapped.setDcOutputVoltageMaximum(status.getDcOutputVoltageMaximum());
        deviceStatusMapped.setEventNotificationsMask(status.getEventNotificationsMask());
        deviceStatusMapped.setExternalFlashMemSize(status.getExternalFlashMemSize());
        deviceStatusMapped.setFirmwareVersion(status.getFirmwareVersion());
        deviceStatusMapped.setHardwareId(status.getHardwareId());
        deviceStatusMapped.setInternalFlashMemSize(status.getInternalFlashMemSize());
        deviceStatusMapped.setLastInternalTestResultCode(status.getLastInternalTestResultCode());
        deviceStatusMapped.setMacAddress(status.getMacAddress());
        deviceStatusMapped.setMaximumOutputPowerOnDcOutput(status.getMaximumOutputPowerOnDcOutput());
        deviceStatusMapped.setName(status.getName());
        deviceStatusMapped.setNumberOfOutputs(status.getNumberOfOutputs());
        deviceStatusMapped.setSerialNumber(status.getSerialNumber());
        deviceStatusMapped.setStartupCounter(status.getStartupCounter());
        // Return mapped status using GetStatusResponse instance.
        response.setDeviceStatusMapped(deviceStatusMapped);
    } else {
        // No status received, create bad response.
        response.setDeviceStatusMapped(null);
        response.setOsgpException(new TechnicalException(ComponentType.DOMAIN_CORE, "SSLD was not able to report relay status", new NoDeviceResponseException()));
        response.setResult(ResponseMessageResultType.NOT_OK);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) NoDeviceResponseException(org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException) HashMap(java.util.HashMap) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)19 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)16 ArrayList (java.util.ArrayList)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)7 Given (io.cucumber.java.en.Given)6 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 HashMap (java.util.HashMap)3 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)3 DeviceStatusMapped (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped)3 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)3 Date (java.util.Date)2 Ean (org.opensmartgridplatform.domain.core.entities.Ean)2 RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)2 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1