Java Code Examples for net.sf.mpxj.ProjectFile#getProjectProperties()

The following examples show how to use net.sf.mpxj.ProjectFile#getProjectProperties() . 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: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 2
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Implements common project properties tests.
 *
 * @param file target project file
 */
private void testProperties(ProjectFile file)
{
   ProjectProperties properties = file.getProjectProperties();
   assertEquals("Project Title Text", properties.getProjectTitle());
   assertEquals("Author Text", properties.getAuthor());
   assertEquals("Comments Text", properties.getComments());
   assertEquals("Company Text", properties.getCompany());
   assertEquals("Keywords Text", properties.getKeywords());
   assertEquals("Manager Text", properties.getManager());
   assertEquals("Subject Text", properties.getSubject());
}
 
Example 3
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 4
Source File: TaskBaselinesTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testTaskBaselineValues(File file) throws MPXJException
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   ProjectFile project = reader.read(file);

   int startTaskID = 1;
   int maxBaselines = file.getName().contains("project98") || file.getName().contains("project2000") ? 1 : 11;
   startTaskID = testCosts(project, startTaskID, maxBaselines);
   startTaskID = testDurations(project, startTaskID, maxBaselines);
   startTaskID = testFinishes(project, startTaskID, maxBaselines);
   startTaskID = testStarts(project, startTaskID, maxBaselines);
   startTaskID = testWorks(project, startTaskID, maxBaselines);

   //
   // Handle different file content depending on which application and file version have been used
   //
   ProjectProperties properties = project.getProjectProperties();
   if (NumberHelper.getInt(properties.getApplicationVersion()) >= ApplicationVersion.PROJECT_2010 && NumberHelper.getInt(properties.getMppFileType()) >= 14)
   {
      startTaskID = testEstimatedDurations(project, startTaskID, maxBaselines);
      startTaskID = testEstimatedFinishes(project, startTaskID, maxBaselines);
      startTaskID = testEstimatedStarts(project, startTaskID, maxBaselines);
      startTaskID = testFixedCosts(project, startTaskID, maxBaselines);
      testFixedCostAccruals(project, startTaskID, maxBaselines);
   }
}
 
Example 5
Source File: AbstractView.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param parent parent file
 */
public AbstractView(ProjectFile parent)
{
   m_properties = parent.getProjectProperties();
   m_tables = parent.getTables();
}
 
Example 6
Source File: ProjectPropertiesTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testProjectProperties(File file) throws MPXJException
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   //DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

   ProjectFile project = reader.read(file);
   ProjectProperties properties = project.getProjectProperties();

   //
   // We are reading title successfully - it's just that when MS Project saves
   // the test data files, sometimes it sets the value we asked for... sometimes
   // it reverts to the file name.
   //
   //assertEquals("Title", properties.getProjectTitle());

   assertEquals(file.getName(), "Subject", properties.getSubject());
   assertEquals("Author", properties.getAuthor());
   assertEquals("Keywords", properties.getKeywords());
   assertEquals("Comments", properties.getComments());
   assertEquals("Template", properties.getTemplate());
   assertEquals("Category", properties.getCategory());
   assertEquals("Format", properties.getPresentationFormat());
   assertEquals("Manager", properties.getManager());
   assertEquals("Company", properties.getCompany());

   if (NumberHelper.getInt(project.getProjectProperties().getMppFileType()) > 9)
   {
      assertEquals("Content type", properties.getContentType());
      assertEquals("Content status", properties.getContentStatus());
      assertEquals("Language", properties.getLanguage());
      assertEquals("Document version", properties.getDocumentVersion());
   }

   Map<String, Object> custom = properties.getCustomProperties();
   assertEquals(Integer.valueOf(1000), custom.get("CustomNumber"));
   assertEquals(Double.valueOf(1.5), custom.get("CustomFloat"));
   assertEquals("This is a custom property.", custom.get("CustomString"));
   // Project 2019 returns a time one hour behind what we expect. DST maybe?
   // TODO: investigate further
   //assertEquals(file.getName(), "01/01/2014", df.format((Date) custom.get("CustomDate")));
}
 
Example 7
Source File: MppProjectPropertiesTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test the project properties as read from an MPP file.
 *
 * @param mpp project file
 * @param isMPP is the source an MPP file
 */
private void testProperties(ProjectFile mpp, boolean isMPP)
{
   //
   // Create time and date formatters
   //
   DateFormat tf = new SimpleDateFormat("HH:mm");
   DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

   //
   // Check the values of project properties.
   // The order of these tests should be the same as the order
   // in which the attributes are read from the MPP file
   // for ease of reference.
   //
   ProjectProperties ph = mpp.getProjectProperties();
   assertEquals(ScheduleFrom.FINISH, ph.getScheduleFrom());
   assertEquals("24 Hours", ph.getDefaultCalendarName());
   assertEquals("08:35", tf.format(ph.getDefaultStartTime()));
   assertEquals("17:35", tf.format(ph.getDefaultEndTime()));
   assertEquals("01/08/2006", df.format(ph.getStatusDate()));

   assertEquals(TimeUnit.HOURS, ph.getDefaultDurationUnits());
   assertEquals(7 * 60, ph.getMinutesPerDay().intValue());
   assertEquals(41 * 60, ph.getMinutesPerWeek().intValue());
   assertEquals(2.0, ph.getDefaultOvertimeRate().getAmount(), 0);
   assertEquals(TimeUnit.HOURS, ph.getDefaultOvertimeRate().getUnits());
   assertEquals(1.0, ph.getDefaultStandardRate().getAmount(), 0);
   assertEquals(TimeUnit.HOURS, ph.getDefaultStandardRate().getUnits());
   assertEquals(TimeUnit.WEEKS, ph.getDefaultWorkUnits());
   assertFalse(ph.getSplitInProgressTasks());
   assertFalse(ph.getUpdatingTaskStatusUpdatesResourceStatus());

   assertEquals(1, ph.getCurrencyDigits().intValue());
   assertEquals("X", ph.getCurrencySymbol());
   assertEquals(CurrencySymbolPosition.AFTER, ph.getSymbolPosition());

   assertEquals("title", ph.getProjectTitle());
   assertEquals("subject", ph.getSubject());
   assertEquals("author", ph.getAuthor());
   assertEquals("keywords", ph.getKeywords());
   assertEquals("company", ph.getCompany());
   assertEquals("manager", ph.getManager());
   assertEquals("category", ph.getCategory());

   // MPP only
   if (isMPP)
   {
      assertEquals("comments", ph.getComments());
      assertTrue(ph.getCalculateMultipleCriticalPaths());
   }
}
 
Example 8
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write a file with embedded line break (\r and \n) characters in
 * various text fields. Ensure that a valid file is written,
 * and that it can be read successfully.
 *
 * @throws Exception
 */
@Test public void testEmbeddedLineBreaks() throws Exception
{
   //
   // Create a simple MPX file
   //
   SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
   ProjectFile file = new ProjectFile();
   file.addDefaultBaseCalendar();

   ProjectProperties properties = file.getProjectProperties();
   properties.setComments("Project Header Comments: Some\rExample\nText\r\nWith\n\rBreaks");
   properties.setStartDate(df.parse("01/01/2003"));

   Resource resource1 = file.addResource();
   resource1.setName("Resource1: Some\rExample\nText\r\nWith\n\rBreaks");
   resource1.setNotes("Resource1 Notes: Some\rExample\nText\r\nWith\n\rBreaks");

   Task task1 = file.addTask();
   task1.setName("Task1: Some\rExample\nText\r\nWith\n\rBreaks");
   task1.setNotes("Task1 Notes: Some\rExample\nText\r\nWith\n\rBreaks");

   //
   // Write the file
   //
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(file, out);

   //
   // Ensure we can read it successfully
   //
   file = new MPXReader().read(out);
   assertEquals(1, file.getTasks().size());
   assertEquals(1, file.getResources().size());

   properties = file.getProjectProperties();
   assertEquals("Project Header Comments: Some\nExample\nText\nWith\nBreaks", properties.getComments());

   task1 = file.getTaskByUniqueID(Integer.valueOf(1));
   assertEquals("Task1: Some\nExample\nText\nWith\nBreaks", task1.getName());
   assertEquals("Task1 Notes: Some\nExample\nText\nWith\nBreaks", task1.getNotes());

   resource1 = file.getResourceByUniqueID(Integer.valueOf(1));
   assertEquals("Resource1: Some\nExample\nText\nWith\nBreaks", resource1.getName());
   assertEquals("Resource1 Notes: Some\nExample\nText\nWith\nBreaks", resource1.getNotes());
   out.deleteOnExit();
}