Java Code Examples for net.sf.mpxj.Task#getNotes()

The following examples show how to use net.sf.mpxj.Task#getNotes() . 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: GanttDesignerReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read an individual remark type from a Gantt Designer file.
 *
 * @param remark remark type
 */
private void processRemarks(GanttDesignerRemark remark)
{
   for (GanttDesignerRemark.Task remarkTask : remark.getTask())
   {
      Integer id = remarkTask.getRow();
      Task task = m_projectFile.getTaskByID(id);
      String notes = task.getNotes();
      if (notes.isEmpty())
      {
         notes = remarkTask.getContent();
      }
      else
      {
         notes = notes + '\n' + remarkTask.getContent();
      }
      task.setNotes(notes);
   }
}
 
Example 2
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method lists any notes attached to tasks.
 *
 * @param file MPX file
 */
private static void listTaskNotes(ProjectFile file)
{
   for (Task task : file.getTasks())
   {
      String notes = task.getNotes();

      if (notes.length() != 0)
      {
         System.out.println("Notes for " + task.getName() + ": " + notes);
      }
   }

   System.out.println();
}
 
Example 3
Source File: MPXWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write a task.
 *
 * @param record task instance
 * @throws IOException
 */
private void writeTask(Task record) throws IOException
{
   m_buffer.setLength(0);

   //
   // Write the task
   //
   int[] fields = m_taskModel.getModel();
   int field;

   m_buffer.append(MPXConstants.TASK_RECORD_NUMBER);
   for (int loop = 0; loop < fields.length; loop++)
   {
      field = fields[loop];
      if (field == -1)
      {
         break;
      }

      TaskField taskField = MPXTaskField.getMpxjField(field);
      Object value = record.getCachedValue(taskField);
      value = formatType(taskField.getDataType(), value);

      m_buffer.append(m_delimiter);
      m_buffer.append(format(value));
   }

   stripTrailingDelimiters(m_buffer);
   m_buffer.append(MPXConstants.EOL);
   m_writer.write(m_buffer.toString());

   //
   // Write the task notes
   //
   String notes = record.getNotes();
   if (notes.length() != 0)
   {
      writeNotes(MPXConstants.TASK_NOTES_RECORD_NUMBER, notes);
   }

   //
   // Write the recurring task
   //
   if (record.getRecurringTask() != null)
   {
      writeRecurringTask(record.getRecurringTask());
   }

   //
   // Write any resource assignments
   //
   if (record.getResourceAssignments().isEmpty() == false)
   {
      for (ResourceAssignment assignment : record.getResourceAssignments())
      {
         writeResourceAssignment(assignment);
      }
   }

   m_eventManager.fireTaskWrittenEvent(record);
}
 
Example 4
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method exercises task notes, ensuring that
 * embedded commas and quotes are handled correctly.
 *
 * @throws Exception
 */
@Test public void testTaskNotes() throws Exception
{
   String notes1 = "Notes, containing a comma. Done.";
   String notes2 = "Notes \"containing embedded quotes\" Done.";
   String notes3 = "Notes, \"containing embedded quotes, and comma's too.\" Done.";
   String notes4 = "\"Notes containing embedded quotes as first and last chars. Done.\"";
   String notes5 = "Normal unquoted notes. Done.";

   ProjectFile file1 = new ProjectFile();

   Task task1 = file1.addTask();
   task1.setName("Test Task 1");
   task1.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task1.setStart(new Date());
   task1.setNotes(notes1);

   Task task2 = file1.addTask();
   task2.setName("Test Task 2");
   task2.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task2.setStart(new Date());
   task2.setNotes(notes2);

   Task task3 = file1.addTask();
   task3.setName("Test Task 3");
   task3.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task3.setStart(new Date());
   task3.setNotes(notes3);

   Task task4 = file1.addTask();
   task4.setName("Test Task 4");
   task4.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task4.setStart(new Date());
   task4.setNotes(notes4);

   Task task5 = file1.addTask();
   task5.setName("Test Task 5");
   task5.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task5.setStart(new Date());
   task5.setNotes(notes5);

   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(file1, out);

   ProjectFile file2 = new MPXReader().read(out);
   String notes;
   Task task1a = file2.getTaskByUniqueID(task1.getUniqueID());
   notes = task1a.getNotes();
   assertEquals(notes1, notes);

   Task task2a = file2.getTaskByUniqueID(task2.getUniqueID());
   notes = task2a.getNotes();
   assertEquals(notes2, notes);

   Task task3a = file2.getTaskByUniqueID(task3.getUniqueID());
   notes = task3a.getNotes();
   assertEquals(notes3, notes);

   Task task4a = file2.getTaskByUniqueID(task4.getUniqueID());
   notes = task4a.getNotes();
   assertEquals(notes4, notes);

   Task task5a = file2.getTaskByUniqueID(task5.getUniqueID());
   notes = task5a.getNotes();
   assertEquals(notes5, notes);

   out.deleteOnExit();
}
 
Example 5
Source File: MppEmbeddedTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Tests common to all file types.
 *
 * @param file project file
 */
private void testEmbeddedObjects(ProjectFile file)
{
   Task task = file.getTaskByID(Integer.valueOf(1));
   assertEquals("Task 1", task.getName());
   String notes = task.getNotes();
   assertNotNull(notes);
   List<List<RTFEmbeddedObject>> list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNull(list);

   task = file.getTaskByID(Integer.valueOf(2));
   assertEquals("Task 2", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(1, list.size());
   List<RTFEmbeddedObject> objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));

   task = file.getTaskByID(Integer.valueOf(3));
   assertEquals("Task 3", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(1, list.size());
   objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));

   task = file.getTaskByID(Integer.valueOf(4));
   assertEquals("Task 4", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(1, list.size());
   objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));

   task = file.getTaskByID(Integer.valueOf(5));
   assertEquals("Task 5", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(1, list.size());
   objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));

   task = file.getTaskByID(Integer.valueOf(6));
   assertEquals("Task 6", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(2, list.size());
   objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));
   objectList = list.get(1);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));

   task = file.getTaskByID(Integer.valueOf(7));
   assertEquals("Task 7", task.getName());
   notes = task.getNotes();
   assertNotNull(notes);
   list = RTFEmbeddedObject.getEmbeddedObjects(notes);
   assertNotNull(list);
   assertEquals(2, list.size());
   objectList = list.get(0);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));
   objectList = list.get(1);
   assertEquals(4, objectList.size());
   assertEquals("Package", new String(objectList.get(0).getData(), 0, 7));
   assertEquals("METAFILEPICT", new String(objectList.get(2).getData(), 0, 12));
}