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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations