Search in sources :

Example 1 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.LightValue in project open-smart-grid-platform by OSGP.

the class SetLightScheduleSteps method addScheduleForRequest.

private void addScheduleForRequest(final SetScheduleRequest request, final WeekDayType weekDay, final String startDay, final String endDay, final ActionTimeType actionTime, final String time, final String scheduleLightValue, final String triggerType, final String triggerWindow) throws DatatypeConfigurationException {
    final Schedule schedule = new Schedule();
    schedule.setWeekDay(weekDay);
    if (StringUtils.isNotBlank(startDay)) {
        schedule.setStartDay(DatatypeFactory.newInstance().newXMLGregorianCalendar(DateTime.parse(startDay).toDateTime(DateTimeZone.UTC).toGregorianCalendar()));
    }
    if (StringUtils.isNotBlank(endDay)) {
        schedule.setEndDay(DatatypeFactory.newInstance().newXMLGregorianCalendar(DateTime.parse(endDay).toDateTime(DateTimeZone.UTC).toGregorianCalendar()));
    }
    schedule.setActionTime(actionTime);
    schedule.setTime(time);
    for (final String lightValue : scheduleLightValue.split(";")) {
        final LightValue lv = new LightValue();
        final String[] lightValues = lightValue.split(",");
        lv.setIndex(Integer.parseInt(lightValues[0]));
        lv.setOn(Boolean.parseBoolean(lightValues[1]));
        if (lightValues.length > 2) {
            lv.setDimValue(Integer.parseInt(lightValues[2]));
        }
        schedule.getLightValue().add(lv);
    }
    if (!triggerType.isEmpty()) {
        schedule.setTriggerType(TriggerType.valueOf(triggerType));
    }
    if (StringUtils.isNotBlank(triggerWindow)) {
        final String[] windowTypeValues = triggerWindow.split(",");
        if (windowTypeValues.length == 2) {
            final WindowType windowType = new WindowType();
            windowType.setMinutesBefore(Integer.parseInt(windowTypeValues[0]));
            windowType.setMinutesAfter(Integer.parseInt(windowTypeValues[1]));
            schedule.setTriggerWindow(windowType);
        }
    }
    request.getSchedules().add(schedule);
}
Also used : Schedule(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.Schedule) LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.LightValue) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) WindowType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.WindowType)

Aggregations

LightValue (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.LightValue)1 Schedule (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.Schedule)1 WindowType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.WindowType)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1