use of org.opennms.core.utils.OwnedInterval in project opennms by OpenNMS.
the class TimeIntervalSequenceTest method testExtensionUnscheduled.
@Test
public void testExtensionUnscheduled() throws Exception {
// seg with three entryies 8-5 on aug 18, aug 19 and aug 20
OwnedIntervalSequence seq = new OwnedIntervalSequence(ownedOneAndTwo(aug(18, 8, 17)));
seq.addInterval(ownedOneAndTwo(aug(19, 8, 17)));
seq.addInterval(ownedOneAndTwo(aug(20, 8, 17)));
OwnedIntervalSequence unscheduled = new OwnedIntervalSequence(owned(aug(18)));
unscheduled.removeAll(seq);
OwnedInterval[] expected = { owned(aug(18, 0, 8)), owned(aug(18, 17, 24)) };
assertTimeIntervalSequence(expected, unscheduled);
}
use of org.opennms.core.utils.OwnedInterval in project opennms by OpenNMS.
the class TimeIntervalSequenceTest method testExtensionRemoveAllOwners.
@Test
public void testExtensionRemoveAllOwners() throws Exception {
// seg with three entryies 8-5 on aug 18, aug 19 and aug 20
OwnedIntervalSequence seq = new OwnedIntervalSequence(ownedOneAndTwo(aug(18, 8, 17)));
seq.addInterval(ownedOneAndTwo(aug(19, 8, 17)));
seq.addInterval(ownedOneAndTwo(aug(20, 8, 17)));
// now add interval from aug 18 12 to aug 20 24)
seq.removeInterval(ownedOneAndTwo(aug(18, 12, 20, 13)));
// expect a sequence containing non overlapping segments
OwnedInterval[] expected = { ownedOneAndTwo(aug(18, 8, 12)), ownedOneAndTwo(aug(20, 13, 17)) };
assertTimeIntervalSequence(expected, seq);
}
use of org.opennms.core.utils.OwnedInterval in project opennms by OpenNMS.
the class BasicScheduleUtilsTest method testComplexScheduleIncluded.
@Test
public void testComplexScheduleIncluded() throws Exception {
String schedSpec = " <schedule name=\"complex\" type=\"specific\">" + " <time day=\"thursday\" begins=\"13:00:00\" ends=\"14:00:00\"/>\n" + " <time day=\"friday\" begins=\"07:00:00\" ends=\"08:00:00\"/>\n" + " <time day=\"18\" begins=\"19:00:00\" ends=\"20:00:00\"/>\n" + " <time day=\"19\" begins=\"09:00:00\" ends=\"10:00:00\"/>\n" + " <time begins=\"18-Aug-2005 16:00:00\" ends=\"18-Aug-2005 17:00:00\"/>\n" + " </schedule>";
Schedule simpleSchedule = JaxbUtils.unmarshal(Schedule.class, schedSpec);
Owner owner = new Owner("unnamed", "complex", 0);
OwnedIntervalSequence intervals = BasicScheduleUtils.getIntervalsCovering(aug(18), BasicScheduleUtils.getGroupSchedule(simpleSchedule), owner);
assertNotNull(intervals);
OwnedInterval[] expected = { owned(owner, aug(18, 13, 14)), owned(owner, aug(18, 16, 17)), owned(owner, aug(18, 19, 20)) };
assertTimeIntervalSequence(expected, intervals);
}
use of org.opennms.core.utils.OwnedInterval in project opennms by OpenNMS.
the class BasicScheduleUtilsTest method testGetIntervalsMonthly.
@Test
public void testGetIntervalsMonthly() throws Exception {
String schedSpec = " <schedule name=\"simple\" type=\"monthly\">" + " <time day=\"7\" begins=\"11:00:00\" ends=\"14:00:00\"/>\n" + " </schedule>";
Schedule simpleSchedule = JaxbUtils.unmarshal(Schedule.class, schedSpec);
BasicSchedule basicSchedule = BasicScheduleUtils.getGroupSchedule(simpleSchedule);
Owner owner = new Owner("unnamed", "simple", 0, 0);
OwnedIntervalSequence intervals = BasicScheduleUtils.getIntervals(interval(6, /* june */
7, 13, 11, /* nov */
7, 12), basicSchedule.getTime(0), owner);
assertNotNull(intervals);
OwnedInterval[] expected = { owned(owner, jun(7, 13, 14)), owned(owner, jul(7, 11, 14)), owned(owner, aug(7, 11, 14)), owned(owner, sep(7, 11, 14)), owned(owner, oct(7, 11, 14)), owned(owner, nov(7, 11, 12)) };
assertTimeIntervalSequence(expected, intervals);
}
use of org.opennms.core.utils.OwnedInterval in project opennms by OpenNMS.
the class GroupManager method getRoleScheduleEntries.
/**
* <p>getRoleScheduleEntries</p>
*
* @param roleid a {@link java.lang.String} object.
* @param start a {@link java.util.Date} object.
* @param end a {@link java.util.Date} object.
* @return a {@link org.opennms.core.utils.OwnedIntervalSequence} object.
* @throws java.io.IOException if any.
*/
public OwnedIntervalSequence getRoleScheduleEntries(String roleid, Date start, Date end) throws IOException {
update();
OwnedIntervalSequence schedEntries = new OwnedIntervalSequence();
Role role = getRole(roleid);
for (int i = 0; i < role.getSchedules().size(); i++) {
final int index = i;
Schedule sched = (Schedule) role.getSchedules().get(index);
Owner owner = new Owner(roleid, sched.getName(), i);
schedEntries.addAll(BasicScheduleUtils.getIntervalsCovering(start, end, BasicScheduleUtils.getGroupSchedule(sched), owner));
}
OwnedIntervalSequence defaultEntries = new OwnedIntervalSequence(new OwnedInterval(start, end));
defaultEntries.removeAll(schedEntries);
Owner supervisor = new Owner(roleid, role.getSupervisor());
for (Iterator<OwnedInterval> it = defaultEntries.iterator(); it.hasNext(); ) {
OwnedInterval interval = it.next();
interval.addOwner(supervisor);
}
schedEntries.addAll(defaultEntries);
return schedEntries;
}
Aggregations