/** * Return if time is part of specified outage. * * @param cal * the calendar to lookup * @param outage * the outage * * @return true if time is in outage */ private boolean isTimeInSchedule(final Calendar cal, final Schedule schedule) { return BasicScheduleUtils.isTimeInSchedule(cal, BasicScheduleUtils.getRancidSchedule(schedule)); }
/** * Return if time is part of specified outage. * * @param cal * the calendar to lookup * @param getOutageSchedule(outage) * the outage * @return true if time is in outage */ public boolean isTimeInOutage(final Calendar cal, final Outage outage) { return BasicScheduleUtils.isTimeInSchedule(cal, BasicScheduleUtils.getBasicOutageSchedule(outage)); }
/** * <p>getWeeklyTime</p> * * @param referenceTime a {@link java.util.Date} object. * @param day a {@link java.lang.String} object. * @param timeString a {@link java.lang.String} object. * @return a {@link java.util.Date} object. */ public static Date getWeeklyTime(final Date referenceTime, final String day, final String timeString) { final Calendar ref = Calendar.getInstance(); ref.setTime(referenceTime); ref.set(Calendar.DAY_OF_WEEK, getDayOfWeekIndex(day).intValue()); setOutCalTime(ref, timeString); return ref.getTime(); }
/** * Return a calendar representing the end time of this outage, assuming it's * currently active (i.e. right now is within one of the time periods) * * FIXME: This code is almost identical to isTimeInOutage... We need to fix * it * * @param getOutageSchedule(out) a {@link org.opennms.netmgt.config.poller.outages.Outage} object. * @return a {@link java.util.Calendar} object. */ public static Calendar getEndOfOutage(final Outage out) { // FIXME: We need one that takes the time as a parm. This makes it more testable return BasicScheduleUtils.getEndOfSchedule(BasicScheduleUtils.getBasicOutageSchedule(out)); }
/** * <p>getInterval</p> * * @param ref a {@link java.util.Date} object. * @param time a {@link org.opennms.netmgt.config.poller.outages.common.Time} object. * @param owner a {@link org.opennms.core.utils.Owner} object. * @return a {@link org.opennms.core.utils.OwnedInterval} object. */ public static OwnedInterval getInterval(final Date ref, final Time time, final Owner owner) { final String begins = time.getBegins(); final String ends = time.getEnds(); final String day = time.getDay().orElse(null); if (isWeekly(time)) { return new OwnedInterval(owner, getWeeklyTime(ref, day, begins), getWeeklyTime(ref, day, ends)); } else if (isMonthly(time)) { return new OwnedInterval(owner, getMonthlyTime(ref, day, begins), getMonthlyTime(ref, day, ends)); } else if (isDaily(time)) { return new OwnedInterval(owner, getDailyTime(ref, begins), getDailyTime(ref, ends)); } else { return new OwnedInterval(owner, getSpecificTime(begins), getSpecificTime(ends)); } }
if (isWeekly(time)) { final Date done = nextWeek(end); for(Date ref = start; done.after(ref); ref = nextWeek(ref)) { seq.addInterval(getInterval(ref, time, owner)); } else if (isMonthly(time)) { final Date done = nextMonth(end); for(Date ref = start; done.after(ref); ref = nextMonth(ref)) { seq.addInterval(getInterval(ref, time, owner)); } else if (isDaily(time)) { final Date done = nextDay(end); for(Date ref = start; done.after(ref); ref = nextDay(ref)) { seq.addInterval(getInterval(ref, time, owner)); seq.addInterval(getInterval(start, time, owner));
/** * <p>getSchedulesForRoleAt</p> * * @param roleId a {@link java.lang.String} object. * @param time a {@link java.util.Date} object. * @return a {@link java.util.List} object. * @throws java.io.IOException if any. */ public List<Schedule> getSchedulesForRoleAt(String roleId, Date time) throws IOException { update(); List<Schedule> schedules = new ArrayList<Schedule>(); for (Schedule sched : getRole(roleId).getSchedules()) { if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) { schedules.add(sched); } } return schedules; }
/** * <p>isTimeInSchedule</p> * * @param time a {@link java.util.Date} object. * @param sched a {@link org.opennms.netmgt.config.poller.outages.common.BasicSchedule} object. * @return a boolean. */ public static boolean isTimeInSchedule(final Date time, final BasicSchedule sched) { final Calendar cal = Calendar.getInstance(); cal.setTime(time); return isTimeInSchedule(cal, sched); }
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));
/** * <p>isWeekly</p> * * @param time a {@link org.opennms.netmgt.config.poller.outages.common.Time} object. * @return a boolean. */ public static boolean isWeekly(final Time time) { return getDayOfWeekIndex(time.getDay().orElse(null)) != null; }
/** * <p>getIntervals</p> * * @param interval a {@link org.opennms.core.utils.TimeInterval} object. * @param time a {@link org.opennms.netmgt.config.poller.outages.common.Time} object. * @param owner a {@link org.opennms.core.utils.Owner} object. * @return a {@link org.opennms.core.utils.OwnedIntervalSequence} object. */ public static OwnedIntervalSequence getIntervals(final TimeInterval interval, final Time time, final Owner owner) { return getIntervals(interval.getStart(), interval.getEnd(), time, owner); }
/** * <p>getIntervalsCovering</p> * * @param interval a {@link org.opennms.core.utils.TimeInterval} object. * @param sched a {@link org.opennms.netmgt.config.poller.outages.common.BasicSchedule} object. * @param owner a {@link org.opennms.core.utils.Owner} object. * @return a {@link org.opennms.core.utils.OwnedIntervalSequence} object. */ public static OwnedIntervalSequence getIntervalsCovering(final TimeInterval interval, final BasicSchedule sched, final Owner owner) { return getIntervalsCovering(interval.getStart(), interval.getEnd(), sched, owner); }
/** * <p>isUserScheduledForRole</p> * * @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 java.io.IOException if any. */ public boolean isUserScheduledForRole(String userId, String roleId, Date time) throws 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.getSchedules()) { if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) { // we found another scheduled user return false; } } return true; } return false; }
/** * <p>isMonthly</p> * * @param time a {@link org.opennms.netmgt.config.poller.outages.common.Time} object. * @return a boolean. */ public static boolean isMonthly(final Time time) { return time.getDay().isPresent() && getDayOfWeekIndex(time.getDay().get()) == null; }
/** * <p>getIntervalsCovering</p> * * @param start a {@link java.util.Date} object. * @param end a {@link java.util.Date} object. * @param sched a {@link org.opennms.netmgt.config.poller.outages.common.BasicSchedule} object. * @param owner a {@link org.opennms.core.utils.Owner} object. * @return a {@link org.opennms.core.utils.OwnedIntervalSequence} object. */ public static OwnedIntervalSequence getIntervalsCovering(final Date start, final Date end, final BasicSchedule sched, final Owner owner) { final OwnedIntervalSequence seq = new OwnedIntervalSequence(); for (int i = 0; i < sched.getTimeCount(); i++) { final Time time = sched.getTime(i); final Owner thisOwner = owner.addTimeIndex(i); seq.addAll(getIntervals(start, end, time, thisOwner)); } return seq; }
/** * Return if time is part of specified outage. * * @param cal * the calendar to lookup * @param outage * the outage * * @return true if time is in outage */ private boolean isTimeInSchedule(final Calendar cal, final Schedule schedule) { return BasicScheduleUtils.isTimeInSchedule(cal, BasicScheduleUtils.getRancidSchedule(schedule)); }
final Integer dayInMap = getDayOfWeekIndex(oTimeDay); if (dayInMap != null) { setOutCalTime(outCalBegin, begins); setOutCalTime(outCalEnd, ends);
final Integer dayInMap = getDayOfWeekIndex(oTimeDay); if (dayInMap != null) { setOutCalTime(outCalBegin, begins); setOutCalTime(outCalEnd, ends);