Search in sources :

Example 41 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class DayTimeframe method buildMidnightAdjustedInterval.

protected Interval buildMidnightAdjustedInterval(LocalDateTime now) {
    if (start != null && end != null) {
        LocalDateTime earliestStartDateTime = new LocalDate(now).toLocalDateTime(start.toLocalTime());
        LocalDateTime latestEndDateTime = new LocalDate(now).toLocalDateTime(end.toLocalTime());
        if (isOverMidnight(earliestStartDateTime, latestEndDateTime)) {
            if (now.toLocalTime().isAfter(start.toLocalTime())) {
                // before midnight
                latestEndDateTime = latestEndDateTime.plusHours(24);
            } else if (now.toLocalTime().isBefore(end.toLocalTime())) {
                // after midnight, before end
                earliestStartDateTime = earliestStartDateTime.minusHours(24);
            } else {
                // after midnight, after end
                latestEndDateTime = latestEndDateTime.plusHours(24);
            }
        }
        return new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime()).withChronology(ISOChronology.getInstance());
    }
    return null;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalDate(org.joda.time.LocalDate) Interval(org.joda.time.Interval)

Example 42 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempController method planningRequest.

@RequestMapping(value = BASE_URL + "/PlanningRequest", method = RequestMethod.GET, produces = "application/xml")
public String planningRequest(@RequestParam(value = "DeviceId", required = false) String deviceId) {
    LocalDateTime now = new LocalDateTime();
    List<PlanningRequest> planningRequests = new ArrayList<PlanningRequest>();
    if (deviceId != null) {
        logger.debug("{}: Planning request requested", deviceId);
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
        PlanningRequest planningRequest = createPlanningRequest(now, appliance);
        addPlanningRequest(planningRequests, planningRequest);
    } else {
        logger.debug("Planning request requested of all devices");
        List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
        for (Appliance appliance : appliances) {
            PlanningRequest planningRequest = createPlanningRequest(now, appliance);
            addPlanningRequest(planningRequests, planningRequest);
        }
    }
    Device2EM device2EM = new Device2EM();
    if (planningRequests.size() > 0) {
        device2EM.setPlanningRequest(planningRequests);
    }
    return marshall(device2EM);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Appliance(de.avanux.smartapplianceenabler.appliance.Appliance) ArrayList(java.util.ArrayList)

Example 43 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ApplianceTest method createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight.

@Test
public void createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight() {
    LocalDateTime now = toToday(23, 30, 0);
    Schedule schedule = new Schedule(7200, null, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
    Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
    Assert.assertEquals(16200, (int) runtimeRequest.getLatestEnd());
    Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
    Assert.assertNull(runtimeRequest.getMaxRunningTime());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 44 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive.

@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive() {
    int nowSeconds = 10;
    LocalDateTime now = toToday(8, 0, nowSeconds);
    Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
    List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), null, true, 3600 - nowSeconds, null);
    Assert.assertEquals(3, runtimeRequests.size());
    Assert.assertEquals(new RuntimeRequest(0, 14400 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
    Assert.assertEquals(new RuntimeRequest(86400 - nowSeconds, 100800 - nowSeconds, 3600, null), runtimeRequests.get(1));
    Assert.assertEquals(new RuntimeRequest(172800 - nowSeconds, 187200 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 45 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient.

@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient() {
    int nowSeconds = 10;
    LocalDateTime now = toToday(8, 0, nowSeconds);
    Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
    TimeframeInterval activeTimeframeInterval = schedule.getTimeframe().getIntervals(now).get(0);
    List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), activeTimeframeInterval, true, 3600 - nowSeconds, null);
    Assert.assertEquals(3, runtimeRequests.size());
    Assert.assertEquals(new RuntimeRequest(0, 14400 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
    Assert.assertEquals(new RuntimeRequest(86400 - nowSeconds, 100800 - nowSeconds, 3600, null), runtimeRequests.get(1));
    Assert.assertEquals(new RuntimeRequest(172800 - nowSeconds, 187200 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4