private void postProcessTasks ( ) throws MPXJException { // // Renumber ID values using a large increment to allow // space for later inserts. // TreeMap < Integer , Integer > taskMap = new TreeMap < Integer , Integer > ( ) ; // I've found a pathological case of an MPP file with around 102k blank tasks... int nextIDIncrement = 102000 ; int nextID = ( m_file . getTaskByUniqueID ( Integer . valueOf ( 0 ) ) == null ? nextIDIncrement : 0 ) ; for ( Map . Entry < Long , Integer > entry : m_taskOrder . entrySet ( ) ) { taskMap . put ( Integer . valueOf ( nextID ) , entry . getValue ( ) ) ; nextID += nextIDIncrement ; } // // Insert any null tasks into the correct location // int insertionCount = 0 ; Map < Integer , Integer > offsetMap = new HashMap < Integer , Integer > ( ) ; for ( Map . Entry < Integer , Integer > entry : m_nullTaskOrder . entrySet ( ) ) { int idValue = entry . getKey ( ) . intValue ( ) ; int baseTargetIdValue = ( idValue - insertionCount ) * nextIDIncrement ; int targetIDValue = baseTargetIdValue ; Integer previousOffsetKey = Integer . valueOf ( baseTargetIdValue ) ; Integer previousOffset = offsetMap . get ( previousOffsetKey ) ; int offset = previousOffset == null ? 0 : previousOffset . intValue ( ) + 1 ; ++ insertionCount ; while ( taskMap . containsKey ( Integer . valueOf ( targetIDValue ) ) ) { ++ offset ; if ( offset == nextIDIncrement ) { throw new MPXJException ( "Unable to fix task order" ) ; } targetIDValue = baseTargetIdValue - ( nextIDIncrement - offset ) ; } offsetMap . put ( previousOffsetKey , Integer . valueOf ( offset ) ) ; taskMap . put ( Integer . valueOf ( targetIDValue ) , entry . getValue ( ) ) ; } // // Finally, we can renumber the tasks // nextID = ( m_file . getTaskByUniqueID ( Integer . valueOf ( 0 ) ) == null ? 1 : 0 ) ; for ( Map . Entry < Integer , Integer > entry : taskMap . entrySet ( ) ) { Task task = m_file . getTaskByUniqueID ( entry . getValue ( ) ) ; if ( task != null ) { task . setID ( Integer . valueOf ( nextID ) ) ; } nextID ++ ; } }
MPP14 files seem to exhibit some occasional weirdness with duplicate ID values which leads to the task structure being reported incorrectly . The following method attempts to correct this . The method uses ordering data embedded in the file to reconstruct the correct ID order of the tasks .