Skip to content

Commit

Permalink
Suretrak (#43)
Browse files Browse the repository at this point in the history
* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress

* Work in progress
  • Loading branch information
joniles authored Mar 23, 2018
1 parent 00896dc commit 4ed63de
Show file tree
Hide file tree
Showing 40 changed files with 2,086 additions and 96 deletions.
7 changes: 6 additions & 1 deletion src/net/sf/mpxj/common/DateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,15 @@ public static Date getTimeFromMinutesPastMidnight(Integer time)
*/
public static final long MS_PER_MINUTE = 60 * 1000;

/**
* Number of milliseconds per minute.
*/
public static final long MS_PER_HOUR = 60 * MS_PER_MINUTE;

/**
* Number of milliseconds per day.
*/
public static final long MS_PER_DAY = 24 * 60 * MS_PER_MINUTE;
public static final long MS_PER_DAY = 24 * MS_PER_HOUR;

/**
* Default value to use for DST savings if we are using a version
Expand Down
13 changes: 13 additions & 0 deletions src/net/sf/mpxj/common/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,17 @@ public static final File createTempDir() throws IOException
mkdirs(dir);
return dir;
}

/**
* Create a new file. Raise an exception if the file exists.
*
* @param file file to create
*/
public static final void createNewFile(File file) throws IOException
{
if (!file.createNewFile())
{
throw new IOException("Failed to create new file");
}
}
}
2 changes: 1 addition & 1 deletion src/net/sf/mpxj/explorer/ProjectExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void initialize()
final FileChooserController fileChooserController = new FileChooserController(fileChooserModel);
@SuppressWarnings("unused")
FileChooserView fileChooserView = new FileChooserView(m_frame, fileChooserModel);
fileChooserModel.setExtensions("mpp", "mpx", "xml", "planner", "xer", "pmxml", "pp", "zip", "ppx", "fts", "pod", "mdb", "zip", "gan", "pep", "prx");
fileChooserModel.setExtensions("mpp", "mpx", "xml", "planner", "xer", "pmxml", "pp", "zip", "ppx", "fts", "pod", "mdb", "zip", "gan", "pep", "prx", "stx");

final FileSaverModel fileSaverModel = new FileSaverModel();
final FileSaverController fileSaverController = new FileSaverController(fileSaverModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Common column implementation methods.
Expand Down
60 changes: 60 additions & 0 deletions src/net/sf/mpxj/primavera/common/AbstractIntColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* file: AbstractIntColumn.java
* author: Jon Iles
* copyright: (c) Packwood Software 2018
* date: 01/03/2018
*/

/*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.common;

/**
* Extract column data from a table.
*/
public abstract class AbstractIntColumn extends AbstractColumn
{
/**
* Constructor.
*
* @param name column name
* @param offset offset within data
*/
public AbstractIntColumn(String name, int offset)
{
super(name, offset);
}

/**
* Read a four byte integer from the data.
*
* @param offset current offset into data block
* @param data data block
* @return int value
*/
public int readInt(int offset, byte[] data)
{
int result = 0;
int i = offset + m_offset;
for (int shiftBy = 0; shiftBy < 32; shiftBy += 8)
{
result |= ((data[i] & 0xff)) << shiftBy;
++i;
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Common methods for columns based on short integers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* file: WbsFormat.java
* file: AbstractWbsFormat.java
* author: Jon Iles
* copyright: (c) Packwood Software 2018
* date: 01/03/2018
Expand All @@ -21,40 +21,18 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

import java.util.ArrayList;
import java.util.List;

/**
* Reads the WBS format definition from a P3 database, and allows
* that format to be applied to WBS values.
* Common methods to support reading the WBS format definition from P3 and SureTrak.
*/
public class WbsFormat
public class AbstractWbsFormat
{
/**
* Constructor. Reads the format definition.
*
* @param row database row containing WBS format
*/
public WbsFormat(MapRow row)
{
int index = 1;
while (true)
{
String suffix = String.format("%02d", Integer.valueOf(index++));
Integer length = row.getInteger("WBSW_" + suffix);
if (length == null || length.intValue() == 0)
{
break;
}
m_lengths.add(length);
m_separators.add(row.getString("WBSS_" + suffix));
}
}

/**
* Parses a raw WBS value from the darabase and breaks it into
* Parses a raw WBS value from the database and breaks it into
* component parts ready for formatting.
*
* @param value raw WBS value
Expand Down Expand Up @@ -89,11 +67,21 @@ public void parseRawValue(String value)
*
* @return formatted WBS value
*/
public String getFormatedValue()
public String getFormattedValue()
{
return joinElements(m_elements.size());
}

/**
* Retrieves the level of this WBS code.
*
* @return level value
*/
public Integer getLevel()
{
return Integer.valueOf((m_elements.size() + 1) / 2);
}

/**
* Retrieves the formatted parent WBS value.
*
Expand Down Expand Up @@ -126,6 +114,6 @@ private String joinElements(int length)
}

private final List<String> m_elements = new ArrayList<String>();
private final List<Integer> m_lengths = new ArrayList<Integer>();
private final List<String> m_separators = new ArrayList<String>();
protected final List<Integer> m_lengths = new ArrayList<Integer>();
protected final List<String> m_separators = new ArrayList<String>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
* which decompresses to "AIAIAIAIAIAIA" (without the quotes).
*/

package net.sf.mpxj.common;
package net.sf.mpxj.primavera.common;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Extract column data from a table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Classes which implement this interface define how columns
* of a specific type can be read from the P3 database.
*/
interface ColumnDefinition
public interface ColumnDefinition
{
/**
* Retrieve the name of the column.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Extract column data from a table.
*/
public class IntColumn extends AbstractColumn
public class IntColumn extends AbstractIntColumn
{
/**
* Constructor.
Expand All @@ -41,13 +41,6 @@ public IntColumn(String name, int offset)

@Override public Integer read(int offset, byte[] data)
{
int result = 0;
int i = offset + m_offset;
for (int shiftBy = 0; shiftBy < 32; shiftBy += 8)
{
result |= ((data[i] & 0xff)) << shiftBy;
++i;
}
return Integer.valueOf(result);
return Integer.valueOf(readInt(offset, data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

import java.util.Date;
import java.util.Map;
Expand All @@ -36,7 +36,7 @@
* from an individual row. Provides type-specific
* methods to retrieve the column values.
*/
class MapRow
public class MapRow
{
/**
* Constructor.
Expand Down Expand Up @@ -120,6 +120,17 @@ public final Date getDate(String name)
return (Date) getObject(name);
}

/**
* Retrieve a byte array value.
*
* @param name column name
* @return byte array value
*/
public final byte[] getRaw(String name)
{
return (byte[]) getObject(name);
}

/**
* Retrieve a value without being specific about its type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Extract column data from a table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Extract column data from a table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

import java.util.Iterator;
import java.util.Map;
Expand All @@ -31,7 +31,7 @@
* Represents the rows which make up a table. Allows iteration across these rows.
* If a primary key column has been defined for the table, allows lookup by primary key.
*/
class Table implements Iterable<MapRow>
public class Table implements Iterable<MapRow>
{
/**
* {@inheritDoc}
Expand Down Expand Up @@ -64,14 +64,15 @@ public void addRow(String primaryKeyColumnName, Map<String, Object> map)
{
Integer rowNumber = Integer.valueOf(m_rowNumber++);
map.put("ROW_NUMBER", rowNumber);
Object primaryKey;
if (primaryKeyColumnName == null)
Object primaryKey = null;
if (primaryKeyColumnName != null)
{
primaryKey = rowNumber;
primaryKey = map.get(primaryKeyColumnName);
}
else

if (primaryKey == null)
{
primaryKey = map.get(primaryKeyColumnName);
primaryKey = rowNumber;
}

MapRow newRow = new MapRow(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj.primavera.p3;
package net.sf.mpxj.primavera.common;

/**
* Represents the structure of a Btrieve table.
* Represents the structure of a P3 or SureTrak table.
*/
public class TableDefinition
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public TableDefinition(int pageSize, int recordSize, String primaryKeyColumnName
/**
* Retrieve the page size.
*
* @return page sze in bytes
* @return page size in bytes
*/
public int getPageSize()
{
Expand Down
Loading

0 comments on commit 4ed63de

Please sign in to comment.