idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
20,900
private void processResource ( MapRow row ) throws IOException { Resource resource = m_project . addResource ( ) ; resource . setName ( row . getString ( "NAME" ) ) ; resource . setGUID ( row . getUUID ( "UUID" ) ) ; resource . setEmailAddress ( row . getString ( "EMAIL" ) ) ; resource . setHyperlink ( row . getString ( "URL" ) ) ; resource . setNotes ( getNotes ( row . getRows ( "COMMENTARY" ) ) ) ; resource . setText ( 1 , row . getString ( "DESCRIPTION" ) ) ; resource . setText ( 2 , row . getString ( "SUPPLY_REFERENCE" ) ) ; resource . setActive ( true ) ; List < MapRow > resources = row . getRows ( "RESOURCES" ) ; if ( resources != null ) { for ( MapRow childResource : sort ( resources , "NAME" ) ) { processResource ( childResource ) ; } } m_resourceMap . put ( resource . getGUID ( ) , resource ) ; }
Extract data for a single resource .
20,901
private void processTasks ( ) throws IOException { TaskReader reader = new TaskReader ( m_data . getTableData ( "Tasks" ) ) ; reader . read ( ) ; for ( MapRow row : reader . getRows ( ) ) { processTask ( m_project , row ) ; } updateDates ( ) ; }
Extract task data .
20,902
private void processTask ( ChildTaskContainer parent , MapRow row ) throws IOException { Task task = parent . addTask ( ) ; task . setName ( row . getString ( "NAME" ) ) ; task . setGUID ( row . getUUID ( "UUID" ) ) ; task . setText ( 1 , row . getString ( "ID" ) ) ; task . setDuration ( row . getDuration ( "PLANNED_DURATION" ) ) ; task . setRemainingDuration ( row . getDuration ( "REMAINING_DURATION" ) ) ; task . setHyperlink ( row . getString ( "URL" ) ) ; task . setPercentageComplete ( row . getDouble ( "PERCENT_COMPLETE" ) ) ; task . setNotes ( getNotes ( row . getRows ( "COMMENTARY" ) ) ) ; task . setMilestone ( task . getDuration ( ) . getDuration ( ) == 0 ) ; ProjectCalendar calendar = m_calendarMap . get ( row . getUUID ( "CALENDAR_UUID" ) ) ; if ( calendar != m_project . getDefaultCalendar ( ) ) { task . setCalendar ( calendar ) ; } switch ( row . getInteger ( "STATUS" ) . intValue ( ) ) { case 1 : { task . setStart ( row . getDate ( "PLANNED_START" ) ) ; task . setFinish ( task . getEffectiveCalendar ( ) . getDate ( task . getStart ( ) , task . getDuration ( ) , false ) ) ; break ; } case 2 : { task . setActualStart ( row . getDate ( "ACTUAL_START" ) ) ; task . setStart ( task . getActualStart ( ) ) ; task . setFinish ( row . getDate ( "ESTIMATED_FINISH" ) ) ; if ( task . getFinish ( ) == null ) { task . setFinish ( row . getDate ( "PLANNED_FINISH" ) ) ; } break ; } case 3 : { task . setActualStart ( row . getDate ( "ACTUAL_START" ) ) ; task . setActualFinish ( row . getDate ( "ACTUAL_FINISH" ) ) ; task . setPercentageComplete ( Double . valueOf ( 100.0 ) ) ; task . setStart ( task . getActualStart ( ) ) ; task . setFinish ( task . getActualFinish ( ) ) ; break ; } } setConstraints ( task , row ) ; processChildTasks ( task , row ) ; m_taskMap . put ( task . getGUID ( ) , task ) ; List < MapRow > predecessors = row . getRows ( "PREDECESSORS" ) ; if ( predecessors != null && ! predecessors . isEmpty ( ) ) { m_predecessorMap . put ( task , predecessors ) ; } List < MapRow > resourceAssignmnets = row . getRows ( "RESOURCE_ASSIGNMENTS" ) ; if ( resourceAssignmnets != null && ! resourceAssignmnets . isEmpty ( ) ) { processResourceAssignments ( task , resourceAssignmnets ) ; } }
Extract data for a single task .
20,903
private void processChildTasks ( Task task , MapRow row ) throws IOException { List < MapRow > tasks = row . getRows ( "TASKS" ) ; if ( tasks != null ) { for ( MapRow childTask : tasks ) { processTask ( task , childTask ) ; } } }
Extract child task data .
20,904
private void processPredecessors ( ) { for ( Map . Entry < Task , List < MapRow > > entry : m_predecessorMap . entrySet ( ) ) { Task task = entry . getKey ( ) ; List < MapRow > predecessors = entry . getValue ( ) ; for ( MapRow predecessor : predecessors ) { processPredecessor ( task , predecessor ) ; } } }
Extract predecessor data .
20,905
private void processPredecessor ( Task task , MapRow row ) { Task predecessor = m_taskMap . get ( row . getUUID ( "PREDECESSOR_UUID" ) ) ; if ( predecessor != null ) { task . addPredecessor ( predecessor , row . getRelationType ( "RELATION_TYPE" ) , row . getDuration ( "LAG" ) ) ; } }
Extract data for a single predecessor .
20,906
private void processResourceAssignments ( Task task , List < MapRow > assignments ) { for ( MapRow row : assignments ) { processResourceAssignment ( task , row ) ; } }
Extract resource assignments for a task .
20,907
private void processResourceAssignment ( Task task , MapRow row ) { Resource resource = m_resourceMap . get ( row . getUUID ( "RESOURCE_UUID" ) ) ; task . addResourceAssignment ( resource ) ; }
Extract data for a single resource assignment .
20,908
private void setConstraints ( Task task , MapRow row ) { ConstraintType constraintType = null ; Date constraintDate = null ; Date lateDate = row . getDate ( "CONSTRAINT_LATE_DATE" ) ; Date earlyDate = row . getDate ( "CONSTRAINT_EARLY_DATE" ) ; switch ( row . getInteger ( "CONSTRAINT_TYPE" ) . intValue ( ) ) { case 2 : { constraintType = ConstraintType . MUST_START_ON ; constraintDate = task . getStart ( ) ; break ; } case 12 : { constraintType = ConstraintType . MUST_FINISH_ON ; constraintDate = lateDate ; break ; } case 10 : { constraintType = ConstraintType . FINISH_NO_EARLIER_THAN ; constraintDate = earlyDate ; break ; } case 11 : { constraintType = ConstraintType . FINISH_NO_LATER_THAN ; constraintDate = lateDate ; break ; } case 13 : case 5 : case 9 : { constraintType = ConstraintType . MUST_START_ON ; constraintDate = earlyDate ; break ; } case 14 : { constraintType = ConstraintType . MUST_FINISH_ON ; constraintDate = earlyDate ; break ; } case 4 : { constraintType = ConstraintType . AS_LATE_AS_POSSIBLE ; break ; } case 3 : { constraintType = ConstraintType . AS_SOON_AS_POSSIBLE ; break ; } case 8 : { constraintType = ConstraintType . AS_SOON_AS_POSSIBLE ; constraintDate = earlyDate ; break ; } case 6 : { constraintType = ConstraintType . START_NO_LATER_THAN ; constraintDate = earlyDate ; break ; } case 15 : { constraintType = ConstraintType . START_NO_EARLIER_THAN ; constraintDate = earlyDate ; break ; } } task . setConstraintType ( constraintType ) ; task . setConstraintDate ( constraintDate ) ; }
Map Synchro constraints to MPXJ constraints .
20,909
private String getNotes ( List < MapRow > rows ) { String result = null ; if ( rows != null && ! rows . isEmpty ( ) ) { StringBuilder sb = new StringBuilder ( ) ; for ( MapRow row : rows ) { sb . append ( row . getString ( "TITLE" ) ) ; sb . append ( '\n' ) ; sb . append ( row . getString ( "TEXT" ) ) ; sb . append ( "\n\n" ) ; } result = sb . toString ( ) ; } return result ; }
Common mechanism to convert Synchro commentary recorss into notes .
20,910
private List < MapRow > sort ( List < MapRow > rows , final String attribute ) { Collections . sort ( rows , new Comparator < MapRow > ( ) { public int compare ( MapRow o1 , MapRow o2 ) { String value1 = o1 . getString ( attribute ) ; String value2 = o2 . getString ( attribute ) ; return value1 . compareTo ( value2 ) ; } } ) ; return rows ; }
Sort MapRows based on a named attribute .
20,911
private void updateDates ( Task parentTask ) { if ( parentTask . hasChildTasks ( ) ) { Date plannedStartDate = null ; Date plannedFinishDate = null ; for ( Task task : parentTask . getChildTasks ( ) ) { updateDates ( task ) ; plannedStartDate = DateHelper . min ( plannedStartDate , task . getStart ( ) ) ; plannedFinishDate = DateHelper . max ( plannedFinishDate , task . getFinish ( ) ) ; } parentTask . setStart ( plannedStartDate ) ; parentTask . setFinish ( plannedFinishDate ) ; } }
Recursively update parent task dates .
20,912
protected Date parseNonNullDate ( String str , ParsePosition pos ) { Date result = null ; for ( int index = 0 ; index < m_formats . length ; index ++ ) { result = m_formats [ index ] . parse ( str , pos ) ; if ( pos . getIndex ( ) != 0 ) { break ; } result = null ; } return result ; }
We have a non - null date try each format in turn to see if it can be parsed .
20,913
public void renumberIDs ( ) { if ( ! isEmpty ( ) ) { Collections . sort ( this ) ; T firstEntity = get ( 0 ) ; int id = NumberHelper . getInt ( firstEntity . getID ( ) ) ; if ( id != 0 ) { id = 1 ; } for ( T entity : this ) { entity . setID ( Integer . valueOf ( id ++ ) ) ; } } }
This method can be called to ensure that the IDs of all entities are sequential and start from an appropriate point . If entities are added to and removed from this list then the project is loaded into Microsoft project if the ID values have gaps in the sequence there will be blank rows shown .
20,914
public static Priority getInstance ( int priority ) { Priority result ; if ( priority >= LOWEST && priority <= DO_NOT_LEVEL && ( priority % 100 == 0 ) ) { result = VALUE [ ( priority / 100 ) - 1 ] ; } else { result = new Priority ( priority ) ; } return ( result ) ; }
This method takes an integer enumeration of a priority and returns an appropriate instance of this class . Note that unrecognised values are treated as medium priority .
20,915
private void processFile ( InputStream is ) throws MPXJException { try { InputStreamReader reader = new InputStreamReader ( is , CharsetHelper . UTF8 ) ; Tokenizer tk = new ReaderTokenizer ( reader ) { protected boolean startQuotedIsValid ( StringBuilder buffer ) { return buffer . length ( ) == 1 && buffer . charAt ( 0 ) == '<' ; } } ; tk . setDelimiter ( DELIMITER ) ; ArrayList < String > columns = new ArrayList < String > ( ) ; String nextTokenPrefix = null ; while ( tk . getType ( ) != Tokenizer . TT_EOF ) { columns . clear ( ) ; TableDefinition table = null ; while ( tk . nextToken ( ) == Tokenizer . TT_WORD ) { String token = tk . getToken ( ) ; if ( columns . size ( ) == 0 ) { if ( token . charAt ( 0 ) == '#' ) { int index = token . lastIndexOf ( ':' ) ; if ( index != - 1 ) { String headerToken ; if ( token . endsWith ( "-" ) || token . endsWith ( "=" ) ) { headerToken = token ; token = null ; } else { headerToken = token . substring ( 0 , index ) ; token = token . substring ( index + 1 ) ; } RowHeader header = new RowHeader ( headerToken ) ; table = m_tableDefinitions . get ( header . getType ( ) ) ; columns . add ( header . getID ( ) ) ; } } else { if ( token . charAt ( 0 ) == 0 ) { processFileType ( token ) ; } } } if ( table != null && token != null ) { if ( token . startsWith ( "<\"" ) && ! token . endsWith ( "\">" ) ) { nextTokenPrefix = token ; } else { if ( nextTokenPrefix != null ) { token = nextTokenPrefix + DELIMITER + token ; nextTokenPrefix = null ; } columns . add ( token ) ; } } } if ( table != null && columns . size ( ) > 1 ) { TextFileRow row = new TextFileRow ( table , columns , m_epochDateFormat ) ; List < Row > rows = m_tables . get ( table . getName ( ) ) ; if ( rows == null ) { rows = new LinkedList < Row > ( ) ; m_tables . put ( table . getName ( ) , rows ) ; } rows . add ( row ) ; } } } catch ( Exception ex ) { throw new MPXJException ( MPXJException . READ_ERROR , ex ) ; } }
Tokenizes the input file and extracts the required data .
20,916
private void processFileType ( String token ) throws MPXJException { String version = token . substring ( 2 ) . split ( " " ) [ 0 ] ; Class < ? extends AbstractFileFormat > fileFormatClass = FILE_VERSION_MAP . get ( Integer . valueOf ( version ) ) ; if ( fileFormatClass == null ) { throw new MPXJException ( "Unsupported PP file format version " + version ) ; } try { AbstractFileFormat format = fileFormatClass . newInstance ( ) ; m_tableDefinitions = format . tableDefinitions ( ) ; m_epochDateFormat = format . epochDateFormat ( ) ; } catch ( Exception ex ) { throw new MPXJException ( "Failed to configure file format" , ex ) ; } }
Reads the file version and configures the expected file format .
20,917
private void processCalendars ( ) throws SQLException { List < Row > rows = getTable ( "EXCEPTIONN" ) ; Map < Integer , DayType > exceptionMap = m_reader . createExceptionTypeMap ( rows ) ; rows = getTable ( "WORK_PATTERN" ) ; Map < Integer , Row > workPatternMap = m_reader . createWorkPatternMap ( rows ) ; rows = new LinkedList < Row > ( ) ; Map < Integer , List < Row > > workPatternAssignmentMap = m_reader . createWorkPatternAssignmentMap ( rows ) ; rows = getTable ( "EXCEPTION_ASSIGNMENT" ) ; Map < Integer , List < Row > > exceptionAssignmentMap = m_reader . createExceptionAssignmentMap ( rows ) ; rows = getTable ( "TIME_ENTRY" ) ; Map < Integer , List < Row > > timeEntryMap = m_reader . createTimeEntryMap ( rows ) ; rows = getTable ( "CALENDAR" ) ; Collections . sort ( rows , CALENDAR_COMPARATOR ) ; for ( Row row : rows ) { m_reader . processCalendar ( row , workPatternMap , workPatternAssignmentMap , exceptionAssignmentMap , timeEntryMap , exceptionMap ) ; } m_reader . getProject ( ) . getProjectConfig ( ) . updateUniqueCounters ( ) ; }
Extract calendar data from the file .
20,918
private List < Row > join ( List < Row > leftRows , String leftColumn , String rightTable , List < Row > rightRows , String rightColumn ) { List < Row > result = new LinkedList < Row > ( ) ; RowComparator leftComparator = new RowComparator ( new String [ ] { leftColumn } ) ; RowComparator rightComparator = new RowComparator ( new String [ ] { rightColumn } ) ; Collections . sort ( leftRows , leftComparator ) ; Collections . sort ( rightRows , rightComparator ) ; ListIterator < Row > rightIterator = rightRows . listIterator ( ) ; Row rightRow = rightIterator . hasNext ( ) ? rightIterator . next ( ) : null ; for ( Row leftRow : leftRows ) { Integer leftValue = leftRow . getInteger ( leftColumn ) ; boolean match = false ; while ( rightRow != null ) { Integer rightValue = rightRow . getInteger ( rightColumn ) ; int comparison = leftValue . compareTo ( rightValue ) ; if ( comparison == 0 ) { match = true ; break ; } if ( comparison < 0 ) { if ( rightIterator . hasPrevious ( ) ) { rightRow = rightIterator . previous ( ) ; } break ; } rightRow = rightIterator . next ( ) ; } if ( match && rightRow != null ) { Map < String , Object > newMap = new HashMap < String , Object > ( ( ( MapRow ) leftRow ) . getMap ( ) ) ; for ( Entry < String , Object > entry : ( ( MapRow ) rightRow ) . getMap ( ) . entrySet ( ) ) { String key = entry . getKey ( ) ; if ( newMap . containsKey ( key ) ) { key = rightTable + "." + key ; } newMap . put ( key , entry . getValue ( ) ) ; } result . add ( new MapRow ( newMap ) ) ; } } return result ; }
Very basic implementation of an inner join between two result sets .
20,919
private List < Row > getTable ( String name ) { List < Row > result = m_tables . get ( name ) ; if ( result == null ) { result = Collections . emptyList ( ) ; } return result ; }
Retrieve table data return an empty result set if no table data is present .
20,920
private void readProjectProperties ( Project ganttProject ) { ProjectProperties mpxjProperties = m_projectFile . getProjectProperties ( ) ; mpxjProperties . setName ( ganttProject . getName ( ) ) ; mpxjProperties . setCompany ( ganttProject . getCompany ( ) ) ; mpxjProperties . setDefaultDurationUnits ( TimeUnit . DAYS ) ; String locale = ganttProject . getLocale ( ) ; if ( locale == null ) { locale = "en_US" ; } m_localeDateFormat = DateFormat . getDateInstance ( DateFormat . SHORT , new Locale ( locale ) ) ; }
This method extracts project properties from a GanttProject file .
20,921
private void readCalendars ( Project ganttProject ) { m_mpxjCalendar = m_projectFile . addCalendar ( ) ; m_mpxjCalendar . setName ( ProjectCalendar . DEFAULT_BASE_CALENDAR_NAME ) ; Calendars gpCalendar = ganttProject . getCalendars ( ) ; setWorkingDays ( m_mpxjCalendar , gpCalendar ) ; setExceptions ( m_mpxjCalendar , gpCalendar ) ; m_eventManager . fireCalendarReadEvent ( m_mpxjCalendar ) ; }
This method extracts calendar data from a GanttProject file .
20,922
private void setWorkingDays ( ProjectCalendar mpxjCalendar , Calendars gpCalendar ) { DayTypes dayTypes = gpCalendar . getDayTypes ( ) ; DefaultWeek defaultWeek = dayTypes . getDefaultWeek ( ) ; if ( defaultWeek == null ) { mpxjCalendar . setWorkingDay ( Day . SUNDAY , false ) ; mpxjCalendar . setWorkingDay ( Day . MONDAY , true ) ; mpxjCalendar . setWorkingDay ( Day . TUESDAY , true ) ; mpxjCalendar . setWorkingDay ( Day . WEDNESDAY , true ) ; mpxjCalendar . setWorkingDay ( Day . THURSDAY , true ) ; mpxjCalendar . setWorkingDay ( Day . FRIDAY , true ) ; mpxjCalendar . setWorkingDay ( Day . SATURDAY , false ) ; } else { mpxjCalendar . setWorkingDay ( Day . MONDAY , isWorkingDay ( defaultWeek . getMon ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . TUESDAY , isWorkingDay ( defaultWeek . getTue ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . WEDNESDAY , isWorkingDay ( defaultWeek . getWed ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . THURSDAY , isWorkingDay ( defaultWeek . getThu ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . FRIDAY , isWorkingDay ( defaultWeek . getFri ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . SATURDAY , isWorkingDay ( defaultWeek . getSat ( ) ) ) ; mpxjCalendar . setWorkingDay ( Day . SUNDAY , isWorkingDay ( defaultWeek . getSun ( ) ) ) ; } for ( Day day : Day . values ( ) ) { if ( mpxjCalendar . isWorkingDay ( day ) ) { ProjectCalendarHours hours = mpxjCalendar . addCalendarHours ( day ) ; hours . addRange ( ProjectCalendarWeek . DEFAULT_WORKING_MORNING ) ; hours . addRange ( ProjectCalendarWeek . DEFAULT_WORKING_AFTERNOON ) ; } } }
Add working days and working time to a calendar .
20,923
private void setExceptions ( ProjectCalendar mpxjCalendar , Calendars gpCalendar ) { List < net . sf . mpxj . ganttproject . schema . Date > dates = gpCalendar . getDate ( ) ; for ( net . sf . mpxj . ganttproject . schema . Date date : dates ) { addException ( mpxjCalendar , date ) ; } }
Add exceptions to the calendar .
20,924
private void addException ( ProjectCalendar mpxjCalendar , net . sf . mpxj . ganttproject . schema . Date date ) { String year = date . getYear ( ) ; if ( year == null || year . isEmpty ( ) ) { } else { Calendar calendar = DateHelper . popCalendar ( ) ; calendar . set ( Calendar . YEAR , Integer . parseInt ( year ) ) ; calendar . set ( Calendar . MONTH , NumberHelper . getInt ( date . getMonth ( ) ) ) ; calendar . set ( Calendar . DAY_OF_MONTH , NumberHelper . getInt ( date . getDate ( ) ) ) ; Date exceptionDate = calendar . getTime ( ) ; DateHelper . pushCalendar ( calendar ) ; ProjectCalendarException exception = mpxjCalendar . addCalendarException ( exceptionDate , exceptionDate ) ; if ( "WORKING_DAY" . equals ( date . getType ( ) ) ) { exception . addRange ( ProjectCalendarWeek . DEFAULT_WORKING_MORNING ) ; exception . addRange ( ProjectCalendarWeek . DEFAULT_WORKING_AFTERNOON ) ; } } }
Add a single exception to a calendar .
20,925
private void readResources ( Project ganttProject ) { Resources resources = ganttProject . getResources ( ) ; readResourceCustomPropertyDefinitions ( resources ) ; readRoleDefinitions ( ganttProject ) ; for ( net . sf . mpxj . ganttproject . schema . Resource gpResource : resources . getResource ( ) ) { readResource ( gpResource ) ; } }
This method extracts resource data from a GanttProject file .
20,926
private void readResourceCustomPropertyDefinitions ( Resources gpResources ) { CustomField field = m_projectFile . getCustomFields ( ) . getCustomField ( ResourceField . TEXT1 ) ; field . setAlias ( "Phone" ) ; for ( CustomPropertyDefinition definition : gpResources . getCustomPropertyDefinition ( ) ) { String type = definition . getType ( ) ; FieldType fieldType = RESOURCE_PROPERTY_TYPES . get ( type ) . getField ( ) ; if ( fieldType == null ) { fieldType = RESOURCE_PROPERTY_TYPES . get ( "text" ) . getField ( ) ; } if ( fieldType != null ) { field = m_projectFile . getCustomFields ( ) . getCustomField ( fieldType ) ; field . setAlias ( definition . getName ( ) ) ; String defaultValue = definition . getDefaultValue ( ) ; if ( defaultValue != null && defaultValue . isEmpty ( ) ) { defaultValue = null ; } m_resourcePropertyDefinitions . put ( definition . getId ( ) , new Pair < FieldType , String > ( fieldType , defaultValue ) ) ; } } }
Read custom property definitions for resources .
20,927
private void readTaskCustomPropertyDefinitions ( Tasks gpTasks ) { for ( Taskproperty definition : gpTasks . getTaskproperties ( ) . getTaskproperty ( ) ) { if ( ! "custom" . equals ( definition . getType ( ) ) ) { continue ; } String type = definition . getValuetype ( ) ; FieldType fieldType = TASK_PROPERTY_TYPES . get ( type ) . getField ( ) ; if ( fieldType == null ) { fieldType = TASK_PROPERTY_TYPES . get ( "text" ) . getField ( ) ; } if ( fieldType != null ) { CustomField field = m_projectFile . getCustomFields ( ) . getCustomField ( fieldType ) ; field . setAlias ( definition . getName ( ) ) ; String defaultValue = definition . getDefaultvalue ( ) ; if ( defaultValue != null && defaultValue . isEmpty ( ) ) { defaultValue = null ; } m_taskPropertyDefinitions . put ( definition . getId ( ) , new Pair < FieldType , String > ( fieldType , defaultValue ) ) ; } } }
Read custom property definitions for tasks .
20,928
private void readRoleDefinitions ( Project gpProject ) { m_roleDefinitions . put ( "Default:1" , "project manager" ) ; for ( Roles roles : gpProject . getRoles ( ) ) { if ( "Default" . equals ( roles . getRolesetName ( ) ) ) { continue ; } for ( Role role : roles . getRole ( ) ) { m_roleDefinitions . put ( role . getId ( ) , role . getName ( ) ) ; } } }
Read the role definitions from a GanttProject project .
20,929
private void readResource ( net . sf . mpxj . ganttproject . schema . Resource gpResource ) { Resource mpxjResource = m_projectFile . addResource ( ) ; mpxjResource . setUniqueID ( Integer . valueOf ( NumberHelper . getInt ( gpResource . getId ( ) ) + 1 ) ) ; mpxjResource . setName ( gpResource . getName ( ) ) ; mpxjResource . setEmailAddress ( gpResource . getContacts ( ) ) ; mpxjResource . setText ( 1 , gpResource . getPhone ( ) ) ; mpxjResource . setGroup ( m_roleDefinitions . get ( gpResource . getFunction ( ) ) ) ; net . sf . mpxj . ganttproject . schema . Rate gpRate = gpResource . getRate ( ) ; if ( gpRate != null ) { mpxjResource . setStandardRate ( new Rate ( gpRate . getValueAttribute ( ) , TimeUnit . DAYS ) ) ; } readResourceCustomFields ( gpResource , mpxjResource ) ; m_eventManager . fireResourceReadEvent ( mpxjResource ) ; }
This method extracts data for a single resource from a GanttProject file .
20,930
private void readResourceCustomFields ( net . sf . mpxj . ganttproject . schema . Resource gpResource , Resource mpxjResource ) { Map < FieldType , Object > customFields = new HashMap < FieldType , Object > ( ) ; for ( Pair < FieldType , String > definition : m_resourcePropertyDefinitions . values ( ) ) { customFields . put ( definition . getFirst ( ) , definition . getSecond ( ) ) ; } for ( CustomResourceProperty property : gpResource . getCustomProperty ( ) ) { Pair < FieldType , String > definition = m_resourcePropertyDefinitions . get ( property . getDefinitionId ( ) ) ; if ( definition != null ) { String value = property . getValueAttribute ( ) ; if ( value . isEmpty ( ) ) { value = null ; } if ( value != null ) { Object result ; switch ( definition . getFirst ( ) . getDataType ( ) ) { case NUMERIC : { if ( value . indexOf ( '.' ) == - 1 ) { result = Integer . valueOf ( value ) ; } else { result = Double . valueOf ( value ) ; } break ; } case DATE : { try { result = m_localeDateFormat . parse ( value ) ; } catch ( ParseException ex ) { result = null ; } break ; } case BOOLEAN : { result = Boolean . valueOf ( value . equals ( "true" ) ) ; break ; } default : { result = value ; break ; } } if ( result != null ) { customFields . put ( definition . getFirst ( ) , result ) ; } } } } for ( Map . Entry < FieldType , Object > item : customFields . entrySet ( ) ) { if ( item . getValue ( ) != null ) { mpxjResource . set ( item . getKey ( ) , item . getValue ( ) ) ; } } }
Read custom fields for a GanttProject resource .
20,931
private void readTaskCustomFields ( net . sf . mpxj . ganttproject . schema . Task gpTask , Task mpxjTask ) { Map < FieldType , Object > customFields = new HashMap < FieldType , Object > ( ) ; for ( Pair < FieldType , String > definition : m_taskPropertyDefinitions . values ( ) ) { customFields . put ( definition . getFirst ( ) , definition . getSecond ( ) ) ; } for ( CustomTaskProperty property : gpTask . getCustomproperty ( ) ) { Pair < FieldType , String > definition = m_taskPropertyDefinitions . get ( property . getTaskpropertyId ( ) ) ; if ( definition != null ) { String value = property . getValueAttribute ( ) ; if ( value . isEmpty ( ) ) { value = null ; } if ( value != null ) { Object result ; switch ( definition . getFirst ( ) . getDataType ( ) ) { case NUMERIC : { if ( value . indexOf ( '.' ) == - 1 ) { result = Integer . valueOf ( value ) ; } else { result = Double . valueOf ( value ) ; } break ; } case DATE : { try { result = m_dateFormat . parse ( value ) ; } catch ( ParseException ex ) { result = null ; } break ; } case BOOLEAN : { result = Boolean . valueOf ( value . equals ( "true" ) ) ; break ; } default : { result = value ; break ; } } if ( result != null ) { customFields . put ( definition . getFirst ( ) , result ) ; } } } } for ( Map . Entry < FieldType , Object > item : customFields . entrySet ( ) ) { if ( item . getValue ( ) != null ) { mpxjTask . set ( item . getKey ( ) , item . getValue ( ) ) ; } } }
Read custom fields for a GanttProject task .
20,932
private void readTasks ( Project gpProject ) { Tasks tasks = gpProject . getTasks ( ) ; readTaskCustomPropertyDefinitions ( tasks ) ; for ( net . sf . mpxj . ganttproject . schema . Task task : tasks . getTask ( ) ) { readTask ( m_projectFile , task ) ; } }
Read the top level tasks from GanttProject .
20,933
private void readTask ( ChildTaskContainer mpxjParent , net . sf . mpxj . ganttproject . schema . Task gpTask ) { Task mpxjTask = mpxjParent . addTask ( ) ; mpxjTask . setUniqueID ( Integer . valueOf ( NumberHelper . getInt ( gpTask . getId ( ) ) + 1 ) ) ; mpxjTask . setName ( gpTask . getName ( ) ) ; mpxjTask . setPercentageComplete ( gpTask . getComplete ( ) ) ; mpxjTask . setPriority ( getPriority ( gpTask . getPriority ( ) ) ) ; mpxjTask . setHyperlink ( gpTask . getWebLink ( ) ) ; Duration duration = Duration . getInstance ( NumberHelper . getDouble ( gpTask . getDuration ( ) ) , TimeUnit . DAYS ) ; mpxjTask . setDuration ( duration ) ; if ( duration . getDuration ( ) == 0 ) { mpxjTask . setMilestone ( true ) ; } else { mpxjTask . setStart ( gpTask . getStart ( ) ) ; mpxjTask . setFinish ( m_mpxjCalendar . getDate ( gpTask . getStart ( ) , mpxjTask . getDuration ( ) , false ) ) ; } mpxjTask . setConstraintDate ( gpTask . getThirdDate ( ) ) ; if ( mpxjTask . getConstraintDate ( ) != null ) { mpxjTask . setConstraintType ( ConstraintType . START_NO_EARLIER_THAN ) ; } readTaskCustomFields ( gpTask , mpxjTask ) ; m_eventManager . fireTaskReadEvent ( mpxjTask ) ; for ( net . sf . mpxj . ganttproject . schema . Task childTask : gpTask . getTask ( ) ) { readTask ( mpxjTask , childTask ) ; } }
Recursively read a task and any sub tasks .
20,934
private Priority getPriority ( Integer gpPriority ) { int result ; if ( gpPriority == null ) { result = Priority . MEDIUM ; } else { int index = gpPriority . intValue ( ) ; if ( index < 0 || index >= PRIORITY . length ) { result = Priority . MEDIUM ; } else { result = PRIORITY [ index ] ; } } return Priority . getInstance ( result ) ; }
Given a GanttProject priority value turn this into an MPXJ Priority instance .
20,935
private void readRelationships ( Project gpProject ) { for ( net . sf . mpxj . ganttproject . schema . Task gpTask : gpProject . getTasks ( ) . getTask ( ) ) { readRelationships ( gpTask ) ; } }
Read all task relationships from a GanttProject .
20,936
private void readRelationships ( net . sf . mpxj . ganttproject . schema . Task gpTask ) { for ( Depend depend : gpTask . getDepend ( ) ) { Task task1 = m_projectFile . getTaskByUniqueID ( Integer . valueOf ( NumberHelper . getInt ( gpTask . getId ( ) ) + 1 ) ) ; Task task2 = m_projectFile . getTaskByUniqueID ( Integer . valueOf ( NumberHelper . getInt ( depend . getId ( ) ) + 1 ) ) ; if ( task1 != null && task2 != null ) { Duration lag = Duration . getInstance ( NumberHelper . getInt ( depend . getDifference ( ) ) , TimeUnit . DAYS ) ; Relation relation = task2 . addPredecessor ( task1 , getRelationType ( depend . getType ( ) ) , lag ) ; m_eventManager . fireRelationReadEvent ( relation ) ; } } }
Read the relationships for an individual GanttProject task .
20,937
private RelationType getRelationType ( Integer gpType ) { RelationType result = null ; if ( gpType != null ) { int index = NumberHelper . getInt ( gpType ) ; if ( index > 0 && index < RELATION . length ) { result = RELATION [ index ] ; } } if ( result == null ) { result = RelationType . FINISH_START ; } return result ; }
Convert a GanttProject task relationship type into an MPXJ RelationType instance .
20,938
private void readResourceAssignments ( Project gpProject ) { Allocations allocations = gpProject . getAllocations ( ) ; if ( allocations != null ) { for ( Allocation allocation : allocations . getAllocation ( ) ) { readResourceAssignment ( allocation ) ; } } }
Read all resource assignments from a GanttProject project .
20,939
private void readResourceAssignment ( Allocation gpAllocation ) { Integer taskID = Integer . valueOf ( NumberHelper . getInt ( gpAllocation . getTaskId ( ) ) + 1 ) ; Integer resourceID = Integer . valueOf ( NumberHelper . getInt ( gpAllocation . getResourceId ( ) ) + 1 ) ; Task task = m_projectFile . getTaskByUniqueID ( taskID ) ; Resource resource = m_projectFile . getResourceByUniqueID ( resourceID ) ; if ( task != null && resource != null ) { ResourceAssignment mpxjAssignment = task . addResourceAssignment ( resource ) ; mpxjAssignment . setUnits ( gpAllocation . getLoad ( ) ) ; m_eventManager . fireAssignmentReadEvent ( mpxjAssignment ) ; } }
Read an individual GanttProject resource assignment .
20,940
private void writeCustomFields ( ) throws IOException { m_writer . writeStartList ( "custom_fields" ) ; for ( CustomField field : m_projectFile . getCustomFields ( ) ) { writeCustomField ( field ) ; } m_writer . writeEndList ( ) ; }
Write a list of custom field attributes .
20,941
private void writeCustomField ( CustomField field ) throws IOException { if ( field . getAlias ( ) != null ) { m_writer . writeStartObject ( null ) ; m_writer . writeNameValuePair ( "field_type_class" , field . getFieldType ( ) . getFieldTypeClass ( ) . name ( ) . toLowerCase ( ) ) ; m_writer . writeNameValuePair ( "field_type" , field . getFieldType ( ) . name ( ) . toLowerCase ( ) ) ; m_writer . writeNameValuePair ( "field_alias" , field . getAlias ( ) ) ; m_writer . writeEndObject ( ) ; } }
Write attributes for an individual custom field . Note that at present we are only writing a subset of the available data ... in this instance the field alias . If the field does not have an alias we won t write an entry .
20,942
private void writeProperties ( ) throws IOException { writeAttributeTypes ( "property_types" , ProjectField . values ( ) ) ; writeFields ( "property_values" , m_projectFile . getProjectProperties ( ) , ProjectField . values ( ) ) ; }
This method writes project property data to a JSON file .
20,943
private void writeResources ( ) throws IOException { writeAttributeTypes ( "resource_types" , ResourceField . values ( ) ) ; m_writer . writeStartList ( "resources" ) ; for ( Resource resource : m_projectFile . getResources ( ) ) { writeFields ( null , resource , ResourceField . values ( ) ) ; } m_writer . writeEndList ( ) ; }
This method writes resource data to a JSON file .
20,944
private void writeTasks ( ) throws IOException { writeAttributeTypes ( "task_types" , TaskField . values ( ) ) ; m_writer . writeStartList ( "tasks" ) ; for ( Task task : m_projectFile . getChildTasks ( ) ) { writeTask ( task ) ; } m_writer . writeEndList ( ) ; }
This method writes task data to a JSON file . Note that we write the task hierarchy in order to make rebuilding the hierarchy easier .
20,945
private void writeTask ( Task task ) throws IOException { writeFields ( null , task , TaskField . values ( ) ) ; for ( Task child : task . getChildTasks ( ) ) { writeTask ( child ) ; } }
This method is called recursively to write a task and its child tasks to the JSON file .
20,946
private void writeAssignments ( ) throws IOException { writeAttributeTypes ( "assignment_types" , AssignmentField . values ( ) ) ; m_writer . writeStartList ( "assignments" ) ; for ( ResourceAssignment assignment : m_projectFile . getResourceAssignments ( ) ) { writeFields ( null , assignment , AssignmentField . values ( ) ) ; } m_writer . writeEndList ( ) ; }
This method writes assignment data to a JSON file .
20,947
private void writeAttributeTypes ( String name , FieldType [ ] types ) throws IOException { m_writer . writeStartObject ( name ) ; for ( FieldType field : types ) { m_writer . writeNameValuePair ( field . name ( ) . toLowerCase ( ) , field . getDataType ( ) . getValue ( ) ) ; } m_writer . writeEndObject ( ) ; }
Generates a mapping between attribute names and data types .
20,948
private void writeFields ( String objectName , FieldContainer container , FieldType [ ] fields ) throws IOException { m_writer . writeStartObject ( objectName ) ; for ( FieldType field : fields ) { Object value = container . getCurrentValue ( field ) ; if ( value != null ) { writeField ( field , value ) ; } } m_writer . writeEndObject ( ) ; }
Write a set of fields from a field container to a JSON file .
20,949
private void writeIntegerField ( String fieldName , Object value ) throws IOException { int val = ( ( Number ) value ) . intValue ( ) ; if ( val != 0 ) { m_writer . writeNameValuePair ( fieldName , val ) ; } }
Write an integer field to the JSON file .
20,950
private void writeDoubleField ( String fieldName , Object value ) throws IOException { double val = ( ( Number ) value ) . doubleValue ( ) ; if ( val != 0 ) { m_writer . writeNameValuePair ( fieldName , val ) ; } }
Write an double field to the JSON file .
20,951
private void writeBooleanField ( String fieldName , Object value ) throws IOException { boolean val = ( ( Boolean ) value ) . booleanValue ( ) ; if ( val ) { m_writer . writeNameValuePair ( fieldName , val ) ; } }
Write a boolean field to the JSON file .
20,952
private void writeDurationField ( String fieldName , Object value ) throws IOException { if ( value instanceof String ) { m_writer . writeNameValuePair ( fieldName + "_text" , ( String ) value ) ; } else { Duration val = ( Duration ) value ; if ( val . getDuration ( ) != 0 ) { Duration minutes = val . convertUnits ( TimeUnit . MINUTES , m_projectFile . getProjectProperties ( ) ) ; long seconds = ( long ) ( minutes . getDuration ( ) * 60.0 ) ; m_writer . writeNameValuePair ( fieldName , seconds ) ; } } }
Write a duration field to the JSON file .
20,953
private void writeDateField ( String fieldName , Object value ) throws IOException { if ( value instanceof String ) { m_writer . writeNameValuePair ( fieldName + "_text" , ( String ) value ) ; } else { Date val = ( Date ) value ; m_writer . writeNameValuePair ( fieldName , val ) ; } }
Write a date field to the JSON file .
20,954
private void writeTimeUnitsField ( String fieldName , Object value ) throws IOException { TimeUnit val = ( TimeUnit ) value ; if ( val != m_projectFile . getProjectProperties ( ) . getDefaultDurationUnits ( ) ) { m_writer . writeNameValuePair ( fieldName , val . toString ( ) ) ; } }
Write a time units field to the JSON file .
20,955
private void writePriorityField ( String fieldName , Object value ) throws IOException { m_writer . writeNameValuePair ( fieldName , ( ( Priority ) value ) . getValue ( ) ) ; }
Write a priority field to the JSON file .
20,956
private void writeMap ( String fieldName , Object value ) throws IOException { @ SuppressWarnings ( "unchecked" ) Map < String , Object > map = ( Map < String , Object > ) value ; m_writer . writeStartObject ( fieldName ) ; for ( Map . Entry < String , Object > entry : map . entrySet ( ) ) { Object entryValue = entry . getValue ( ) ; if ( entryValue != null ) { DataType type = TYPE_MAP . get ( entryValue . getClass ( ) . getName ( ) ) ; if ( type == null ) { type = DataType . STRING ; entryValue = entryValue . toString ( ) ; } writeField ( entry . getKey ( ) , type , entryValue ) ; } } m_writer . writeEndObject ( ) ; }
Write a map field to the JSON file .
20,957
private void writeStringField ( String fieldName , Object value ) throws IOException { String val = value . toString ( ) ; if ( ! val . isEmpty ( ) ) { m_writer . writeNameValuePair ( fieldName , val ) ; } }
Write a string field to the JSON file .
20,958
private void writeRelationList ( String fieldName , Object value ) throws IOException { @ SuppressWarnings ( "unchecked" ) List < Relation > list = ( List < Relation > ) value ; if ( ! list . isEmpty ( ) ) { m_writer . writeStartList ( fieldName ) ; for ( Relation relation : list ) { m_writer . writeStartObject ( null ) ; writeIntegerField ( "task_unique_id" , relation . getTargetTask ( ) . getUniqueID ( ) ) ; writeDurationField ( "lag" , relation . getLag ( ) ) ; writeStringField ( "type" , relation . getType ( ) ) ; m_writer . writeEndObject ( ) ; } m_writer . writeEndList ( ) ; } }
Write a relation list field to the JSON file .
20,959
public static ResourceField getMpxjField ( int value ) { ResourceField result = null ; if ( value >= 0 && value < MPX_MPXJ_ARRAY . length ) { result = MPX_MPXJ_ARRAY [ value ] ; } return ( result ) ; }
Retrieve an instance of the ResourceField class based on the data read from an MPX file .
20,960
public boolean evaluate ( FieldContainer container , Map < GenericCriteriaPrompt , Object > promptValues ) { boolean result = true ; if ( m_criteria != null ) { result = m_criteria . evaluate ( container , promptValues ) ; if ( ! result && m_showRelatedSummaryRows && container instanceof Task ) { for ( Task task : ( ( Task ) container ) . getChildTasks ( ) ) { if ( evaluate ( task , promptValues ) ) { result = true ; break ; } } } } return ( result ) ; }
Evaluates the filter returns true if the supplied Task or Resource instance matches the filter criteria .
20,961
public void parseRawValue ( String value ) { int valueIndex = 0 ; int elementIndex = 0 ; m_elements . clear ( ) ; while ( valueIndex < value . length ( ) && elementIndex < m_elements . size ( ) ) { int elementLength = m_lengths . get ( elementIndex ) . intValue ( ) ; if ( elementIndex > 0 ) { m_elements . add ( m_separators . get ( elementIndex - 1 ) ) ; } int endIndex = valueIndex + elementLength ; if ( endIndex > value . length ( ) ) { endIndex = value . length ( ) ; } String element = value . substring ( valueIndex , endIndex ) ; m_elements . add ( element ) ; valueIndex += elementLength ; elementIndex ++ ; } }
Parses a raw WBS value from the database and breaks it into component parts ready for formatting .
20,962
public String getFormattedParentValue ( ) { String result = null ; if ( m_elements . size ( ) > 2 ) { result = joinElements ( m_elements . size ( ) - 2 ) ; } return result ; }
Retrieves the formatted parent WBS value .
20,963
private String joinElements ( int length ) { StringBuilder sb = new StringBuilder ( ) ; for ( int index = 0 ; index < length ; index ++ ) { sb . append ( m_elements . get ( index ) ) ; } return sb . toString ( ) ; }
Joins the individual WBS elements to make the formated value .
20,964
private void addTasks ( MpxjTreeNode parentNode , ChildTaskContainer parent ) { for ( Task task : parent . getChildTasks ( ) ) { final Task t = task ; MpxjTreeNode childNode = new MpxjTreeNode ( task , TASK_EXCLUDED_METHODS ) { public String toString ( ) { return t . getName ( ) ; } } ; parentNode . add ( childNode ) ; addTasks ( childNode , task ) ; } }
Add tasks to the tree .
20,965
private void addResources ( MpxjTreeNode parentNode , ProjectFile file ) { for ( Resource resource : file . getResources ( ) ) { final Resource r = resource ; MpxjTreeNode childNode = new MpxjTreeNode ( resource ) { public String toString ( ) { return r . getName ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add resources to the tree .
20,966
private void addCalendars ( MpxjTreeNode parentNode , ProjectFile file ) { for ( ProjectCalendar calendar : file . getCalendars ( ) ) { addCalendar ( parentNode , calendar ) ; } }
Add calendars to the tree .
20,967
private void addCalendar ( MpxjTreeNode parentNode , final ProjectCalendar calendar ) { MpxjTreeNode calendarNode = new MpxjTreeNode ( calendar , CALENDAR_EXCLUDED_METHODS ) { public String toString ( ) { return calendar . getName ( ) ; } } ; parentNode . add ( calendarNode ) ; MpxjTreeNode daysFolder = new MpxjTreeNode ( "Days" ) ; calendarNode . add ( daysFolder ) ; for ( Day day : Day . values ( ) ) { addCalendarDay ( daysFolder , calendar , day ) ; } MpxjTreeNode exceptionsFolder = new MpxjTreeNode ( "Exceptions" ) ; calendarNode . add ( exceptionsFolder ) ; for ( ProjectCalendarException exception : calendar . getCalendarExceptions ( ) ) { addCalendarException ( exceptionsFolder , exception ) ; } }
Add a calendar node .
20,968
private void addCalendarDay ( MpxjTreeNode parentNode , ProjectCalendar calendar , final Day day ) { MpxjTreeNode dayNode = new MpxjTreeNode ( day ) { public String toString ( ) { return day . name ( ) ; } } ; parentNode . add ( dayNode ) ; addHours ( dayNode , calendar . getHours ( day ) ) ; }
Add a calendar day node .
20,969
private void addHours ( MpxjTreeNode parentNode , ProjectCalendarDateRanges hours ) { for ( DateRange range : hours ) { final DateRange r = range ; MpxjTreeNode rangeNode = new MpxjTreeNode ( range ) { public String toString ( ) { return m_timeFormat . format ( r . getStart ( ) ) + " - " + m_timeFormat . format ( r . getEnd ( ) ) ; } } ; parentNode . add ( rangeNode ) ; } }
Add hours to a parent object .
20,970
private void addCalendarException ( MpxjTreeNode parentNode , final ProjectCalendarException exception ) { MpxjTreeNode exceptionNode = new MpxjTreeNode ( exception , CALENDAR_EXCEPTION_EXCLUDED_METHODS ) { public String toString ( ) { return m_dateFormat . format ( exception . getFromDate ( ) ) ; } } ; parentNode . add ( exceptionNode ) ; addHours ( exceptionNode , exception ) ; }
Add an exception to a calendar .
20,971
private void addGroups ( MpxjTreeNode parentNode , ProjectFile file ) { for ( Group group : file . getGroups ( ) ) { final Group g = group ; MpxjTreeNode childNode = new MpxjTreeNode ( group ) { public String toString ( ) { return g . getName ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add groups to the tree .
20,972
private void addCustomFields ( MpxjTreeNode parentNode , ProjectFile file ) { for ( CustomField field : file . getCustomFields ( ) ) { final CustomField c = field ; MpxjTreeNode childNode = new MpxjTreeNode ( field ) { public String toString ( ) { FieldType type = c . getFieldType ( ) ; return type == null ? "(unknown)" : type . getFieldTypeClass ( ) + "." + type . toString ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add custom fields to the tree .
20,973
private void addViews ( MpxjTreeNode parentNode , ProjectFile file ) { for ( View view : file . getViews ( ) ) { final View v = view ; MpxjTreeNode childNode = new MpxjTreeNode ( view ) { public String toString ( ) { return v . getName ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add views to the tree .
20,974
private void addTables ( MpxjTreeNode parentNode , ProjectFile file ) { for ( Table table : file . getTables ( ) ) { final Table t = table ; MpxjTreeNode childNode = new MpxjTreeNode ( table , TABLE_EXCLUDED_METHODS ) { public String toString ( ) { return t . getName ( ) ; } } ; parentNode . add ( childNode ) ; addColumns ( childNode , table ) ; } }
Add tables to the tree .
20,975
private void addColumns ( MpxjTreeNode parentNode , Table table ) { for ( Column column : table . getColumns ( ) ) { final Column c = column ; MpxjTreeNode childNode = new MpxjTreeNode ( column ) { public String toString ( ) { return c . getTitle ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add columns to the tree .
20,976
private void addFilters ( MpxjTreeNode parentNode , List < Filter > filters ) { for ( Filter field : filters ) { final Filter f = field ; MpxjTreeNode childNode = new MpxjTreeNode ( field ) { public String toString ( ) { return f . getName ( ) ; } } ; parentNode . add ( childNode ) ; } }
Add filters to the tree .
20,977
private void addAssignments ( MpxjTreeNode parentNode , ProjectFile file ) { for ( ResourceAssignment assignment : file . getResourceAssignments ( ) ) { final ResourceAssignment a = assignment ; MpxjTreeNode childNode = new MpxjTreeNode ( a ) { public String toString ( ) { Resource resource = a . getResource ( ) ; String resourceName = resource == null ? "(unknown resource)" : resource . getName ( ) ; Task task = a . getTask ( ) ; String taskName = task == null ? "(unknown task)" : task . getName ( ) ; return resourceName + "->" + taskName ; } } ; parentNode . add ( childNode ) ; } }
Add assignments to the tree .
20,978
public void saveFile ( File file , String type ) { try { Class < ? extends ProjectWriter > fileClass = WRITER_MAP . get ( type ) ; if ( fileClass == null ) { throw new IllegalArgumentException ( "Cannot write files of type: " + type ) ; } ProjectWriter writer = fileClass . newInstance ( ) ; writer . write ( m_projectFile , file ) ; } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } }
Save the current file as the given type .
20,979
private static Set < String > excludedMethods ( String ... methodNames ) { Set < String > set = new HashSet < String > ( MpxjTreeNode . DEFAULT_EXCLUDED_METHODS ) ; set . addAll ( Arrays . asList ( methodNames ) ) ; return set ; }
Generates a set of excluded method names .
20,980
public void close ( ) throws IOException { long skippedLast = 0 ; if ( m_remaining > 0 ) { skippedLast = skip ( m_remaining ) ; while ( m_remaining > 0 && skippedLast > 0 ) { skippedLast = skip ( m_remaining ) ; } } }
Closing will only skip to the end of this fixed length input stream and not call the parent s close method .
20,981
public static void setLocale ( ProjectProperties properties , Locale locale ) { properties . setMpxDelimiter ( LocaleData . getChar ( locale , LocaleData . FILE_DELIMITER ) ) ; properties . setMpxProgramName ( LocaleData . getString ( locale , LocaleData . PROGRAM_NAME ) ) ; properties . setMpxCodePage ( ( CodePage ) LocaleData . getObject ( locale , LocaleData . CODE_PAGE ) ) ; properties . setCurrencySymbol ( LocaleData . getString ( locale , LocaleData . CURRENCY_SYMBOL ) ) ; properties . setSymbolPosition ( ( CurrencySymbolPosition ) LocaleData . getObject ( locale , LocaleData . CURRENCY_SYMBOL_POSITION ) ) ; properties . setCurrencyDigits ( LocaleData . getInteger ( locale , LocaleData . CURRENCY_DIGITS ) ) ; properties . setThousandsSeparator ( LocaleData . getChar ( locale , LocaleData . CURRENCY_THOUSANDS_SEPARATOR ) ) ; properties . setDecimalSeparator ( LocaleData . getChar ( locale , LocaleData . CURRENCY_DECIMAL_SEPARATOR ) ) ; properties . setDateOrder ( ( DateOrder ) LocaleData . getObject ( locale , LocaleData . DATE_ORDER ) ) ; properties . setTimeFormat ( ( ProjectTimeFormat ) LocaleData . getObject ( locale , LocaleData . TIME_FORMAT ) ) ; properties . setDefaultStartTime ( DateHelper . getTimeFromMinutesPastMidnight ( LocaleData . getInteger ( locale , LocaleData . DEFAULT_START_TIME ) ) ) ; properties . setDateSeparator ( LocaleData . getChar ( locale , LocaleData . DATE_SEPARATOR ) ) ; properties . setTimeSeparator ( LocaleData . getChar ( locale , LocaleData . TIME_SEPARATOR ) ) ; properties . setAMText ( LocaleData . getString ( locale , LocaleData . AM_TEXT ) ) ; properties . setPMText ( LocaleData . getString ( locale , LocaleData . PM_TEXT ) ) ; properties . setDateFormat ( ( ProjectDateFormat ) LocaleData . getObject ( locale , LocaleData . DATE_FORMAT ) ) ; properties . setBarTextDateFormat ( ( ProjectDateFormat ) LocaleData . getObject ( locale , LocaleData . DATE_FORMAT ) ) ; }
This method is called when the locale of the parent file is updated . It resets the locale specific currency attributes to the default values for the new locale .
20,982
public String getTitle ( Locale locale ) { String result = null ; if ( m_title != null ) { result = m_title ; } else { if ( m_fieldType != null ) { result = m_project . getCustomFields ( ) . getCustomField ( m_fieldType ) . getAlias ( ) ; if ( result == null ) { result = m_fieldType . getName ( locale ) ; } } } return ( result ) ; }
Retrieves the column title for the given locale .
20,983
public static AccrueType getInstance ( String type , Locale locale ) { AccrueType result = null ; String [ ] typeNames = LocaleData . getStringArray ( locale , LocaleData . ACCRUE_TYPES ) ; for ( int loop = 0 ; loop < typeNames . length ; loop ++ ) { if ( typeNames [ loop ] . equalsIgnoreCase ( type ) == true ) { result = AccrueType . getInstance ( loop + 1 ) ; break ; } } if ( result == null ) { result = AccrueType . PRORATED ; } return ( result ) ; }
This method takes the textual version of an accrue type name and populates the class instance appropriately . Note that unrecognised values are treated as Prorated .
20,984
public void process ( Connection connection , String directory ) throws Exception { connection . setAutoCommit ( true ) ; DatabaseMetaData dmd = connection . getMetaData ( ) ; String [ ] types = { "TABLE" } ; FileWriter fw = new FileWriter ( directory ) ; PrintWriter pw = new PrintWriter ( fw ) ; pw . println ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ) ; pw . println ( ) ; pw . println ( "<database>" ) ; ResultSet tables = dmd . getTables ( null , null , null , types ) ; while ( tables . next ( ) == true ) { processTable ( pw , connection , tables . getString ( "TABLE_NAME" ) ) ; } pw . println ( "</database>" ) ; pw . close ( ) ; tables . close ( ) ; }
Export data base contents to a directory using supplied connection .
20,985
private String escapeText ( StringBuilder sb , String text ) { int length = text . length ( ) ; char c ; sb . setLength ( 0 ) ; for ( int loop = 0 ; loop < length ; loop ++ ) { c = text . charAt ( loop ) ; switch ( c ) { case '<' : { sb . append ( "&lt;" ) ; break ; } case '>' : { sb . append ( "&gt;" ) ; break ; } case '&' : { sb . append ( "&amp;" ) ; break ; } default : { if ( validXMLCharacter ( c ) ) { if ( c > 127 ) { sb . append ( "&#" + ( int ) c + ";" ) ; } else { sb . append ( c ) ; } } break ; } } } return ( sb . toString ( ) ) ; }
Quick and dirty XML text escape .
20,986
public static String rset ( String input , int width ) { String result ; StringBuilder pad = new StringBuilder ( ) ; if ( input == null ) { for ( int i = 0 ; i < width - 1 ; i ++ ) { pad . append ( ' ' ) ; } result = " " + pad ; } else { if ( input . length ( ) >= width ) { result = input . substring ( 0 , width ) ; } else { int padLength = width - input . length ( ) ; for ( int i = 0 ; i < padLength ; i ++ ) { pad . append ( ' ' ) ; } result = pad + input ; } } return result ; }
Another method to force an input string into a fixed width field and set it on the right with the left side filled with space characters .
20,987
public static String workDays ( ProjectCalendar input ) { StringBuilder result = new StringBuilder ( ) ; DayType [ ] test = input . getDays ( ) ; for ( DayType i : test ) { if ( i == DayType . NON_WORKING ) { result . append ( "N" ) ; } else { result . append ( "Y" ) ; } } return result . toString ( ) ; }
This method takes a calendar of MPXJ library type then returns a String of the general working days USACE format . For example the regular 5 - day work week is NYYYYYN
20,988
public static File writeStreamToTempFile ( InputStream inputStream , String tempFileSuffix ) throws IOException { FileOutputStream outputStream = null ; try { File file = File . createTempFile ( "mpxj" , tempFileSuffix ) ; outputStream = new FileOutputStream ( file ) ; byte [ ] buffer = new byte [ 1024 ] ; while ( true ) { int bytesRead = inputStream . read ( buffer ) ; if ( bytesRead == - 1 ) { break ; } outputStream . write ( buffer , 0 , bytesRead ) ; } return file ; } finally { if ( outputStream != null ) { outputStream . close ( ) ; } } }
Copy the data from an InputStream to a temp file .
20,989
public static Record getRecord ( String text ) { Record root ; try { root = new Record ( text ) ; } catch ( Exception ex ) { root = null ; } return root ; }
Create a structured Record instance from the flat text data . Null is returned if errors are encountered during parse .
20,990
public Record getChild ( String key ) { Record result = null ; if ( key != null ) { for ( Record record : m_records ) { if ( key . equals ( record . getField ( ) ) ) { result = record ; break ; } } } return result ; }
Retrieve a child record by name .
20,991
private int getClosingParenthesisPosition ( String text , int opening ) { if ( text . charAt ( opening ) != '(' ) { return - 1 ; } int count = 0 ; for ( int i = opening ; i < text . length ( ) ; i ++ ) { char c = text . charAt ( i ) ; switch ( c ) { case '(' : { ++ count ; break ; } case ')' : { -- count ; if ( count == 0 ) { return i ; } break ; } } } return - 1 ; }
Look for the closing parenthesis corresponding to the one at position represented by the opening index .
20,992
public static final long getLong ( byte [ ] data , int offset ) { if ( data . length != 8 ) { throw new UnexpectedStructureException ( ) ; } long result = 0 ; int i = offset ; for ( int shiftBy = 0 ; shiftBy < 64 ; shiftBy += 8 ) { result |= ( ( long ) ( data [ i ] & 0xff ) ) << shiftBy ; ++ i ; } return result ; }
This method reads an eight byte integer from the input array .
20,993
public static final TimeUnit getTimeUnit ( int value ) { TimeUnit result = null ; switch ( value ) { case 1 : { result = TimeUnit . ELAPSED_DAYS ; break ; } case 2 : { result = TimeUnit . HOURS ; break ; } case 4 : { result = TimeUnit . DAYS ; break ; } case 6 : { result = TimeUnit . WEEKS ; break ; } case 8 : case 10 : { result = TimeUnit . MONTHS ; break ; } case 12 : { result = TimeUnit . YEARS ; break ; } default : { break ; } } return result ; }
Convert an integer value into a TimeUnit instance .
20,994
public static int skipToNextMatchingShort ( byte [ ] buffer , int offset , int value ) { int nextOffset = offset ; while ( getShort ( buffer , nextOffset ) != value ) { ++ nextOffset ; } nextOffset += 2 ; return nextOffset ; }
Skip to the next matching short value .
20,995
public static final String hexdump ( byte [ ] buffer , int offset , int length , boolean ascii , int columns , String prefix ) { StringBuilder sb = new StringBuilder ( ) ; if ( buffer != null ) { int index = offset ; DecimalFormat df = new DecimalFormat ( "00000" ) ; while ( index < ( offset + length ) ) { if ( index + columns > ( offset + length ) ) { columns = ( offset + length ) - index ; } sb . append ( prefix ) ; sb . append ( df . format ( index - offset ) ) ; sb . append ( ":" ) ; sb . append ( hexdump ( buffer , index , columns , ascii ) ) ; sb . append ( '\n' ) ; index += columns ; } } return ( sb . toString ( ) ) ; }
Dump raw data as hex .
20,996
public void generateWBS ( Task parent ) { String wbs ; if ( parent == null ) { if ( NumberHelper . getInt ( getUniqueID ( ) ) == 0 ) { wbs = "0" ; } else { wbs = Integer . toString ( getParentFile ( ) . getChildTasks ( ) . size ( ) + 1 ) ; } } else { wbs = parent . getWBS ( ) ; int childTaskCount = parent . getChildTasks ( ) . size ( ) + 1 ; if ( wbs . equals ( "0" ) ) { wbs = Integer . toString ( childTaskCount ) ; } else { wbs += ( "." + childTaskCount ) ; } } setWBS ( wbs ) ; }
This method is used to automatically generate a value for the WBS field of this task .
20,997
public void generateOutlineNumber ( Task parent ) { String outline ; if ( parent == null ) { if ( NumberHelper . getInt ( getUniqueID ( ) ) == 0 ) { outline = "0" ; } else { outline = Integer . toString ( getParentFile ( ) . getChildTasks ( ) . size ( ) + 1 ) ; } } else { outline = parent . getOutlineNumber ( ) ; int index = outline . lastIndexOf ( ".0" ) ; if ( index != - 1 ) { outline = outline . substring ( 0 , index ) ; } int childTaskCount = parent . getChildTasks ( ) . size ( ) + 1 ; if ( outline . equals ( "0" ) ) { outline = Integer . toString ( childTaskCount ) ; } else { outline += ( "." + childTaskCount ) ; } } setOutlineNumber ( outline ) ; }
This method is used to automatically generate a value for the Outline Number field of this task .
20,998
public Task addTask ( ) { ProjectFile parent = getParentFile ( ) ; Task task = new Task ( parent , this ) ; m_children . add ( task ) ; parent . getTasks ( ) . add ( task ) ; setSummary ( true ) ; return ( task ) ; }
This method allows nested tasks to be added with the WBS being completed automatically .
20,999
public void addChildTask ( Task child , int childOutlineLevel ) { int outlineLevel = NumberHelper . getInt ( getOutlineLevel ( ) ) ; if ( ( outlineLevel + 1 ) == childOutlineLevel ) { m_children . add ( child ) ; setSummary ( true ) ; } else { if ( m_children . isEmpty ( ) == false ) { ( m_children . get ( m_children . size ( ) - 1 ) ) . addChildTask ( child , childOutlineLevel ) ; } } }
This method is used to associate a child task with the current task instance . It has package access and has been designed to allow the hierarchical outline structure of tasks in an MPX file to be constructed as the file is read in .