net.sf.mpxj.ProjectFile Java Examples
The following examples show how to use
net.sf.mpxj.ProjectFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomerDataTest.java From mpxj with GNU Lesser General Public License v2.1 | 7 votes |
/** * Test a project from a Primavera SQLite database. * * @param reader PrimaveraDatabaseReader instance * @param projectID ID of the project to extract * @param projectName Name of the project to extract * @return true if project read and validated successfully */ private Boolean testPrimaveraProject(PrimaveraDatabaseReader reader, int projectID, String projectName) { Boolean result = Boolean.TRUE; try { reader.setProjectID(projectID); ProjectFile project = reader.read(); if (!testBaseline(projectName, project, m_primaveraBaselineDir)) { System.err.println("Failed to validate Primavera database project baseline " + projectName); result = Boolean.FALSE; } } catch (Exception e) { System.err.println("Failed to read Primavera database project: " + projectName); result = Boolean.FALSE; } return result; }
Example #2
Source File: TaskDatesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskDates(File file) throws Exception { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } ProjectFile project = reader.read(file); int maxIndex = 10; for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Date" + index, task.getName()); testTaskDates(file, task, index, maxIndex); } }
Example #3
Source File: InvalidCalendarTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test reading an XER file which contains invalid calendar data. */ @Test public void testInvalidPrimaveraCalendar() throws MPXJException { File testDataDir = new File(MpxjTestData.filePath("calendar/invalid")); File file = new File(testDataDir, "invalid-8.4.xer"); PrimaveraXERFileReader reader = new PrimaveraXERFileReader(); ProjectFile project = reader.read(file); ProjectCalendar calendar = project.getCalendarByUniqueID(Integer.valueOf(178)); assertEquals("Corporate - Standard Full Time", calendar.getName()); calendar = project.getCalendarByUniqueID(Integer.valueOf(179)); assertEquals("Test - Valid", calendar.getName()); calendar = project.getCalendarByUniqueID(Integer.valueOf(180)); assertEquals("Test - Invalid", calendar.getName()); }
Example #4
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline starts. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testStarts(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Date value; if (index == 0) { value = task.getBaselineStart(); } else { value = task.getBaselineStart(index); } assertEquals(STARTS[index], m_dateFormat.format(value)); } return taskID; }
Example #5
Source File: FastTrackReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ @Override public ProjectFile read(InputStream inputStream) throws MPXJException { File file = null; try { file = InputStreamHelper.writeStreamToTempFile(inputStream, ".fts"); return read(file); } catch (IOException ex) { throw new MPXJException(MPXJException.INVALID_FILE, ex); } finally { FileHelper.deleteQuietly(file); } }
Example #6
Source File: ProjectCalendarTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Simple tests to exercise the ProjectCalendar.getStartTime method. * * @throws Exception */ @Test public void testStartTime() throws Exception { ProjectFile file = new ProjectFile(); ProjectCalendar cal = file.addDefaultBaseCalendar(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm"); // // Working day // assertEquals("01/01/0001 08:00", df.format(cal.getStartTime(df.parse("09/10/2003 00:00")))); // // Non-working day // assertNull(cal.getStartTime(df.parse("11/10/2003 00:00"))); }
Example #7
Source File: TaskCostsTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskCosts(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 3 : 10; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Cost" + index, task.getName()); testTaskCosts(file, task, index, maxIndex); } }
Example #8
Source File: ProjectTreeController.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Add views to the tree. * * @param parentNode parent tree node * @param file views container */ private void addViews(MpxjTreeNode parentNode, ProjectFile file) { for (View view : file.getViews()) { final View v = view; MpxjTreeNode childNode = new MpxjTreeNode(view) { @Override public String toString() { return v.getName(); } }; parentNode.add(childNode); } }
Example #9
Source File: ProjectTreeController.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Add tables to the tree. * * @param parentNode parent tree node * @param file tables container */ private void addTables(MpxjTreeNode parentNode, ProjectFile file) { for (Table table : file.getTables()) { final Table t = table; MpxjTreeNode childNode = new MpxjTreeNode(table, TABLE_EXCLUDED_METHODS) { @Override public String toString() { return t.getName(); } }; parentNode.add(childNode); addColumns(childNode, table); } }
Example #10
Source File: MerlinReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ @Override public ProjectFile read(InputStream stream) throws MPXJException { File file = null; try { file = InputStreamHelper.writeStreamToTempFile(stream, ".sqlite"); return read(file); } catch (IOException ex) { throw new MPXJException("", ex); } finally { FileHelper.deleteQuietly(file); } }
Example #11
Source File: TaskNumbersTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskNumbers(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 5 : 20; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Number" + index, task.getName()); testTaskNumbers(file, task, index, maxIndex); } }
Example #12
Source File: MppResourceTypeTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test the resource types present in an individual MPP file. * * @param file MPP file to test */ private void testResourceType(File file) throws MPXJException { ProjectFile project = new MPPReader().read(file); List<Resource> resources = project.getResources(); assertEquals(10, resources.size()); testResource(file, project, 1, "Work 1", ResourceType.WORK); testResource(file, project, 2, "Work 2", ResourceType.WORK); testResource(file, project, 3, "Work 3", ResourceType.WORK); testResource(file, project, 4, "Material 1", ResourceType.MATERIAL); testResource(file, project, 5, "Material 2", ResourceType.MATERIAL); testResource(file, project, 6, "Material 3", ResourceType.MATERIAL); // // The cost resource type was introduced in MPP12 // ResourceType expectedType = NumberHelper.getInt(project.getProjectProperties().getMppFileType()) > 9 ? ResourceType.COST : ResourceType.MATERIAL; testResource(file, project, 7, "Cost 1", expectedType); testResource(file, project, 8, "Cost 2", expectedType); testResource(file, project, 9, "Cost 3", expectedType); }
Example #13
Source File: ResourceTextTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testResourceText(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 10 : 30; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Resource resource = project.getResourceByID(Integer.valueOf(index)); assertEquals("Text" + index, resource.getName()); testResourceText(file, resource, index, maxIndex); } }
Example #14
Source File: DurationTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Validates duration values. * * @param mpp project file */ private void testDurations(ProjectFile mpp) { Task task = mpp.getTaskByID(Integer.valueOf(1)); assertEquals(Duration.getInstance(1, TimeUnit.MINUTES), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(2)); assertEquals(Duration.getInstance(1, TimeUnit.HOURS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(3)); assertEquals(Duration.getInstance(1, TimeUnit.DAYS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(4)); assertEquals(Duration.getInstance(1, TimeUnit.WEEKS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(5)); assertEquals(Duration.getInstance(1, TimeUnit.MONTHS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(6)); assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_MINUTES), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(7)); assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_HOURS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(8)); assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_DAYS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(9)); assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_WEEKS), task.getDuration()); task = mpp.getTaskByID(Integer.valueOf(10)); assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_MONTHS), task.getDuration()); }
Example #15
Source File: MpxjQuery.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Reads basic summary details from the project properties. * * @param file MPX file */ private static void listProjectProperties(ProjectFile file) { SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm z"); ProjectProperties properties = file.getProjectProperties(); Date startDate = properties.getStartDate(); Date finishDate = properties.getFinishDate(); String formattedStartDate = startDate == null ? "(none)" : df.format(startDate); String formattedFinishDate = finishDate == null ? "(none)" : df.format(finishDate); System.out.println("MPP file type: " + properties.getMppFileType()); System.out.println("Project Properties: StartDate=" + formattedStartDate + " FinishDate=" + formattedFinishDate); System.out.println(); }
Example #16
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Implements common project properties tests. * * @param file target project file */ private void testMspdiProperties(ProjectFile file) { ProjectProperties properties = file.getProjectProperties(); assertEquals("Project Title Text", properties.getProjectTitle()); assertEquals("Author Text", properties.getAuthor()); // Looks like an oversight in the schema - the Notes field is present in files, but not in the schema //assertEquals("Comments Text", properties.getComments()); assertEquals("Company Text", properties.getCompany()); // Doesn't look like keywords is present in MSPDI files at all //assertEquals("Keywords Text", properties.getKeywords()); assertEquals("Manager Text", properties.getManager()); assertEquals("Subject Text", properties.getSubject()); }
Example #17
Source File: ExportMSProject.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
private static void addTask(final ProjectFile file, final Map<Serializable, Task> taskMap, final Task parentTask, final GanttTask ganttTask) { final Task task; if (parentTask == null) { task = file.addTask(); } else { task = parentTask.addTask(); } taskMap.put(ganttTask.getId(), task); task.setName(ganttTask.getTitle()); if (ganttTask.getStartDate() != null) { task.setStart(ganttTask.getStartDate()); } if (ganttTask.getEndDate() != null) { task.setFinish(ganttTask.getEndDate()); } final BigDecimal duration = ganttTask.getDuration(); final double value; if (duration == null) { value = 0.0; } else { value = duration.doubleValue(); } task.setDuration(Duration.getInstance(value, TimeUnit.DAYS)); if (ganttTask.getProgress() != null) { task.setPercentageComplete(ganttTask.getProgress()); } // task2.setActualStart(df.parse("01/01/2003")); // milestone1.setDuration(Duration.getInstance(0, TimeUnit.DAYS)); final List<GanttTask> children = ganttTask.getChildren(); if (children == null) { return; } for (final GanttTask child : children) { addTask(file, taskMap, task, child); } }
Example #18
Source File: TaskDurationsTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test duration values. * * @param file project file * @param reader reader used to parse the file * @param project project file */ private void testDurationValues(File file, ProjectReader reader, ProjectFile project) { int maxIndex = reader instanceof MPXReader ? 3 : 10; for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Duration" + index, task.getName()); testTaskDurations(file, task, index, maxIndex); } }
Example #19
Source File: MerlinReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * By the time we reach this method, we should be looking at the SQLite * database file itself. * * @param file SQLite database file * @return ProjectFile instance */ private ProjectFile readFile(File file) throws MPXJException { try { String url = "jdbc:sqlite:" + file.getAbsolutePath(); Properties props = new Properties(); m_connection = org.sqlite.JDBC.createConnection(url, props); m_documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); m_dayTimeIntervals = xpath.compile("/array/dayTimeInterval"); m_entityMap = new HashMap<>(); return read(); } catch (Exception ex) { throw new MPXJException(MPXJException.INVALID_FORMAT, ex); } finally { AutoCloseableHelper.closeQuietly(m_connection); m_documentBuilder = null; m_dayTimeIntervals = null; m_entityMap = null; } }
Example #20
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Exercise PlannerWriter. * * @throws Exception */ @Test public void testRewrite5() throws Exception { File in = new File(MpxjTestData.filePath("legacy/sample.mpx")); ProjectFile mpx = new MPXReader().read(in); File out = File.createTempFile("junit", ".planner"); new PlannerWriter().write(mpx, out); //success = FileUtility.equals (in, out); //assertTrue ("Files are not identical", success); out.deleteOnExit(); }
Example #21
Source File: MppAssignmentTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test assignment fields read from an MPP12 file, saved by Project 2010. * * @throws Exception */ @Test public void testMpp12FieldsFrom14() throws Exception { MPPReader reader = new MPPReader(); ProjectFile mpp = reader.read(MpxjTestData.filePath("mpp12assignmentfields-from14.mpp")); testFields(mpp, "230CA12B-3792-4F3B-B69E-89ABAF1C9042", "C3FDB823-3C82-422B-A854-391F7E235EA2"); }
Example #22
Source File: ProjectFileExporter.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public ProjectFileExporter(IGanttProject nativeProject) { myNativeProject = nativeProject; myOutputProject = new ProjectFile(); myOutputProject.getProjectConfig().setAutoOutlineLevel(true); myOutputProject.getProjectConfig().setAutoWBS(true); myOutputProject.getProjectConfig().setAutoOutlineNumber(true); myOutputProject.getProjectConfig().setAutoResourceUniqueID(false); myOutputProject.getProjectConfig().setAutoTaskUniqueID(false); }
Example #23
Source File: MppResourceTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * In the original MPP14 reader implementation, the ID and Unique ID * resource fields were read the wrong way around. This test validates * that the values are read correctly, especially when the ID != Unique ID. */ @Test public void testResourceIdAndUniqueID() throws Exception { MPPReader reader = new MPPReader(); ProjectFile file = reader.read(MpxjTestData.filePath("ResourceIdAndUniqueId-project2013-mpp14.mpp")); validateIdValues(file); file = reader.read(MpxjTestData.filePath("ResourceIdAndUniqueId-project2010-mpp14.mpp")); validateIdValues(file); }
Example #24
Source File: MppEmbeddedTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test MPP14 file. * * @throws Exception */ @Test public void testMpp14Embedded() throws Exception { MPPReader reader = new MPPReader(); reader.setPreserveNoteFormatting(true); ProjectFile mpp = reader.read(MpxjTestData.filePath("mpp14embedded.mpp")); testEmbeddedObjects(mpp); }
Example #25
Source File: MppEmbeddedTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test MPP9 file saved by Project 2007. * * @throws Exception */ @Test public void testMpp9From12Embedded() throws Exception { MPPReader reader = new MPPReader(); reader.setPreserveNoteFormatting(true); ProjectFile mpp = reader.read(MpxjTestData.filePath("mpp9embedded-from12.mpp")); testEmbeddedObjects(mpp); }
Example #26
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Basic rewrite test to exercise the MPX calendar exception read/write code. * * @throws Exception */ @Test public void testProjectCalendarExceptions() throws Exception { File in = new File(MpxjTestData.filePath("legacy/calendarExceptions.mpx")); ProjectFile mpx = new MPXReader().read(in); File out = File.createTempFile("junit", ".mpx"); MPXWriter writer = new MPXWriter(); writer.setUseLocaleDefaults(false); writer.write(mpx, out); boolean success = FileUtility.equals(in, out); assertTrue("Files are not identical", success); out.deleteOnExit(); }
Example #27
Source File: MppResourceTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test resource data read from an MPP12 file. * * @throws Exception */ @Test public void testMpp12Resource() throws Exception { MPPReader reader = new MPPReader(); reader.setPreserveNoteFormatting(false); ProjectFile mpp = reader.read(MpxjTestData.filePath("mpp12resource.mpp")); testResources(mpp); testNotes(mpp); testResourceAssignments(mpp); testResourceOutlineCodes(mpp); }
Example #28
Source File: MppAssignmentTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test assignment fields read from an MPP9 file, saved by Project 2010. * * @throws Exception */ @Test public void testMpp9FieldsFrom14() throws Exception { MPPReader reader = new MPPReader(); ProjectFile mpp = reader.read(MpxjTestData.filePath("mpp9assignmentfields-from14.mpp")); testFields(mpp, null, null); }
Example #29
Source File: ProjectFileImporter.java From ganttproject with GNU General Public License v3.0 | 5 votes |
private void importResourceAssignments(ProjectFile pf, Map<Integer, GanttTask> foreignId2nativeTask, Map<Integer, HumanResource> foreignId2nativeResource) { for (ResourceAssignment ra : pf.getAllResourceAssignments()) { GanttTask nativeTask = foreignId2nativeTask.get(foreignId(ra.getTask())); if (nativeTask == null) { myErrors.add(Pair.create(Level.SEVERE, String.format( "Failed to import resource assignment=%s because its task with ID=%d and name=%s was not found or not imported", ra, foreignId(ra.getTask()), ra.getTask().getName()))); continue; } Resource resource = ra.getResource(); if (resource == null) { continue; } HumanResource nativeResource = foreignId2nativeResource.get(resource.getUniqueID()); if (nativeResource == null) { myErrors.add(Pair.create(Level.SEVERE, String.format( "Failed to import resource assignment=%s because its resource with ID=%d and name=%s was not found or not imported", ra, resource.getUniqueID(), resource.getName()))); continue; } net.sourceforge.ganttproject.task.ResourceAssignment nativeAssignment = nativeTask.getAssignmentCollection().addAssignment( nativeResource); Preconditions.checkNotNull(nativeAssignment); if (ra.getUnits() == null) { myErrors.add(Pair.create(Level.INFO, String.format( "Units not found in resource assignment=%s. Replaced with 100", ra))); nativeAssignment.setLoad(100f); } else { nativeAssignment.setLoad(ra.getUnits().floatValue()); } } }
Example #30
Source File: UniversalProjectReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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. * * @param stream schedule data * @return ProjectFile instance */ 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); } }