Java Code Examples for net.sf.mpxj.ProjectCalendar#addCalendarException()

The following examples show how to use net.sf.mpxj.ProjectCalendar#addCalendarException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MPXReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Populates a calendar exception instance.
 *
 * @param record MPX record
 * @param calendar calendar to which the exception will be added
 * @throws MPXJException
 */
private void populateCalendarException(Record record, ProjectCalendar calendar) throws MPXJException
{
   Date fromDate = record.getDate(0);
   Date toDate = record.getDate(1);
   boolean working = record.getNumericBoolean(2);

   // I have found an example MPX file where a single day exception is expressed with just the start date set.
   // If we find this for we assume that the end date is the same as the start date.
   if (fromDate != null && toDate == null)
   {
      toDate = fromDate;
   }

   ProjectCalendarException exception = calendar.addCalendarException(fromDate, toDate);
   if (working)
   {
      addExceptionRange(exception, record.getTime(3), record.getTime(4));
      addExceptionRange(exception, record.getTime(5), record.getTime(6));
      addExceptionRange(exception, record.getTime(7), record.getTime(8));
   }
}
 
Example 2
Source File: TurboProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read exceptions for a calendar.
 *
 * @param table calendar exception data
 * @param calendar calendar
 * @param exceptionID first exception ID
 */
private void addCalendarExceptions(Table table, ProjectCalendar calendar, Integer exceptionID)
{
   Integer currentExceptionID = exceptionID;
   while (true)
   {
      MapRow row = table.find(currentExceptionID);
      if (row == null)
      {
         break;
      }

      Date date = row.getDate("DATE");
      ProjectCalendarException exception = calendar.addCalendarException(date, date);
      if (row.getBoolean("WORKING"))
      {
         exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_MORNING);
         exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_AFTERNOON);
      }

      currentExceptionID = row.getInteger("NEXT_CALENDAR_EXCEPTION_ID");
   }
}
 
Example 3
Source File: PlannerReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process exception days.
 *
 * @param mpxjCalendar MPXJ calendar
 * @param plannerCalendar Planner calendar
 */
private void processExceptionDays(ProjectCalendar mpxjCalendar, net.sf.mpxj.planner.schema.Calendar plannerCalendar) throws MPXJException
{
   Days days = plannerCalendar.getDays();
   if (days != null)
   {
      List<net.sf.mpxj.planner.schema.Day> dayList = days.getDay();
      for (net.sf.mpxj.planner.schema.Day day : dayList)
      {
         if (day.getType().equals("day-type"))
         {
            Date exceptionDate = getDate(day.getDate());
            ProjectCalendarException exception = mpxjCalendar.addCalendarException(exceptionDate, exceptionDate);
            if (getInt(day.getId()) == 0)
            {
               for (int hoursIndex = 0; hoursIndex < m_defaultWorkingHours.size(); hoursIndex++)
               {
                  DateRange range = m_defaultWorkingHours.get(hoursIndex);
                  exception.addRange(range);
               }
            }
         }
      }
   }
}
 
Example 4
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process a calendar exception.
 *
 * @param calendar parent calendar
 * @param row calendar exception data
 */
private void processCalendarException(ProjectCalendar calendar, Row row)
{
   Date fromDate = row.getDate("CD_FROM_DATE");
   Date toDate = row.getDate("CD_TO_DATE");
   boolean working = row.getInt("CD_WORKING") != 0;
   ProjectCalendarException exception = calendar.addCalendarException(fromDate, toDate);
   if (working)
   {
      exception.addRange(new DateRange(row.getDate("CD_FROM_TIME1"), row.getDate("CD_TO_TIME1")));
      exception.addRange(new DateRange(row.getDate("CD_FROM_TIME2"), row.getDate("CD_TO_TIME2")));
      exception.addRange(new DateRange(row.getDate("CD_FROM_TIME3"), row.getDate("CD_TO_TIME3")));
      exception.addRange(new DateRange(row.getDate("CD_FROM_TIME4"), row.getDate("CD_TO_TIME4")));
      exception.addRange(new DateRange(row.getDate("CD_FROM_TIME5"), row.getDate("CD_TO_TIME5")));
   }
}
 
Example 5
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process calendar exceptions.
 *
 * @param calendar project calendar
 * @param root calendar data
 */
private void processCalendarExceptions(ProjectCalendar calendar, Record root)
{
   // Retrieve exceptions
   Record exceptions = root.getChild("Exceptions");
   if (exceptions != null)
   {
      for (Record exception : exceptions.getChildren())
      {
         long daysFromEpoch = Integer.parseInt(exception.getValue().split("\\|")[1]);
         Date startEx = DateHelper.getDateFromLong(EXCEPTION_EPOCH + (daysFromEpoch * DateHelper.MS_PER_DAY));

         ProjectCalendarException pce = calendar.addCalendarException(startEx, startEx);
         for (Record exceptionHours : exception.getChildren())
         {
            addHours(pce, exceptionHours);
         }
      }
   }
}
 
Example 6
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read holidays from the database and create calendar exceptions.
 */
private void readHolidays()
{
   for (MapRow row : m_tables.get("HOL"))
   {
      ProjectCalendar calendar = m_calendarMap.get(row.getInteger("CALENDAR_ID"));
      if (calendar != null)
      {
         Date date = row.getDate("DATE");
         ProjectCalendarException exception = calendar.addCalendarException(date, date);
         if (row.getBoolean("ANNUAL"))
         {
            RecurringData recurring = new RecurringData();
            recurring.setRecurrenceType(RecurrenceType.YEARLY);
            recurring.setYearlyAbsoluteFromDate(date);
            recurring.setStartDate(date);
            exception.setRecurring(recurring);
            // TODO set end date based on project end date
         }
      }
   }
}
 
Example 7
Source File: ProjectCommanderReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read a calendar exception.
 *
 * @param calendar parent calendar
 * @param ranges default day of week working times
 * @param data byte array
 */
private void readCalendarException(ProjectCalendar calendar, Map<Day, List<DateRange>> ranges, byte[] data)
{
   long timestampInDays = DatatypeConverter.getShort(data, 2, 0);

   // Heuristic to filter out odd exception dates
   if (timestampInDays > 0xFF)
   {
      long timestampInMilliseconds = timestampInDays * 24 * 60 * 60 * 1000;
      Date exceptionDate = DateHelper.getTimestampFromLong(timestampInMilliseconds);

      Calendar cal = DateHelper.popCalendar();
      cal.setTime(exceptionDate);
      Day day = Day.getInstance(cal.get(Calendar.DAY_OF_WEEK));
      DateHelper.pushCalendar(cal);

      ProjectCalendarException ex = calendar.addCalendarException(exceptionDate, exceptionDate);
      if (!calendar.isWorkingDay(day))
      {
         ranges.get(day).stream().forEach(range -> ex.addRange(range));
      }
   }
}
 
Example 8
Source File: ProjectFileExporter.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private void exportDaysOff(HumanResource hr, Resource mpxjResource) throws MPXJException {
  DefaultListModel daysOff = hr.getDaysOff();
  if (!daysOff.isEmpty()) {
    ProjectCalendar resourceCalendar = mpxjResource.addResourceCalendar();
    resourceCalendar.addDefaultCalendarHours();
    exportWeekends(resourceCalendar);
    resourceCalendar.setParent(myOutputProject.getDefaultCalendar());
    // resourceCalendar.setUniqueID(hr.getId());
    for (int i = 0; i < daysOff.size(); i++) {
      GanttDaysOff dayOff = (GanttDaysOff) daysOff.get(i);
      resourceCalendar.addCalendarException(dayOff.getStart().getTime(), dayOff.getFinish().getTime());
    }
  }
}
 
Example 9
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts data for an exception day from an MSPDI file.
 *
 * @param calendar Calendar data
 * @param day Day data
 */
private void readExceptionDay(ProjectCalendar calendar, Project.Calendars.Calendar.WeekDays.WeekDay day)
{
   Project.Calendars.Calendar.WeekDays.WeekDay.TimePeriod timePeriod = day.getTimePeriod();
   Date fromDate = timePeriod.getFromDate();
   Date toDate = timePeriod.getToDate();
   Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes times = day.getWorkingTimes();
   ProjectCalendarException exception = calendar.addCalendarException(fromDate, toDate);

   if (times != null)
   {
      List<Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes.WorkingTime> time = times.getWorkingTime();
      for (Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes.WorkingTime period : time)
      {
         Date startTime = period.getFromTime();
         Date endTime = period.getToTime();

         if (startTime != null && endTime != null)
         {
            if (startTime.getTime() >= endTime.getTime())
            {
               endTime = DateHelper.addDays(endTime, 1);
            }

            exception.addRange(new DateRange(startTime, endTime));
         }
      }
   }
}
 
Example 10
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read a single calendar exception.
 *
 * @param bc parent calendar
 * @param exception exception data
 */
private void readException(ProjectCalendar bc, Project.Calendars.Calendar.Exceptions.Exception exception)
{
   Date fromDate = exception.getTimePeriod().getFromDate();
   Date toDate = exception.getTimePeriod().getToDate();

   // Vico Schedule Planner seems to write start and end dates to FromTime and ToTime
   // rather than FromDate and ToDate. This is plain wrong, and appears to be ignored by MS Project
   // so we will ignore it too!
   if (fromDate != null && toDate != null)
   {
      ProjectCalendarException bce = bc.addCalendarException(fromDate, toDate);
      bce.setName(exception.getName());
      readRecurringData(bce, exception);
      Project.Calendars.Calendar.Exceptions.Exception.WorkingTimes times = exception.getWorkingTimes();
      if (times != null)
      {
         List<Project.Calendars.Calendar.Exceptions.Exception.WorkingTimes.WorkingTime> time = times.getWorkingTime();
         for (Project.Calendars.Calendar.Exceptions.Exception.WorkingTimes.WorkingTime period : time)
         {
            Date startTime = period.getFromTime();
            Date endTime = period.getToTime();

            if (startTime != null && endTime != null)
            {
               if (startTime.getTime() >= endTime.getTime())
               {
                  endTime = DateHelper.addDays(endTime, 1);
               }

               bce.addRange(new DateRange(startTime, endTime));
            }
         }
      }
   }
}
 
Example 11
Source File: ConceptDrawProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an exception day for a calendar.
 *
 * @param mpxjCalendar ProjectCalendar instance
 * @param day ConceptDraw PROJECT exception day
 */
private void readExceptionDay(ProjectCalendar mpxjCalendar, ExceptedDay day)
{
   ProjectCalendarException mpxjException = mpxjCalendar.addCalendarException(day.getDate(), day.getDate());
   if (day.isIsDayWorking())
   {
      for (Document.Calendars.Calendar.ExceptedDays.ExceptedDay.TimePeriods.TimePeriod period : day.getTimePeriods().getTimePeriod())
      {
         mpxjException.addRange(new DateRange(period.getFrom(), period.getTo()));
      }
   }
}
 
Example 12
Source File: GanttProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Add a single exception to a calendar.
 *
 * @param mpxjCalendar MPXJ calendar
 * @param date calendar exception
 */
private void addException(ProjectCalendar mpxjCalendar, net.sf.mpxj.ganttproject.schema.Date date)
{
   String year = date.getYear();
   if (year == null || year.isEmpty())
   {
      // In order to process recurring exceptions using MPXJ, we need a start and end date
      // to constrain the number of dates we generate.
      // May need to pre-process the tasks in order to calculate a start and finish date.
      // TODO: handle recurring exceptions
   }
   else
   {
      Calendar calendar = DateHelper.popCalendar();
      calendar.set(Calendar.YEAR, Integer.parseInt(year));
      calendar.set(Calendar.MONTH, NumberHelper.getInt(date.getMonth()));
      calendar.set(Calendar.DAY_OF_MONTH, NumberHelper.getInt(date.getDate()));
      Date exceptionDate = calendar.getTime();
      DateHelper.pushCalendar(calendar);
      ProjectCalendarException exception = mpxjCalendar.addCalendarException(exceptionDate, exceptionDate);

      // TODO: not sure how NEUTRAL should be handled
      if ("WORKING_DAY".equals(date.getType()))
      {
         exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_MORNING);
         exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_AFTERNOON);
      }
   }
}
 
Example 13
Source File: MerlinReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process calendar exceptions.
 *
 * @param calendar parent calendar.
 */
private void processExceptions(ProjectCalendar calendar) throws Exception
{
   List<Row> rows = getRows("select * from zcalendarrule where zcalendar=? and z_ent=?", calendar.getUniqueID(), m_entityMap.get("CalendarExceptionRule"));
   for (Row row : rows)
   {
      Date startDay = row.getDate("ZSTARTDAY");
      Date endDay = row.getDate("ZENDDAY");
      ProjectCalendarException exception = calendar.addCalendarException(startDay, endDay);

      String timeIntervals = row.getString("ZTIMEINTERVALS");
      if (timeIntervals != null)
      {
         NodeList nodes = getNodeList(timeIntervals, m_dayTimeIntervals);
         for (int loop = 0; loop < nodes.getLength(); loop++)
         {
            NamedNodeMap attributes = nodes.item(loop).getAttributes();
            Date startTime = m_calendarTimeFormat.parse(attributes.getNamedItem("startTime").getTextContent());
            Date endTime = m_calendarTimeFormat.parse(attributes.getNamedItem("endTime").getTextContent());

            if (startTime.getTime() >= endTime.getTime())
            {
               endTime = DateHelper.addDays(endTime, 1);
            }

            exception.addRange(new DateRange(startTime, endTime));
         }
      }
   }
}
 
Example 14
Source File: HolidayRecord.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override public void process(Context context)
{
   ProjectCalendar calendar = context.getCalendar(getString(0));
   if (calendar != null)
   {
      for (int index = 1; index < 16; index++)
      {
         Date date = getDate(index);
         if (date != null)
         {
            calendar.addCalendarException(date, date);
         }
      }
   }
}
 
Example 15
Source File: GanttDesignerReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read the calendar data from a Gantt Designer file.
 *
 * @param gantt Gantt Designer file.
 */
private void readCalendar(Gantt gantt)
{
   Gantt.Calendar ganttCalendar = gantt.getCalendar();
   m_projectFile.getProjectProperties().setWeekStartDay(ganttCalendar.getWeekStart());

   ProjectCalendar calendar = m_projectFile.addCalendar();
   calendar.setName("Standard");
   m_projectFile.setDefaultCalendar(calendar);

   String workingDays = ganttCalendar.getWorkDays();
   calendar.setWorkingDay(Day.SUNDAY, workingDays.charAt(0) == '1');
   calendar.setWorkingDay(Day.MONDAY, workingDays.charAt(1) == '1');
   calendar.setWorkingDay(Day.TUESDAY, workingDays.charAt(2) == '1');
   calendar.setWorkingDay(Day.WEDNESDAY, workingDays.charAt(3) == '1');
   calendar.setWorkingDay(Day.THURSDAY, workingDays.charAt(4) == '1');
   calendar.setWorkingDay(Day.FRIDAY, workingDays.charAt(5) == '1');
   calendar.setWorkingDay(Day.SATURDAY, workingDays.charAt(6) == '1');

   for (int i = 1; i <= 7; i++)
   {
      Day day = Day.getInstance(i);
      ProjectCalendarHours hours = calendar.addCalendarHours(day);
      if (calendar.isWorkingDay(day))
      {
         hours.addRange(ProjectCalendarWeek.DEFAULT_WORKING_MORNING);
         hours.addRange(ProjectCalendarWeek.DEFAULT_WORKING_AFTERNOON);
      }
   }

   for (Gantt.Holidays.Holiday holiday : gantt.getHolidays().getHoliday())
   {
      ProjectCalendarException exception = calendar.addCalendarException(holiday.getDate(), holiday.getDate());
      exception.setName(holiday.getContent());
   }
}
 
Example 16
Source File: MPP9CalendarFactory.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts any exceptions associated with a calendar.
 *
 * @param data calendar data block
 * @param cal calendar instance
 */
@Override protected void processCalendarExceptions(byte[] data, ProjectCalendar cal)
{
   //
   // Handle any exceptions
   //
   int exceptionCount = MPPUtility.getShort(data, 0);

   if (exceptionCount != 0)
   {
      int index;
      int offset;
      ProjectCalendarException exception;
      long duration;
      int periodCount;
      Date start;

      for (index = 0; index < exceptionCount; index++)
      {
         offset = 4 + (60 * 7) + (index * 64);

         Date fromDate = MPPUtility.getDate(data, offset);
         Date toDate = MPPUtility.getDate(data, offset + 2);
         exception = cal.addCalendarException(fromDate, toDate);

         periodCount = MPPUtility.getShort(data, offset + 6);
         if (periodCount != 0)
         {
            for (int exceptionPeriodIndex = 0; exceptionPeriodIndex < periodCount; exceptionPeriodIndex++)
            {
               start = MPPUtility.getTime(data, offset + 12 + (exceptionPeriodIndex * 2));
               duration = MPPUtility.getDuration(data, offset + 24 + (exceptionPeriodIndex * 4));
               exception.addRange(new DateRange(start, new Date(start.getTime() + duration)));
            }
         }
      }
   }
}