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

The following examples show how to use net.sf.mpxj.ProjectFile#getResourceByID() . 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: ResourceNumbersTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testResourceNumbers(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++)
   {
      Resource resource = project.getResourceByID(Integer.valueOf(index));
      assertEquals("Number" + index, resource.getName());
      testResourceNumbers(file, resource, index, maxIndex);
   }
}
 
Example 2
Source File: ResourceTextTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 3
Source File: ResourceFlagsTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testResourceFlags(File file) throws MPXJException
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   int maxIndex = reader instanceof MPXReader ? 10 : 20;
   ProjectFile project = reader.read(file);
   for (int index = 1; index <= maxIndex; index++)
   {
      Resource resource = project.getResourceByID(Integer.valueOf(index));
      assertEquals("Flag" + index, resource.getName());
      testResourceFlags(file, resource, index, maxIndex);
   }
}
 
Example 4
Source File: ResourceMiscTest.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 testResourceMisc(File file) throws MPXJException
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   ProjectFile project = reader.read(file);

   Resource resource1 = project.getResourceByID(Integer.valueOf(1));
   assertEquals("Resource 1", resource1.getName());
   assertEquals("Code1", resource1.getCode());
   assertEquals(Double.valueOf(1.23), resource1.getCostPerUse());
   assertEquals("[email protected]", resource1.getEmailAddress());
   assertEquals("Group1", resource1.getGroup());
   assertEquals("R1", resource1.getInitials());
   assertEquals("Notes1", resource1.getNotes());

   Resource resource2 = project.getResourceByID(Integer.valueOf(2));
   assertEquals("Resource 2", resource2.getName());
   assertEquals("Code2", resource2.getCode());
   assertEquals(Double.valueOf(4.56), resource2.getCostPerUse());
   assertEquals("[email protected]", resource2.getEmailAddress());
   assertEquals("Group2", resource2.getGroup());
   assertEquals("R2", resource2.getInitials());
   assertEquals("Notes2", resource2.getNotes());
}
 
Example 5
Source File: MppEnterpriseTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests enterprise fields.
 *
 * @param mpp The ProjectFile being tested.
 * @throws Exception
 */
private void testEnterpriseFields(ProjectFile mpp) throws Exception
{
   SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
   Task task = mpp.getTaskByID(Integer.valueOf(1));

   assertEquals(1, task.getEnterpriseCost(1).intValue());
   assertEquals(10, task.getEnterpriseCost(10).intValue());
   assertEquals("01/01/1991", df.format(task.getEnterpriseDate(1)));
   assertEquals("01/01/2020", df.format(task.getEnterpriseDate(30)));
   //assertEquals(1, (int) task.getEnterpriseDuration(1).getDuration()); zero in 2010 beta
   assertEquals(TimeUnit.DAYS, task.getEnterpriseDuration(1).getUnits());
   //assertEquals(10, (int) task.getEnterpriseDuration(10).getDuration()); zero in 2010 beta
   assertEquals(TimeUnit.DAYS, task.getEnterpriseDuration(10).getUnits());
   assertEquals(1, task.getEnterpriseNumber(1).intValue());
   assertEquals(40, task.getEnterpriseNumber(40).intValue());
   assertEquals("ET1", task.getEnterpriseText(1));
   assertEquals("ET40", task.getEnterpriseText(40));
   assertTrue(task.getEnterpriseFlag(1));
   assertFalse(task.getEnterpriseFlag(20));

   Resource resource = mpp.getResourceByID(Integer.valueOf(1));
   assertEquals(1, resource.getEnterpriseCost(1).intValue());
   assertEquals(10, resource.getEnterpriseCost(10).intValue());
   assertEquals("01/01/2008", df.format(resource.getEnterpriseDate(1)));
   assertEquals("30/01/2008", df.format(resource.getEnterpriseDate(30)));
   //assertEquals(1, (int) resource.getEnterpriseDuration(1).getDuration()); zero in 2010 beta
   assertEquals(TimeUnit.DAYS, resource.getEnterpriseDuration(1).getUnits());
   //assertEquals(10, (int) resource.getEnterpriseDuration(10).getDuration()); zero in 2010 beta
   assertEquals(TimeUnit.DAYS, resource.getEnterpriseDuration(10).getUnits());
   assertEquals(1, resource.getEnterpriseNumber(1).intValue());
   assertEquals(40, resource.getEnterpriseNumber(40).intValue());
   assertEquals("RET1", resource.getEnterpriseText(1));
   assertEquals("RET40", resource.getEnterpriseText(40));
   assertFalse(resource.getEnterpriseFlag(1));
   assertTrue(resource.getEnterpriseFlag(20));
}
 
Example 6
Source File: AvailabilityTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Common availability tests.
 *
 * @param file project file
 */
private void testAvailability(ProjectFile file) throws Exception
{
   //
   // Resource with empty availability table
   //
   Resource resource = file.getResourceByID(Integer.valueOf(1));
   assertEquals("Resource One", resource.getName());
   AvailabilityTable table = resource.getAvailability();
   assertEquals(0, table.size());

   //
   // Resource with populated availability table
   //
   resource = file.getResourceByID(Integer.valueOf(2));
   assertEquals("Resource Two", resource.getName());
   table = resource.getAvailability();
   assertEquals(3, table.size());

   assertAvailabilityEquals("01/06/2009 00:00", "01/07/2009 23:59", 100.0, table, 0);
   assertAvailabilityEquals("02/07/2009 00:00", "01/08/2009 23:59", 60.0, table, 1);
   assertAvailabilityEquals("20/08/2009 00:00", "30/08/2009 23:59", 75.0, table, 2);

   //
   // Validate date-based row selection
   //
   Availability entry = table.getEntryByDate(m_df.parse("01/05/2009 12:00"));
   assertNull(entry);
   entry = table.getEntryByDate(m_df.parse("03/07/2009 12:00"));
   assertAvailabilityEquals("02/07/2009 00:00", "01/08/2009 23:59", 60.0, table, 1);
   entry = table.getEntryByDate(m_df.parse("02/08/2009 12:00"));
   assertNull(entry);
   entry = table.getEntryByDate(m_df.parse("21/08/2009 12:00"));
   assertAvailabilityEquals("20/08/2009 00:00", "30/08/2009 23:59", 75.0, table, 2);
   entry = table.getEntryByDate(m_df.parse("01/09/2009 12:00"));
   assertNull(entry);
}
 
Example 7
Source File: MppResourceTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test resource outline codes.
 *
 * @param mpp project file
 * @throws Exception
 */
private void testResourceOutlineCodes(ProjectFile mpp) throws Exception
{
   Resource resourceWade = mpp.getResourceByID(Integer.valueOf(1));
   assertEquals("AAA", resourceWade.getOutlineCode1());
   assertEquals("BBB", resourceWade.getOutlineCode2());
   assertEquals("CCC", resourceWade.getOutlineCode3());
   assertEquals("DDD", resourceWade.getOutlineCode4());
   assertEquals("EEE", resourceWade.getOutlineCode5());
   assertEquals("FFF", resourceWade.getOutlineCode6());
   assertEquals("GGG", resourceWade.getOutlineCode7());
   assertEquals("HHH", resourceWade.getOutlineCode8());
   assertEquals("III", resourceWade.getOutlineCode9());
   assertEquals("JJJ", resourceWade.getOutlineCode10());
}
 
Example 8
Source File: MppResourceTypeTest.java    From mpxj with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Validate the name and type of an individual resource.
 *
 * @param file MPP file
 * @param project project read from MPP file
 * @param id resource ID
 * @param expectedName expected name
 * @param expectedType expected type
 */
private void testResource(File file, ProjectFile project, int id, String expectedName, ResourceType expectedType)
{
   Resource resource = project.getResourceByID(Integer.valueOf(id));
   assertEquals(file.getName(), expectedName, resource.getName());
   assertEquals(file.getName(), expectedType, resource.getType());
}