Search in sources :

Example 6 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue 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)

Aggregations

LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)6 ArrayList (java.util.ArrayList)3 Device (org.opensmartgridplatform.domain.core.entities.Device)2 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)2 ScheduleEntry (org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry)2 TariffValue (org.opensmartgridplatform.domain.core.valueobjects.TariffValue)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Date (java.util.Date)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 GetStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse)1 ResumeScheduleAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse)1 SetLightAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse)1 SetTransitionAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse)1 TariffValue (org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffValue)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)1