Search in sources :

Example 1 with PendingSetScheduleRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest in project open-smart-grid-platform by OSGP.

the class PublicLightingSetScheduleRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting set schedule request message");
    final MessageMetadata messageMetadata;
    final ScheduleDto schedule;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        schedule = (ScheduleDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    try {
        this.pendingSetScheduleRequestService.removeExpiredPendingSetScheduleRequestRecords(messageMetadata.getDeviceIdentification());
        final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceIdentificationNotExpired(messageMetadata.getDeviceIdentification());
        if (!pendingSetScheduleRequestList.isEmpty()) {
            throw new FunctionalException(FunctionalExceptionType.SET_SCHEDULE_WITH_ASTRONOMICAL_OFFSETS_IN_PROGRESS, ComponentType.PROTOCOL_OSLP, new Throwable(String.format("A set schedule with astronomical offsets is already in progress for device %s", messageMetadata.getDeviceIdentification())));
        }
        ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(schedule);
        if (schedule.getAstronomicalSunriseOffset() != null || schedule.getAstronomicalSunsetOffset() != null) {
            LOGGER.info("Set a schedule for a device with astronomical offsets");
            builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.RETRIEVE_CONFIGURATION);
        }
        final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
        this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
        final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
        this.deviceService.setSchedule(deviceRequest);
    } catch (final RuntimeException e) {
        this.handleError(e, messageMetadata);
    } catch (final FunctionalException e) {
        this.handleFunctionalException(e, messageMetadata);
    }
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 2 with PendingSetScheduleRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method aPendingSetScheduleRequest.

@Given("^a pending set schedule request that expires within \"([^\"]*)\" minutes$")
public void aPendingSetScheduleRequest(final int expiresInMinutes, final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final String deviceUid = getString(settings, PlatformKeys.KEY_DEVICE_UID, PlatformDefaults.DEVICE_UID);
    final String organisationIdentification = getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    final Date expireDateTime = Date.from(ZonedDateTime.now().plusMinutes(expiresInMinutes).toInstant());
    // just add a dummy DeviceRequest and a dummy
    // ScheduleMessageDataContainerDto
    final PendingSetScheduleRequest pendingSetScheduleRequest = PendingSetScheduleRequest.builder().deviceIdentification(deviceIdentification).deviceUid(deviceUid).expiredAt(expireDateTime).deviceRequest(new DeviceRequest(organisationIdentification, deviceIdentification, null, 4)).scheduleMessageDataContainerDto(new ScheduleMessageDataContainerDto.Builder(null).build()).build();
    this.pendingSetScheduleRequestRepository.save(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) Date(java.util.Date) Given(io.cucumber.java.en.Given)

Example 3 with PendingSetScheduleRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method handleSetSchedule.

public void handleSetSchedule(final String deviceUid) throws TechnicalException {
    final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceUidNotExpired(deviceUid);
    if (pendingSetScheduleRequestList.isEmpty()) {
        // schedule with astronomical offsets
        return;
    }
    if (pendingSetScheduleRequestList.size() > 1) {
        throw new TechnicalException(String.format("Currently there are %d pending set schedule requests for device %s. Only one is allowed.", pendingSetScheduleRequestList.size(), deviceUid));
    }
    final PendingSetScheduleRequest pendingSetScheduleRequest = pendingSetScheduleRequestList.get(0);
    final ScheduleMessageDataContainerDto dto = pendingSetScheduleRequest.getScheduleMessageDataContainerDto();
    ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(dto.getSchedule());
    builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE);
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
    final DeviceRequest deviceRequest = pendingSetScheduleRequest.getDeviceRequest();
    final MessageMetadata messageMetadata = this.getMessageMetadataFromDeviceRequest(deviceRequest);
    final SetScheduleDeviceRequest newDeviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
    this.deviceService.setSchedule(newDeviceRequest);
    this.pendingSetScheduleRequestService.remove(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)

Example 4 with PendingSetScheduleRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest in project open-smart-grid-platform by OSGP.

the class PublicLightingSetScheduleRequestMessageProcessor method handleSetScheduleSetRebootResponse.

private void handleSetScheduleSetRebootResponse(final SetScheduleDeviceRequest deviceRequest) {
    // The device will reboot now.
    // At this point we will need to save the current state to the
    // pending_set_schedule_request table
    LOGGER.info(LOG_MESSAGE_CALL_DEVICE_SERVICE, deviceRequest.getMessageType(), ScheduleMessageTypeDto.SET_SCHEDULE, deviceRequest.getDomain(), deviceRequest.getDomainVersion());
    final ScheduleMessageDataContainerDto dataContainer = new ScheduleMessageDataContainerDto.Builder(deviceRequest.getScheduleMessageDataContainer().getSchedule()).withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE).build();
    final String deviceIdentification = deviceRequest.getDeviceIdentification();
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
    final String deviceUid = oslpDevice.getDeviceUid();
    final Date expireDateTime = Date.from(ZonedDateTime.now().plusMinutes(this.pendingSetScheduleRequestExpiresInMinutes).toInstant());
    final PendingSetScheduleRequest pendingSetScheduleRequest = PendingSetScheduleRequest.builder().deviceIdentification(deviceIdentification).deviceUid(deviceUid).scheduleMessageDataContainerDto(dataContainer).deviceRequest(deviceRequest).expiredAt(expireDateTime).build();
    this.pendingSetScheduleRequestService.add(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) Date(java.util.Date)

Aggregations

PendingSetScheduleRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest)4 ScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto)4 Date (java.util.Date)2 DeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)2 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 Given (io.cucumber.java.en.Given)1 JMSException (javax.jms.JMSException)1 OslpDevice (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1