Search in sources :

Example 16 with DeviceOutputSetting

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

the class AdHocManagementService method isRelayOn.

private boolean isRelayOn(final boolean isHighTariff, final Ssld device, final Integer externalIndex) {
    // The relay state is on, during the LOW tariff period
    boolean state = !isHighTariff;
    final DeviceOutputSetting setting = device.getOutputSetting(externalIndex);
    if (setting != null && setting.getOutputType() == RelayType.TARIFF_REVERSED) {
        // Invert the state because TARIFF_REVERSED uses inverse values.
        state = !state;
    }
    return state;
}
Also used : DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)

Example 17 with DeviceOutputSetting

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

the class ScheduleManagementService method setTariffSchedule.

// === SET TARIFF SCHEDULE ===
/**
 * Set a tariff schedule.
 */
public void setTariffSchedule(final CorrelationIds ids, final List<ScheduleEntry> schedules, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.info("setTariffSchedule called with organisation {} and device {}.", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    if (Ssld.PSLD_TYPE.equals(device.getDeviceType())) {
        throw new FunctionalException(FunctionalExceptionType.TARIFF_SCHEDULE_NOT_ALLOWED_FOR_PSLD, ComponentType.DOMAIN_TARIFF_SWITCHING, new ValidationException("Set tariff schedule is not allowed for PSLD."));
    }
    // Reverse schedule switching for TARIFF_REVERSED relays.
    for (final DeviceOutputSetting dos : this.getSsldForDevice(device).getOutputSettings()) {
        if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
            for (final ScheduleEntry schedule : schedules) {
                for (final LightValue lightValue : schedule.getLightValue()) {
                    lightValue.invertIsOn();
                }
            }
        }
    }
    LOGGER.info("Mapping to schedule DTO");
    final List<org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto> schedulesDto = this.domainCoreMapper.mapAsList(schedules, org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto.class);
    final ScheduleDto scheduleDto = new ScheduleDto(schedulesDto);
    LOGGER.info("Sending message");
    this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, scheduleDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Device(org.opensmartgridplatform.domain.core.entities.Device) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto) ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 18 with DeviceOutputSetting

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

the class AdHocManagementService method handleSsld.

private void handleSsld(final String deviceIdentification, final DeviceStatus status, final DomainType allowedDomainType, 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, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
        // Update the relay overview with the relay information.
        this.updateDeviceRelayStatusForGetStatus(ssld, deviceStatusMapped);
        // 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_PUBLIC_LIGHTING, "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)

Example 19 with DeviceOutputSetting

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

the class SsldConverter method convertTo.

@Override
public org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device convertTo(final Ssld source, final Type<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device destination = this.helper.initJaxb(source);
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(source.getDeviceIdentification());
    if (ssld != null) {
        final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
        for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
            final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting();
            newDeviceOutputSetting.setExternalId(deviceOutputSetting.getExternalId());
            newDeviceOutputSetting.setInternalId(deviceOutputSetting.getInternalId());
            newDeviceOutputSetting.setRelayType(deviceOutputSetting.getOutputType() == null ? null : RelayType.valueOf(deviceOutputSetting.getOutputType().name()));
            newDeviceOutputSetting.setAlias(deviceOutputSetting.getAlias());
            deviceOutputSettings.add(newDeviceOutputSetting);
        }
        destination.getOutputSettings().addAll(deviceOutputSettings);
        destination.setPublicKeyPresent(ssld.isPublicKeyPresent());
        destination.setHasSchedule(ssld.getHasSchedule());
        final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean> eans = new ArrayList<>();
        for (final org.opensmartgridplatform.domain.core.entities.Ean ean : ssld.getEans()) {
            final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean newEan = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean();
            newEan.setCode(ean.getCode());
            newEan.setDescription(ean.getDescription());
            eans.add(newEan);
        }
        destination.getEans().addAll(eans);
        this.addRelayStatuses(destination, ssld);
    }
    return destination;
}
Also used : ArrayList(java.util.ArrayList) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ean(org.opensmartgridplatform.domain.core.entities.Ean) 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