Java Code Examples for net.sf.mpxj.Day#getInstance()

The following examples show how to use net.sf.mpxj.Day#getInstance() . 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: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process hours in a working day.
 *
 * @param calendar project calendar
 * @param dayRecord working day data
 */
private void processCalendarHours(ProjectCalendar calendar, Record dayRecord)
{
   // ... for each day of the week
   Day day = Day.getInstance(Integer.parseInt(dayRecord.getField()));
   // Get hours
   List<Record> recHours = dayRecord.getChildren();
   if (recHours.size() == 0)
   {
      // No data -> not working
      calendar.setWorkingDay(day, false);
   }
   else
   {
      calendar.setWorkingDay(day, true);
      // Read hours
      ProjectCalendarHours hours = calendar.addCalendarHours(day);
      for (Record recWorkingHours : recHours)
      {
         addHours(hours, recWorkingHours);
      }
   }
}
 
Example 2
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 3
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 a normal working day from an MSPDI file.
 *
 * @param calendar Calendar data
 * @param weekDay Day data
 */
private void readNormalDay(ProjectCalendar calendar, Project.Calendars.Calendar.WeekDays.WeekDay weekDay)
{
   int dayNumber = weekDay.getDayType().intValue();
   Day day = Day.getInstance(dayNumber);
   calendar.setWorkingDay(day, BooleanHelper.getBoolean(weekDay.isDayWorking()));
   ProjectCalendarHours hours = calendar.addCalendarHours(day);

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

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

            hours.addRange(new DateRange(startTime, endTime));
         }
      }
   }
}
 
Example 4
Source File: MapRow.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override public Day getDay(String name)
{
   Day result = null;
   Integer value = getInteger(name);
   if (value != null)
   {
      result = Day.getInstance(value.intValue() + 1);
   }
   return result;
}
 
Example 5
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 6
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Read the work weeks associated with this calendar.
 *
 * @param xmlCalendar XML calendar object
 * @param mpxjCalendar MPXJ calendar object
 */
private void readWorkWeeks(Project.Calendars.Calendar xmlCalendar, ProjectCalendar mpxjCalendar)
{
   WorkWeeks ww = xmlCalendar.getWorkWeeks();
   if (ww != null)
   {
      for (WorkWeek xmlWeek : ww.getWorkWeek())
      {
         ProjectCalendarWeek week = mpxjCalendar.addWorkWeek();
         week.setName(xmlWeek.getName());
         Date startTime = xmlWeek.getTimePeriod().getFromDate();
         Date endTime = xmlWeek.getTimePeriod().getToDate();
         week.setDateRange(new DateRange(startTime, endTime));

         WeekDays xmlWeekDays = xmlWeek.getWeekDays();
         if (xmlWeekDays != null)
         {
            for (WeekDay xmlWeekDay : xmlWeekDays.getWeekDay())
            {
               int dayNumber = xmlWeekDay.getDayType().intValue();
               Day day = Day.getInstance(dayNumber);
               week.setWorkingDay(day, BooleanHelper.getBoolean(xmlWeekDay.isDayWorking()));
               ProjectCalendarHours hours = week.addCalendarHours(day);

               Project.Calendars.Calendar.WorkWeeks.WorkWeek.WeekDays.WeekDay.WorkingTimes times = xmlWeekDay.getWorkingTimes();
               if (times != null)
               {
                  for (Project.Calendars.Calendar.WorkWeeks.WorkWeek.WeekDays.WeekDay.WorkingTimes.WorkingTime period : times.getWorkingTime())
                  {
                     startTime = period.getFromTime();
                     endTime = period.getToTime();

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

                        hours.addRange(new DateRange(startTime, endTime));
                     }
                  }
               }
            }
         }
      }
   }
}
 
Example 7
Source File: PlannerWriter.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 a Planner file.
 *
 * @param mpxjCalendar MPXJ calendar instance
 * @param plannerCalendar Planner calendar instance
 * @throws JAXBException on xml creation errors
 */
private void writeCalendar(ProjectCalendar mpxjCalendar, net.sf.mpxj.planner.schema.Calendar plannerCalendar) throws JAXBException
{
   //
   // Populate basic details
   //
   plannerCalendar.setId(getIntegerString(mpxjCalendar.getUniqueID()));
   plannerCalendar.setName(getString(mpxjCalendar.getName()));

   //
   // Set working and non working days
   //
   DefaultWeek dw = m_factory.createDefaultWeek();
   plannerCalendar.setDefaultWeek(dw);
   dw.setMon(getWorkingDayString(mpxjCalendar, Day.MONDAY));
   dw.setTue(getWorkingDayString(mpxjCalendar, Day.TUESDAY));
   dw.setWed(getWorkingDayString(mpxjCalendar, Day.WEDNESDAY));
   dw.setThu(getWorkingDayString(mpxjCalendar, Day.THURSDAY));
   dw.setFri(getWorkingDayString(mpxjCalendar, Day.FRIDAY));
   dw.setSat(getWorkingDayString(mpxjCalendar, Day.SATURDAY));
   dw.setSun(getWorkingDayString(mpxjCalendar, Day.SUNDAY));

   //
   // Set working hours
   //
   OverriddenDayTypes odt = m_factory.createOverriddenDayTypes();
   plannerCalendar.setOverriddenDayTypes(odt);
   List<OverriddenDayType> typeList = odt.getOverriddenDayType();
   Sequence uniqueID = new Sequence(0);

   //
   // This is a bit arbitrary, so not ideal, however...
   // The idea here is that MS Project allows us to specify working hours
   // for each day of the week individually. Planner doesn't do this,
   // but instead allows us to specify working hours for each day type.
   // What we are doing here is stepping through the days of the week to
   // find the first working day, then using the hours for that day
   // as the hours for the working day type in Planner.
   //
   for (int dayLoop = 1; dayLoop < 8; dayLoop++)
   {
      Day day = Day.getInstance(dayLoop);
      if (mpxjCalendar.isWorkingDay(day))
      {
         processWorkingHours(mpxjCalendar, uniqueID, day, typeList);
         break;
      }
   }

   //
   // Process exception days
   //
   Days plannerDays = m_factory.createDays();
   plannerCalendar.setDays(plannerDays);
   List<net.sf.mpxj.planner.schema.Day> dayList = plannerDays.getDay();
   processExceptionDays(mpxjCalendar, dayList);

   m_eventManager.fireCalendarWrittenEvent(mpxjCalendar);

   //
   // Process any derived calendars
   //
   List<net.sf.mpxj.planner.schema.Calendar> calendarList = plannerCalendar.getCalendar();

   for (ProjectCalendar mpxjDerivedCalendar : mpxjCalendar.getDerivedCalendars())
   {
      net.sf.mpxj.planner.schema.Calendar plannerDerivedCalendar = m_factory.createCalendar();
      calendarList.add(plannerDerivedCalendar);
      writeCalendar(mpxjDerivedCalendar, plannerDerivedCalendar);
   }
}
 
Example 8
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process calendar hours.
 *
 * @param calendar parent calendar
 * @param row calendar hours data
 * @param dayIndex day index
 */
private void processCalendarHours(ProjectCalendar calendar, Row row, int dayIndex)
{
   Day day = Day.getInstance(dayIndex);
   boolean working = row.getInt("CD_WORKING") != 0;
   calendar.setWorkingDay(day, working);
   if (working == true)
   {
      ProjectCalendarHours hours = calendar.addCalendarHours(day);

      Date start = row.getDate("CD_FROM_TIME1");
      Date end = row.getDate("CD_TO_TIME1");
      if (start != null && end != null)
      {
         hours.addRange(new DateRange(start, end));
      }

      start = row.getDate("CD_FROM_TIME2");
      end = row.getDate("CD_TO_TIME2");
      if (start != null && end != null)
      {
         hours.addRange(new DateRange(start, end));
      }

      start = row.getDate("CD_FROM_TIME3");
      end = row.getDate("CD_TO_TIME3");
      if (start != null && end != null)
      {
         hours.addRange(new DateRange(start, end));
      }

      start = row.getDate("CD_FROM_TIME4");
      end = row.getDate("CD_TO_TIME4");
      if (start != null && end != null)
      {
         hours.addRange(new DateRange(start, end));
      }

      start = row.getDate("CD_FROM_TIME5");
      end = row.getDate("CD_TO_TIME5");
      if (start != null && end != null)
      {
         hours.addRange(new DateRange(start, end));
      }
   }
}
 
Example 9
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Parse a day.
 *
 * @param value day value
 * @return Day instance
 */
public static final Day parseDay(Number value)
{
   return (Day.getInstance(NumberHelper.getInt(value) + 1));
}
 
Example 10
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Parse a Day.
 *
 * @param value String representation
 * @return Day instance
 */
public static final Day parseDay(String value)
{
   return Day.getInstance(Integer.parseInt(value) + 1);
}
 
Example 11
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Parse a Day value.
 *
 * @param value string representation of a day
 * @return Day instance
 */
public static final Day parseDay(String value)
{
   return Day.getInstance(Integer.parseInt(value) + 1);
}