Package net.sf.mpxj

Examples of net.sf.mpxj.ProjectCalendar


      TimephasedDataFactory timephasedFactory = new TimephasedDataFactory();
      SplitTaskFactory splitFactory = new SplitTaskFactory();
      TimephasedWorkNormaliser normaliser = new MPPTimephasedWorkNormaliser();
      TimephasedWorkNormaliser baselineWorkNormaliser = new MPPTimephasedBaselineWorkNormaliser();
      TimephasedCostNormaliser baselineCostNormaliser = new MPPTimephasedBaselineCostNormaliser()
      ProjectCalendar baselineCalendar = file.getBaselineCalendar();
      RTFUtility rtf = new RTFUtility();

      //System.out.println(assnFixedMeta);
      //System.out.println(assnFixedData);
      //System.out.println(assnVarMeta.toString(fieldMap));
      //System.out.println(assnVarData);

      for (int loop = 0; loop < count; loop++)
      {
         byte[] meta = assnFixedMeta.getByteArrayValue(loop);
         if (meta[0] != 0)
         {
            continue;
         }

         int offset = MPPUtility.getInt(meta, 4);
         byte[] data = assnFixedData.getByteArrayValue(assnFixedData.getIndexFromOffset(offset));
         if (data == null)
         {
            continue;
         }

         if (data.length <= fieldMap.getMaxFixedDataOffset(0))
         {
            byte[] newData = new byte[fieldMap.getMaxFixedDataOffset(0) + 8];
            System.arraycopy(data, 0, newData, 0, data.length);
            data = newData;
         }

         int id = MPPUtility.getInt(data, fieldMap.getFixedDataOffset(AssignmentField.UNIQUE_ID));
         final Integer varDataId = Integer.valueOf(id);
         if (set.contains(varDataId) == false)
         {
            continue;
         }

         byte[] data2 = null;
         if (assnFixedData2 != null)
         {
            data2 = assnFixedData2.getByteArrayValue(loop);
         }

         ResourceAssignment assignment = new ResourceAssignment(file);

         assignment.disableEvents();
         fieldMap.populateContainer(assignment, varDataId, new byte[][]
         {
            data,
            data2
         }, assnVarData);
         assignment.enableEvents();

         if (fieldMap.getFieldLocation(AssignmentField.FLAG1) != FieldMap.FieldLocation.VAR_DATA)
         {
            assignment.setFlag(1, (meta[28] & 0x80) != 0);

            assignment.setFlag(2, (meta[29] & 0x01) != 0);
            assignment.setFlag(3, (meta[29] & 0x02) != 0);
            assignment.setFlag(4, (meta[29] & 0x04) != 0);
            assignment.setFlag(5, (meta[29] & 0x08) != 0);
            assignment.setFlag(6, (meta[29] & 0x10) != 0);
            assignment.setFlag(7, (meta[29] & 0x20) != 0);
            assignment.setFlag(8, (meta[29] & 0x40) != 0);
            assignment.setFlag(9, (meta[29] & 0x80) != 0);

            assignment.setFlag(10, (meta[30] & 0x01) != 0);
            assignment.setFlag(11, (meta[30] & 0x02) != 0);
            assignment.setFlag(12, (meta[30] & 0x04) != 0);
            assignment.setFlag(13, (meta[30] & 0x08) != 0);
            assignment.setFlag(14, (meta[30] & 0x10) != 0);
            assignment.setFlag(15, (meta[30] & 0x20) != 0);
            assignment.setFlag(16, (meta[30] & 0x40) != 0);
            assignment.setFlag(17, (meta[30] & 0x80) != 0);

            assignment.setFlag(18, (meta[31] & 0x01) != 0);
            assignment.setFlag(19, (meta[31] & 0x02) != 0);
            assignment.setFlag(20, (meta[31] & 0x04) != 0);
         }

         if (fieldMap.getFieldLocation(AssignmentField.CONFIRMED) != FieldMap.FieldLocation.VAR_DATA)
         {
            assignment.setConfirmed((meta[8] & 0x80) != 0);
         }

         if (fieldMap.getFieldLocation(AssignmentField.RESPONSE_PENDING) != FieldMap.FieldLocation.VAR_DATA)
         {
            assignment.setResponsePending((meta[9] & 0x01) != 0);
         }

         if (fieldMap.getFieldLocation(AssignmentField.TEAM_STATUS_PENDING) != FieldMap.FieldLocation.VAR_DATA)
         {
            assignment.setTeamStatusPending((meta[10] & 0x02) != 0);
         }

         processHyperlinkData(assignment, assnVarData.getByteArray(varDataId, fieldMap.getVarDataKey(AssignmentField.HYPERLINK_DATA)));

         //
         // Post processing
         //
         if (file.getMppFileType() == 9 && assignment.getCreateDate() == null)
         {
            byte[] creationData = assnVarData.getByteArray(varDataId, MPP9_CREATION_DATA);
            if (creationData != null && creationData.length >= 28)
            {
               assignment.setCreateDate(MPPUtility.getTimestamp(creationData, 24));
            }
         }

         String notes = assignment.getNotes();
         if (notes != null)
         {
            if (!preserveNoteFormatting)
            {
               notes = rtf.strip(notes);
            }

            assignment.setNotes(notes);
         }

         Task task = file.getTaskByUniqueID(assignment.getTaskUniqueID());
         if (task != null)
         {
            task.addResourceAssignment(assignment);

            Resource resource = file.getResourceByUniqueID(assignment.getResourceUniqueID());

            ProjectCalendar calendar = null;
            if (resource != null)
            {
               calendar = resource.getResourceCalendar();
            }
View Full Code Here


    mpxResource.setUniqueID((int)uid); // note using id and not unique id
    mpxResource.setMaxUnits(projityResource.getMaximumUnits());

    WorkingCalendar projityCalendar = (WorkingCalendar)projityResource.getWorkCalendar();
    if (projityCalendar != null) { // there should be a calendar, except for the unassigned instance
      ProjectCalendar mpxCalendar = null;
      try {
        mpxCalendar = mpxResource.addResourceCalendar();
      } catch (MPXJException e) {
        e.printStackTrace();
        return;
View Full Code Here

      //file.setThousandsSeparator('.');

      //
      // Add a default calendar called "Standard"
      //
      ProjectCalendar calendar = file.addDefaultBaseCalendar();

      //
      // Add a holiday to the calendar to demonstrate calendar exceptions
      //
      calendar.addCalendarException(df.parse("13/03/2006"), df.parse("13/03/2006"));

      //
      // Retrieve the project header and set the start date. Note Microsoft
      // Project appears to reset all task dates relative to this date, so this
      // date must match the start date of the earliest task for you to see
View Full Code Here

   {
      DirectoryEntry calDir = (DirectoryEntry) m_projectDir.getEntry("TBkndCal");
      FixFix calendarFixedData = new FixFix(36, new DocumentInputStream(((DocumentEntry) calDir.getEntry("FixFix   0"))));
      FixDeferFix calendarVarData = new FixDeferFix(new DocumentInputStream(((DocumentEntry) calDir.getEntry("FixDeferFix   0"))));

      ProjectCalendar cal;
      ProjectCalendarHours hours;
      ProjectCalendarException exception;
      String name;
      byte[] baseData;
      byte[] extData;

      int periodCount;
      int index;
      int offset;
      int defaultFlag;
      Date start;
      long duration;
      int exceptionCount;

      //
      // Configure default time ranges
      //
      SimpleDateFormat df = new SimpleDateFormat("HH:mm");
      Date defaultStart1;
      Date defaultEnd1;
      Date defaultStart2;
      Date defaultEnd2;

      try
      {
         defaultStart1 = df.parse("08:00");
         defaultEnd1 = df.parse("12:00");
         defaultStart2 = df.parse("13:00");
         defaultEnd2 = df.parse("17:00");
      }

      catch (ParseException ex)
      {
         throw new MPXJException(MPXJException.INVALID_FORMAT, ex);
      }

      int calendars = calendarFixedData.getItemCount();
      int calendarID;
      int baseCalendarID;
      int periodIndex;
      Day day;
      List<Pair<ProjectCalendar, Integer>> baseCalendars = new LinkedList<Pair<ProjectCalendar, Integer>>();

      for (int loop = 0; loop < calendars; loop++)
      {
         baseData = calendarFixedData.getByteArrayValue(loop);
         calendarID = MPPUtility.getInt(baseData, 0);
         baseCalendarID = MPPUtility.getInt(baseData, 4);
         name = calendarVarData.getUnicodeString(getOffset(baseData, 20));

         //
         // Uncommenting the call to this method is useful when trying
         // to determine the function of unknown task data.
         //
         //dumpUnknownData (name + " " + MPPUtility.getInt(baseData), UNKNOWN_CALENDAR_DATA, baseData);

         //
         // Skip calendars with negative ID values
         //
         if (calendarID < 0)
         {
            continue;
         }

         //
         // Populate the basic calendar
         //
         ExtendedData ed = new ExtendedData(calendarVarData, getOffset(baseData, 32));
         offset = -1 - ed.getInt(Integer.valueOf(8));

         if (offset == -1)
         {
            if (baseCalendarID > 0)
            {
               cal = m_file.getDefaultResourceCalendar();
               baseCalendars.add(new Pair<ProjectCalendar, Integer>(cal, Integer.valueOf(baseCalendarID)));
            }
            else
            {
               cal = m_file.addDefaultBaseCalendar();
               cal.setName(name);
            }

            cal.setUniqueID(Integer.valueOf(calendarID));
         }
         else
         {
            if (baseCalendarID > 0)
            {
               cal = m_file.addResourceCalendar();
               baseCalendars.add(new Pair<ProjectCalendar, Integer>(cal, Integer.valueOf(baseCalendarID)));
            }
            else
            {
               cal = m_file.addBaseCalendar();
               cal.setName(name);
            }

            cal.setUniqueID(Integer.valueOf(calendarID));

            extData = calendarVarData.getByteArray(offset);

            for (index = 0; index < 7; index++)
            {
               offset = 4 + (40 * index);

               defaultFlag = MPPUtility.getShort(extData, offset);
               day = Day.getInstance(index + 1);

               if (defaultFlag == 1)
               {
                  cal.setWorkingDay(day, DEFAULT_WORKING_WEEK[index]);
                  if (cal.isWorkingDay(day) == true)
                  {
                     hours = cal.addCalendarHours(net.sf.mpxj.Day.getInstance(index + 1));
                     hours.addRange(new DateRange(defaultStart1, defaultEnd1));
                     hours.addRange(new DateRange(defaultStart2, defaultEnd2));
                  }
               }
               else
               {
                  periodCount = MPPUtility.getShort(extData, offset + 2);
                  if (periodCount == 0)
                  {
                     cal.setWorkingDay(day, false);
                  }
                  else
                  {
                     cal.setWorkingDay(day, true);
                     hours = cal.addCalendarHours(Day.getInstance(index + 1));

                     for (periodIndex = 0; periodIndex < periodCount; periodIndex++)
                     {
                        start = MPPUtility.getTime(extData, offset + 8 + (periodIndex * 2));
                        duration = MPPUtility.getDuration(extData, offset + 16 + (periodIndex * 4));
                        hours.addRange(new DateRange(start, new Date(start.getTime() + duration)));
                     }
                  }
               }
            }

            //
            // Handle any exceptions
            //
            exceptionCount = MPPUtility.getShort(extData, 0);
            if (exceptionCount != 0)
            {
               for (index = 0; index < exceptionCount; index++)
               {
                  offset = 4 + (40 * 7) + (index * 44);

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

                  periodCount = MPPUtility.getShort(extData, offset + 6);
                  if (periodCount != 0)
                  {
                     for (int exceptionPeriodIndex = 0; exceptionPeriodIndex < periodCount; exceptionPeriodIndex++)
View Full Code Here

    */
   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);
         }
      }
View Full Code Here

      byte[] data;
      int id;
      Resource resource;
      String notes;
      RTFUtility rtf = new RTFUtility();
      ProjectCalendar calendar;

      for (int loop = 0; loop < resources; loop++)
      {
         data = rscFixedData.getByteArrayValue(loop);
View Full Code Here

    calendar.setId(new CalendarId(mpxCalendar.getUniqueID()));
   
   
    //base calendar
    WorkCalendar standardCalendar = state.getCalendarManager().getStandardBaseCalendar();
    ProjectCalendar mpxBaseCalendar=null;
    WorkCalendar baseCalendar=null;
    if (mpxCalendar.isDerived()) {
      mpxBaseCalendar = mpxCalendar.getParent();
      if (mpxBaseCalendar==null){
        mpxBaseCalendar=state.getMpxStandardBaseCalendar();
      }
      baseCalendar=state.getCalendarManager().getCalendar(new CalendarId(mpxBaseCalendar.getUniqueID()));
      if (baseCalendar == null)
        baseCalendar = standardCalendar;
      calendar.setBase(baseCalendar);
    }
   
   
    //work weeks
    WorkWeek week=new WorkWeek();
    calendar.setWeek(week);
    MpxRangeConverter rangeConverter=new MpxRangeConverter();
    for (int i=0; i<7; i++) {
      Day mpxDayId=Day.getInstance(i+1);
      ProjectCalendarHours mpxDay=mpxCalendar.getCalendarHours(mpxDayId);
      net.sf.mpxj.DayType mpxDayType=mpxCalendar.getWorkingDay(mpxDayId);
      WorkDay day=null;
      if (mpxDay == null) {
        if (mpxCalendar.isDerived() &&
              mpxBaseCalendar!=null &&
              mpxBaseCalendar.isWorkingDay(mpxDayId))
          day = WorkDay.getNonWorkingDay();       
      } else {
        day=new WorkDay(DayType.getInstance(mpxDayType.getValue()));
        rangeConverter.from(mpxDay,day);
      }
View Full Code Here

   {
      Duration variance = null;

      if (date1 != null && date2 != null)
      {
         ProjectCalendar calendar = task.getCalendar();
         if (calendar == null)
         {
            calendar = task.getParentFile().getCalendar();
         }

         if (calendar != null)
         {
            variance = calendar.getWork(date1, date2, format);
         }
      }

      if (variance == null)
      {
View Full Code Here

  public WorkCalendar findImportedCalendar(ProjectCalendar mpxCal) {
    return (WorkCalendar) importedCalendarMap.get(mpxCal);
  }
  public ProjectCalendar findImportedMPXCalendar(String name) {
    Iterator i = importedCalendarMap.keySet().iterator();
    ProjectCalendar cal;
    if (name == null)
      return null;
    while (i.hasNext()) {
      cal = (ProjectCalendar)i.next();
      if (name.equals(cal.getName()))
        return cal;
    }
    return null;
  }
View Full Code Here

  }
  protected void writeProjectCalendar(Project project) {
    // projity addition
    int id = 1; // if not found below, use the default standard calendar
    ProjectCalendar cal = ImportedCalendarService.getInstance().findExportedCalendar(
        CalendarService.findBaseCalendar(m_projectFile.getProjectHeader().getCalendarName()));
    if (cal != null) {
      id = cal.getUniqueID();
    } else {
      log.warn("EXPORT: Could not export project calendar: Project: " + m_projectFile.getProjectHeader().getName() + " calendar "
          + m_projectFile.getProjectHeader().getCalendarName());
    }
    project.setCalendarUID(BigInteger.valueOf(id));
View Full Code Here

TOP

Related Classes of net.sf.mpxj.ProjectCalendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.