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

The following examples show how to use net.sf.mpxj.ProjectCalendar#getParent() . 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: PlannerWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Used to determine if a particular day of the week is normally
 * a working day.
 *
 * @param mpxjCalendar ProjectCalendar instance
 * @param day Day instance
 * @return boolean flag
 */
private boolean isWorkingDay(ProjectCalendar mpxjCalendar, Day day)
{
   boolean result = false;
   net.sf.mpxj.DayType type = mpxjCalendar.getWorkingDay(day);
   if (type == null)
   {
      type = net.sf.mpxj.DayType.DEFAULT;
   }

   switch (type)
   {
      case WORKING:
      {
         result = true;
         break;
      }

      case NON_WORKING:
      {
         result = false;
         break;
      }

      case DEFAULT:
      {
         if (mpxjCalendar.getParent() == null)
         {
            result = false;
         }
         else
         {
            result = isWorkingDay(mpxjCalendar.getParent(), day);
         }
         break;
      }
   }

   return (result);
}
 
Example 2
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 3
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);
   }
}