Search in sources :

Example 1 with ScheduleEntry

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

the class PublicLightingScheduleManagementEndpoint method setLightSchedule.

// === SET LIGHT SCHEDULE ===
@PayloadRoot(localPart = "SetScheduleRequest", namespace = NAMESPACE)
@ResponsePayload
public SetScheduleAsyncResponse setLightSchedule(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetScheduleRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Schedule Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetScheduleAsyncResponse response = new SetScheduleAsyncResponse();
    try {
        // Get the request parameters, make sure that they are in UTC.
        // Maybe add an adapter to the service, so that all datetime are
        // converted to utc automatically.
        final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
        final List<ScheduleEntry> scheduleEntries = this.scheduleManagementMapper.mapAsList(request.getSchedules(), org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry.class);
        final Schedule schedule = new Schedule(scheduleEntries, request.getAstronomicalSunriseOffset(), request.getAstronomicalSunsetOffset());
        final String correlationUid = this.scheduleManagementService.enqueueSetLightSchedule(organisationIdentification, request.getDeviceIdentification(), schedule, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) DateTime(org.joda.time.DateTime) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SetScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleAsyncResponse) ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) Schedule(org.opensmartgridplatform.domain.core.valueobjects.Schedule) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleAsyncResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 2 with ScheduleEntry

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

the class ScheduleConverter method convertTo.

@Override
public ScheduleEntry convertTo(final org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto source, final Type<ScheduleEntry> destinationType, final MappingContext context) {
    final ScheduleEntry schedule = new ScheduleEntry();
    schedule.setActionTime(this.mapperFacade.map(source.getActionTime(), ActionTimeType.class));
    schedule.setEndDay(source.getEndDay());
    schedule.setLightValue(this.mapperFacade.mapAsList(source.getLightValue(), LightValue.class));
    schedule.setStartDay(source.getStartDay());
    schedule.setTime(source.getTime());
    schedule.setTriggerType(this.mapperFacade.map(source.getTriggerType(), TriggerType.class));
    schedule.setTriggerWindow(this.mapperFacade.map(source.getTriggerWindow(), WindowType.class));
    schedule.setWeekDay(this.mapperFacade.map(source.getWeekDay(), WeekDayType.class));
    schedule.setIndex(source.getIndex());
    schedule.setIsEnabled(source.getIsEnabled());
    schedule.setMinimumLightsOn(source.getMinimumLightsOn());
    return schedule;
}
Also used : TriggerType(org.opensmartgridplatform.domain.core.valueobjects.TriggerType) ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) WindowType(org.opensmartgridplatform.domain.core.valueobjects.WindowType) WeekDayType(org.opensmartgridplatform.domain.core.valueobjects.WeekDayType) ActionTimeType(org.opensmartgridplatform.domain.core.valueobjects.ActionTimeType)

Example 3 with ScheduleEntry

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

the class TariffScheduleToScheduleConverter method convert.

@Override
public ScheduleEntry convert(final TariffSchedule source, final Type<? extends ScheduleEntry> destinationType, final MappingContext context) {
    final ScheduleEntry schedule = new ScheduleEntry();
    // Copy values
    schedule.setWeekDay(this.mapperFacade.map(source.getWeekDay(), WeekDayType.class));
    schedule.setStartDay(this.mapperFacade.map(source.getStartDay(), DateTime.class));
    schedule.setEndDay(this.mapperFacade.map(source.getEndDay(), DateTime.class));
    schedule.setTime(source.getTime());
    schedule.setIndex(source.getIndex());
    schedule.setIsEnabled(source.isIsEnabled());
    schedule.setMinimumLightsOn(source.getMinimumLightsOn());
    // Set the lightvalue
    // For now a High tariff means the Relay is switched off (Situation
    // in Zaltbommel)
    // schedule.setLightValue( Arrays.asList(new LightValue(null,
    // !source.isHigh(), null)) )
    final List<LightValue> lightValues = new ArrayList<>();
    for (final TariffValue tariffValue : source.getTariffValue()) {
        final LightValue lightValue = new LightValue(tariffValue.getIndex(), !tariffValue.isHigh(), null);
        lightValues.add(lightValue);
    }
    schedule.setLightValue(lightValues);
    // Set defaults for Tariff schedules
    schedule.setActionTime(ActionTimeType.ABSOLUTETIME);
    schedule.setTriggerType(null);
    return schedule;
}
Also used : ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) TariffValue(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffValue) WeekDayType(org.opensmartgridplatform.domain.core.valueobjects.WeekDayType) DateTime(org.joda.time.DateTime)

Example 4 with ScheduleEntry

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

the class ScheduleEntryConverter method convertTo.

@Override
public ScheduleEntry convertTo(final org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto source, final Type<ScheduleEntry> destinationType, final MappingContext context) {
    final ScheduleEntry schedule = new ScheduleEntry();
    schedule.setActionTime(this.mapperFacade.map(source.getActionTime(), ActionTimeType.class));
    schedule.setEndDay(source.getEndDay());
    schedule.setLightValue(this.mapperFacade.mapAsList(source.getLightValue(), LightValue.class));
    schedule.setStartDay(source.getStartDay());
    schedule.setTime(source.getTime());
    schedule.setTriggerType(this.mapperFacade.map(source.getTriggerType(), TriggerType.class));
    schedule.setTriggerWindow(this.mapperFacade.map(source.getTriggerWindow(), WindowType.class));
    schedule.setWeekDay(this.mapperFacade.map(source.getWeekDay(), WeekDayType.class));
    schedule.setIndex(source.getIndex());
    schedule.setIsEnabled(source.getIsEnabled());
    schedule.setMinimumLightsOn(source.getMinimumLightsOn());
    return schedule;
}
Also used : TriggerType(org.opensmartgridplatform.domain.core.valueobjects.TriggerType) ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) WindowType(org.opensmartgridplatform.domain.core.valueobjects.WindowType) WeekDayType(org.opensmartgridplatform.domain.core.valueobjects.WeekDayType) ActionTimeType(org.opensmartgridplatform.domain.core.valueobjects.ActionTimeType)

Example 5 with ScheduleEntry

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

ScheduleEntry (org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry)5 LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)4 WeekDayType (org.opensmartgridplatform.domain.core.valueobjects.WeekDayType)3 DateTime (org.joda.time.DateTime)2 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)2 ActionTimeType (org.opensmartgridplatform.domain.core.valueobjects.ActionTimeType)2 TriggerType (org.opensmartgridplatform.domain.core.valueobjects.TriggerType)2 WindowType (org.opensmartgridplatform.domain.core.valueobjects.WindowType)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 ArrayList (java.util.ArrayList)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse)1 SetScheduleAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleAsyncResponse)1 TariffValue (org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffValue)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 Schedule (org.opensmartgridplatform.domain.core.valueobjects.Schedule)1 ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1