use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.
the class GroupManager method isGroupOnDuty.
/**
* 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.
*/
public boolean isGroupOnDuty(String group, Calendar time) throws IOException {
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;
}
use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.
the class GroupManager method buildDutySchedules.
/**
* Builds a mapping between groups and duty schedules. These are used when
* determining to send a notice to a given group. This helps speed up the decision process.
* @param groups the map of groups parsed from the XML configuration file
*/
private static void buildDutySchedules(Map<String, Group> groups) {
m_dutySchedules = new HashMap<String, List<DutySchedule>>();
for (final Entry<String, Group> entry : groups.entrySet()) {
final String key = entry.getKey();
final Group curGroup = entry.getValue();
if (curGroup.getDutySchedules().size() > 0) {
final List<DutySchedule> dutyList = new ArrayList<DutySchedule>();
for (final String duty : curGroup.getDutySchedules()) {
dutyList.add(new DutySchedule(duty));
}
m_dutySchedules.put(key, dutyList);
}
}
}
use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.
the class GroupManager method groupNextOnDuty.
/**
* 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.
*/
public long groupNextOnDuty(String group, Calendar time) throws IOException {
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;
}
use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.
the class UserManager method isUserOnDuty.
/**
* Determines if a user is on duty at a given time. If a user has no duty
* schedules listed in the configuration file, that user is assumed to always be on
* duty.
*
* @param user
* the user id
* @param time
* the time to check for a duty schedule
* @return boolean, true if the user is on duty, false otherwise.
* @throws java.io.IOException if any.
*/
public boolean isUserOnDuty(final String user, final Calendar time) throws IOException {
update();
m_readLock.lock();
try {
// if the user has no duty schedules then he is on duty
if (!m_dutySchedules.containsKey(user))
return true;
for (final DutySchedule curSchedule : m_dutySchedules.get(user)) {
if (curSchedule.isInSchedule(time)) {
return true;
}
}
} finally {
m_readLock.unlock();
}
return false;
}
use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.
the class RemoveGroupDutySchedulesServlet method doPost.
/** {@inheritDoc} */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession userSession = request.getSession(true);
Group group = (Group) userSession.getAttribute("group.modifyGroup.jsp");
GroupInfo groupInfo = group.getGroupInfo();
List<DutySchedule> dutySchedules = groupInfo.getDutySchedules();
int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
for (int i = 0; i < dutyCount; i++) {
String curDuty = request.getParameter("deleteDuty" + i);
if (curDuty != null) {
dutySchedules.remove(i);
}
}
// forward the request for proper display
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/groups/modifyGroup.jsp");
dispatcher.forward(request, response);
}
Aggregations