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

The following examples show how to use net.sf.mpxj.ProjectCalendar#getCalendarExceptions() . 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: SDEFWriter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Write calendar exceptions.
 *
 * @param records list of ProjectCalendars
 * @throws IOException
 */
private void writeExceptions(List<ProjectCalendar> records) throws IOException
{
   for (ProjectCalendar record : records)
   {
      if (!record.getCalendarExceptions().isEmpty())
      {
         // Need to move HOLI up here and get 15 exceptions per line as per USACE spec.
         // for now, we'll write one line for each calendar exception, hope there aren't too many
         //
         // changing this would be a serious upgrade, too much coding to do today....
         for (ProjectCalendarException ex : record.getCalendarExceptions())
         {
            writeCalendarException(record, ex);
         }
      }
      m_eventManager.fireCalendarWrittenEvent(record); // left here from MPX template, maybe not needed???
   }
}
 
Example 2
Source File: ProjectTreeController.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Add a calendar node.
 *
 * @param parentNode parent node
 * @param calendar calendar
 */
private void addCalendar(MpxjTreeNode parentNode, final ProjectCalendar calendar)
{
   MpxjTreeNode calendarNode = new MpxjTreeNode(calendar, CALENDAR_EXCLUDED_METHODS)
   {
      @Override public String toString()
      {
         return calendar.getName();
      }
   };
   parentNode.add(calendarNode);

   MpxjTreeNode daysFolder = new MpxjTreeNode("Days");
   calendarNode.add(daysFolder);

   for (Day day : Day.values())
   {
      addCalendarDay(daysFolder, calendar, day);
   }

   MpxjTreeNode exceptionsFolder = new MpxjTreeNode("Exceptions");
   calendarNode.add(exceptionsFolder);

   for (ProjectCalendarException exception : calendar.getCalendarExceptions())
   {
      addCalendarException(exceptionsFolder, exception);
   }
}
 
Example 3
Source File: MSPDIWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method writes data for a single calendar to an MSPDI file.
 *
 * @param bc Base calendar data
 * @return New MSPDI calendar instance
 */
private Project.Calendars.Calendar writeCalendar(ProjectCalendar bc)
{
   //
   // Create a calendar
   //
   Project.Calendars.Calendar calendar = m_factory.createProjectCalendarsCalendar();
   calendar.setUID(NumberHelper.getBigInteger(bc.getUniqueID()));
   calendar.setIsBaseCalendar(Boolean.valueOf(!bc.isDerived()));

   ProjectCalendar base = bc.getParent();
   // SF-329: null default required to keep Powerproject happy when importing MSPDI files
   calendar.setBaseCalendarUID(base == null ? NULL_CALENDAR_ID : NumberHelper.getBigInteger(base.getUniqueID()));
   calendar.setName(bc.getName());

   //
   // Create a list of normal days
   //
   Project.Calendars.Calendar.WeekDays days = m_factory.createProjectCalendarsCalendarWeekDays();
   Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes.WorkingTime time;
   ProjectCalendarHours bch;

   List<Project.Calendars.Calendar.WeekDays.WeekDay> dayList = days.getWeekDay();

   for (int loop = 1; loop < 8; loop++)
   {
      DayType workingFlag = bc.getWorkingDay(Day.getInstance(loop));

      if (workingFlag != DayType.DEFAULT)
      {
         Project.Calendars.Calendar.WeekDays.WeekDay day = m_factory.createProjectCalendarsCalendarWeekDaysWeekDay();
         dayList.add(day);
         day.setDayType(BigInteger.valueOf(loop));
         day.setDayWorking(Boolean.valueOf(workingFlag == DayType.WORKING));

         if (workingFlag == DayType.WORKING)
         {
            Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes times = m_factory.createProjectCalendarsCalendarWeekDaysWeekDayWorkingTimes();
            day.setWorkingTimes(times);
            List<Project.Calendars.Calendar.WeekDays.WeekDay.WorkingTimes.WorkingTime> timesList = times.getWorkingTime();

            bch = bc.getCalendarHours(Day.getInstance(loop));
            if (bch != null)
            {
               for (DateRange range : bch)
               {
                  if (range != null)
                  {
                     time = m_factory.createProjectCalendarsCalendarWeekDaysWeekDayWorkingTimesWorkingTime();
                     timesList.add(time);

                     time.setFromTime(range.getStart());
                     time.setToTime(range.getEnd());
                  }
               }
            }
         }
      }
   }

   //
   // Create a list of exceptions
   //
   // A quirk of MS Project is that these exceptions must be
   // in date order in the file, otherwise they are ignored
   //
   List<ProjectCalendarException> exceptions = new ArrayList<>(bc.getCalendarExceptions());
   if (!exceptions.isEmpty())
   {
      Collections.sort(exceptions);
      writeExceptions(calendar, dayList, exceptions);
   }

   //
   // Do not add a weekdays tag to the calendar unless it
   // has valid entries.
   // Fixes SourceForge bug 1854747: MPXJ and MSP 2007 XML formats
   //
   if (!dayList.isEmpty())
   {
      calendar.setWeekDays(days);
   }

   writeWorkWeeks(calendar, bc);

   m_eventManager.fireCalendarWrittenEvent(bc);

   return (calendar);
}
 
Example 4
Source File: MPXWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write a calendar.
 *
 * @param record calendar instance
 * @throws IOException
 */
private void writeCalendar(ProjectCalendar record) throws IOException
{
   //
   // Test used to ensure that we don't write the default calendar used for the "Unassigned" resource
   //
   if (record.getParent() == null || record.getResource() != null)
   {
      m_buffer.setLength(0);

      if (record.getParent() == null)
      {
         m_buffer.append(MPXConstants.BASE_CALENDAR_RECORD_NUMBER);
         m_buffer.append(m_delimiter);
         if (record.getName() != null)
         {
            m_buffer.append(record.getName());
         }
      }
      else
      {
         m_buffer.append(MPXConstants.RESOURCE_CALENDAR_RECORD_NUMBER);
         m_buffer.append(m_delimiter);
         m_buffer.append(record.getParent().getName());
      }

      for (DayType day : record.getDays())
      {
         if (day == null)
         {
            day = DayType.DEFAULT;
         }
         m_buffer.append(m_delimiter);
         m_buffer.append(day.getValue());
      }

      m_buffer.append(MPXConstants.EOL);
      m_writer.write(m_buffer.toString());

      ProjectCalendarHours[] hours = record.getHours();
      for (int loop = 0; loop < hours.length; loop++)
      {
         if (hours[loop] != null)
         {
            writeCalendarHours(record, hours[loop]);
         }
      }

      if (!record.getCalendarExceptions().isEmpty())
      {
         //
         // A quirk of MS Project is that these exceptions must be
         // in date order in the file, otherwise they are ignored.
         // The getCalendarExceptions method now guarantees that
         // the exceptions list is sorted when retrieved.
         //
         for (ProjectCalendarException ex : record.getCalendarExceptions())
         {
            writeCalendarException(record, ex);
         }
      }

      m_eventManager.fireCalendarWrittenEvent(record);
   }
}
 
Example 5
Source File: MppCalendarTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test calendar exceptions.
 *
 * @param mpp ProjectFile instance
 */
private void testExceptions(ProjectFile mpp)
{
   DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
   DateFormat tf = new SimpleDateFormat("HH:mm");

   List<ProjectCalendar> baseCalendars = mpp.getCalendars();
   assertEquals(2, baseCalendars.size());

   ProjectCalendar cal = mpp.getCalendarByUniqueID(Integer.valueOf(1));
   assertNotNull(cal);
   assertEquals("Standard", cal.getName());
   assertNull(cal.getParent());
   assertFalse(cal.isDerived());
   assertEquals(DayType.WORKING, cal.getWorkingDay(Day.MONDAY));
   assertEquals(DayType.NON_WORKING, cal.getWorkingDay(Day.TUESDAY));
   assertEquals(DayType.WORKING, cal.getWorkingDay(Day.WEDNESDAY));
   assertEquals(DayType.WORKING, cal.getWorkingDay(Day.THURSDAY));
   assertEquals(DayType.WORKING, cal.getWorkingDay(Day.FRIDAY));
   assertEquals(DayType.WORKING, cal.getWorkingDay(Day.SATURDAY));
   assertEquals(DayType.NON_WORKING, cal.getWorkingDay(Day.SUNDAY));

   List<net.sf.mpxj.ProjectCalendarException> exceptions = cal.getCalendarExceptions();
   assertEquals(3, exceptions.size());

   ProjectCalendarException exception = exceptions.get(0);
   assertFalse(exception.getWorking());
   assertEquals("05/03/2008 00:00", df.format(exception.getFromDate()));
   assertEquals("05/03/2008 23:59", df.format(exception.getToDate()));
   assertNull(exception.getRange(0).getStart());
   assertNull(exception.getRange(0).getEnd());
   assertNull(exception.getRange(1).getStart());
   assertNull(exception.getRange(1).getEnd());
   assertNull(exception.getRange(2).getStart());
   assertNull(exception.getRange(2).getEnd());
   assertNull(exception.getRange(3).getStart());
   assertNull(exception.getRange(3).getEnd());
   assertNull(exception.getRange(4).getStart());
   assertNull(exception.getRange(4).getEnd());

   exception = exceptions.get(1);
   assertTrue(exception.getWorking());
   assertEquals("09/03/2008 00:00", df.format(exception.getFromDate()));
   assertEquals("09/03/2008 23:59", df.format(exception.getToDate()));
   assertEquals("08:00", tf.format(exception.getRange(0).getStart()));
   assertEquals("12:00", tf.format(exception.getRange(0).getEnd()));
   assertEquals("13:00", tf.format(exception.getRange(1).getStart()));
   assertEquals("17:00", tf.format(exception.getRange(1).getEnd()));
   assertNull(exception.getRange(2).getStart());
   assertNull(exception.getRange(2).getEnd());
   assertNull(exception.getRange(3).getStart());
   assertNull(exception.getRange(3).getEnd());
   assertNull(exception.getRange(4).getStart());
   assertNull(exception.getRange(4).getEnd());

   exception = exceptions.get(2);
   assertTrue(exception.getWorking());
   assertEquals("16/03/2008 00:00", df.format(exception.getFromDate()));
   assertEquals("16/03/2008 23:59", df.format(exception.getToDate()));
   assertEquals("08:00", tf.format(exception.getRange(0).getStart()));
   assertEquals("09:00", tf.format(exception.getRange(0).getEnd()));
   assertEquals("11:00", tf.format(exception.getRange(1).getStart()));
   assertEquals("12:00", tf.format(exception.getRange(1).getEnd()));
   assertEquals("14:00", tf.format(exception.getRange(2).getStart()));
   assertEquals("15:00", tf.format(exception.getRange(2).getEnd()));
   assertEquals("16:00", tf.format(exception.getRange(3).getStart()));
   assertEquals("17:00", tf.format(exception.getRange(3).getEnd()));
   assertEquals("18:00", tf.format(exception.getRange(4).getStart()));
   assertEquals("19:00", tf.format(exception.getRange(4).getEnd()));
}