Example #1
0
  /**
   * getRoleScheduleEntries
   *
   * @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 org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public OwnedIntervalSequence getRoleScheduleEntries(String roleid, Date start, Date end)
      throws MarshalException, ValidationException, IOException {
    update();

    OwnedIntervalSequence schedEntries = new OwnedIntervalSequence();
    Role role = getRole(roleid);
    for (int i = 0; i < role.getScheduleCount(); i++) {
      Schedule sched = (Schedule) role.getSchedule(i);
      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;
  }