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

The following examples show how to use net.sf.mpxj.ProjectCalendar#setParent() . 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 instance.
 *
 * @param record MPX record
 * @param calendar calendar instance
 * @param isBaseCalendar true if this is a base calendar
 */
private void populateCalendar(Record record, ProjectCalendar calendar, boolean isBaseCalendar)
{
   if (isBaseCalendar == true)
   {
      calendar.setName(record.getString(0));
   }
   else
   {
      calendar.setParent(m_projectFile.getCalendarByName(record.getString(0)));
   }

   calendar.setWorkingDay(Day.SUNDAY, record.getDayType(1));
   calendar.setWorkingDay(Day.MONDAY, record.getDayType(2));
   calendar.setWorkingDay(Day.TUESDAY, record.getDayType(3));
   calendar.setWorkingDay(Day.WEDNESDAY, record.getDayType(4));
   calendar.setWorkingDay(Day.THURSDAY, record.getDayType(5));
   calendar.setWorkingDay(Day.FRIDAY, record.getDayType(6));
   calendar.setWorkingDay(Day.SATURDAY, record.getDayType(7));

   m_eventManager.fireCalendarReadEvent(calendar);
}
 
Example 2
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read resources.
 */
private void readResources()
{
   m_resourceMap = new HashMap<>();
   for (MapRow row : m_tables.get("RLB"))
   {
      Resource resource = m_projectFile.addResource();
      setFields(RESOURCE_FIELDS, row, resource);
      ProjectCalendar calendar = m_calendarMap.get(row.getInteger("CALENDAR_ID"));
      if (calendar != null)
      {
         ProjectCalendar baseCalendar = m_calendarMap.get(row.getInteger("BASE_CALENDAR_ID"));
         calendar.setParent(baseCalendar);
         resource.setResourceCalendar(calendar);
      }
      m_resourceMap.put(resource.getCode(), resource);
   }
}
 
Example 3
Source File: AbstractCalendarFactory.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * The way calendars are stored in an MPP14 file means that there
 * can be forward references between the base calendar unique ID for a
 * derived calendar, and the base calendar itself. To get around this,
 * we initially populate the base calendar name attribute with the
 * base calendar unique ID, and now in this method we can convert those
 * ID values into the correct names.
 *
 * @param baseCalendars list of calendars and base calendar IDs
 * @param map map of calendar ID values and calendar objects
 */
private void updateBaseCalendarNames(List<Pair<ProjectCalendar, Integer>> baseCalendars, HashMap<Integer, ProjectCalendar> map)
{
   for (Pair<ProjectCalendar, Integer> pair : baseCalendars)
   {
      ProjectCalendar cal = pair.getFirst();
      Integer baseCalendarID = pair.getSecond();
      ProjectCalendar baseCal = map.get(baseCalendarID);
      if (baseCal != null && baseCal.getName() != null)
      {
         cal.setParent(baseCal);
      }
      else
      {
         // Remove invalid calendar to avoid serious problems later.
         m_file.removeCalendar(cal);
      }
   }
}
 
Example 4
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 5
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The way calendars are stored in an MSPDI file means that there
 * can be forward references between the base calendar unique ID for a
 * derived calendar, and the base calendar itself. To get around this,
 * we initially populate the base calendar name attribute with the
 * base calendar unique ID, and now in this method we can convert those
 * ID values into the correct names.
 *
 * @param baseCalendars list of calendars and base calendar IDs
 * @param map map of calendar ID values and calendar objects
 */
private static void updateBaseCalendarNames(List<Pair<ProjectCalendar, BigInteger>> baseCalendars, HashMap<BigInteger, ProjectCalendar> map)
{
   for (Pair<ProjectCalendar, BigInteger> pair : baseCalendars)
   {
      ProjectCalendar cal = pair.getFirst();
      BigInteger baseCalendarID = pair.getSecond();
      ProjectCalendar baseCal = map.get(baseCalendarID);
      if (baseCal != null)
      {
         cal.setParent(baseCal);
      }
   }

}
 
Example 6
Source File: AstaReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Derive a calendar for a resource.
 *
 * @param parentCalendarID calendar from which resource calendar is derived
 * @return new calendar for a resource
 */
private ProjectCalendar deriveResourceCalendar(Integer parentCalendarID)
{
   ProjectCalendar calendar = m_project.addDefaultDerivedCalendar();
   calendar.setUniqueID(Integer.valueOf(m_project.getProjectConfig().getNextCalendarUniqueID()));
   calendar.setParent(m_project.getCalendarByUniqueID(parentCalendarID));
   return calendar;
}
 
Example 7
Source File: PlannerReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts data for a single resource from a Planner file.
 *
 * @param plannerResource Resource data
 */
private void readResource(net.sf.mpxj.planner.schema.Resource plannerResource) throws MPXJException
{
   Resource mpxjResource = m_projectFile.addResource();

   //mpxjResource.setResourceCalendar(m_projectFile.getBaseCalendarByUniqueID(getInteger(plannerResource.getCalendar())));
   mpxjResource.setEmailAddress(plannerResource.getEmail());
   mpxjResource.setUniqueID(getInteger(plannerResource.getId()));
   mpxjResource.setName(plannerResource.getName());
   mpxjResource.setNotes(plannerResource.getNote());
   mpxjResource.setInitials(plannerResource.getShortName());
   mpxjResource.setType(getInt(plannerResource.getType()) == 2 ? ResourceType.MATERIAL : ResourceType.WORK);
   //plannerResource.getStdRate();
   //plannerResource.getOvtRate();
   //plannerResource.getUnits();
   //plannerResource.getProperties();

   ProjectCalendar calendar = mpxjResource.addResourceCalendar();

   calendar.setWorkingDay(Day.SUNDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.MONDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.TUESDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.WEDNESDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.THURSDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.FRIDAY, DayType.DEFAULT);
   calendar.setWorkingDay(Day.SATURDAY, DayType.DEFAULT);

   ProjectCalendar baseCalendar = m_projectFile.getCalendarByUniqueID(getInteger(plannerResource.getCalendar()));
   if (baseCalendar == null)
   {
      baseCalendar = m_defaultCalendar;
   }
   calendar.setParent(baseCalendar);

   m_eventManager.fireResourceReadEvent(mpxjResource);
}
 
Example 8
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The way calendars are stored in an MPP9 file means that there
 * can be forward references between the base calendar unique ID for a
 * derived calendar, and the base calendar itself. To get around this,
 * we initially populate the base calendar name attribute with the
 * base calendar unique ID, and now in this method we can convert those
 * ID values into the correct names.
 */
protected void updateBaseCalendarNames()
{
   for (Pair<ProjectCalendar, Integer> pair : m_baseCalendarReferences)
   {
      ProjectCalendar cal = pair.getFirst();
      Integer baseCalendarID = pair.getSecond();
      ProjectCalendar baseCal = m_calendarMap.get(baseCalendarID);
      if (baseCal != null)
      {
         cal.setParent(baseCal);
      }
   }
}
 
Example 9
Source File: MPP8Reader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The way calendars are stored in an MPP8 file means that there
 * can be forward references between the base calendar unique ID for a
 * derived calendar, and the base calendar itself. To get around this,
 * we initially populate the base calendar name attribute with the
 * base calendar unique ID, and now in this method we can convert those
 * ID values into the correct names.
 *
 * @param baseCalendars list of calendars and base calendar IDs
 */
private void updateBaseCalendarNames(List<Pair<ProjectCalendar, Integer>> baseCalendars)
{
   for (Pair<ProjectCalendar, Integer> pair : baseCalendars)
   {
      ProjectCalendar cal = pair.getFirst();
      Integer baseCalendarID = pair.getSecond();
      ProjectCalendar baseCal = m_calendarMap.get(baseCalendarID);
      if (baseCal != null)
      {
         cal.setParent(baseCal);
      }
   }
}
 
Example 10
Source File: PlannerReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method extracts data for a single calendar from a Planner file.
 *
 * @param plannerCalendar Calendar data
 * @param parentMpxjCalendar parent of derived calendar
 */
private void readCalendar(net.sf.mpxj.planner.schema.Calendar plannerCalendar, ProjectCalendar parentMpxjCalendar) throws MPXJException
{
   //
   // Create a calendar instance
   //
   ProjectCalendar mpxjCalendar = m_projectFile.addCalendar();

   //
   // Populate basic details
   //
   mpxjCalendar.setUniqueID(getInteger(plannerCalendar.getId()));
   mpxjCalendar.setName(plannerCalendar.getName());
   mpxjCalendar.setParent(parentMpxjCalendar);

   //
   // Set working and non working days
   //
   DefaultWeek dw = plannerCalendar.getDefaultWeek();
   setWorkingDay(mpxjCalendar, Day.MONDAY, dw.getMon());
   setWorkingDay(mpxjCalendar, Day.TUESDAY, dw.getTue());
   setWorkingDay(mpxjCalendar, Day.WEDNESDAY, dw.getWed());
   setWorkingDay(mpxjCalendar, Day.THURSDAY, dw.getThu());
   setWorkingDay(mpxjCalendar, Day.FRIDAY, dw.getFri());
   setWorkingDay(mpxjCalendar, Day.SATURDAY, dw.getSat());
   setWorkingDay(mpxjCalendar, Day.SUNDAY, dw.getSun());

   //
   // Set working hours
   //
   processWorkingHours(mpxjCalendar, plannerCalendar);

   //
   // Process exception days
   //
   processExceptionDays(mpxjCalendar, plannerCalendar);

   m_eventManager.fireCalendarReadEvent(mpxjCalendar);

   //
   // Process any derived calendars
   //
   List<net.sf.mpxj.planner.schema.Calendar> calendarList = plannerCalendar.getCalendar();
   for (net.sf.mpxj.planner.schema.Calendar cal : calendarList)
   {
      readCalendar(cal, mpxjCalendar);
   }
}
 
Example 11
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Retrieve the correct calendar for a resource.
 *
 * @param calendarID calendar ID
 * @return calendar for resource
 */
private ProjectCalendar getResourceCalendar(Integer calendarID)
{
   ProjectCalendar result = null;
   if (calendarID != null)
   {
      ProjectCalendar calendar = m_project.getCalendarByUniqueID(calendarID);
      if (calendar != null)
      {
         //
         // If the resource is linked to a base calendar, derive
         // a default calendar from the base calendar.
         //
         if (!calendar.isDerived())
         {
            ProjectCalendar resourceCalendar = m_project.addCalendar();
            resourceCalendar.setParent(calendar);
            resourceCalendar.setWorkingDay(Day.MONDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.TUESDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.WEDNESDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.THURSDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.FRIDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.SATURDAY, DayType.DEFAULT);
            resourceCalendar.setWorkingDay(Day.SUNDAY, DayType.DEFAULT);
            result = resourceCalendar;
         }
         else
         {
            //
            // Primavera seems to allow a calendar to be shared between resources
            // whereas in the MS Project model there is a one-to-one
            // relationship. If we find a shared calendar, take a copy of it
            //
            if (calendar.getResource() == null)
            {
               result = calendar;
            }
            else
            {
               ProjectCalendar copy = m_project.addCalendar();
               copy.copy(calendar);
               result = copy;
            }
         }
      }
   }

   return result;
}
 
Example 12
Source File: PrimaveraPMFileReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process resources.
 *
 * @param apibo xml container
 */
private void processResources(APIBusinessObjects apibo)
{
   List<ResourceType> resources = apibo.getResource();
   for (ResourceType xml : resources)
   {
      Resource resource = m_projectFile.addResource();
      resource.setUniqueID(xml.getObjectId());
      resource.setName(xml.getName());
      resource.setCode(xml.getEmployeeId());
      resource.setEmailAddress(xml.getEmailAddress());
      resource.setGUID(DatatypeConverter.parseUUID(xml.getGUID()));
      resource.setNotes(xml.getResourceNotes());
      resource.setCreationDate(xml.getCreateDate());
      resource.setType(RESOURCE_TYPE_MAP.get(xml.getResourceType()));
      resource.setMaxUnits(reversePercentage(xml.getMaxUnitsPerTime()));
      resource.setParentID(xml.getParentObjectId());

      Integer calendarID = xml.getCalendarObjectId();
      if (calendarID != null)
      {
         ProjectCalendar calendar = m_projectFile.getCalendarByUniqueID(calendarID);
         if (calendar != null)
         {
            if (calendar.isDerived())
            {
               //
               // Primavera seems to allow a calendar to be shared between resources
               // whereas in the MS Project model there is a one-to-one
               // relationship. If we find a calendar is shared between resources,
               // take a copy of it so each resource has its own copy.
               //
               if (calendar.getResource() == null)
               {
                  resource.setResourceCalendar(calendar);
               }
               else
               {
                  ProjectCalendar copy = m_projectFile.addCalendar();
                  copy.copy(calendar);
                  resource.setResourceCalendar(copy);
               }
            }
            else
            {
               //
               // If the resource is linked to a base calendar, derive
               // a default calendar from the base calendar.
               //
               ProjectCalendar resourceCalendar = m_projectFile.addCalendar();
               resourceCalendar.setParent(calendar);
               resourceCalendar.setWorkingDay(Day.MONDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.TUESDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.WEDNESDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.THURSDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.FRIDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.SATURDAY, DayType.DEFAULT);
               resourceCalendar.setWorkingDay(Day.SUNDAY, DayType.DEFAULT);
               resource.setResourceCalendar(resourceCalendar);
            }
         }
      }

      readUDFTypes(resource, xml.getUDF());

      m_eventManager.fireResourceReadEvent(resource);
   }
}