Search in sources :

Example 6 with ScheduleDto

use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method buildOslpRequestSetScheduleSingle.

private void buildOslpRequestSetScheduleSingle(final SetScheduleDeviceRequest deviceRequest) {
    final List<Oslp.Schedule> oslpSchedules = this.convertToOslpSchedules(deviceRequest.getScheduleMessageDataContainer().getSchedule().getScheduleList());
    final Oslp.SetScheduleRequest.Builder request = SetScheduleRequest.newBuilder().addAllSchedules(oslpSchedules).setScheduleType(this.mapper.map(deviceRequest.getRelayType(), org.opensmartgridplatform.oslp.Oslp.RelayType.class));
    final ScheduleDto schedule = new ScheduleDto(deviceRequest.getScheduleMessageDataContainer().getSchedule().getScheduleList());
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = new ScheduleMessageDataContainerDto.Builder(schedule).build();
    this.buildAndSignEnvelope(deviceRequest, Oslp.Message.newBuilder().setSetScheduleRequest(request.build()).build(), scheduleMessageDataContainer);
}
Also used : SetScheduleRequest(org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 7 with ScheduleDto

use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method buildOslpRequestSetSchedulePaged.

private void buildOslpRequestSetSchedulePaged(final SetScheduleDeviceRequest deviceRequest, final Pager pager) {
    final List<Oslp.Schedule> oslpSchedules = this.convertToOslpSchedules(deviceRequest.getScheduleMessageDataContainer().getSchedule().getScheduleList().subList(pager.getIndexFrom(), pager.getIndexTo()));
    final Oslp.SetScheduleRequest.Builder oslpRequestBuilder = SetScheduleRequest.newBuilder().addAllSchedules(oslpSchedules).setScheduleType(this.mapper.map(deviceRequest.getRelayType(), org.opensmartgridplatform.oslp.Oslp.RelayType.class)).setPageInfo(Oslp.PageInfo.newBuilder().setCurrentPage(pager.getCurrentPage()).setPageSize(pager.getPageSize()).setTotalPages(pager.getNumberOfPages()));
    final PageInfoDto pageInfo = new PageInfoDto(pager.getCurrentPage(), pager.getPageSize(), pager.getNumberOfPages());
    final ScheduleDto schedule = new ScheduleDto(deviceRequest.getScheduleMessageDataContainer().getSchedule().getScheduleList());
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = new ScheduleMessageDataContainerDto.Builder(schedule).withPageInfo(pageInfo).build();
    this.buildAndSignEnvelope(deviceRequest, Oslp.Message.newBuilder().setSetScheduleRequest(oslpRequestBuilder.build()).build(), scheduleMessageDataContainer);
}
Also used : SetScheduleRequest(org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest) PageInfoDto(org.opensmartgridplatform.dto.valueobjects.PageInfoDto) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) Oslp(org.opensmartgridplatform.oslp.Oslp) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 8 with ScheduleDto

use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method buildOslpRequestSetScheduleAstronomicalOffsets.

private void buildOslpRequestSetScheduleAstronomicalOffsets(final SetScheduleDeviceRequest deviceRequest) {
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = deviceRequest.getScheduleMessageDataContainer();
    final ScheduleDto schedule = scheduleMessageDataContainer.getSchedule();
    final ConfigurationDto configuration = scheduleMessageDataContainer.getConfiguration();
    // First, sort the relay mapping on (internal) index number (FLEX-2514)
    if (configuration.getRelayConfiguration() != null) {
        Collections.sort(configuration.getRelayConfiguration().getRelayMap(), (rm1, rm2) -> rm1.getIndex().compareTo(rm2.getIndex()));
    }
    int sunriseOffset = 0;
    if (schedule.getAstronomicalSunriseOffset() != null) {
        sunriseOffset = schedule.getAstronomicalSunriseOffset();
    }
    int sunsetOffset = 0;
    if (schedule.getAstronomicalSunsetOffset() != null) {
        sunsetOffset = schedule.getAstronomicalSunsetOffset();
    }
    configuration.setAstroGateSunRiseOffset(sunriseOffset);
    configuration.setAstroGateSunSetOffset(sunsetOffset);
    final Oslp.SetConfigurationRequest request = this.mapper.map(configuration, Oslp.SetConfigurationRequest.class);
    this.buildAndSignEnvelope(deviceRequest, Oslp.Message.newBuilder().setSetConfigurationRequest(request).build(), scheduleMessageDataContainer);
}
Also used : ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) Oslp(org.opensmartgridplatform.oslp.Oslp) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 9 with ScheduleDto

use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto 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 10 with ScheduleDto

use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.

the class TariffSwitchingSetScheduleRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing tariff switching set schedule request message");
    MessageMetadata messageMetadata;
    ScheduleDto scheduleDto;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        scheduleDto = (ScheduleDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
    this.printDomainInfo(requestMessageData);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
    this.deviceService.setSchedule(new SetScheduleDeviceRequest(deviceRequestBuilder, scheduleDto, RelayTypeDto.TARIFF), iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) DeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest) RequestMessageData(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Aggregations

ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)10 ScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto)5 JMSException (javax.jms.JMSException)4 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest)2 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)2 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)2 Device (org.opensmartgridplatform.domain.core.entities.Device)2 Oslp (org.opensmartgridplatform.oslp.Oslp)2 SetScheduleRequest (org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest)2 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850SetScheduleFunction (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction)1 PendingSetScheduleRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1