private void writeAssignments ( Project project ) { Project . Assignments assignments = m_factory . createProjectAssignments ( ) ; project . setAssignments ( assignments ) ; List < Project . Assignments . Assignment > list = assignments . getAssignment ( ) ; for ( ResourceAssignment assignment : m_projectFile . getResourceAssignments ( ) ) { list . add ( writeAssignment ( assignment ) ) ; } // // Check to see if we have any tasks that have a percent complete value // but do not have resource assignments. If any exist, then we must // write a dummy resource assignment record to ensure that the MSPDI // file shows the correct percent complete amount for the task. // ProjectConfig config = m_projectFile . getProjectConfig ( ) ; boolean autoUniqueID = config . getAutoAssignmentUniqueID ( ) ; if ( ! autoUniqueID ) { config . setAutoAssignmentUniqueID ( true ) ; } for ( Task task : m_projectFile . getTasks ( ) ) { double percentComplete = NumberHelper . getDouble ( task . getPercentageComplete ( ) ) ; if ( percentComplete != 0 && task . getResourceAssignments ( ) . isEmpty ( ) == true ) { ResourceAssignment dummy = new ResourceAssignment ( m_projectFile , task ) ; Duration duration = task . getDuration ( ) ; if ( duration == null ) { duration = Duration . getInstance ( 0 , TimeUnit . HOURS ) ; } double durationValue = duration . getDuration ( ) ; TimeUnit durationUnits = duration . getUnits ( ) ; double actualWork = ( durationValue * percentComplete ) / 100 ; double remainingWork = durationValue - actualWork ; dummy . setResourceUniqueID ( NULL_RESOURCE_ID ) ; dummy . setWork ( duration ) ; dummy . setActualWork ( Duration . getInstance ( actualWork , durationUnits ) ) ; dummy . setRemainingWork ( Duration . getInstance ( remainingWork , durationUnits ) ) ; // Without this, MS Project will mark a 100% complete milestone as 99% complete if ( percentComplete == 100 && duration . getDuration ( ) == 0 ) { dummy . setActualFinish ( task . getActualStart ( ) ) ; } list . add ( writeAssignment ( dummy ) ) ; } } config . setAutoAssignmentUniqueID ( autoUniqueID ) ; }
This method writes assignment data to an MSPDI file .