idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
144,000
private void readCalendars ( Project project , HashMap < BigInteger , ProjectCalendar > map ) { Project . Calendars calendars = project . getCalendars ( ) ; if ( calendars != null ) { LinkedList < Pair < ProjectCalendar , BigInteger > > baseCalendars = new LinkedList < Pair < ProjectCalendar , BigInteger > > ( ) ; for ( Project . Calendars . Calendar cal : calendars . getCalendar ( ) ) { readCalendar ( cal , map , baseCalendars ) ; } updateBaseCalendarNames ( baseCalendars , map ) ; } try { ProjectProperties properties = m_projectFile . getProjectProperties ( ) ; BigInteger calendarID = new BigInteger ( properties . getDefaultCalendarName ( ) ) ; ProjectCalendar calendar = map . get ( calendarID ) ; m_projectFile . setDefaultCalendar ( calendar ) ; } catch ( Exception ex ) { // Ignore exceptions } }
This method extracts calendar data from an MSPDI file .
203
12
144,001
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 ) ; } } }
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 .
118
68
144,002
private void readCalendar ( Project . Calendars . Calendar calendar , HashMap < BigInteger , ProjectCalendar > map , List < Pair < ProjectCalendar , BigInteger > > baseCalendars ) { ProjectCalendar bc = m_projectFile . addCalendar ( ) ; bc . setUniqueID ( NumberHelper . getInteger ( calendar . getUID ( ) ) ) ; bc . setName ( calendar . getName ( ) ) ; BigInteger baseCalendarID = calendar . getBaseCalendarUID ( ) ; if ( baseCalendarID != null ) { baseCalendars . add ( new Pair < ProjectCalendar , BigInteger > ( bc , baseCalendarID ) ) ; } readExceptions ( calendar , bc ) ; boolean readExceptionsFromDays = bc . getCalendarExceptions ( ) . isEmpty ( ) ; Project . Calendars . Calendar . WeekDays days = calendar . getWeekDays ( ) ; if ( days != null ) { for ( Project . Calendars . Calendar . WeekDays . WeekDay weekDay : days . getWeekDay ( ) ) { readDay ( bc , weekDay , readExceptionsFromDays ) ; } } else { bc . setWorkingDay ( Day . SUNDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . MONDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . TUESDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . WEDNESDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . THURSDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . FRIDAY , DayType . DEFAULT ) ; bc . setWorkingDay ( Day . SATURDAY , DayType . DEFAULT ) ; } readWorkWeeks ( calendar , bc ) ; map . put ( calendar . getUID ( ) , bc ) ; m_eventManager . fireCalendarReadEvent ( bc ) ; }
This method extracts data for a single calendar from an MSPDI file .
423
15
144,003
private void readDay ( ProjectCalendar calendar , Project . Calendars . Calendar . WeekDays . WeekDay day , boolean readExceptionsFromDays ) { BigInteger dayType = day . getDayType ( ) ; if ( dayType != null ) { if ( dayType . intValue ( ) == 0 ) { if ( readExceptionsFromDays ) { readExceptionDay ( calendar , day ) ; } } else { readNormalDay ( calendar , day ) ; } } }
This method extracts data for a single day from an MSPDI file .
100
15
144,004
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 ) ) ; } } } }
This method extracts data for a normal working day from an MSPDI file .
256
16
144,005
private void readExceptionDay ( ProjectCalendar calendar , Project . Calendars . Calendar . WeekDays . WeekDay day ) { Project . Calendars . Calendar . WeekDays . WeekDay . TimePeriod timePeriod = day . getTimePeriod ( ) ; Date fromDate = timePeriod . getFromDate ( ) ; Date toDate = timePeriod . getToDate ( ) ; Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes times = day . getWorkingTimes ( ) ; ProjectCalendarException exception = calendar . addCalendarException ( fromDate , toDate ) ; if ( times != null ) { List < Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes . WorkingTime > time = times . getWorkingTime ( ) ; for ( Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes . WorkingTime period : time ) { Date startTime = period . getFromTime ( ) ; Date endTime = period . getToTime ( ) ; if ( startTime != null && endTime != null ) { if ( startTime . getTime ( ) >= endTime . getTime ( ) ) { endTime = DateHelper . addDays ( endTime , 1 ) ; } exception . addRange ( new DateRange ( startTime , endTime ) ) ; } } } }
This method extracts data for an exception day from an MSPDI file .
284
15
144,006
private void readExceptions ( Project . Calendars . Calendar calendar , ProjectCalendar bc ) { Project . Calendars . Calendar . Exceptions exceptions = calendar . getExceptions ( ) ; if ( exceptions != null ) { for ( Project . Calendars . Calendar . Exceptions . Exception exception : exceptions . getException ( ) ) { readException ( bc , exception ) ; } } }
Reads any exceptions present in the file . This is only used in MSPDI file versions saved by Project 2007 and later .
80
26
144,007
private void readException ( ProjectCalendar bc , Project . Calendars . Calendar . Exceptions . Exception exception ) { Date fromDate = exception . getTimePeriod ( ) . getFromDate ( ) ; Date toDate = exception . getTimePeriod ( ) . getToDate ( ) ; // Vico Schedule Planner seems to write start and end dates to FromTime and ToTime // rather than FromDate and ToDate. This is plain wrong, and appears to be ignored by MS Project // so we will ignore it too! if ( fromDate != null && toDate != null ) { ProjectCalendarException bce = bc . addCalendarException ( fromDate , toDate ) ; bce . setName ( exception . getName ( ) ) ; readRecurringData ( bce , exception ) ; Project . Calendars . Calendar . Exceptions . Exception . WorkingTimes times = exception . getWorkingTimes ( ) ; if ( times != null ) { List < Project . Calendars . Calendar . Exceptions . Exception . WorkingTimes . WorkingTime > time = times . getWorkingTime ( ) ; for ( Project . Calendars . Calendar . Exceptions . Exception . WorkingTimes . WorkingTime period : time ) { Date startTime = period . getFromTime ( ) ; Date endTime = period . getToTime ( ) ; if ( startTime != null && endTime != null ) { if ( startTime . getTime ( ) >= endTime . getTime ( ) ) { endTime = DateHelper . addDays ( endTime , 1 ) ; } bce . addRange ( new DateRange ( startTime , endTime ) ) ; } } } } }
Read a single calendar exception .
350
6
144,008
private void readRecurringData ( ProjectCalendarException bce , Project . Calendars . Calendar . Exceptions . Exception exception ) { RecurrenceType rt = getRecurrenceType ( NumberHelper . getInt ( exception . getType ( ) ) ) ; if ( rt != null ) { RecurringData rd = new RecurringData ( ) ; rd . setStartDate ( bce . getFromDate ( ) ) ; rd . setFinishDate ( bce . getToDate ( ) ) ; rd . setRecurrenceType ( rt ) ; rd . setRelative ( getRelative ( NumberHelper . getInt ( exception . getType ( ) ) ) ) ; rd . setOccurrences ( NumberHelper . getInteger ( exception . getOccurrences ( ) ) ) ; switch ( rd . getRecurrenceType ( ) ) { case DAILY : { rd . setFrequency ( getFrequency ( exception ) ) ; break ; } case WEEKLY : { rd . setWeeklyDaysFromBitmap ( NumberHelper . getInteger ( exception . getDaysOfWeek ( ) ) , DAY_MASKS ) ; rd . setFrequency ( getFrequency ( exception ) ) ; break ; } case MONTHLY : { if ( rd . getRelative ( ) ) { rd . setDayOfWeek ( Day . getInstance ( NumberHelper . getInt ( exception . getMonthItem ( ) ) - 2 ) ) ; rd . setDayNumber ( Integer . valueOf ( NumberHelper . getInt ( exception . getMonthPosition ( ) ) + 1 ) ) ; } else { rd . setDayNumber ( NumberHelper . getInteger ( exception . getMonthDay ( ) ) ) ; } rd . setFrequency ( getFrequency ( exception ) ) ; break ; } case YEARLY : { if ( rd . getRelative ( ) ) { rd . setDayOfWeek ( Day . getInstance ( NumberHelper . getInt ( exception . getMonthItem ( ) ) - 2 ) ) ; rd . setDayNumber ( Integer . valueOf ( NumberHelper . getInt ( exception . getMonthPosition ( ) ) + 1 ) ) ; } else { rd . setDayNumber ( NumberHelper . getInteger ( exception . getMonthDay ( ) ) ) ; } rd . setMonthNumber ( Integer . valueOf ( NumberHelper . getInt ( exception . getMonth ( ) ) + 1 ) ) ; break ; } } if ( rd . getRecurrenceType ( ) != RecurrenceType . DAILY || rd . getDates ( ) . length > 1 ) { bce . setRecurring ( rd ) ; } } }
Read recurring data for a calendar exception .
579
8
144,009
private Integer getFrequency ( Project . Calendars . Calendar . Exceptions . Exception exception ) { Integer period = NumberHelper . getInteger ( exception . getPeriod ( ) ) ; if ( period == null ) { period = Integer . valueOf ( 1 ) ; } return period ; }
Retrieve the frequency of an exception .
60
8
144,010
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 ) ) ; } } } } } } } }
Read the work weeks associated with this calendar .
450
9
144,011
private void readProjectExtendedAttributes ( Project project ) { Project . ExtendedAttributes attributes = project . getExtendedAttributes ( ) ; if ( attributes != null ) { for ( Project . ExtendedAttributes . ExtendedAttribute ea : attributes . getExtendedAttribute ( ) ) { readFieldAlias ( ea ) ; } } }
This method extracts project extended attribute data from an MSPDI file .
67
14
144,012
private void readFieldAlias ( Project . ExtendedAttributes . ExtendedAttribute attribute ) { String alias = attribute . getAlias ( ) ; if ( alias != null && alias . length ( ) != 0 ) { FieldType field = FieldTypeHelper . getInstance ( Integer . parseInt ( attribute . getFieldID ( ) ) ) ; m_projectFile . getCustomFields ( ) . getCustomField ( field ) . setAlias ( attribute . getAlias ( ) ) ; } }
Read a single field alias from an extended attribute .
99
10
144,013
private void readResources ( Project project , HashMap < BigInteger , ProjectCalendar > calendarMap ) { Project . Resources resources = project . getResources ( ) ; if ( resources != null ) { for ( Project . Resources . Resource resource : resources . getResource ( ) ) { readResource ( resource , calendarMap ) ; } } }
This method extracts resource data from an MSPDI file .
70
12
144,014
private void readResourceBaselines ( Project . Resources . Resource xmlResource , Resource mpxjResource ) { for ( Project . Resources . Resource . Baseline baseline : xmlResource . getBaseline ( ) ) { int number = NumberHelper . getInt ( baseline . getNumber ( ) ) ; Double cost = DatatypeConverter . parseCurrency ( baseline . getCost ( ) ) ; Duration work = DatatypeConverter . parseDuration ( m_projectFile , TimeUnit . HOURS , baseline . getWork ( ) ) ; if ( number == 0 ) { mpxjResource . setBaselineCost ( cost ) ; mpxjResource . setBaselineWork ( work ) ; } else { mpxjResource . setBaselineCost ( number , cost ) ; mpxjResource . setBaselineWork ( number , work ) ; } } }
Reads baseline values for the current resource .
184
9
144,015
private void readResourceExtendedAttributes ( Project . Resources . Resource xml , Resource mpx ) { for ( Project . Resources . Resource . ExtendedAttribute attrib : xml . getExtendedAttribute ( ) ) { int xmlFieldID = Integer . parseInt ( attrib . getFieldID ( ) ) & 0x0000FFFF ; ResourceField mpxFieldID = MPPResourceField . getInstance ( xmlFieldID ) ; TimeUnit durationFormat = DatatypeConverter . parseDurationTimeUnits ( attrib . getDurationFormat ( ) , null ) ; DatatypeConverter . parseExtendedAttribute ( m_projectFile , mpx , attrib . getValue ( ) , mpxFieldID , durationFormat ) ; } }
This method processes any extended attributes associated with a resource .
158
11
144,016
private void readCostRateTables ( Resource resource , Rates rates ) { if ( rates == null ) { CostRateTable table = new CostRateTable ( ) ; table . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; resource . setCostRateTable ( 0 , table ) ; table = new CostRateTable ( ) ; table . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; resource . setCostRateTable ( 1 , table ) ; table = new CostRateTable ( ) ; table . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; resource . setCostRateTable ( 2 , table ) ; table = new CostRateTable ( ) ; table . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; resource . setCostRateTable ( 3 , table ) ; table = new CostRateTable ( ) ; table . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; resource . setCostRateTable ( 4 , table ) ; } else { Set < CostRateTable > tables = new HashSet < CostRateTable > ( ) ; for ( net . sf . mpxj . mspdi . schema . Project . Resources . Resource . Rates . Rate rate : rates . getRate ( ) ) { Rate standardRate = DatatypeConverter . parseRate ( rate . getStandardRate ( ) ) ; TimeUnit standardRateFormat = DatatypeConverter . parseTimeUnit ( rate . getStandardRateFormat ( ) ) ; Rate overtimeRate = DatatypeConverter . parseRate ( rate . getOvertimeRate ( ) ) ; TimeUnit overtimeRateFormat = DatatypeConverter . parseTimeUnit ( rate . getOvertimeRateFormat ( ) ) ; Double costPerUse = DatatypeConverter . parseCurrency ( rate . getCostPerUse ( ) ) ; Date endDate = rate . getRatesTo ( ) ; CostRateTableEntry entry = new CostRateTableEntry ( standardRate , standardRateFormat , overtimeRate , overtimeRateFormat , costPerUse , endDate ) ; int tableIndex = rate . getRateTable ( ) . intValue ( ) ; CostRateTable table = resource . getCostRateTable ( tableIndex ) ; if ( table == null ) { table = new CostRateTable ( ) ; resource . setCostRateTable ( tableIndex , table ) ; } table . add ( entry ) ; tables . add ( table ) ; } for ( CostRateTable table : tables ) { Collections . sort ( table ) ; } } }
Reads the cost rate tables from the file .
543
10
144,017
private void readAvailabilityTable ( Resource resource , AvailabilityPeriods periods ) { if ( periods != null ) { AvailabilityTable table = resource . getAvailability ( ) ; List < AvailabilityPeriod > list = periods . getAvailabilityPeriod ( ) ; for ( AvailabilityPeriod period : list ) { Date start = period . getAvailableFrom ( ) ; Date end = period . getAvailableTo ( ) ; Number units = DatatypeConverter . parseUnits ( period . getAvailableUnits ( ) ) ; Availability availability = new Availability ( start , end , units ) ; table . add ( availability ) ; } Collections . sort ( table ) ; } }
Reads the availability table from the file .
137
9
144,018
private void readTasks ( Project project ) { Project . Tasks tasks = project . getTasks ( ) ; if ( tasks != null ) { int tasksWithoutIDCount = 0 ; for ( Project . Tasks . Task task : tasks . getTask ( ) ) { Task mpxjTask = readTask ( task ) ; if ( mpxjTask . getID ( ) == null ) { ++ tasksWithoutIDCount ; } } for ( Project . Tasks . Task task : tasks . getTask ( ) ) { readPredecessors ( task ) ; } // // MS Project will happily read tasks from an MSPDI file without IDs, // it will just generate ID values based on the task order in the file. // If we find that there are no ID values present, we'll do the same. // if ( tasksWithoutIDCount == tasks . getTask ( ) . size ( ) ) { m_projectFile . getTasks ( ) . renumberIDs ( ) ; } } m_projectFile . updateStructure ( ) ; }
This method extracts task data from an MSPDI file .
221
12
144,019
private void updateProjectProperties ( Task task ) { ProjectProperties props = m_projectFile . getProjectProperties ( ) ; props . setComments ( task . getNotes ( ) ) ; }
Update the project properties from the project summary task .
42
10
144,020
private void readTaskBaselines ( Project . Tasks . Task xmlTask , Task mpxjTask , TimeUnit durationFormat ) { for ( Project . Tasks . Task . Baseline baseline : xmlTask . getBaseline ( ) ) { int number = NumberHelper . getInt ( baseline . getNumber ( ) ) ; Double cost = DatatypeConverter . parseCurrency ( baseline . getCost ( ) ) ; Duration duration = DatatypeConverter . parseDuration ( m_projectFile , durationFormat , baseline . getDuration ( ) ) ; Date finish = baseline . getFinish ( ) ; Date start = baseline . getStart ( ) ; Duration work = DatatypeConverter . parseDuration ( m_projectFile , TimeUnit . HOURS , baseline . getWork ( ) ) ; if ( number == 0 ) { mpxjTask . setBaselineCost ( cost ) ; mpxjTask . setBaselineDuration ( duration ) ; mpxjTask . setBaselineFinish ( finish ) ; mpxjTask . setBaselineStart ( start ) ; mpxjTask . setBaselineWork ( work ) ; } else { mpxjTask . setBaselineCost ( number , cost ) ; mpxjTask . setBaselineDuration ( number , duration ) ; mpxjTask . setBaselineFinish ( number , finish ) ; mpxjTask . setBaselineStart ( number , start ) ; mpxjTask . setBaselineWork ( number , work ) ; } } }
Reads baseline values for the current task .
324
9
144,021
private void readTaskExtendedAttributes ( Project . Tasks . Task xml , Task mpx ) { for ( Project . Tasks . Task . ExtendedAttribute attrib : xml . getExtendedAttribute ( ) ) { int xmlFieldID = Integer . parseInt ( attrib . getFieldID ( ) ) & 0x0000FFFF ; TaskField mpxFieldID = MPPTaskField . getInstance ( xmlFieldID ) ; TimeUnit durationFormat = DatatypeConverter . parseDurationTimeUnits ( attrib . getDurationFormat ( ) , null ) ; DatatypeConverter . parseExtendedAttribute ( m_projectFile , mpx , attrib . getValue ( ) , mpxFieldID , durationFormat ) ; } }
This method processes any extended attributes associated with a task .
159
11
144,022
private ProjectCalendar getTaskCalendar ( Project . Tasks . Task task ) { ProjectCalendar calendar = null ; BigInteger calendarID = task . getCalendarUID ( ) ; if ( calendarID != null ) { calendar = m_projectFile . getCalendarByUniqueID ( Integer . valueOf ( calendarID . intValue ( ) ) ) ; } return ( calendar ) ; }
This method is used to retrieve the calendar associated with a task . If no calendar is associated with a task this method returns null .
83
26
144,023
private void readPredecessors ( Project . Tasks . Task task ) { Integer uid = task . getUID ( ) ; if ( uid != null ) { Task currTask = m_projectFile . getTaskByUniqueID ( uid ) ; if ( currTask != null ) { for ( Project . Tasks . Task . PredecessorLink link : task . getPredecessorLink ( ) ) { readPredecessor ( currTask , link ) ; } } } }
This method extracts predecessor data from an MSPDI file .
106
12
144,024
private void readPredecessor ( Task currTask , Project . Tasks . Task . PredecessorLink link ) { BigInteger uid = link . getPredecessorUID ( ) ; if ( uid != null ) { Task prevTask = m_projectFile . getTaskByUniqueID ( Integer . valueOf ( uid . intValue ( ) ) ) ; if ( prevTask != null ) { RelationType type ; if ( link . getType ( ) != null ) { type = RelationType . getInstance ( link . getType ( ) . intValue ( ) ) ; } else { type = RelationType . FINISH_START ; } TimeUnit lagUnits = DatatypeConverter . parseDurationTimeUnits ( link . getLagFormat ( ) ) ; Duration lagDuration ; int lag = NumberHelper . getInt ( link . getLinkLag ( ) ) ; if ( lag == 0 ) { lagDuration = Duration . getInstance ( 0 , lagUnits ) ; } else { if ( lagUnits == TimeUnit . PERCENT || lagUnits == TimeUnit . ELAPSED_PERCENT ) { lagDuration = Duration . getInstance ( lag , lagUnits ) ; } else { lagDuration = Duration . convertUnits ( lag / 10.0 , TimeUnit . MINUTES , lagUnits , m_projectFile . getProjectProperties ( ) ) ; } } Relation relation = currTask . addPredecessor ( prevTask , type , lagDuration ) ; m_eventManager . fireRelationReadEvent ( relation ) ; } } }
This method extracts data for a single predecessor from an MSPDI file .
344
15
144,025
private void readAssignments ( Project project ) { Project . Assignments assignments = project . getAssignments ( ) ; if ( assignments != null ) { SplitTaskFactory splitFactory = new SplitTaskFactory ( ) ; TimephasedWorkNormaliser normaliser = new MSPDITimephasedWorkNormaliser ( ) ; for ( Project . Assignments . Assignment assignment : assignments . getAssignment ( ) ) { readAssignment ( assignment , splitFactory , normaliser ) ; } } }
This method extracts assignment data from an MSPDI file .
105
12
144,026
private void readAssignmentBaselines ( Project . Assignments . Assignment assignment , ResourceAssignment mpx ) { for ( Project . Assignments . Assignment . Baseline baseline : assignment . getBaseline ( ) ) { int number = NumberHelper . getInt ( baseline . getNumber ( ) ) ; //baseline.getBCWP() //baseline.getBCWS() Number cost = DatatypeConverter . parseExtendedAttributeCurrency ( baseline . getCost ( ) ) ; Date finish = DatatypeConverter . parseExtendedAttributeDate ( baseline . getFinish ( ) ) ; //baseline.getNumber() Date start = DatatypeConverter . parseExtendedAttributeDate ( baseline . getStart ( ) ) ; Duration work = DatatypeConverter . parseDuration ( m_projectFile , TimeUnit . HOURS , baseline . getWork ( ) ) ; if ( number == 0 ) { mpx . setBaselineCost ( cost ) ; mpx . setBaselineFinish ( finish ) ; mpx . setBaselineStart ( start ) ; mpx . setBaselineWork ( work ) ; } else { mpx . setBaselineCost ( number , cost ) ; mpx . setBaselineWork ( number , work ) ; mpx . setBaselineStart ( number , start ) ; mpx . setBaselineFinish ( number , finish ) ; } } }
Extracts assignment baseline data .
301
7
144,027
private void readAssignmentExtendedAttributes ( Project . Assignments . Assignment xml , ResourceAssignment mpx ) { for ( Project . Assignments . Assignment . ExtendedAttribute attrib : xml . getExtendedAttribute ( ) ) { int xmlFieldID = Integer . parseInt ( attrib . getFieldID ( ) ) & 0x0000FFFF ; AssignmentField mpxFieldID = MPPAssignmentField . getInstance ( xmlFieldID ) ; TimeUnit durationFormat = DatatypeConverter . parseDurationTimeUnits ( attrib . getDurationFormat ( ) , null ) ; DatatypeConverter . parseExtendedAttribute ( m_projectFile , mpx , attrib . getValue ( ) , mpxFieldID , durationFormat ) ; } }
This method processes any extended attributes associated with a resource assignment .
165
12
144,028
private boolean isSplit ( ProjectCalendar calendar , List < TimephasedWork > list ) { boolean result = false ; for ( TimephasedWork assignment : list ) { if ( calendar != null && assignment . getTotalAmount ( ) . getDuration ( ) == 0 ) { Duration calendarWork = calendar . getWork ( assignment . getStart ( ) , assignment . getFinish ( ) , TimeUnit . MINUTES ) ; if ( calendarWork . getDuration ( ) != 0 ) { result = true ; break ; } } } return result ; }
Test to determine if this is a split task .
115
10
144,029
private LinkedList < TimephasedWork > readTimephasedAssignment ( ProjectCalendar calendar , Project . Assignments . Assignment assignment , int type ) { LinkedList < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; for ( TimephasedDataType item : assignment . getTimephasedData ( ) ) { if ( NumberHelper . getInt ( item . getType ( ) ) != type ) { continue ; } Date startDate = item . getStart ( ) ; Date finishDate = item . getFinish ( ) ; // Exclude ranges which don't have a start and end date. // These seem to be generated by Synchro and have a zero duration. if ( startDate == null && finishDate == null ) { continue ; } Duration work = DatatypeConverter . parseDuration ( m_projectFile , TimeUnit . MINUTES , item . getValue ( ) ) ; if ( work == null ) { work = Duration . getInstance ( 0 , TimeUnit . MINUTES ) ; } else { work = Duration . getInstance ( NumberHelper . round ( work . getDuration ( ) , 2 ) , TimeUnit . MINUTES ) ; } TimephasedWork tra = new TimephasedWork ( ) ; tra . setStart ( startDate ) ; tra . setFinish ( finishDate ) ; tra . setTotalAmount ( work ) ; result . add ( tra ) ; } return result ; }
Reads timephased assignment data .
313
8
144,030
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 ; }
Derive a calendar for a resource .
93
8
144,031
public void processTasks ( List < Row > bars , List < Row > expandedTasks , List < Row > tasks , List < Row > milestones ) { List < Row > parentBars = buildRowHierarchy ( bars , expandedTasks , tasks , milestones ) ; createTasks ( m_project , "" , parentBars ) ; deriveProjectCalendar ( ) ; updateStructure ( ) ; }
Organises the data from Asta into a hierarchy and converts this into tasks .
87
16
144,032
private List < Row > buildRowHierarchy ( List < Row > bars , List < Row > expandedTasks , List < Row > tasks , List < Row > milestones ) { // // Create a list of leaf nodes by merging the task and milestone lists // List < Row > leaves = new ArrayList < Row > ( ) ; leaves . addAll ( tasks ) ; leaves . addAll ( milestones ) ; // // Sort the bars and the leaves // Collections . sort ( bars , BAR_COMPARATOR ) ; Collections . sort ( leaves , LEAF_COMPARATOR ) ; // // Map bar IDs to bars // Map < Integer , Row > barIdToBarMap = new HashMap < Integer , Row > ( ) ; for ( Row bar : bars ) { barIdToBarMap . put ( bar . getInteger ( "BARID" ) , bar ) ; } // // Merge expanded task attributes with parent bars // and create an expanded task ID to bar map. // Map < Integer , Row > expandedTaskIdToBarMap = new HashMap < Integer , Row > ( ) ; for ( Row expandedTask : expandedTasks ) { Row bar = barIdToBarMap . get ( expandedTask . getInteger ( "BAR" ) ) ; bar . merge ( expandedTask , "_" ) ; Integer expandedTaskID = bar . getInteger ( "_EXPANDED_TASKID" ) ; expandedTaskIdToBarMap . put ( expandedTaskID , bar ) ; } // // Build the hierarchy // List < Row > parentBars = new ArrayList < Row > ( ) ; for ( Row bar : bars ) { Integer expandedTaskID = bar . getInteger ( "EXPANDED_TASK" ) ; Row parentBar = expandedTaskIdToBarMap . get ( expandedTaskID ) ; if ( parentBar == null ) { parentBars . add ( bar ) ; } else { parentBar . addChild ( bar ) ; } } // // Attach the leaves // for ( Row leaf : leaves ) { Integer barID = leaf . getInteger ( "BAR" ) ; Row bar = barIdToBarMap . get ( barID ) ; bar . addChild ( leaf ) ; } // // Prune any "displaced items" from the top level. // We're using a heuristic here as this is the only thing I // can see which differs between bars that we want to include // and bars that we want to exclude. // Iterator < Row > iter = parentBars . iterator ( ) ; while ( iter . hasNext ( ) ) { Row bar = iter . next ( ) ; String barName = bar . getString ( "NAMH" ) ; if ( barName == null || barName . isEmpty ( ) || barName . equals ( "Displaced Items" ) ) { iter . remove ( ) ; } } // // If we only have a single top level node (effectively a summary task) prune that too. // if ( parentBars . size ( ) == 1 ) { parentBars = parentBars . get ( 0 ) . getChildRows ( ) ; } return parentBars ; }
Builds the task hierarchy .
671
6
144,033
private void createTasks ( ChildTaskContainer parent , String parentName , List < Row > rows ) { for ( Row row : rows ) { boolean rowIsBar = ( row . getInteger ( "BARID" ) != null ) ; // // Don't export hammock tasks. // if ( rowIsBar && row . getChildRows ( ) . isEmpty ( ) ) { continue ; } Task task = parent . addTask ( ) ; // // Do we have a bar, task, or milestone? // if ( rowIsBar ) { // // If the bar only has one child task, we skip it and add the task directly // if ( skipBar ( row ) ) { populateLeaf ( row . getString ( "NAMH" ) , row . getChildRows ( ) . get ( 0 ) , task ) ; } else { populateBar ( row , task ) ; createTasks ( task , task . getName ( ) , row . getChildRows ( ) ) ; } } else { populateLeaf ( parentName , row , task ) ; } m_eventManager . fireTaskReadEvent ( task ) ; } }
Recursively descend through the hierarchy creating tasks .
244
10
144,034
private boolean skipBar ( Row row ) { List < Row > childRows = row . getChildRows ( ) ; return childRows . size ( ) == 1 && childRows . get ( 0 ) . getChildRows ( ) . isEmpty ( ) ; }
Returns true if we should skip this bar i . e . the bar only has a single child task .
59
21
144,035
private void populateLeaf ( String parentName , Row row , Task task ) { if ( row . getInteger ( "TASKID" ) != null ) { populateTask ( row , task ) ; } else { populateMilestone ( row , task ) ; } String name = task . getName ( ) ; if ( name == null || name . isEmpty ( ) ) { task . setName ( parentName ) ; } }
Adds a leaf node which could be a task or a milestone .
91
13
144,036
private void populateTask ( Row row , Task task ) { //"PROJID" task . setUniqueID ( row . getInteger ( "TASKID" ) ) ; //GIVEN_DURATIONTYPF //GIVEN_DURATIONELA_MONTHS task . setDuration ( row . getDuration ( "GIVEN_DURATIONHOURS" ) ) ; task . setResume ( row . getDate ( "RESUME" ) ) ; //task.setStart(row.getDate("GIVEN_START")); //LATEST_PROGRESS_PERIOD //TASK_WORK_RATE_TIME_UNIT //TASK_WORK_RATE //PLACEMENT //BEEN_SPLIT //INTERRUPTIBLE //HOLDING_PIN ///ACTUAL_DURATIONTYPF //ACTUAL_DURATIONELA_MONTHS task . setActualDuration ( row . getDuration ( "ACTUAL_DURATIONHOURS" ) ) ; task . setEarlyStart ( row . getDate ( "EARLY_START_DATE" ) ) ; task . setLateStart ( row . getDate ( "LATE_START_DATE" ) ) ; //FREE_START_DATE //START_CONSTRAINT_DATE //END_CONSTRAINT_DATE //task.setBaselineWork(row.getDuration("EFFORT_BUDGET")); //NATURAO_ORDER //LOGICAL_PRECEDENCE //SPAVE_INTEGER //SWIM_LANE //USER_PERCENT_COMPLETE task . setPercentageComplete ( row . getDouble ( "OVERALL_PERCENV_COMPLETE" ) ) ; //OVERALL_PERCENT_COMPL_WEIGHT task . setName ( row . getString ( "NARE" ) ) ; task . setNotes ( getNotes ( row ) ) ; task . setText ( 1 , row . getString ( "UNIQUE_TASK_ID" ) ) ; task . setCalendar ( m_project . getCalendarByUniqueID ( row . getInteger ( "CALENDAU" ) ) ) ; //EFFORT_TIMI_UNIT //WORL_UNIT //LATEST_ALLOC_PROGRESS_PERIOD //WORN //BAR //CONSTRAINU //PRIORITB //CRITICAM //USE_PARENU_CALENDAR //BUFFER_TASK //MARK_FOS_HIDING //OWNED_BY_TIMESHEEV_X //START_ON_NEX_DAY //LONGEST_PATH //DURATIOTTYPF //DURATIOTELA_MONTHS //DURATIOTHOURS task . setStart ( row . getDate ( "STARZ" ) ) ; task . setFinish ( row . getDate ( "ENJ" ) ) ; //DURATION_TIMJ_UNIT //UNSCHEDULABLG //SUBPROJECT_ID //ALT_ID //LAST_EDITED_DATE //LAST_EDITED_BY processConstraints ( row , task ) ; if ( NumberHelper . getInt ( task . getPercentageComplete ( ) ) != 0 ) { task . setActualStart ( task . getStart ( ) ) ; if ( task . getPercentageComplete ( ) . intValue ( ) == 100 ) { task . setActualFinish ( task . getFinish ( ) ) ; task . setDuration ( task . getActualDuration ( ) ) ; } } }
Populate a task from a Row instance .
806
9
144,037
private void populateBar ( Row row , Task task ) { Integer calendarID = row . getInteger ( "CALENDAU" ) ; ProjectCalendar calendar = m_project . getCalendarByUniqueID ( calendarID ) ; //PROJID task . setUniqueID ( row . getInteger ( "BARID" ) ) ; task . setStart ( row . getDate ( "STARV" ) ) ; task . setFinish ( row . getDate ( "ENF" ) ) ; //NATURAL_ORDER //SPARI_INTEGER task . setName ( row . getString ( "NAMH" ) ) ; //EXPANDED_TASK //PRIORITY //UNSCHEDULABLE //MARK_FOR_HIDING //TASKS_MAY_OVERLAP //SUBPROJECT_ID //ALT_ID //LAST_EDITED_DATE //LAST_EDITED_BY //Proc_Approve //Proc_Design_info //Proc_Proc_Dur //Proc_Procurement //Proc_SC_design //Proc_Select_SC //Proc_Tender //QA Checked //Related_Documents task . setCalendar ( calendar ) ; }
Uses data from a bar to populate a task .
275
11
144,038
private void populateMilestone ( Row row , Task task ) { task . setMilestone ( true ) ; //PROJID task . setUniqueID ( row . getInteger ( "MILESTONEID" ) ) ; task . setStart ( row . getDate ( "GIVEN_DATE_TIME" ) ) ; task . setFinish ( row . getDate ( "GIVEN_DATE_TIME" ) ) ; //PROGREST_PERIOD //SYMBOL_APPEARANCE //MILESTONE_TYPE //PLACEMENU task . setPercentageComplete ( row . getBoolean ( "COMPLETED" ) ? COMPLETE : INCOMPLETE ) ; //INTERRUPTIBLE_X //ACTUAL_DURATIONTYPF //ACTUAL_DURATIONELA_MONTHS //ACTUAL_DURATIONHOURS task . setEarlyStart ( row . getDate ( "EARLY_START_DATE" ) ) ; task . setLateStart ( row . getDate ( "LATE_START_DATE" ) ) ; //FREE_START_DATE //START_CONSTRAINT_DATE //END_CONSTRAINT_DATE //EFFORT_BUDGET //NATURAO_ORDER //LOGICAL_PRECEDENCE //SPAVE_INTEGER //SWIM_LANE //USER_PERCENT_COMPLETE //OVERALL_PERCENV_COMPLETE //OVERALL_PERCENT_COMPL_WEIGHT task . setName ( row . getString ( "NARE" ) ) ; //NOTET task . setText ( 1 , row . getString ( "UNIQUE_TASK_ID" ) ) ; task . setCalendar ( m_project . getCalendarByUniqueID ( row . getInteger ( "CALENDAU" ) ) ) ; //EFFORT_TIMI_UNIT //WORL_UNIT //LATEST_ALLOC_PROGRESS_PERIOD //WORN //CONSTRAINU //PRIORITB //CRITICAM //USE_PARENU_CALENDAR //BUFFER_TASK //MARK_FOS_HIDING //OWNED_BY_TIMESHEEV_X //START_ON_NEX_DAY //LONGEST_PATH //DURATIOTTYPF //DURATIOTELA_MONTHS //DURATIOTHOURS //STARZ //ENJ //DURATION_TIMJ_UNIT //UNSCHEDULABLG //SUBPROJECT_ID //ALT_ID //LAST_EDITED_DATE //LAST_EDITED_BY task . setDuration ( Duration . getInstance ( 0 , TimeUnit . HOURS ) ) ; }
Populate a milestone from a Row instance .
620
9
144,039
private String getInitials ( String name ) { String result = null ; if ( name != null && name . length ( ) != 0 ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( name . charAt ( 0 ) ) ; int index = 1 ; while ( true ) { index = name . indexOf ( ' ' , index ) ; if ( index == - 1 ) { break ; } ++ index ; if ( index < name . length ( ) && name . charAt ( index ) != ' ' ) { sb . append ( name . charAt ( index ) ) ; } ++ index ; } result = sb . toString ( ) ; } return result ; }
Convert a name into initials .
148
7
144,040
private void deriveProjectCalendar ( ) { // // Count the number of times each calendar is used // Map < ProjectCalendar , Integer > map = new HashMap < ProjectCalendar , Integer > ( ) ; for ( Task task : m_project . getTasks ( ) ) { ProjectCalendar calendar = task . getCalendar ( ) ; Integer count = map . get ( calendar ) ; if ( count == null ) { count = Integer . valueOf ( 1 ) ; } else { count = Integer . valueOf ( count . intValue ( ) + 1 ) ; } map . put ( calendar , count ) ; } // // Find the most frequently used calendar // int maxCount = 0 ; ProjectCalendar defaultCalendar = null ; for ( Entry < ProjectCalendar , Integer > entry : map . entrySet ( ) ) { if ( entry . getValue ( ) . intValue ( ) > maxCount ) { maxCount = entry . getValue ( ) . intValue ( ) ; defaultCalendar = entry . getKey ( ) ; } } // // Set the default calendar for the project // and remove it's use as a task-specific calendar. // if ( defaultCalendar != null ) { m_project . setDefaultCalendar ( defaultCalendar ) ; for ( Task task : m_project . getTasks ( ) ) { if ( task . getCalendar ( ) == defaultCalendar ) { task . setCalendar ( null ) ; } } } }
Asta Powerproject assigns an explicit calendar for each task . This method is used to find the most common calendar and use this as the default project calendar . This allows the explicitly assigned task calendars to be removed .
311
42
144,041
private void processConstraints ( Row row , Task task ) { ConstraintType constraintType = ConstraintType . AS_SOON_AS_POSSIBLE ; Date constraintDate = null ; switch ( row . getInt ( "CONSTRAINU" ) ) { case 0 : { if ( row . getInt ( "PLACEMENT" ) == 0 ) { constraintType = ConstraintType . AS_SOON_AS_POSSIBLE ; } else { constraintType = ConstraintType . AS_LATE_AS_POSSIBLE ; } break ; } case 1 : { constraintType = ConstraintType . MUST_START_ON ; constraintDate = row . getDate ( "START_CONSTRAINT_DATE" ) ; break ; } case 2 : { constraintType = ConstraintType . START_NO_LATER_THAN ; constraintDate = row . getDate ( "START_CONSTRAINT_DATE" ) ; break ; } case 3 : { constraintType = ConstraintType . START_NO_EARLIER_THAN ; constraintDate = row . getDate ( "START_CONSTRAINT_DATE" ) ; break ; } case 4 : { constraintType = ConstraintType . MUST_FINISH_ON ; constraintDate = row . getDate ( "END_CONSTRAINT_DATE" ) ; break ; } case 5 : { constraintType = ConstraintType . FINISH_NO_LATER_THAN ; constraintDate = row . getDate ( "END_CONSTRAINT_DATE" ) ; break ; } case 6 : { constraintType = ConstraintType . FINISH_NO_EARLIER_THAN ; constraintDate = row . getDate ( "END_CONSTRAINT_DATE" ) ; break ; } case 8 : { task . setDeadline ( row . getDate ( "END_CONSTRAINT_DATE" ) ) ; break ; } } task . setConstraintType ( constraintType ) ; task . setConstraintDate ( constraintDate ) ; }
Determines the constraints relating to a task .
461
10
144,042
public Map < Integer , Row > createWorkPatternMap ( List < Row > rows ) { Map < Integer , Row > map = new HashMap < Integer , Row > ( ) ; for ( Row row : rows ) { map . put ( row . getInteger ( "WORK_PATTERNID" ) , row ) ; } return map ; }
Creates a map of work pattern rows indexed by the primary key .
73
14
144,043
public Map < Integer , List < Row > > createWorkPatternAssignmentMap ( List < Row > rows ) { Map < Integer , List < Row > > map = new HashMap < Integer , List < Row > > ( ) ; for ( Row row : rows ) { Integer calendarID = row . getInteger ( "WORK_PATTERN_ASSIGNMENTID" ) ; List < Row > list = map . get ( calendarID ) ; if ( list == null ) { list = new LinkedList < Row > ( ) ; map . put ( calendarID , list ) ; } list . add ( row ) ; } return map ; }
Creates a map between a calendar ID and a list of work pattern assignment rows .
136
17
144,044
public Map < Integer , List < Row > > createTimeEntryMap ( List < Row > rows ) { Map < Integer , List < Row > > map = new HashMap < Integer , List < Row > > ( ) ; for ( Row row : rows ) { Integer workPatternID = row . getInteger ( "TIME_ENTRYID" ) ; List < Row > list = map . get ( workPatternID ) ; if ( list == null ) { list = new LinkedList < Row > ( ) ; map . put ( workPatternID , list ) ; } list . add ( row ) ; } return map ; }
Creates a map between a work pattern ID and a list of time entry rows .
132
17
144,045
public void processCalendar ( Row calendarRow , Map < Integer , Row > workPatternMap , Map < Integer , List < Row > > workPatternAssignmentMap , Map < Integer , List < Row > > exceptionAssignmentMap , Map < Integer , List < Row > > timeEntryMap , Map < Integer , DayType > exceptionTypeMap ) { // // Create the calendar and add the default working hours // ProjectCalendar calendar = m_project . addCalendar ( ) ; Integer dominantWorkPatternID = calendarRow . getInteger ( "DOMINANT_WORK_PATTERN" ) ; calendar . setUniqueID ( calendarRow . getInteger ( "CALENDARID" ) ) ; processWorkPattern ( calendar , dominantWorkPatternID , workPatternMap , timeEntryMap , exceptionTypeMap ) ; calendar . setName ( calendarRow . getString ( "NAMK" ) ) ; // // Add any additional working weeks // List < Row > rows = workPatternAssignmentMap . get ( calendar . getUniqueID ( ) ) ; if ( rows != null ) { for ( Row row : rows ) { Integer workPatternID = row . getInteger ( "WORK_PATTERN" ) ; if ( ! workPatternID . equals ( dominantWorkPatternID ) ) { ProjectCalendarWeek week = calendar . addWorkWeek ( ) ; week . setDateRange ( new DateRange ( row . getDate ( "START_DATE" ) , row . getDate ( "END_DATE" ) ) ) ; processWorkPattern ( week , workPatternID , workPatternMap , timeEntryMap , exceptionTypeMap ) ; } } } // // Add exceptions - not sure how exceptions which turn non-working days into working days are handled by Asta - if at all? // rows = exceptionAssignmentMap . get ( calendar . getUniqueID ( ) ) ; if ( rows != null ) { for ( Row row : rows ) { Date startDate = row . getDate ( "STARU_DATE" ) ; Date endDate = row . getDate ( "ENE_DATE" ) ; calendar . addCalendarException ( startDate , endDate ) ; } } m_eventManager . fireCalendarReadEvent ( calendar ) ; }
Creates a ProjectCalendar instance from the Asta data .
479
13
144,046
private void processWorkPattern ( ProjectCalendarWeek week , Integer workPatternID , Map < Integer , Row > workPatternMap , Map < Integer , List < Row > > timeEntryMap , Map < Integer , DayType > exceptionTypeMap ) { Row workPatternRow = workPatternMap . get ( workPatternID ) ; if ( workPatternRow != null ) { week . setName ( workPatternRow . getString ( "NAMN" ) ) ; List < Row > timeEntryRows = timeEntryMap . get ( workPatternID ) ; if ( timeEntryRows != null ) { long lastEndTime = Long . MIN_VALUE ; Day currentDay = Day . SUNDAY ; ProjectCalendarHours hours = week . addCalendarHours ( currentDay ) ; Arrays . fill ( week . getDays ( ) , DayType . NON_WORKING ) ; for ( Row row : timeEntryRows ) { Date startTime = row . getDate ( "START_TIME" ) ; Date endTime = row . getDate ( "END_TIME" ) ; if ( startTime == null ) { startTime = DateHelper . getDayStartDate ( new Date ( 0 ) ) ; } if ( endTime == null ) { endTime = DateHelper . getDayEndDate ( new Date ( 0 ) ) ; } if ( startTime . getTime ( ) > endTime . getTime ( ) ) { endTime = DateHelper . addDays ( endTime , 1 ) ; } if ( startTime . getTime ( ) < lastEndTime ) { currentDay = currentDay . getNextDay ( ) ; hours = week . addCalendarHours ( currentDay ) ; } DayType type = exceptionTypeMap . get ( row . getInteger ( "EXCEPTIOP" ) ) ; if ( type == DayType . WORKING ) { hours . addRange ( new DateRange ( startTime , endTime ) ) ; week . setWorkingDay ( currentDay , DayType . WORKING ) ; } lastEndTime = endTime . getTime ( ) ; } } } }
Populates a ProjectCalendarWeek instance from Asta work pattern data .
444
15
144,047
private String getNotes ( Row row ) { String notes = row . getString ( "NOTET" ) ; if ( notes != null ) { if ( notes . isEmpty ( ) ) { notes = null ; } else { if ( notes . indexOf ( LINE_BREAK ) != - 1 ) { notes = notes . replace ( LINE_BREAK , "\n" ) ; } } } return notes ; }
Extract note text .
87
5
144,048
private void addListeners ( ProjectReader reader ) { if ( m_projectListeners != null ) { for ( ProjectListener listener : m_projectListeners ) { reader . addProjectListener ( listener ) ; } } }
Adds any listeners attached to this reader to the reader created internally .
47
13
144,049
private ProjectFile readTextFile ( InputStream inputStream ) throws MPXJException { ProjectReader reader = new AstaTextFileReader ( ) ; addListeners ( reader ) ; return reader . read ( inputStream ) ; }
Process a text - based PP file .
48
8
144,050
private ProjectFile readDatabaseFile ( InputStream inputStream ) throws MPXJException { ProjectReader reader = new AstaDatabaseFileReader ( ) ; addListeners ( reader ) ; return reader . read ( inputStream ) ; }
Process a SQLite database PP file .
48
8
144,051
public static String getFileFormat ( POIFSFileSystem fs ) throws IOException { String fileFormat = "" ; DirectoryEntry root = fs . getRoot ( ) ; if ( root . getEntryNames ( ) . contains ( "\1CompObj" ) ) { CompObj compObj = new CompObj ( new DocumentInputStream ( ( DocumentEntry ) root . getEntry ( "\1CompObj" ) ) ) ; fileFormat = compObj . getFileFormat ( ) ; } return fileFormat ; }
This method allows us to peek into the OLE compound document to extract the file format . This allows the UniversalProjectReader to determine if this is an MPP file or if it is another type of OLE compound document .
105
45
144,052
public ProjectFile read ( POIFSFileSystem fs ) throws MPXJException { try { ProjectFile projectFile = new ProjectFile ( ) ; ProjectConfig config = projectFile . getProjectConfig ( ) ; config . setAutoTaskID ( false ) ; config . setAutoTaskUniqueID ( false ) ; config . setAutoResourceID ( false ) ; config . setAutoResourceUniqueID ( false ) ; config . setAutoOutlineLevel ( false ) ; config . setAutoOutlineNumber ( false ) ; config . setAutoWBS ( false ) ; config . setAutoCalendarUniqueID ( false ) ; config . setAutoAssignmentUniqueID ( false ) ; projectFile . getEventManager ( ) . addProjectListeners ( m_projectListeners ) ; // // Open the file system and retrieve the root directory // DirectoryEntry root = fs . getRoot ( ) ; // // Retrieve the CompObj data, validate the file format and process // CompObj compObj = new CompObj ( new DocumentInputStream ( ( DocumentEntry ) root . getEntry ( "\1CompObj" ) ) ) ; ProjectProperties projectProperties = projectFile . getProjectProperties ( ) ; projectProperties . setFullApplicationName ( compObj . getApplicationName ( ) ) ; projectProperties . setApplicationVersion ( compObj . getApplicationVersion ( ) ) ; String format = compObj . getFileFormat ( ) ; Class < ? extends MPPVariantReader > readerClass = FILE_CLASS_MAP . get ( format ) ; if ( readerClass == null ) { throw new MPXJException ( MPXJException . INVALID_FILE + ": " + format ) ; } MPPVariantReader reader = readerClass . newInstance ( ) ; reader . process ( this , projectFile , root ) ; // // Update the internal structure. We'll take this opportunity to // generate outline numbers for the tasks as they don't appear to // be present in the MPP file. // config . setAutoOutlineNumber ( true ) ; projectFile . updateStructure ( ) ; config . setAutoOutlineNumber ( false ) ; // // Perform post-processing to set the summary flag and clean // up any instances where a task has an empty splits list. // for ( Task task : projectFile . getTasks ( ) ) { task . setSummary ( task . hasChildTasks ( ) ) ; List < DateRange > splits = task . getSplits ( ) ; if ( splits != null && splits . isEmpty ( ) ) { task . setSplits ( null ) ; } validationRelations ( task ) ; } // // Ensure that the unique ID counters are correct // config . updateUniqueCounters ( ) ; // // Add some analytics // String projectFilePath = projectFile . getProjectProperties ( ) . getProjectFilePath ( ) ; if ( projectFilePath != null && projectFilePath . startsWith ( "<>\\" ) ) { projectProperties . setFileApplication ( "Microsoft Project Server" ) ; } else { projectProperties . setFileApplication ( "Microsoft" ) ; } projectProperties . setFileType ( "MPP" ) ; return ( projectFile ) ; } catch ( IOException ex ) { throw new MPXJException ( MPXJException . READ_ERROR , ex ) ; } catch ( IllegalAccessException ex ) { throw new MPXJException ( MPXJException . READ_ERROR , ex ) ; } catch ( InstantiationException ex ) { throw new MPXJException ( MPXJException . READ_ERROR , ex ) ; } }
Alternative entry point allowing an MPP file to be read from a user - supplied POI file stream .
762
21
144,053
private void validationRelations ( Task task ) { List < Relation > predecessors = task . getPredecessors ( ) ; if ( ! predecessors . isEmpty ( ) ) { ArrayList < Relation > invalid = new ArrayList < Relation > ( ) ; for ( Relation relation : predecessors ) { Task sourceTask = relation . getSourceTask ( ) ; Task targetTask = relation . getTargetTask ( ) ; String sourceOutlineNumber = sourceTask . getOutlineNumber ( ) ; String targetOutlineNumber = targetTask . getOutlineNumber ( ) ; if ( sourceOutlineNumber != null && targetOutlineNumber != null && sourceOutlineNumber . startsWith ( targetOutlineNumber + ' ' ) ) { invalid . add ( relation ) ; } } for ( Relation relation : invalid ) { relation . getSourceTask ( ) . removePredecessor ( relation . getTargetTask ( ) , relation . getType ( ) , relation . getLag ( ) ) ; } } }
This method validates all relationships for a task removing any which have been incorrectly read from the MPP file and point to a parent task .
211
28
144,054
public static TaskField getMpxjField ( int value ) { TaskField result = null ; if ( value >= 0 && value < MPX_MPXJ_ARRAY . length ) { result = MPX_MPXJ_ARRAY [ value ] ; } return ( result ) ; }
Retrieve an instance of the TaskField class based on the data read from an MPX file .
63
20
144,055
public static int getMpxField ( int value ) { int result = 0 ; if ( value >= 0 && value < MPXJ_MPX_ARRAY . length ) { result = MPXJ_MPX_ARRAY [ value ] ; } return ( result ) ; }
Retrieve the integer value used to represent a task field in an MPX file .
60
17
144,056
public Task add ( ) { Task task = new Task ( m_projectFile , ( Task ) null ) ; add ( task ) ; m_projectFile . getChildTasks ( ) . add ( task ) ; return task ; }
Add a task to the project .
49
7
144,057
public void synchronizeTaskIDToHierarchy ( ) { clear ( ) ; int currentID = ( getByID ( Integer . valueOf ( 0 ) ) == null ? 1 : 0 ) ; for ( Task task : m_projectFile . getChildTasks ( ) ) { task . setID ( Integer . valueOf ( currentID ++ ) ) ; add ( task ) ; currentID = synchroizeTaskIDToHierarchy ( task , currentID ) ; } }
Microsoft Project bases the order of tasks displayed on their ID value . This method takes the hierarchical structure of tasks represented in MPXJ and renumbers the ID values to ensure that this structure is displayed as expected in Microsoft Project . This is typically used to deal with the case where a hierarchical task structure has been created programmatically in MPXJ .
103
69
144,058
private int synchroizeTaskIDToHierarchy ( Task parentTask , int currentID ) { for ( Task task : parentTask . getChildTasks ( ) ) { task . setID ( Integer . valueOf ( currentID ++ ) ) ; add ( task ) ; currentID = synchroizeTaskIDToHierarchy ( task , currentID ) ; } return currentID ; }
Called recursively to renumber child task IDs .
85
12
144,059
public void updateStructure ( ) { if ( size ( ) > 1 ) { Collections . sort ( this ) ; m_projectFile . getChildTasks ( ) . clear ( ) ; Task lastTask = null ; int lastLevel = - 1 ; boolean autoWbs = m_projectFile . getProjectConfig ( ) . getAutoWBS ( ) ; boolean autoOutlineNumber = m_projectFile . getProjectConfig ( ) . getAutoOutlineNumber ( ) ; for ( Task task : this ) { task . clearChildTasks ( ) ; Task parent = null ; if ( ! task . getNull ( ) ) { int level = NumberHelper . getInt ( task . getOutlineLevel ( ) ) ; if ( lastTask != null ) { if ( level == lastLevel || task . getNull ( ) ) { parent = lastTask . getParentTask ( ) ; level = lastLevel ; } else { if ( level > lastLevel ) { parent = lastTask ; } else { while ( level <= lastLevel ) { parent = lastTask . getParentTask ( ) ; if ( parent == null ) { break ; } lastLevel = NumberHelper . getInt ( parent . getOutlineLevel ( ) ) ; lastTask = parent ; } } } } lastTask = task ; lastLevel = level ; if ( autoWbs || task . getWBS ( ) == null ) { task . generateWBS ( parent ) ; } if ( autoOutlineNumber ) { task . generateOutlineNumber ( parent ) ; } } if ( parent == null ) { m_projectFile . getChildTasks ( ) . add ( task ) ; } else { parent . addChildTask ( task ) ; } } } }
This method is used to recreate the hierarchical structure of the project file from scratch . The method sorts the list of all tasks then iterates through it creating the parent - child structure defined by the outline level field .
365
42
144,060
private void process ( String input , String output ) throws MPXJException , IOException { // // Extract the project data // MPPReader reader = new MPPReader ( ) ; m_project = reader . read ( input ) ; String varDataFileName ; String projectDirName ; int mppFileType = NumberHelper . getInt ( m_project . getProjectProperties ( ) . getMppFileType ( ) ) ; switch ( mppFileType ) { case 8 : { projectDirName = " 1" ; varDataFileName = "FixDeferFix 0" ; break ; } case 9 : { projectDirName = " 19" ; varDataFileName = "Var2Data" ; break ; } case 12 : { projectDirName = " 112" ; varDataFileName = "Var2Data" ; break ; } case 14 : { projectDirName = " 114" ; varDataFileName = "Var2Data" ; break ; } default : { throw new IllegalArgumentException ( "Unsupported file type " + mppFileType ) ; } } // // Load the raw file // FileInputStream is = new FileInputStream ( input ) ; POIFSFileSystem fs = new POIFSFileSystem ( is ) ; is . close ( ) ; // // Locate the root of the project file system // DirectoryEntry root = fs . getRoot ( ) ; m_projectDir = ( DirectoryEntry ) root . getEntry ( projectDirName ) ; // // Process Tasks // Map < String , String > replacements = new HashMap < String , String > ( ) ; for ( Task task : m_project . getTasks ( ) ) { mapText ( task . getName ( ) , replacements ) ; } processReplacements ( ( ( DirectoryEntry ) m_projectDir . getEntry ( "TBkndTask" ) ) , varDataFileName , replacements , true ) ; // // Process Resources // replacements . clear ( ) ; for ( Resource resource : m_project . getResources ( ) ) { mapText ( resource . getName ( ) , replacements ) ; mapText ( resource . getInitials ( ) , replacements ) ; } processReplacements ( ( DirectoryEntry ) m_projectDir . getEntry ( "TBkndRsc" ) , varDataFileName , replacements , true ) ; // // Process project properties // replacements . clear ( ) ; ProjectProperties properties = m_project . getProjectProperties ( ) ; mapText ( properties . getProjectTitle ( ) , replacements ) ; processReplacements ( m_projectDir , "Props" , replacements , true ) ; replacements . clear ( ) ; mapText ( properties . getProjectTitle ( ) , replacements ) ; mapText ( properties . getSubject ( ) , replacements ) ; mapText ( properties . getAuthor ( ) , replacements ) ; mapText ( properties . getKeywords ( ) , replacements ) ; mapText ( properties . getComments ( ) , replacements ) ; processReplacements ( root , "\005SummaryInformation" , replacements , false ) ; replacements . clear ( ) ; mapText ( properties . getManager ( ) , replacements ) ; mapText ( properties . getCompany ( ) , replacements ) ; mapText ( properties . getCategory ( ) , replacements ) ; processReplacements ( root , "\005DocumentSummaryInformation" , replacements , false ) ; // // Write the replacement raw file // FileOutputStream os = new FileOutputStream ( output ) ; fs . writeFilesystem ( os ) ; os . flush ( ) ; os . close ( ) ; fs . close ( ) ; }
Process an MPP file to make it anonymous .
761
10
144,061
private void mapText ( String oldText , Map < String , String > replacements ) { char c2 = 0 ; if ( oldText != null && oldText . length ( ) != 0 && ! replacements . containsKey ( oldText ) ) { StringBuilder newText = new StringBuilder ( oldText . length ( ) ) ; for ( int loop = 0 ; loop < oldText . length ( ) ; loop ++ ) { char c = oldText . charAt ( loop ) ; if ( Character . isUpperCase ( c ) ) { newText . append ( ' ' ) ; } else { if ( Character . isLowerCase ( c ) ) { newText . append ( ' ' ) ; } else { if ( Character . isDigit ( c ) ) { newText . append ( ' ' ) ; } else { if ( Character . isLetter ( c ) ) { // Handle other codepages etc. If possible find a way to // maintain the same code page as original. // E.g. replace with a character from the same alphabet. // This 'should' work for most cases if ( c2 == 0 ) { c2 = c ; } newText . append ( c2 ) ; } else { newText . append ( c ) ; } } } } } replacements . put ( oldText , newText . toString ( ) ) ; } }
Converts plan text into anonymous text . Preserves upper case lower case punctuation whitespace and digits while making the text unreadable .
287
27
144,062
private byte [ ] getBytes ( String value , boolean unicode ) { byte [ ] result ; if ( unicode ) { int start = 0 ; // Get the bytes in UTF-16 byte [ ] bytes ; try { bytes = value . getBytes ( "UTF-16" ) ; } catch ( UnsupportedEncodingException e ) { bytes = value . getBytes ( ) ; } if ( bytes . length > 2 && bytes [ 0 ] == - 2 && bytes [ 1 ] == - 1 ) { // Skip the unicode identifier start = 2 ; } result = new byte [ bytes . length - start ] ; for ( int loop = start ; loop < bytes . length - 1 ; loop += 2 ) { // Swap the order here result [ loop - start ] = bytes [ loop + 1 ] ; result [ loop + 1 - start ] = bytes [ loop ] ; } } else { result = new byte [ value . length ( ) + 1 ] ; System . arraycopy ( value . getBytes ( ) , 0 , result , 0 , value . length ( ) ) ; } return ( result ) ; }
Convert a Java String instance into the equivalent array of single or double bytes .
232
16
144,063
private boolean compareBytes ( byte [ ] lhs , byte [ ] rhs , int rhsOffset ) { boolean result = true ; for ( int loop = 0 ; loop < lhs . length ; loop ++ ) { if ( lhs [ loop ] != rhs [ rhsOffset + loop ] ) { result = false ; break ; } } return ( result ) ; }
Compare an array of bytes with a subsection of a larger array of bytes .
79
15
144,064
private void writeCurrency ( ) { ProjectProperties props = m_projectFile . getProjectProperties ( ) ; CurrencyType currency = m_factory . createCurrencyType ( ) ; m_apibo . getCurrency ( ) . add ( currency ) ; String positiveSymbol = getCurrencyFormat ( props . getSymbolPosition ( ) ) ; String negativeSymbol = "(" + positiveSymbol + ")" ; currency . setDecimalPlaces ( props . getCurrencyDigits ( ) ) ; currency . setDecimalSymbol ( getSymbolName ( props . getDecimalSeparator ( ) ) ) ; currency . setDigitGroupingSymbol ( getSymbolName ( props . getThousandsSeparator ( ) ) ) ; currency . setExchangeRate ( Double . valueOf ( 1.0 ) ) ; currency . setId ( "CUR" ) ; currency . setName ( "Default Currency" ) ; currency . setNegativeSymbol ( negativeSymbol ) ; currency . setObjectId ( DEFAULT_CURRENCY_ID ) ; currency . setPositiveSymbol ( positiveSymbol ) ; currency . setSymbol ( props . getCurrencySymbol ( ) ) ; }
Create a handful of default currencies to keep Primavera happy .
264
14
144,065
private String getSymbolName ( char c ) { String result = null ; switch ( c ) { case ' ' : { result = "Comma" ; break ; } case ' ' : { result = "Period" ; break ; } } return result ; }
Map the currency separator character to a symbol name .
56
11
144,066
private String getCurrencyFormat ( CurrencySymbolPosition position ) { String result ; switch ( position ) { case AFTER : { result = "1.1#" ; break ; } case AFTER_WITH_SPACE : { result = "1.1 #" ; break ; } case BEFORE_WITH_SPACE : { result = "# 1.1" ; break ; } default : case BEFORE : { result = "#1.1" ; break ; } } return result ; }
Generate a currency format .
103
6
144,067
private void writeUserFieldDefinitions ( ) { for ( CustomField cf : m_sortedCustomFieldsList ) { if ( cf . getFieldType ( ) != null && cf . getFieldType ( ) . getDataType ( ) != null ) { UDFTypeType udf = m_factory . createUDFTypeType ( ) ; udf . setObjectId ( Integer . valueOf ( FieldTypeHelper . getFieldID ( cf . getFieldType ( ) ) ) ) ; udf . setDataType ( UserFieldDataType . inferUserFieldDataType ( cf . getFieldType ( ) . getDataType ( ) ) ) ; udf . setSubjectArea ( UserFieldDataType . inferUserFieldSubjectArea ( cf . getFieldType ( ) ) ) ; udf . setTitle ( cf . getAlias ( ) ) ; m_apibo . getUDFType ( ) . add ( udf ) ; } } }
Add UDFType objects to a PM XML file .
203
11
144,068
private void writeCalendar ( ProjectCalendar mpxj ) { CalendarType xml = m_factory . createCalendarType ( ) ; m_apibo . getCalendar ( ) . add ( xml ) ; String type = mpxj . getResource ( ) == null ? "Global" : "Resource" ; xml . setBaseCalendarObjectId ( getCalendarUniqueID ( mpxj . getParent ( ) ) ) ; xml . setIsPersonal ( mpxj . getResource ( ) == null ? Boolean . FALSE : Boolean . TRUE ) ; xml . setName ( mpxj . getName ( ) ) ; xml . setObjectId ( mpxj . getUniqueID ( ) ) ; xml . setType ( type ) ; StandardWorkWeek xmlStandardWorkWeek = m_factory . createCalendarTypeStandardWorkWeek ( ) ; xml . setStandardWorkWeek ( xmlStandardWorkWeek ) ; for ( Day day : EnumSet . allOf ( Day . class ) ) { StandardWorkHours xmlHours = m_factory . createCalendarTypeStandardWorkWeekStandardWorkHours ( ) ; xmlStandardWorkWeek . getStandardWorkHours ( ) . add ( xmlHours ) ; xmlHours . setDayOfWeek ( getDayName ( day ) ) ; for ( DateRange range : mpxj . getHours ( day ) ) { WorkTimeType xmlWorkTime = m_factory . createWorkTimeType ( ) ; xmlHours . getWorkTime ( ) . add ( xmlWorkTime ) ; xmlWorkTime . setStart ( range . getStart ( ) ) ; xmlWorkTime . setFinish ( getEndTime ( range . getEnd ( ) ) ) ; } } HolidayOrExceptions xmlExceptions = m_factory . createCalendarTypeHolidayOrExceptions ( ) ; xml . setHolidayOrExceptions ( xmlExceptions ) ; if ( ! mpxj . getCalendarExceptions ( ) . isEmpty ( ) ) { Calendar calendar = DateHelper . popCalendar ( ) ; for ( ProjectCalendarException mpxjException : mpxj . getCalendarExceptions ( ) ) { calendar . setTime ( mpxjException . getFromDate ( ) ) ; while ( calendar . getTimeInMillis ( ) < mpxjException . getToDate ( ) . getTime ( ) ) { HolidayOrException xmlException = m_factory . createCalendarTypeHolidayOrExceptionsHolidayOrException ( ) ; xmlExceptions . getHolidayOrException ( ) . add ( xmlException ) ; xmlException . setDate ( calendar . getTime ( ) ) ; for ( DateRange range : mpxjException ) { WorkTimeType xmlHours = m_factory . createWorkTimeType ( ) ; xmlException . getWorkTime ( ) . add ( xmlHours ) ; xmlHours . setStart ( range . getStart ( ) ) ; if ( range . getEnd ( ) != null ) { xmlHours . setFinish ( getEndTime ( range . getEnd ( ) ) ) ; } } calendar . add ( Calendar . DAY_OF_YEAR , 1 ) ; } } DateHelper . pushCalendar ( calendar ) ; } }
This method writes data for an individual calendar to a PM XML file .
684
14
144,069
private void writeResources ( ) { for ( Resource resource : m_projectFile . getResources ( ) ) { if ( resource . getUniqueID ( ) . intValue ( ) != 0 ) { writeResource ( resource ) ; } } }
This method writes resource data to a PM XML file .
50
11
144,070
private void writeResource ( Resource mpxj ) { ResourceType xml = m_factory . createResourceType ( ) ; m_apibo . getResource ( ) . add ( xml ) ; xml . setAutoComputeActuals ( Boolean . TRUE ) ; xml . setCalculateCostFromUnits ( Boolean . TRUE ) ; xml . setCalendarObjectId ( getCalendarUniqueID ( mpxj . getResourceCalendar ( ) ) ) ; xml . setCurrencyObjectId ( DEFAULT_CURRENCY_ID ) ; xml . setDefaultUnitsPerTime ( Double . valueOf ( 1.0 ) ) ; xml . setEmailAddress ( mpxj . getEmailAddress ( ) ) ; xml . setGUID ( DatatypeConverter . printUUID ( mpxj . getGUID ( ) ) ) ; xml . setId ( RESOURCE_ID_PREFIX + mpxj . getUniqueID ( ) ) ; xml . setIsActive ( Boolean . TRUE ) ; xml . setMaxUnitsPerTime ( getPercentage ( mpxj . getMaxUnits ( ) ) ) ; xml . setName ( mpxj . getName ( ) ) ; xml . setObjectId ( mpxj . getUniqueID ( ) ) ; xml . setParentObjectId ( mpxj . getParentID ( ) ) ; xml . setResourceNotes ( mpxj . getNotes ( ) ) ; xml . setResourceType ( getResourceType ( mpxj ) ) ; xml . getUDF ( ) . addAll ( writeUDFType ( FieldTypeClass . RESOURCE , mpxj ) ) ; }
Write a single resource .
357
5
144,071
private void writeTask ( Task task ) { if ( ! task . getNull ( ) ) { if ( extractAndConvertTaskType ( task ) == null || task . getSummary ( ) ) { writeWBS ( task ) ; } else { writeActivity ( task ) ; } } }
Given a Task instance this task determines if it should be written to the PM XML file as an activity or as a WBS item and calls the appropriate method .
61
32
144,072
private void writeWBS ( Task mpxj ) { if ( mpxj . getUniqueID ( ) . intValue ( ) != 0 ) { WBSType xml = m_factory . createWBSType ( ) ; m_project . getWBS ( ) . add ( xml ) ; String code = mpxj . getWBS ( ) ; code = code == null || code . length ( ) == 0 ? DEFAULT_WBS_CODE : code ; Task parentTask = mpxj . getParentTask ( ) ; Integer parentObjectID = parentTask == null ? null : parentTask . getUniqueID ( ) ; xml . setCode ( code ) ; xml . setGUID ( DatatypeConverter . printUUID ( mpxj . getGUID ( ) ) ) ; xml . setName ( mpxj . getName ( ) ) ; xml . setObjectId ( mpxj . getUniqueID ( ) ) ; xml . setParentObjectId ( parentObjectID ) ; xml . setProjectObjectId ( PROJECT_OBJECT_ID ) ; xml . setSequenceNumber ( Integer . valueOf ( m_wbsSequence ++ ) ) ; xml . setStatus ( "Active" ) ; } writeChildTasks ( mpxj ) ; }
Writes a WBS entity to the PM XML file .
278
12
144,073
private void writeActivity ( Task mpxj ) { ActivityType xml = m_factory . createActivityType ( ) ; m_project . getActivity ( ) . add ( xml ) ; Task parentTask = mpxj . getParentTask ( ) ; Integer parentObjectID = parentTask == null ? null : parentTask . getUniqueID ( ) ; xml . setActualStartDate ( mpxj . getActualStart ( ) ) ; xml . setActualFinishDate ( mpxj . getActualFinish ( ) ) ; xml . setAtCompletionDuration ( getDuration ( mpxj . getDuration ( ) ) ) ; xml . setCalendarObjectId ( getCalendarUniqueID ( mpxj . getCalendar ( ) ) ) ; xml . setDurationPercentComplete ( getPercentage ( mpxj . getPercentageComplete ( ) ) ) ; xml . setDurationType ( DURATION_TYPE_MAP . get ( mpxj . getType ( ) ) ) ; xml . setFinishDate ( mpxj . getFinish ( ) ) ; xml . setGUID ( DatatypeConverter . printUUID ( mpxj . getGUID ( ) ) ) ; xml . setId ( getActivityID ( mpxj ) ) ; xml . setName ( mpxj . getName ( ) ) ; xml . setObjectId ( mpxj . getUniqueID ( ) ) ; xml . setPercentComplete ( getPercentage ( mpxj . getPercentageComplete ( ) ) ) ; xml . setPercentCompleteType ( "Duration" ) ; xml . setPrimaryConstraintType ( CONSTRAINT_TYPE_MAP . get ( mpxj . getConstraintType ( ) ) ) ; xml . setPrimaryConstraintDate ( mpxj . getConstraintDate ( ) ) ; xml . setPlannedDuration ( getDuration ( mpxj . getDuration ( ) ) ) ; xml . setPlannedFinishDate ( mpxj . getFinish ( ) ) ; xml . setPlannedStartDate ( mpxj . getStart ( ) ) ; xml . setProjectObjectId ( PROJECT_OBJECT_ID ) ; xml . setRemainingDuration ( getDuration ( mpxj . getRemainingDuration ( ) ) ) ; xml . setRemainingEarlyFinishDate ( mpxj . getEarlyFinish ( ) ) ; xml . setRemainingEarlyStartDate ( mpxj . getResume ( ) ) ; xml . setRemainingLaborCost ( NumberHelper . DOUBLE_ZERO ) ; xml . setRemainingLaborUnits ( NumberHelper . DOUBLE_ZERO ) ; xml . setRemainingNonLaborCost ( NumberHelper . DOUBLE_ZERO ) ; xml . setRemainingNonLaborUnits ( NumberHelper . DOUBLE_ZERO ) ; xml . setStartDate ( mpxj . getStart ( ) ) ; xml . setStatus ( getActivityStatus ( mpxj ) ) ; xml . setType ( extractAndConvertTaskType ( mpxj ) ) ; xml . setWBSObjectId ( parentObjectID ) ; xml . getUDF ( ) . addAll ( writeUDFType ( FieldTypeClass . TASK , mpxj ) ) ; writePredecessors ( mpxj ) ; }
Writes an activity to a PM XML file .
716
10
144,074
private String extractAndConvertTaskType ( Task task ) { String activityType = ( String ) task . getCachedValue ( m_activityTypeField ) ; if ( activityType == null ) { activityType = "Resource Dependent" ; } else { if ( ACTIVITY_TYPE_MAP . containsKey ( activityType ) ) { activityType = ACTIVITY_TYPE_MAP . get ( activityType ) ; } } return activityType ; }
Attempts to locate the activity type value extracted from an existing P6 schedule . If necessary converts to the form which can be used in the PMXML file . Returns Resource Dependent as the default value .
96
41
144,075
private void writeAssignments ( ) { for ( ResourceAssignment assignment : m_projectFile . getResourceAssignments ( ) ) { Resource resource = assignment . getResource ( ) ; if ( resource != null ) { Task task = assignment . getTask ( ) ; if ( task != null && task . getUniqueID ( ) . intValue ( ) != 0 && ! task . getSummary ( ) ) { writeAssignment ( assignment ) ; } } } }
Writes assignment data to a PM XML file .
98
10
144,076
private void writeAssignment ( ResourceAssignment mpxj ) { ResourceAssignmentType xml = m_factory . createResourceAssignmentType ( ) ; m_project . getResourceAssignment ( ) . add ( xml ) ; Task task = mpxj . getTask ( ) ; Task parentTask = task . getParentTask ( ) ; Integer parentTaskUniqueID = parentTask == null ? null : parentTask . getUniqueID ( ) ; xml . setActivityObjectId ( mpxj . getTaskUniqueID ( ) ) ; xml . setActualCost ( getDouble ( mpxj . getActualCost ( ) ) ) ; xml . setActualFinishDate ( mpxj . getActualFinish ( ) ) ; xml . setActualOvertimeUnits ( getDuration ( mpxj . getActualOvertimeWork ( ) ) ) ; xml . setActualRegularUnits ( getDuration ( mpxj . getActualWork ( ) ) ) ; xml . setActualStartDate ( mpxj . getActualStart ( ) ) ; xml . setActualUnits ( getDuration ( mpxj . getActualWork ( ) ) ) ; xml . setAtCompletionUnits ( getDuration ( mpxj . getRemainingWork ( ) ) ) ; xml . setPlannedCost ( getDouble ( mpxj . getActualCost ( ) ) ) ; xml . setFinishDate ( mpxj . getFinish ( ) ) ; xml . setGUID ( DatatypeConverter . printUUID ( mpxj . getGUID ( ) ) ) ; xml . setObjectId ( mpxj . getUniqueID ( ) ) ; xml . setPlannedDuration ( getDuration ( mpxj . getWork ( ) ) ) ; xml . setPlannedFinishDate ( mpxj . getFinish ( ) ) ; xml . setPlannedStartDate ( mpxj . getStart ( ) ) ; xml . setPlannedUnits ( getDuration ( mpxj . getWork ( ) ) ) ; xml . setPlannedUnitsPerTime ( getPercentage ( mpxj . getUnits ( ) ) ) ; xml . setProjectObjectId ( PROJECT_OBJECT_ID ) ; xml . setRateSource ( "Resource" ) ; xml . setRemainingCost ( getDouble ( mpxj . getActualCost ( ) ) ) ; xml . setRemainingDuration ( getDuration ( mpxj . getRemainingWork ( ) ) ) ; xml . setRemainingFinishDate ( mpxj . getFinish ( ) ) ; xml . setRemainingStartDate ( mpxj . getStart ( ) ) ; xml . setRemainingUnits ( getDuration ( mpxj . getRemainingWork ( ) ) ) ; xml . setRemainingUnitsPerTime ( getPercentage ( mpxj . getUnits ( ) ) ) ; xml . setResourceObjectId ( mpxj . getResourceUniqueID ( ) ) ; xml . setStartDate ( mpxj . getStart ( ) ) ; xml . setWBSObjectId ( parentTaskUniqueID ) ; xml . getUDF ( ) . addAll ( writeUDFType ( FieldTypeClass . ASSIGNMENT , mpxj ) ) ; }
Writes a resource assignment to a PM XML file .
710
11
144,077
private void writePredecessors ( Task task ) { List < Relation > relations = task . getPredecessors ( ) ; for ( Relation mpxj : relations ) { RelationshipType xml = m_factory . createRelationshipType ( ) ; m_project . getRelationship ( ) . add ( xml ) ; xml . setLag ( getDuration ( mpxj . getLag ( ) ) ) ; xml . setObjectId ( Integer . valueOf ( ++ m_relationshipObjectID ) ) ; xml . setPredecessorActivityObjectId ( mpxj . getTargetTask ( ) . getUniqueID ( ) ) ; xml . setSuccessorActivityObjectId ( mpxj . getSourceTask ( ) . getUniqueID ( ) ) ; xml . setPredecessorProjectObjectId ( PROJECT_OBJECT_ID ) ; xml . setSuccessorProjectObjectId ( PROJECT_OBJECT_ID ) ; xml . setType ( RELATION_TYPE_MAP . get ( mpxj . getType ( ) ) ) ; } }
Writes task predecessor links to a PM XML file .
228
11
144,078
private List < UDFAssignmentType > writeUDFType ( FieldTypeClass type , FieldContainer mpxj ) { List < UDFAssignmentType > out = new ArrayList < UDFAssignmentType > ( ) ; for ( CustomField cf : m_sortedCustomFieldsList ) { FieldType fieldType = cf . getFieldType ( ) ; if ( fieldType != null && type == fieldType . getFieldTypeClass ( ) ) { Object value = mpxj . getCachedValue ( fieldType ) ; if ( FieldTypeHelper . valueIsNotDefault ( fieldType , value ) ) { UDFAssignmentType udf = m_factory . createUDFAssignmentType ( ) ; udf . setTypeObjectId ( FieldTypeHelper . getFieldID ( fieldType ) ) ; setUserFieldValue ( udf , fieldType . getDataType ( ) , value ) ; out . add ( udf ) ; } } } return out ; }
Writes a list of UDF types .
210
9
144,079
private void setUserFieldValue ( UDFAssignmentType udf , DataType dataType , Object value ) { switch ( dataType ) { case DURATION : { udf . setTextValue ( ( ( Duration ) value ) . toString ( ) ) ; break ; } case CURRENCY : { if ( ! ( value instanceof Double ) ) { value = Double . valueOf ( ( ( Number ) value ) . doubleValue ( ) ) ; } udf . setCostValue ( ( Double ) value ) ; break ; } case BINARY : { udf . setTextValue ( "" ) ; break ; } case STRING : { udf . setTextValue ( ( String ) value ) ; break ; } case DATE : { udf . setStartDateValue ( ( Date ) value ) ; break ; } case NUMERIC : { if ( ! ( value instanceof Double ) ) { value = Double . valueOf ( ( ( Number ) value ) . doubleValue ( ) ) ; } udf . setDoubleValue ( ( Double ) value ) ; break ; } case BOOLEAN : { udf . setIntegerValue ( BooleanHelper . getBoolean ( ( Boolean ) value ) ? Integer . valueOf ( 1 ) : Integer . valueOf ( 0 ) ) ; break ; } case INTEGER : case SHORT : { udf . setIntegerValue ( NumberHelper . getInteger ( ( Number ) value ) ) ; break ; } default : { throw new RuntimeException ( "Unconvertible data type: " + dataType ) ; } } }
Sets the value of a UDF .
334
9
144,080
private Double getDuration ( Duration duration ) { Double result ; if ( duration == null ) { result = null ; } else { if ( duration . getUnits ( ) != TimeUnit . HOURS ) { duration = duration . convertUnits ( TimeUnit . HOURS , m_projectFile . getProjectProperties ( ) ) ; } result = Double . valueOf ( duration . getDuration ( ) ) ; } return result ; }
Retrieve a duration in the form required by Primavera .
91
14
144,081
private String getResourceType ( Resource resource ) { String result ; net . sf . mpxj . ResourceType type = resource . getType ( ) ; if ( type == null ) { type = net . sf . mpxj . ResourceType . WORK ; } switch ( type ) { case MATERIAL : { result = "Material" ; break ; } case COST : { result = "Nonlabor" ; break ; } default : { result = "Labor" ; break ; } } return result ; }
Formats a resource type .
110
6
144,082
private Double getPercentage ( Number number ) { Double result = null ; if ( number != null ) { result = Double . valueOf ( number . doubleValue ( ) / 100 ) ; } return result ; }
Formats a percentage value .
44
6
144,083
private Double getDouble ( Number number ) { Double result = null ; if ( number != null ) { result = Double . valueOf ( number . doubleValue ( ) ) ; } return result ; }
Formats a double value .
41
6
144,084
private String getActivityStatus ( Task mpxj ) { String result ; if ( mpxj . getActualStart ( ) == null ) { result = "Not Started" ; } else { if ( mpxj . getActualFinish ( ) == null ) { result = "In Progress" ; } else { result = "Completed" ; } } return result ; }
Retrieve an activity status .
79
6
144,085
private String getActivityID ( Task task ) { String result = null ; if ( m_activityIDField != null ) { Object value = task . getCachedValue ( m_activityIDField ) ; if ( value != null ) { result = value . toString ( ) ; } } return result ; }
Retrieve the Activity ID value for this task .
65
10
144,086
private void configureCustomFields ( ) { CustomFieldContainer customFields = m_projectFile . getCustomFields ( ) ; // If the caller hasn't already supplied a value for this field if ( m_activityIDField == null ) { m_activityIDField = ( TaskField ) customFields . getFieldByAlias ( FieldTypeClass . TASK , "Code" ) ; if ( m_activityIDField == null ) { m_activityIDField = TaskField . WBS ; } } // If the caller hasn't already supplied a value for this field if ( m_activityTypeField == null ) { m_activityTypeField = ( TaskField ) customFields . getFieldByAlias ( FieldTypeClass . TASK , "Activity Type" ) ; } }
Find the fields in which the Activity ID and Activity Type are stored .
168
14
144,087
private void populateSortedCustomFieldsList ( ) { m_sortedCustomFieldsList = new ArrayList < CustomField > ( ) ; for ( CustomField field : m_projectFile . getCustomFields ( ) ) { FieldType fieldType = field . getFieldType ( ) ; if ( fieldType != null ) { m_sortedCustomFieldsList . add ( field ) ; } } // Sort to ensure consistent order in file Collections . sort ( m_sortedCustomFieldsList , new Comparator < CustomField > ( ) { @ Override public int compare ( CustomField customField1 , CustomField customField2 ) { FieldType o1 = customField1 . getFieldType ( ) ; FieldType o2 = customField2 . getFieldType ( ) ; String name1 = o1 . getClass ( ) . getSimpleName ( ) + "." + o1 . getName ( ) + " " + customField1 . getAlias ( ) ; String name2 = o2 . getClass ( ) . getSimpleName ( ) + "." + o2 . getName ( ) + " " + customField2 . getAlias ( ) ; return name1 . compareTo ( name2 ) ; } } ) ; }
Populate a sorted list of custom fields to ensure that these fields are written to the file in a consistent order .
266
23
144,088
public void setDay ( Day d ) { if ( m_day != null ) { m_parentCalendar . removeHoursFromDay ( this ) ; } m_day = d ; m_parentCalendar . attachHoursToDay ( this ) ; }
Set day .
54
3
144,089
public void applyPatterns ( String [ ] patterns ) { m_formats = new SimpleDateFormat [ patterns . length ] ; for ( int index = 0 ; index < patterns . length ; index ++ ) { m_formats [ index ] = new SimpleDateFormat ( patterns [ index ] ) ; } }
This method is used to configure the format pattern .
65
10
144,090
public static Duration getDuration ( ProjectProperties properties , Integer durationValue , Integer unitsValue ) { Duration result ; if ( durationValue == null ) { result = null ; } else { result = Duration . getInstance ( durationValue . intValue ( ) , TimeUnit . MINUTES ) ; TimeUnit units = getDurationUnits ( unitsValue ) ; if ( result . getUnits ( ) != units ) { result = result . convertUnits ( units , properties ) ; } } return ( result ) ; }
Convert the integer representation of a duration value and duration units into an MPXJ Duration instance .
108
20
144,091
public static Integer getDurationValue ( ProjectProperties properties , Duration duration ) { Integer result ; if ( duration == null ) { result = null ; } else { if ( duration . getUnits ( ) != TimeUnit . MINUTES ) { duration = duration . convertUnits ( TimeUnit . MINUTES , properties ) ; } result = Integer . valueOf ( ( int ) duration . getDuration ( ) ) ; } return ( result ) ; }
Convert an MPXJ Duration instance into an integer duration in minutes ready to be written to an MPX file .
95
24
144,092
public static Integer getDurationUnits ( RecurringTask recurrence ) { Duration duration = recurrence . getDuration ( ) ; Integer result = null ; if ( duration != null ) { result = UNITS_MAP . get ( duration . getUnits ( ) ) ; } return ( result ) ; }
Converts a TimeUnit instance to an integer value suitable for writing to an MPX file .
63
19
144,093
private static TimeUnit getDurationUnits ( Integer value ) { TimeUnit result = null ; if ( value != null ) { int index = value . intValue ( ) ; if ( index >= 0 && index < DURATION_UNITS . length ) { result = DURATION_UNITS [ index ] ; } } if ( result == null ) { result = TimeUnit . DAYS ; } return ( result ) ; }
Maps a duration unit value from a recurring task record in an MPX file to a TimeUnit instance . Defaults to days if any problems are encountered .
90
31
144,094
public static Integer getDays ( String days ) { Integer result = null ; if ( days != null ) { result = Integer . valueOf ( Integer . parseInt ( days , 2 ) ) ; } return ( result ) ; }
Converts the string representation of the days bit field into an integer .
47
14
144,095
public static String getDays ( RecurringTask task ) { StringBuilder sb = new StringBuilder ( ) ; for ( Day day : Day . values ( ) ) { sb . append ( task . getWeeklyDay ( day ) ? "1" : "0" ) ; } return sb . toString ( ) ; }
Convert weekly recurrence days into a bit field .
70
11
144,096
public static Day getDay ( Integer day ) { Day result = null ; if ( day != null ) { result = DAY_ARRAY [ day . intValue ( ) ] ; } return ( result ) ; }
Convert MPX day index to Day instance .
44
10
144,097
public static Integer getDay ( Day day ) { Integer result = null ; if ( day != null ) { result = DAY_MAP . get ( day ) ; } return ( result ) ; }
Convert Day instance to MPX day index .
40
10
144,098
public static Date getYearlyAbsoluteAsDate ( RecurringData data ) { Date result ; Integer yearlyAbsoluteDay = data . getDayNumber ( ) ; Integer yearlyAbsoluteMonth = data . getMonthNumber ( ) ; Date startDate = data . getStartDate ( ) ; if ( yearlyAbsoluteDay == null || yearlyAbsoluteMonth == null || startDate == null ) { result = null ; } else { Calendar cal = DateHelper . popCalendar ( startDate ) ; cal . set ( Calendar . MONTH , yearlyAbsoluteMonth . intValue ( ) - 1 ) ; cal . set ( Calendar . DAY_OF_MONTH , yearlyAbsoluteDay . intValue ( ) ) ; result = cal . getTime ( ) ; DateHelper . pushCalendar ( cal ) ; } return result ; }
Retrieves the yearly absolute date .
173
8
144,099
public int readInt ( int offset , byte [ ] data ) { int result = 0 ; int i = offset + m_offset ; for ( int shiftBy = 0 ; shiftBy < 32 ; shiftBy += 8 ) { result |= ( ( data [ i ] & 0xff ) ) << shiftBy ; ++ i ; } return result ; }
Read a four byte integer from the data .
73
9