idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
20,800
public void writeStartObject ( String name ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; if ( name != null ) { writeName ( name ) ; writeNewLineIndent ( ) ; } m_writer . write ( "{" ) ; increaseIndent ( ) ; }
Begin writing a named object attribute .
20,801
public void writeStartList ( String name ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; writeName ( name ) ; writeNewLineIndent ( ) ; m_writer . write ( "[" ) ; increaseIndent ( ) ; }
Begin writing a named list attribute .
20,802
public void writeNameValuePair ( String name , String value ) throws IOException { internalWriteNameValuePair ( name , escapeString ( value ) ) ; }
Write a string attribute .
20,803
public void writeNameValuePair ( String name , int value ) throws IOException { internalWriteNameValuePair ( name , Integer . toString ( value ) ) ; }
Write an int attribute .
20,804
public void writeNameValuePair ( String name , long value ) throws IOException { internalWriteNameValuePair ( name , Long . toString ( value ) ) ; }
Write a long attribute .
20,805
public void writeNameValuePair ( String name , double value ) throws IOException { internalWriteNameValuePair ( name , Double . toString ( value ) ) ; }
Write a double attribute .
20,806
public void writeNameValuePair ( String name , Date value ) throws IOException { internalWriteNameValuePair ( name , m_format . format ( value ) ) ; }
Write a Date attribute .
20,807
private void internalWriteNameValuePair ( String name , String value ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; writeName ( name ) ; if ( m_pretty ) { m_writer . write ( ' ' ) ; } m_writer . write ( value ) ; }
Core write attribute implementation .
20,808
private String escapeString ( String value ) { m_buffer . setLength ( 0 ) ; m_buffer . append ( '"' ) ; for ( int index = 0 ; index < value . length ( ) ; index ++ ) { char c = value . charAt ( index ) ; switch ( c ) { case '"' : { m_buffer . append ( "\\\"" ) ; break ; } case '\\' : { m_buffer . append ( "\\\\" ) ; break ; } case '/' : { m_buffer . append ( "\\/" ) ; break ; } case '\b' : { m_buffer . append ( "\\b" ) ; break ; } case '\f' : { m_buffer . append ( "\\f" ) ; break ; } case '\n' : { m_buffer . append ( "\\n" ) ; break ; } case '\r' : { m_buffer . append ( "\\r" ) ; break ; } case '\t' : { m_buffer . append ( "\\t" ) ; break ; } default : { if ( c > 0x1f ) { m_buffer . append ( c ) ; } break ; } } } m_buffer . append ( '"' ) ; return m_buffer . toString ( ) ; }
Escape text to ensure valid JSON .
20,809
private void writeComma ( ) throws IOException { if ( m_firstNameValuePair . peek ( ) . booleanValue ( ) ) { m_firstNameValuePair . pop ( ) ; m_firstNameValuePair . push ( Boolean . FALSE ) ; } else { m_writer . write ( ',' ) ; } }
Write a comma to the output stream if required .
20,810
private void writeNewLineIndent ( ) throws IOException { if ( m_pretty ) { if ( ! m_indent . isEmpty ( ) ) { m_writer . write ( '\n' ) ; m_writer . write ( m_indent ) ; } } }
Write a new line and indent .
20,811
private void writeName ( String name ) throws IOException { m_writer . write ( '"' ) ; m_writer . write ( name ) ; m_writer . write ( '"' ) ; m_writer . write ( ":" ) ; }
Write an attribute name .
20,812
private void decreaseIndent ( ) throws IOException { if ( m_pretty ) { m_writer . write ( '\n' ) ; m_indent = m_indent . substring ( 0 , m_indent . length ( ) - INDENT . length ( ) ) ; m_writer . write ( m_indent ) ; } m_firstNameValuePair . pop ( ) ; }
Decrease the indent level .
20,813
public void process ( AvailabilityTable table , byte [ ] data ) { if ( data != null ) { Calendar cal = DateHelper . popCalendar ( ) ; int items = MPPUtility . getShort ( data , 0 ) ; int offset = 12 ; for ( int loop = 0 ; loop < items ; loop ++ ) { double unitsValue = MPPUtility . getDouble ( data , offset + 4 ) ; if ( unitsValue != 0 ) { Date startDate = MPPUtility . getTimestampFromTenths ( data , offset ) ; Date endDate = MPPUtility . getTimestampFromTenths ( data , offset + 20 ) ; cal . setTime ( endDate ) ; cal . add ( Calendar . MINUTE , - 1 ) ; endDate = cal . getTime ( ) ; Double units = NumberHelper . getDouble ( unitsValue / 100 ) ; Availability item = new Availability ( startDate , endDate , units ) ; table . add ( item ) ; } offset += 20 ; } DateHelper . pushCalendar ( cal ) ; Collections . sort ( table ) ; } }
Populates a resource availability table .
20,814
public static final Object getObject ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( bundle . getObject ( key ) ) ; }
Convenience method for retrieving an Object resource .
20,815
@ SuppressWarnings ( "rawtypes" ) public static final Map getMap ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( ( Map ) bundle . getObject ( key ) ) ; }
Convenience method for retrieving a Map resource .
20,816
public static final Integer getInteger ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( ( Integer ) bundle . getObject ( key ) ) ; }
Convenience method for retrieving an Integer resource .
20,817
public static final char getChar ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( bundle . getString ( key ) . charAt ( 0 ) ) ; }
Convenience method for retrieving a char resource .
20,818
public boolean getOverAllocated ( ) { Boolean overallocated = ( Boolean ) getCachedValue ( ResourceField . OVERALLOCATED ) ; if ( overallocated == null ) { Number peakUnits = getPeakUnits ( ) ; Number maxUnits = getMaxUnits ( ) ; overallocated = Boolean . valueOf ( NumberHelper . getDouble ( peakUnits ) > NumberHelper . getDouble ( maxUnits ) ) ; set ( ResourceField . OVERALLOCATED , overallocated ) ; } return ( overallocated . booleanValue ( ) ) ; }
Retrieves the overallocated flag .
20,819
public Date getStart ( ) { Date result = null ; for ( ResourceAssignment assignment : m_assignments ) { if ( result == null || DateHelper . compare ( result , assignment . getStart ( ) ) > 0 ) { result = assignment . getStart ( ) ; } } return ( result ) ; }
Retrieves the earliest start date for all assigned tasks .
20,820
public Duration getWorkVariance ( ) { Duration variance = ( Duration ) getCachedValue ( ResourceField . WORK_VARIANCE ) ; if ( variance == null ) { Duration work = getWork ( ) ; Duration baselineWork = getBaselineWork ( ) ; if ( work != null && baselineWork != null ) { variance = Duration . getInstance ( work . getDuration ( ) - baselineWork . convertUnits ( work . getUnits ( ) , getParentFile ( ) . getProjectProperties ( ) ) . getDuration ( ) , work . getUnits ( ) ) ; set ( ResourceField . WORK_VARIANCE , variance ) ; } } return ( variance ) ; }
Retrieves the work variance .
20,821
public String getNotes ( ) { String notes = ( String ) getCachedValue ( ResourceField . NOTES ) ; return ( notes == null ? "" : notes ) ; }
Retrieves the notes text for this resource .
20,822
public void setResourceCalendar ( ProjectCalendar calendar ) { set ( ResourceField . CALENDAR , calendar ) ; if ( calendar == null ) { setResourceCalendarUniqueID ( null ) ; } else { calendar . setResource ( this ) ; setResourceCalendarUniqueID ( calendar . getUniqueID ( ) ) ; } }
This method allows a pre - existing resource calendar to be attached to a resource .
20,823
public ProjectCalendar addResourceCalendar ( ) throws MPXJException { if ( getResourceCalendar ( ) != null ) { throw new MPXJException ( MPXJException . MAXIMUM_RECORDS ) ; } ProjectCalendar calendar = new ProjectCalendar ( getParentFile ( ) ) ; setResourceCalendar ( calendar ) ; return calendar ; }
This method allows a resource calendar to be added to a resource .
20,824
public void setBaseCalendar ( String val ) { set ( ResourceField . BASE_CALENDAR , val == null || val . length ( ) == 0 ? "Standard" : val ) ; }
Sets the Base Calendar field indicates which calendar is the base calendar for a resource calendar . The list includes the three built - in calendars as well as any new base calendars you have created in the Change Working Time dialog box .
20,825
public void setID ( Integer val ) { ProjectFile parent = getParentFile ( ) ; Integer previous = getID ( ) ; if ( previous != null ) { parent . getResources ( ) . unmapID ( previous ) ; } parent . getResources ( ) . mapID ( val , this ) ; set ( ResourceField . ID , val ) ; }
Sets ID field value .
20,826
public boolean getFlag ( int index ) { return BooleanHelper . getBoolean ( ( Boolean ) getCachedValue ( selectField ( ResourceFieldLists . CUSTOM_FLAG , index ) ) ) ; }
Retrieve a flag value .
20,827
private ResourceField selectField ( ResourceField [ ] fields , int index ) { if ( index < 1 || index > fields . length ) { throw new IllegalArgumentException ( index + " is not a valid field index" ) ; } return ( fields [ index - 1 ] ) ; }
Maps a field index to a ResourceField instance .
20,828
protected void mergeSameWork ( LinkedList < TimephasedWork > list ) { LinkedList < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; TimephasedWork previousAssignment = null ; for ( TimephasedWork assignment : list ) { if ( previousAssignment == null ) { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; result . add ( assignment ) ; } else { Duration previousAssignmentWork = previousAssignment . getAmountPerDay ( ) ; Duration assignmentWork = assignment . getTotalAmount ( ) ; if ( NumberHelper . equals ( previousAssignmentWork . getDuration ( ) , assignmentWork . getDuration ( ) , 0.01 ) ) { Date assignmentStart = previousAssignment . getStart ( ) ; Date assignmentFinish = assignment . getFinish ( ) ; double total = previousAssignment . getTotalAmount ( ) . getDuration ( ) ; total += assignmentWork . getDuration ( ) ; Duration totalWork = Duration . getInstance ( total , TimeUnit . MINUTES ) ; TimephasedWork merged = new TimephasedWork ( ) ; merged . setStart ( assignmentStart ) ; merged . setFinish ( assignmentFinish ) ; merged . setAmountPerDay ( assignmentWork ) ; merged . setTotalAmount ( totalWork ) ; result . removeLast ( ) ; assignment = merged ; } else { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; } result . add ( assignment ) ; } previousAssignment = assignment ; } list . clear ( ) ; list . addAll ( result ) ; }
Merges individual days together into time spans where the same work is undertaken each day .
20,829
protected void convertToHours ( LinkedList < TimephasedWork > list ) { for ( TimephasedWork assignment : list ) { Duration totalWork = assignment . getTotalAmount ( ) ; Duration workPerDay = assignment . getAmountPerDay ( ) ; totalWork = Duration . getInstance ( totalWork . getDuration ( ) / 60 , TimeUnit . HOURS ) ; workPerDay = Duration . getInstance ( workPerDay . getDuration ( ) / 60 , TimeUnit . HOURS ) ; assignment . setTotalAmount ( totalWork ) ; assignment . setAmountPerDay ( workPerDay ) ; } }
Converts assignment duration values from minutes to hours .
20,830
public void addColumn ( FastTrackColumn column ) { FastTrackField type = column . getType ( ) ; Object [ ] data = column . getData ( ) ; for ( int index = 0 ; index < data . length ; index ++ ) { MapRow row = getRow ( index ) ; row . getMap ( ) . put ( type , data [ index ] ) ; } }
Add data for a column to this table .
20,831
private MapRow getRow ( int index ) { MapRow result ; if ( index == m_rows . size ( ) ) { result = new MapRow ( this , new HashMap < FastTrackField , Object > ( ) ) ; m_rows . add ( result ) ; } else { result = m_rows . get ( index ) ; } return result ; }
Retrieve a specific row by index number creating a blank row if this row does not exist .
20,832
private void setRecordNumber ( LinkedList < String > list ) { try { String number = list . remove ( 0 ) ; m_recordNumber = Integer . valueOf ( number ) ; } catch ( NumberFormatException ex ) { } }
Pop the record number from the front of the list and parse it to ensure that it is a valid integer .
20,833
public String getString ( int field ) { String result ; if ( field < m_fields . length ) { result = m_fields [ field ] ; if ( result != null ) { result = result . replace ( MPXConstants . EOL_PLACEHOLDER , '\n' ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a String object representing the contents of an individual field . If the field does not exist in the record null is returned .
20,834
public Character getCharacter ( int field ) { Character result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = Character . valueOf ( m_fields [ field ] . charAt ( 0 ) ) ; } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a char representing the contents of an individual field . If the field does not exist in the record the default character is returned .
20,835
public Number getFloat ( int field ) throws MPXJException { try { Number result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = m_formats . getDecimalFormat ( ) . parse ( m_fields [ field ] ) ; } else { result = null ; } return ( result ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse float" , ex ) ; } }
Accessor method used to retrieve a Float object representing the contents of an individual field . If the field does not exist in the record null is returned .
20,836
public boolean getNumericBoolean ( int field ) { boolean result = false ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = Integer . parseInt ( m_fields [ field ] ) == 1 ; } return ( result ) ; }
Accessor method used to retrieve a Boolean object representing the contents of an individual field . If the field does not exist in the record null is returned .
20,837
public Rate getRate ( int field ) throws MPXJException { Rate result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { try { String rate = m_fields [ field ] ; int index = rate . indexOf ( '/' ) ; double amount ; TimeUnit units ; if ( index == - 1 ) { amount = m_formats . getCurrencyFormat ( ) . parse ( rate ) . doubleValue ( ) ; units = TimeUnit . HOURS ; } else { amount = m_formats . getCurrencyFormat ( ) . parse ( rate . substring ( 0 , index ) ) . doubleValue ( ) ; units = TimeUnitUtility . getInstance ( rate . substring ( index + 1 ) , m_locale ) ; } result = new Rate ( amount , units ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse rate" , ex ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve an Rate object representing the contents of an individual field . If the field does not exist in the record null is returned .
20,838
public Duration getDuration ( int field ) throws MPXJException { Duration result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = DurationUtility . getInstance ( m_fields [ field ] , m_formats . getDurationDecimalFormat ( ) , m_locale ) ; } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve an Duration object representing the contents of an individual field . If the field does not exist in the record null is returned .
20,839
public Number getUnits ( int field ) throws MPXJException { Number result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { try { result = Double . valueOf ( m_formats . getUnitsDecimalFormat ( ) . parse ( m_fields [ field ] ) . doubleValue ( ) * 100 ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse units" , ex ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a Number instance representing the contents of an individual field . If the field does not exist in the record null is returned .
20,840
public CodePage getCodePage ( int field ) { CodePage result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = CodePage . getInstance ( m_fields [ field ] ) ; } else { result = CodePage . getInstance ( null ) ; } return ( result ) ; }
Retrieves a CodePage instance . Defaults to ANSI .
20,841
public AccrueType getAccrueType ( int field ) { AccrueType result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = AccrueTypeUtility . getInstance ( m_fields [ field ] , m_locale ) ; } else { result = null ; } return ( result ) ; }
Accessor method to retrieve an accrue type instance .
20,842
public Boolean getBoolean ( int field , String falseText ) { Boolean result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = ( ( m_fields [ field ] . equalsIgnoreCase ( falseText ) == true ) ? Boolean . FALSE : Boolean . TRUE ) ; } else { result = null ; } return ( result ) ; }
Accessor method to retrieve a Boolean instance .
20,843
public int getIndexFromOffset ( int offset ) { int result = - 1 ; for ( int loop = 0 ; loop < m_offset . length ; loop ++ ) { if ( m_offset [ loop ] == offset ) { result = loop ; break ; } } return ( result ) ; }
This method converts an offset value into an array index which in turn allows the data present in the fixed block to be retrieved . Note that if the requested offset is not found then this method returns - 1 .
20,844
public byte [ ] getByteArray ( int offset ) { byte [ ] result = null ; if ( offset > 0 && offset < m_data . length ) { int nextBlockOffset = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; int itemSize = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; if ( itemSize > 0 && itemSize < m_data . length ) { int blockRemainingSize = 28 ; if ( nextBlockOffset != - 1 || itemSize <= blockRemainingSize ) { int itemRemainingSize = itemSize ; result = new byte [ itemSize ] ; int resultOffset = 0 ; while ( nextBlockOffset != - 1 ) { MPPUtility . getByteArray ( m_data , offset , blockRemainingSize , result , resultOffset ) ; resultOffset += blockRemainingSize ; offset += blockRemainingSize ; itemRemainingSize -= blockRemainingSize ; if ( offset != nextBlockOffset ) { offset = nextBlockOffset ; } nextBlockOffset = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; blockRemainingSize = 32 ; } MPPUtility . getByteArray ( m_data , offset , itemRemainingSize , result , resultOffset ) ; } } } return ( result ) ; }
Retrieve a byte array of containing the data starting at the supplied offset in the FixDeferFix file . Note that this method will return null if the requested data is not found for some reason .
20,845
public List < ResourceRequestType . ResourceRequestCriterion > getResourceRequestCriterion ( ) { if ( resourceRequestCriterion == null ) { resourceRequestCriterion = new ArrayList < ResourceRequestType . ResourceRequestCriterion > ( ) ; } return this . resourceRequestCriterion ; }
Gets the value of the resourceRequestCriterion property .
20,846
private Map < UUID , FieldType > populateCustomFieldMap ( ) { byte [ ] data = m_taskProps . getByteArray ( Props . CUSTOM_FIELDS ) ; int length = MPPUtility . getInt ( data , 0 ) ; int index = length + 36 ; int recordCount = MPPUtility . getInt ( data , index ) ; index += 4 ; index += ( 8 * recordCount ) ; Map < UUID , FieldType > map = new HashMap < UUID , FieldType > ( ) ; while ( index < data . length ) { int blockLength = MPPUtility . getInt ( data , index ) ; if ( blockLength <= 0 || index + blockLength > data . length ) { break ; } int fieldID = MPPUtility . getInt ( data , index + 4 ) ; FieldType field = FieldTypeHelper . getInstance ( fieldID ) ; UUID guid = MPPUtility . getGUID ( data , index + 160 ) ; map . put ( guid , field ) ; index += blockLength ; } return map ; }
Generate a map of UUID values to field types .
20,847
public static final void deleteQuietly ( File file ) { if ( file != null ) { if ( file . isDirectory ( ) ) { File [ ] children = file . listFiles ( ) ; if ( children != null ) { for ( File child : children ) { deleteQuietly ( child ) ; } } } file . delete ( ) ; } }
Delete a file ignoring failures .
20,848
private void extractFile ( InputStream stream , File dir ) throws IOException { byte [ ] header = new byte [ 8 ] ; byte [ ] fileName = new byte [ 13 ] ; byte [ ] dataSize = new byte [ 4 ] ; stream . read ( header ) ; stream . read ( fileName ) ; stream . read ( dataSize ) ; int dataSizeValue = getInt ( dataSize , 0 ) ; String fileNameValue = getString ( fileName , 0 ) ; File file = new File ( dir , fileNameValue ) ; if ( dataSizeValue == 0 ) { FileHelper . createNewFile ( file ) ; } else { OutputStream os = new FileOutputStream ( file ) ; FixedLengthInputStream inputStream = new FixedLengthInputStream ( stream , dataSizeValue ) ; Blast blast = new Blast ( ) ; blast . blast ( inputStream , os ) ; os . close ( ) ; } }
Extracts the data for a single file from the input stream and writes it to a target directory .
20,849
private boolean matchesFingerprint ( byte [ ] buffer , byte [ ] fingerprint ) { return Arrays . equals ( fingerprint , Arrays . copyOf ( buffer , fingerprint . length ) ) ; }
Determine if the start of the buffer matches a fingerprint byte array .
20,850
private boolean matchesFingerprint ( byte [ ] buffer , Pattern fingerprint ) { return fingerprint . matcher ( m_charset == null ? new String ( buffer ) : new String ( buffer , m_charset ) ) . matches ( ) ; }
Determine if the buffer when expressed as text matches a fingerprint regular expression .
20,851
private ProjectFile readProjectFile ( ProjectReader reader , InputStream stream ) throws MPXJException { addListeners ( reader ) ; return reader . read ( stream ) ; }
Adds listeners and reads from a stream .
20,852
private ProjectFile readProjectFile ( ProjectReader reader , File file ) throws MPXJException { addListeners ( reader ) ; return reader . read ( file ) ; }
Adds listeners and reads from a file .
20,853
private ProjectFile handleOleCompoundDocument ( InputStream stream ) throws Exception { POIFSFileSystem fs = new POIFSFileSystem ( POIFSFileSystem . createNonClosingInputStream ( stream ) ) ; String fileFormat = MPPReader . getFileFormat ( fs ) ; if ( fileFormat != null && fileFormat . startsWith ( "MSProject" ) ) { MPPReader reader = new MPPReader ( ) ; addListeners ( reader ) ; return reader . read ( fs ) ; } return null ; }
We have an OLE compound document ... but is it an MPP file?
20,854
private ProjectFile handleMDBFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".mdb" ) ; try { Class . forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ) ; String url = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=" + file . getCanonicalPath ( ) ; Set < String > tableNames = populateTableNames ( url ) ; if ( tableNames . contains ( "MSP_PROJECTS" ) ) { return readProjectFile ( new MPDDatabaseReader ( ) , file ) ; } if ( tableNames . contains ( "EXCEPTIONN" ) ) { return readProjectFile ( new AstaDatabaseReader ( ) , file ) ; } return null ; } finally { FileHelper . deleteQuietly ( file ) ; } }
We have identified that we have an MDB file . This could be a Microsoft Project database or an Asta database . Open the database and use the table names present to determine which type this is .
20,855
private ProjectFile handleSQLiteFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".sqlite" ) ; try { Class . forName ( "org.sqlite.JDBC" ) ; String url = "jdbc:sqlite:" + file . getCanonicalPath ( ) ; Set < String > tableNames = populateTableNames ( url ) ; if ( tableNames . contains ( "EXCEPTIONN" ) ) { return readProjectFile ( new AstaDatabaseFileReader ( ) , file ) ; } if ( tableNames . contains ( "PROJWBS" ) ) { Connection connection = null ; try { Properties props = new Properties ( ) ; props . setProperty ( "date_string_format" , "yyyy-MM-dd HH:mm:ss" ) ; connection = DriverManager . getConnection ( url , props ) ; PrimaveraDatabaseReader reader = new PrimaveraDatabaseReader ( ) ; reader . setConnection ( connection ) ; addListeners ( reader ) ; return reader . read ( ) ; } finally { if ( connection != null ) { connection . close ( ) ; } } } if ( tableNames . contains ( "ZSCHEDULEITEM" ) ) { return readProjectFile ( new MerlinReader ( ) , file ) ; } return null ; } finally { FileHelper . deleteQuietly ( file ) ; } }
We have identified that we have a SQLite file . This could be a Primavera Project database or an Asta database . Open the database and use the table names present to determine which type this is .
20,856
private ProjectFile handleZipFile ( InputStream stream ) throws Exception { File dir = null ; try { dir = InputStreamHelper . writeZipStreamToTempDir ( stream ) ; ProjectFile result = handleDirectory ( dir ) ; if ( result != null ) { return result ; } } finally { FileHelper . deleteQuietly ( dir ) ; } return null ; }
We have identified that we have a zip file . Extract the contents into a temporary directory and process .
20,857
private ProjectFile handleDirectory ( File directory ) throws Exception { ProjectFile result = handleDatabaseInDirectory ( directory ) ; if ( result == null ) { result = handleFileInDirectory ( directory ) ; } return result ; }
We have a directory . Determine if this contains a multi - file database we understand if so process it . If it does not contain a database test each file within the directory structure to determine if it contains a file whose format we understand .
20,858
private ProjectFile handleDatabaseInDirectory ( File directory ) throws Exception { byte [ ] buffer = new byte [ BUFFER_SIZE ] ; File [ ] files = directory . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . isDirectory ( ) ) { continue ; } FileInputStream fis = new FileInputStream ( file ) ; int bytesRead = fis . read ( buffer ) ; fis . close ( ) ; if ( bytesRead != BUFFER_SIZE ) { continue ; } if ( matchesFingerprint ( buffer , BTRIEVE_FINGERPRINT ) ) { return handleP3BtrieveDatabase ( directory ) ; } if ( matchesFingerprint ( buffer , STW_FINGERPRINT ) ) { return handleSureTrakDatabase ( directory ) ; } } } return null ; }
Given a directory determine if it contains a multi - file database whose format we can process .
20,859
private ProjectFile handleByteOrderMark ( InputStream stream , int length , Charset charset ) throws Exception { UniversalProjectReader reader = new UniversalProjectReader ( ) ; reader . setSkipBytes ( length ) ; reader . setCharset ( charset ) ; return reader . read ( stream ) ; }
The file we are working with has a byte order mark . Skip this and try again to read the file .
20,860
private ProjectFile handleDosExeFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".tmp" ) ; InputStream is = null ; try { is = new FileInputStream ( file ) ; if ( is . available ( ) > 1350 ) { StreamHelper . skip ( is , 1024 ) ; byte [ ] data = new byte [ 2 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , WINDOWS_NE_EXE_FINGERPRINT ) ) { StreamHelper . skip ( is , 286 ) ; data = new byte [ 34 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , PRX_FINGERPRINT ) ) { is . close ( ) ; is = null ; return readProjectFile ( new P3PRXFileReader ( ) , file ) ; } } if ( matchesFingerprint ( data , STX_FINGERPRINT ) ) { StreamHelper . skip ( is , 31742 ) ; data = new byte [ 4 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , PRX3_FINGERPRINT ) ) { is . close ( ) ; is = null ; return readProjectFile ( new SureTrakSTXFileReader ( ) , file ) ; } } } return null ; } finally { StreamHelper . closeQuietly ( is ) ; FileHelper . deleteQuietly ( file ) ; } }
This could be a self - extracting archive . If we understand the format expand it and check the content for files we can read .
20,861
private ProjectFile handleXerFile ( InputStream stream ) throws Exception { PrimaveraXERFileReader reader = new PrimaveraXERFileReader ( ) ; reader . setCharset ( m_charset ) ; List < ProjectFile > projects = reader . readAll ( stream ) ; ProjectFile project = null ; for ( ProjectFile file : projects ) { if ( file . getProjectProperties ( ) . getExportFlag ( ) ) { project = file ; break ; } } if ( project == null && ! projects . isEmpty ( ) ) { project = projects . get ( 0 ) ; } return project ; }
XER files can contain multiple projects when there are cross - project dependencies . As the UniversalProjectReader is designed just to read a single project we need to select one project from those available in the XER file . The original project selected for export by the user will have its export flag set to true . We ll return the first project we find where the export flag is set to true otherwise we ll just return the first project we find in the file .
20,862
private Set < String > populateTableNames ( String url ) throws SQLException { Set < String > tableNames = new HashSet < String > ( ) ; Connection connection = null ; ResultSet rs = null ; try { connection = DriverManager . getConnection ( url ) ; DatabaseMetaData dmd = connection . getMetaData ( ) ; rs = dmd . getTables ( null , null , null , null ) ; while ( rs . next ( ) ) { tableNames . add ( rs . getString ( "TABLE_NAME" ) . toUpperCase ( ) ) ; } } finally { if ( rs != null ) { rs . close ( ) ; } if ( connection != null ) { connection . close ( ) ; } } return tableNames ; }
Open a database and build a set of table names .
20,863
public static void skip ( InputStream stream , long skip ) throws IOException { long count = skip ; while ( count > 0 ) { count -= stream . skip ( count ) ; } }
The documentation for InputStream . skip indicates that it can bail out early and not skip the requested number of bytes . I ve encountered this in practice hence this helper method .
20,864
private void processCustomValueLists ( ) throws IOException { CustomFieldValueReader9 reader = new CustomFieldValueReader9 ( m_projectDir , m_file . getProjectProperties ( ) , m_projectProps , m_file . getCustomFields ( ) ) ; reader . process ( ) ; }
Retrieve any task field value lists defined in the MPP file .
20,865
private void processFieldNameAliases ( Map < Integer , FieldType > map , byte [ ] data ) { if ( data != null ) { int offset = 0 ; int index = 0 ; CustomFieldContainer fields = m_file . getCustomFields ( ) ; while ( offset < data . length ) { String alias = MPPUtility . getUnicodeString ( data , offset ) ; if ( ! alias . isEmpty ( ) ) { FieldType field = map . get ( Integer . valueOf ( index ) ) ; if ( field != null ) { fields . getCustomField ( field ) . setAlias ( alias ) ; } } offset += ( alias . length ( ) + 1 ) * 2 ; index ++ ; } } }
Retrieve any resource field aliases defined in the MPP file .
20,866
private TreeMap < Integer , Integer > createResourceMap ( FieldMap fieldMap , FixedMeta rscFixedMeta , FixedData rscFixedData ) { TreeMap < Integer , Integer > resourceMap = new TreeMap < Integer , Integer > ( ) ; int itemCount = rscFixedMeta . getAdjustedItemCount ( ) ; for ( int loop = 0 ; loop < itemCount ; loop ++ ) { byte [ ] data = rscFixedData . getByteArrayValue ( loop ) ; if ( data == null || data . length < fieldMap . getMaxFixedDataSize ( 0 ) ) { continue ; } Integer uniqueID = Integer . valueOf ( MPPUtility . getShort ( data , 0 ) ) ; resourceMap . put ( uniqueID , Integer . valueOf ( loop ) ) ; } return ( resourceMap ) ; }
This method maps the resource unique identifiers to their index number within the FixedData block .
20,867
private void postProcessTasks ( ) { List < Task > allTasks = m_file . getTasks ( ) ; if ( allTasks . size ( ) > 1 ) { Collections . sort ( allTasks ) ; int taskID = - 1 ; int lastTaskID = - 1 ; for ( int i = 0 ; i < allTasks . size ( ) ; i ++ ) { Task task = allTasks . get ( i ) ; taskID = NumberHelper . getInt ( task . getID ( ) ) ; if ( ! task . getNull ( ) && lastTaskID != - 1 && taskID > lastTaskID + 1 ) { task . setNull ( true ) ; } else { lastTaskID = taskID ; } } } }
This method is called to try to catch any invalid tasks that may have sneaked past all our other checks . This is done by validating the tasks by task ID .
20,868
public void process ( String name ) throws Exception { ProjectFile file = new UniversalProjectReader ( ) . read ( name ) ; for ( Task task : file . getTasks ( ) ) { if ( ! task . getSummary ( ) ) { System . out . print ( task . getWBS ( ) ) ; System . out . print ( "\t" ) ; System . out . print ( task . getName ( ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getStart ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getActualStart ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getFinish ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getActualFinish ( ) ) ) ; System . out . println ( ) ; } } }
Dump data for all non - summary tasks to stdout .
20,869
private void readProjectProperties ( Document cdp ) { WorkspaceProperties props = cdp . getWorkspaceProperties ( ) ; ProjectProperties mpxjProps = m_projectFile . getProjectProperties ( ) ; mpxjProps . setSymbolPosition ( props . getCurrencyPosition ( ) ) ; mpxjProps . setCurrencyDigits ( props . getCurrencyDigits ( ) ) ; mpxjProps . setCurrencySymbol ( props . getCurrencySymbol ( ) ) ; mpxjProps . setDaysPerMonth ( props . getDaysPerMonth ( ) ) ; mpxjProps . setMinutesPerDay ( props . getHoursPerDay ( ) ) ; mpxjProps . setMinutesPerWeek ( props . getHoursPerWeek ( ) ) ; m_workHoursPerDay = mpxjProps . getMinutesPerDay ( ) . doubleValue ( ) / 60.0 ; }
Extracts project properties from a ConceptDraw PROJECT file .
20,870
private void readCalendars ( Document cdp ) { for ( Calendar calendar : cdp . getCalendars ( ) . getCalendar ( ) ) { readCalendar ( calendar ) ; } for ( Calendar calendar : cdp . getCalendars ( ) . getCalendar ( ) ) { ProjectCalendar child = m_calendarMap . get ( calendar . getID ( ) ) ; ProjectCalendar parent = m_calendarMap . get ( calendar . getBaseCalendarID ( ) ) ; if ( parent == null ) { m_projectFile . setDefaultCalendar ( child ) ; } else { child . setParent ( parent ) ; } } }
Extracts calendar data from a ConceptDraw PROJECT file .
20,871
private void readWeekDay ( ProjectCalendar mpxjCalendar , WeekDay day ) { if ( day . isIsDayWorking ( ) ) { ProjectCalendarHours hours = mpxjCalendar . addCalendarHours ( day . getDay ( ) ) ; for ( Document . Calendars . Calendar . WeekDays . WeekDay . TimePeriods . TimePeriod period : day . getTimePeriods ( ) . getTimePeriod ( ) ) { hours . addRange ( new DateRange ( period . getFrom ( ) , period . getTo ( ) ) ) ; } } }
Reads a single day for a calendar .
20,872
private void readExceptionDay ( ProjectCalendar mpxjCalendar , ExceptedDay day ) { ProjectCalendarException mpxjException = mpxjCalendar . addCalendarException ( day . getDate ( ) , day . getDate ( ) ) ; if ( day . isIsDayWorking ( ) ) { for ( Document . Calendars . Calendar . ExceptedDays . ExceptedDay . TimePeriods . TimePeriod period : day . getTimePeriods ( ) . getTimePeriod ( ) ) { mpxjException . addRange ( new DateRange ( period . getFrom ( ) , period . getTo ( ) ) ) ; } } }
Read an exception day for a calendar .
20,873
private void readResources ( Document cdp ) { for ( Document . Resources . Resource resource : cdp . getResources ( ) . getResource ( ) ) { readResource ( resource ) ; } }
Reads resource data from a ConceptDraw PROJECT file .
20,874
private void readResource ( Document . Resources . Resource resource ) { Resource mpxjResource = m_projectFile . addResource ( ) ; mpxjResource . setName ( resource . getName ( ) ) ; mpxjResource . setResourceCalendar ( m_calendarMap . get ( resource . getCalendarID ( ) ) ) ; mpxjResource . setStandardRate ( new Rate ( resource . getCost ( ) , resource . getCostTimeUnit ( ) ) ) ; mpxjResource . setEmailAddress ( resource . getEMail ( ) ) ; mpxjResource . setGroup ( resource . getGroup ( ) ) ; mpxjResource . setUniqueID ( resource . getID ( ) ) ; mpxjResource . setNotes ( resource . getNote ( ) ) ; mpxjResource . setID ( Integer . valueOf ( resource . getOutlineNumber ( ) ) ) ; mpxjResource . setType ( resource . getSubType ( ) == null ? resource . getType ( ) : resource . getSubType ( ) ) ; }
Reads a single resource from a ConceptDraw PROJECT file .
20,875
private void readTasks ( Document cdp ) { List < Project > projects = new ArrayList < Project > ( cdp . getProjects ( ) . getProject ( ) ) ; final AlphanumComparator comparator = new AlphanumComparator ( ) ; Collections . sort ( projects , new Comparator < Project > ( ) { public int compare ( Project o1 , Project o2 ) { return comparator . compare ( o1 . getOutlineNumber ( ) , o2 . getOutlineNumber ( ) ) ; } } ) ; for ( Project project : cdp . getProjects ( ) . getProject ( ) ) { readProject ( project ) ; } }
Read the projects from a ConceptDraw PROJECT file as top level tasks .
20,876
private void readProject ( Project project ) { Task mpxjTask = m_projectFile . addTask ( ) ; mpxjTask . setBaselineCost ( project . getBaselineCost ( ) ) ; mpxjTask . setBaselineFinish ( project . getBaselineFinishDate ( ) ) ; mpxjTask . setBaselineStart ( project . getBaselineStartDate ( ) ) ; mpxjTask . setFinish ( project . getFinishDate ( ) ) ; mpxjTask . setName ( project . getName ( ) ) ; mpxjTask . setNotes ( project . getNote ( ) ) ; mpxjTask . setPriority ( project . getPriority ( ) ) ; mpxjTask . setStart ( project . getStartDate ( ) ) ; String projectIdentifier = project . getID ( ) . toString ( ) ; mpxjTask . setGUID ( UUID . nameUUIDFromBytes ( projectIdentifier . getBytes ( ) ) ) ; List < Document . Projects . Project . Task > tasks = new ArrayList < Document . Projects . Project . Task > ( project . getTask ( ) ) ; final AlphanumComparator comparator = new AlphanumComparator ( ) ; Collections . sort ( tasks , new Comparator < Document . Projects . Project . Task > ( ) { public int compare ( Document . Projects . Project . Task o1 , Document . Projects . Project . Task o2 ) { return comparator . compare ( o1 . getOutlineNumber ( ) , o2 . getOutlineNumber ( ) ) ; } } ) ; Map < String , Task > map = new HashMap < String , Task > ( ) ; map . put ( "" , mpxjTask ) ; for ( Document . Projects . Project . Task task : tasks ) { readTask ( projectIdentifier , map , task ) ; } }
Read a project from a ConceptDraw PROJECT file .
20,877
private void readTask ( String projectIdentifier , Map < String , Task > map , Document . Projects . Project . Task task ) { Task parentTask = map . get ( getParentOutlineNumber ( task . getOutlineNumber ( ) ) ) ; Task mpxjTask = parentTask . addTask ( ) ; TimeUnit units = task . getBaseDurationTimeUnit ( ) ; mpxjTask . setCost ( task . getActualCost ( ) ) ; mpxjTask . setDuration ( getDuration ( units , task . getActualDuration ( ) ) ) ; mpxjTask . setFinish ( task . getActualFinishDate ( ) ) ; mpxjTask . setStart ( task . getActualStartDate ( ) ) ; mpxjTask . setBaselineDuration ( getDuration ( units , task . getBaseDuration ( ) ) ) ; mpxjTask . setBaselineFinish ( task . getBaseFinishDate ( ) ) ; mpxjTask . setBaselineCost ( task . getBaselineCost ( ) ) ; mpxjTask . setBaselineStart ( task . getBaseStartDate ( ) ) ; mpxjTask . setPercentageComplete ( task . getComplete ( ) ) ; mpxjTask . setDeadline ( task . getDeadlineDate ( ) ) ; mpxjTask . setName ( task . getName ( ) ) ; mpxjTask . setNotes ( task . getNote ( ) ) ; mpxjTask . setPriority ( task . getPriority ( ) ) ; mpxjTask . setType ( task . getSchedulingType ( ) ) ; if ( task . isIsMilestone ( ) ) { mpxjTask . setMilestone ( true ) ; mpxjTask . setDuration ( Duration . getInstance ( 0 , TimeUnit . HOURS ) ) ; mpxjTask . setBaselineDuration ( Duration . getInstance ( 0 , TimeUnit . HOURS ) ) ; } String taskIdentifier = projectIdentifier + "." + task . getID ( ) ; m_taskIdMap . put ( task . getID ( ) , mpxjTask ) ; mpxjTask . setGUID ( UUID . nameUUIDFromBytes ( taskIdentifier . getBytes ( ) ) ) ; map . put ( task . getOutlineNumber ( ) , mpxjTask ) ; for ( Document . Projects . Project . Task . ResourceAssignments . ResourceAssignment assignment : task . getResourceAssignments ( ) . getResourceAssignment ( ) ) { readResourceAssignment ( mpxjTask , assignment ) ; } }
Read a task from a ConceptDraw PROJECT file .
20,878
private void readRelationships ( Document cdp ) { for ( Link link : cdp . getLinks ( ) . getLink ( ) ) { readRelationship ( link ) ; } }
Read all task relationships from a ConceptDraw PROJECT file .
20,879
private void readRelationship ( Link link ) { Task sourceTask = m_taskIdMap . get ( link . getSourceTaskID ( ) ) ; Task destinationTask = m_taskIdMap . get ( link . getDestinationTaskID ( ) ) ; if ( sourceTask != null && destinationTask != null ) { Duration lag = getDuration ( link . getLagUnit ( ) , link . getLag ( ) ) ; RelationType type = link . getType ( ) ; Relation relation = destinationTask . addPredecessor ( sourceTask , type , lag ) ; relation . setUniqueID ( link . getID ( ) ) ; } }
Read a task relationship .
20,880
private Duration getDuration ( TimeUnit units , Double duration ) { Duration result = null ; if ( duration != null ) { double durationValue = duration . doubleValue ( ) * 100.0 ; switch ( units ) { case MINUTES : { durationValue *= MINUTES_PER_DAY ; break ; } case HOURS : { durationValue *= HOURS_PER_DAY ; break ; } case DAYS : { durationValue *= 3.0 ; break ; } case WEEKS : { durationValue *= 0.6 ; break ; } case MONTHS : { durationValue *= 0.15 ; break ; } default : { throw new IllegalArgumentException ( "Unsupported time units " + units ) ; } } durationValue = Math . round ( durationValue ) / 100.0 ; result = Duration . getInstance ( durationValue , units ) ; } return result ; }
Read a duration .
20,881
private String getParentOutlineNumber ( String outlineNumber ) { String result ; int index = outlineNumber . lastIndexOf ( '.' ) ; if ( index == - 1 ) { result = "" ; } else { result = outlineNumber . substring ( 0 , index ) ; } return result ; }
Return the parent outline number or an empty string if we have a root task .
20,882
public static ConstraintField getInstance ( int value ) { ConstraintField result = null ; if ( value >= 0 && value < FIELD_ARRAY . length ) { result = FIELD_ARRAY [ value ] ; } return ( result ) ; }
Retrieve an instance of the ConstraintField class based on the data read from an MS Project file .
20,883
public void update ( ) { ProjectProperties properties = m_projectFile . getProjectProperties ( ) ; char decimalSeparator = properties . getDecimalSeparator ( ) ; char thousandsSeparator = properties . getThousandsSeparator ( ) ; m_unitsDecimalFormat . applyPattern ( "#.##" , null , decimalSeparator , thousandsSeparator ) ; m_decimalFormat . applyPattern ( "0.00#" , null , decimalSeparator , thousandsSeparator ) ; m_durationDecimalFormat . applyPattern ( "#.##" , null , decimalSeparator , thousandsSeparator ) ; m_percentageDecimalFormat . applyPattern ( "##0.##" , null , decimalSeparator , thousandsSeparator ) ; updateCurrencyFormats ( properties , decimalSeparator , thousandsSeparator ) ; updateDateTimeFormats ( properties ) ; }
Called to update the cached formats when something changes .
20,884
private void updateCurrencyFormats ( ProjectProperties properties , char decimalSeparator , char thousandsSeparator ) { String prefix = "" ; String suffix = "" ; String currencySymbol = quoteFormatCharacters ( properties . getCurrencySymbol ( ) ) ; switch ( properties . getSymbolPosition ( ) ) { case AFTER : { suffix = currencySymbol ; break ; } case BEFORE : { prefix = currencySymbol ; break ; } case AFTER_WITH_SPACE : { suffix = " " + currencySymbol ; break ; } case BEFORE_WITH_SPACE : { prefix = currencySymbol + " " ; break ; } } StringBuilder pattern = new StringBuilder ( prefix ) ; pattern . append ( "#0" ) ; int digits = properties . getCurrencyDigits ( ) . intValue ( ) ; if ( digits > 0 ) { pattern . append ( '.' ) ; for ( int i = 0 ; i < digits ; i ++ ) { pattern . append ( "0" ) ; } } pattern . append ( suffix ) ; String primaryPattern = pattern . toString ( ) ; String [ ] alternativePatterns = new String [ 7 ] ; alternativePatterns [ 0 ] = primaryPattern + ";(" + primaryPattern + ")" ; pattern . insert ( prefix . length ( ) , "#,#" ) ; String secondaryPattern = pattern . toString ( ) ; alternativePatterns [ 1 ] = secondaryPattern ; alternativePatterns [ 2 ] = secondaryPattern + ";(" + secondaryPattern + ")" ; pattern . setLength ( 0 ) ; pattern . append ( "#0" ) ; if ( digits > 0 ) { pattern . append ( '.' ) ; for ( int i = 0 ; i < digits ; i ++ ) { pattern . append ( "0" ) ; } } String noSymbolPrimaryPattern = pattern . toString ( ) ; alternativePatterns [ 3 ] = noSymbolPrimaryPattern ; alternativePatterns [ 4 ] = noSymbolPrimaryPattern + ";(" + noSymbolPrimaryPattern + ")" ; pattern . insert ( 0 , "#,#" ) ; String noSymbolSecondaryPattern = pattern . toString ( ) ; alternativePatterns [ 5 ] = noSymbolSecondaryPattern ; alternativePatterns [ 6 ] = noSymbolSecondaryPattern + ";(" + noSymbolSecondaryPattern + ")" ; m_currencyFormat . applyPattern ( primaryPattern , alternativePatterns , decimalSeparator , thousandsSeparator ) ; }
Update the currency format .
20,885
private String quoteFormatCharacters ( String literal ) { StringBuilder sb = new StringBuilder ( ) ; int length = literal . length ( ) ; char c ; for ( int loop = 0 ; loop < length ; loop ++ ) { c = literal . charAt ( loop ) ; switch ( c ) { case '0' : case '#' : case '.' : case '-' : case ',' : case 'E' : case ';' : case '%' : { sb . append ( "'" ) ; sb . append ( c ) ; sb . append ( "'" ) ; break ; } default : { sb . append ( c ) ; break ; } } } return ( sb . toString ( ) ) ; }
This method is used to quote any special characters that appear in literal text that is required as part of the currency format .
20,886
private void updateDateTimeFormats ( ProjectProperties properties ) { String [ ] timePatterns = getTimePatterns ( properties ) ; String [ ] datePatterns = getDatePatterns ( properties ) ; String [ ] dateTimePatterns = getDateTimePatterns ( properties , timePatterns ) ; m_dateTimeFormat . applyPatterns ( dateTimePatterns ) ; m_dateFormat . applyPatterns ( datePatterns ) ; m_timeFormat . applyPatterns ( timePatterns ) ; m_dateTimeFormat . setLocale ( m_locale ) ; m_dateFormat . setLocale ( m_locale ) ; m_dateTimeFormat . setNullText ( m_nullText ) ; m_dateFormat . setNullText ( m_nullText ) ; m_timeFormat . setNullText ( m_nullText ) ; m_dateTimeFormat . setAmPmText ( properties . getAMText ( ) , properties . getPMText ( ) ) ; m_timeFormat . setAmPmText ( properties . getAMText ( ) , properties . getPMText ( ) ) ; }
Updates the date and time formats .
20,887
private String [ ] getDatePatterns ( ProjectProperties properties ) { String pattern = "" ; char datesep = properties . getDateSeparator ( ) ; DateOrder dateOrder = properties . getDateOrder ( ) ; switch ( dateOrder ) { case DMY : { pattern = "dd" + datesep + "MM" + datesep + "yy" ; break ; } case MDY : { pattern = "MM" + datesep + "dd" + datesep + "yy" ; break ; } case YMD : { pattern = "yy" + datesep + "MM" + datesep + "dd" ; break ; } } return new String [ ] { pattern } ; }
Generate date patterns based on the project configuration .
20,888
private List < String > generateDateTimePatterns ( String datePattern , String [ ] timePatterns ) { List < String > patterns = new ArrayList < String > ( ) ; for ( String timePattern : timePatterns ) { patterns . add ( datePattern + " " + timePattern ) ; } patterns . add ( datePattern ) ; return patterns ; }
Generate a set of datetime patterns to accommodate variations in MPX files .
20,889
public Integer [ ] getUniqueIdentifierArray ( ) { Integer [ ] result = new Integer [ m_table . size ( ) ] ; int index = 0 ; for ( Integer value : m_table . keySet ( ) ) { result [ index ] = value ; ++ index ; } return ( result ) ; }
This method returns an array containing all of the unique identifiers for which data has been stored in the Var2Data block .
20,890
public Integer getOffset ( Integer id , Integer type ) { Integer result = null ; Map < Integer , Integer > map = m_table . get ( id ) ; if ( map != null && type != null ) { result = map . get ( type ) ; } return ( result ) ; }
This method retrieves the offset of a given entry in the Var2Data block . Each entry can be uniquely located by the identifier of the object to which the data belongs and the type of the data .
20,891
public void setRightValue ( int index , Object value ) { m_definedRightValues [ index ] = value ; if ( value instanceof FieldType ) { m_symbolicValues = true ; } else { if ( value instanceof Duration ) { if ( ( ( Duration ) value ) . getUnits ( ) != TimeUnit . HOURS ) { value = ( ( Duration ) value ) . convertUnits ( TimeUnit . HOURS , m_properties ) ; } } } m_workingRightValues [ index ] = value ; }
Add the value to list of values to be used as part of the evaluation of this indicator .
20,892
public boolean evaluate ( FieldContainer container , Map < GenericCriteriaPrompt , Object > promptValues ) { FieldType field = m_leftValue ; Object lhs ; if ( field == null ) { lhs = null ; } else { lhs = container . getCurrentValue ( field ) ; switch ( field . getDataType ( ) ) { case DATE : { if ( lhs != null ) { lhs = DateHelper . getDayStartDate ( ( Date ) lhs ) ; } break ; } case DURATION : { if ( lhs != null ) { Duration dur = ( Duration ) lhs ; lhs = dur . convertUnits ( TimeUnit . HOURS , m_properties ) ; } else { lhs = Duration . getInstance ( 0 , TimeUnit . HOURS ) ; } break ; } case STRING : { lhs = lhs == null ? "" : lhs ; break ; } default : { break ; } } } Object [ ] rhs ; if ( m_symbolicValues == true ) { rhs = processSymbolicValues ( m_workingRightValues , container , promptValues ) ; } else { rhs = m_workingRightValues ; } boolean result ; switch ( m_operator ) { case AND : case OR : { result = evaluateLogicalOperator ( container , promptValues ) ; break ; } default : { result = m_operator . evaluate ( lhs , rhs ) ; break ; } } return result ; }
Evaluate the criteria and return a boolean result .
20,893
private boolean evaluateLogicalOperator ( FieldContainer container , Map < GenericCriteriaPrompt , Object > promptValues ) { boolean result = false ; if ( m_criteriaList . size ( ) == 0 ) { result = true ; } else { for ( GenericCriteria criteria : m_criteriaList ) { result = criteria . evaluate ( container , promptValues ) ; if ( ( m_operator == TestOperator . AND && ! result ) || ( m_operator == TestOperator . OR && result ) ) { break ; } } } return result ; }
Evalutes AND and OR operators .
20,894
private ProjectFile read ( ) throws Exception { m_project = new ProjectFile ( ) ; m_eventManager = m_project . getEventManager ( ) ; m_project . getProjectProperties ( ) . setFileApplication ( "Synchro" ) ; m_project . getProjectProperties ( ) . setFileType ( "SP" ) ; CustomFieldContainer fields = m_project . getCustomFields ( ) ; fields . getCustomField ( TaskField . TEXT1 ) . setAlias ( "Code" ) ; m_eventManager . addProjectListeners ( m_projectListeners ) ; processCalendars ( ) ; processResources ( ) ; processTasks ( ) ; processPredecessors ( ) ; return m_project ; }
Reads data from the SP file .
20,895
private void processCalendars ( ) throws IOException { CalendarReader reader = new CalendarReader ( m_data . getTableData ( "Calendars" ) ) ; reader . read ( ) ; for ( MapRow row : reader . getRows ( ) ) { processCalendar ( row ) ; } m_project . setDefaultCalendar ( m_calendarMap . get ( reader . getDefaultCalendarUUID ( ) ) ) ; }
Extract calendar data .
20,896
private void processCalendar ( MapRow row ) { ProjectCalendar calendar = m_project . addCalendar ( ) ; Map < UUID , List < DateRange > > dayTypeMap = processDayTypes ( row . getRows ( "DAY_TYPES" ) ) ; calendar . setName ( row . getString ( "NAME" ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "SUNDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . SUNDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "MONDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . MONDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "TUESDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . TUESDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "WEDNESDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . WEDNESDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "THURSDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . THURSDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "FRIDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . FRIDAY ) ) ; processRanges ( dayTypeMap . get ( row . getUUID ( "SATURDAY_DAY_TYPE" ) ) , calendar . addCalendarHours ( Day . SATURDAY ) ) ; for ( MapRow assignment : row . getRows ( "DAY_TYPE_ASSIGNMENTS" ) ) { Date date = assignment . getDate ( "DATE" ) ; processRanges ( dayTypeMap . get ( assignment . getUUID ( "DAY_TYPE_UUID" ) ) , calendar . addCalendarException ( date , date ) ) ; } m_calendarMap . put ( row . getUUID ( "UUID" ) , calendar ) ; }
Extract data for a single calendar .
20,897
private void processRanges ( List < DateRange > ranges , ProjectCalendarDateRanges container ) { if ( ranges != null ) { for ( DateRange range : ranges ) { container . addRange ( range ) ; } } }
Populate time ranges .
20,898
private Map < UUID , List < DateRange > > processDayTypes ( List < MapRow > types ) { Map < UUID , List < DateRange > > map = new HashMap < UUID , List < DateRange > > ( ) ; for ( MapRow row : types ) { List < DateRange > ranges = new ArrayList < DateRange > ( ) ; for ( MapRow range : row . getRows ( "TIME_RANGES" ) ) { ranges . add ( new DateRange ( range . getDate ( "START" ) , range . getDate ( "END" ) ) ) ; } map . put ( row . getUUID ( "UUID" ) , ranges ) ; } return map ; }
Extract day type definitions .
20,899
private void processResources ( ) throws IOException { CompanyReader reader = new CompanyReader ( m_data . getTableData ( "Companies" ) ) ; reader . read ( ) ; for ( MapRow companyRow : reader . getRows ( ) ) { for ( MapRow resourceRow : sort ( companyRow . getRows ( "RESOURCES" ) , "NAME" ) ) { processResource ( resourceRow ) ; } } }
Extract resource data .