Beispiel #1
0
  /**
   * userHasRole
   *
   * @param userId a {@link java.lang.String} object.
   * @param roleid a {@link java.lang.String} object.
   * @return a boolean.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public boolean userHasRole(String userId, String roleid)
      throws MarshalException, ValidationException, IOException {
    update();

    for (Schedule sched : getRole(roleid).getScheduleCollection()) {
      if (userId.equals(sched.getName())) {
        return true;
      }
    }
    return false;
  }
Beispiel #2
0
  /**
   * getUserSchedulesForRole
   *
   * @param userId a {@link java.lang.String} object.
   * @param roleId a {@link java.lang.String} object.
   * @return a {@link java.util.List} object.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public List<Schedule> getUserSchedulesForRole(String userId, String roleId)
      throws MarshalException, ValidationException, IOException {
    update();

    List<Schedule> scheds = new ArrayList<Schedule>();
    for (Schedule sched : getRole(roleId).getScheduleCollection()) {
      if (userId.equals(sched.getName())) {
        scheds.add(sched);
      }
    }
    return scheds;
  }
Beispiel #3
0
  /**
   * getSchedulesForRoleAt
   *
   * @param roleId a {@link java.lang.String} object.
   * @param time a {@link java.util.Date} object.
   * @return a {@link java.util.List} object.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public List<Schedule> getSchedulesForRoleAt(String roleId, Date time)
      throws MarshalException, ValidationException, IOException {
    update();

    List<Schedule> schedules = new ArrayList<Schedule>();
    for (Schedule sched : getRole(roleId).getScheduleCollection()) {
      if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) {
        schedules.add(sched);
      }
    }
    return schedules;
  }
Beispiel #4
0
 /**
  * Determines if a group is on duty at a given time. If a group has no duty schedules listed in
  * the configuration file, that group is assumed to always be on duty.
  *
  * @param group the group whose duty schedule we want
  * @param time the time to check for a duty schedule
  * @return boolean, true if the group is on duty, false otherwise.
  * @throws java.io.IOException if any.
  * @throws org.exolab.castor.xml.MarshalException if any.
  * @throws org.exolab.castor.xml.ValidationException if any.
  */
 public boolean isGroupOnDuty(String group, Calendar time)
     throws IOException, MarshalException, ValidationException {
   update();
   // if the group has no duty schedules then it is on duty
   if (!m_dutySchedules.containsKey(group)) {
     return true;
   }
   List<DutySchedule> dutySchedules = m_dutySchedules.get(group);
   for (DutySchedule curSchedule : dutySchedules) {
     if (curSchedule.isInSchedule(time)) {
       return true;
     }
   }
   return false;
 }
Beispiel #5
0
 /**
  * Determines when a group is next on duty. If a group has no duty schedules listed in the
  * configuration file, that group is assumed to always be on duty.
  *
  * @param group the group whose duty schedule we want
  * @param time the time to check for a duty schedule
  * @return long, the time in milliseconds until the group is next on duty
  * @throws java.io.IOException if any.
  * @throws org.exolab.castor.xml.MarshalException if any.
  * @throws org.exolab.castor.xml.ValidationException if any.
  */
 public long groupNextOnDuty(String group, Calendar time)
     throws IOException, MarshalException, ValidationException {
   long next = -1;
   update();
   // if the group has no duty schedules then it is on duty
   if (!m_dutySchedules.containsKey(group)) {
     return 0;
   }
   List<DutySchedule> dutySchedules = m_dutySchedules.get(group);
   for (int i = 0; i < dutySchedules.size(); i++) {
     DutySchedule curSchedule = dutySchedules.get(i);
     long tempnext = curSchedule.nextInSchedule(time);
     if (tempnext < next || next == -1) {
       LOG.debug("isGroupOnDuty: On duty in {} millisec from schedule {}", i, tempnext);
       next = tempnext;
     }
   }
   return next;
 }
 /**
  * Determines when a group is next on duty. If a group has no duty schedules listed in the
  * configuration file, that group is assumed to always be on duty.
  *
  * @param group the group whose duty schedule we want
  * @param time the time to check for a duty schedule
  * @return long, the time in milliseconds until the group is next on duty
  * @throws java.io.IOException if any.
  * @throws org.exolab.castor.xml.MarshalException if any.
  * @throws org.exolab.castor.xml.ValidationException if any.
  */
 public long groupNextOnDuty(String group, Calendar time)
     throws IOException, MarshalException, ValidationException {
   ThreadCategory log = ThreadCategory.getInstance(this.getClass());
   long next = -1;
   update();
   // if the group has no duty schedules then it is on duty
   if (!m_dutySchedules.containsKey(group)) {
     return 0;
   }
   List<DutySchedule> dutySchedules = m_dutySchedules.get(group);
   for (int i = 0; i < dutySchedules.size(); i++) {
     DutySchedule curSchedule = dutySchedules.get(i);
     long tempnext = curSchedule.nextInSchedule(time);
     if (tempnext < next || next == -1) {
       if (log.isDebugEnabled()) {
         log.debug("isGroupOnDuty: On duty in " + tempnext + " millisec from schedule " + i);
       }
       next = tempnext;
     }
   }
   return next;
 }
Beispiel #7
0
  /**
   * isUserScheduledForRole
   *
   * @param userId a {@link java.lang.String} object.
   * @param roleId a {@link java.lang.String} object.
   * @param time a {@link java.util.Date} object.
   * @return a boolean.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public boolean isUserScheduledForRole(String userId, String roleId, Date time)
      throws MarshalException, ValidationException, IOException {
    update();

    for (Schedule sched : getUserSchedulesForRole(userId, roleId)) {
      if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) {
        return true;
      }
    }

    // if no user is scheduled then the supervisor is schedule by default
    Role role = getRole(roleId);
    if (userId.equals(role.getSupervisor())) {
      for (Schedule sched : role.getScheduleCollection()) {
        if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) {
          // we found another scheduled user
          return false;
        }
      }
      return true;
    }
    return false;
  }
Beispiel #8
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;
  }
Beispiel #9
0
  /**
   * Get a group using its name
   *
   * @param name the name of the group to return
   * @return Group, the group specified by name
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public Group getGroup(String name) throws IOException, MarshalException, ValidationException {
    update();

    return m_groups.get(name);
  }
Beispiel #10
0
  /**
   * getGroupNames
   *
   * @return a {@link java.util.List} object.
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public List<String> getGroupNames() throws IOException, MarshalException, ValidationException {
    update();

    return new ArrayList<String>(m_groups.keySet());
  }
Beispiel #11
0
  /**
   * Returns a boolean indicating if the group name appears in the xml file
   *
   * @return true if the group exists in the xml file, false otherwise
   * @param groupName a {@link java.lang.String} object.
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public boolean hasGroup(String groupName)
      throws IOException, MarshalException, ValidationException {
    update();

    return m_groups.containsKey(groupName);
  }
Beispiel #12
0
  /**
   * Get the groups
   *
   * @return a {@link java.util.Map} object.
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public Map<String, Group> getGroups() throws IOException, MarshalException, ValidationException {

    update();

    return Collections.unmodifiableMap(m_groups);
  }