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

The following examples show how to use net.sf.mpxj.Task#getCachedValue() . 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: MSPDIWriter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method writes extended attribute data for a task.
 *
 * @param xml MSPDI task
 * @param mpx MPXJ task
 */
private void writeTaskExtendedAttributes(Project.Tasks.Task xml, Task mpx)
{
   Project.Tasks.Task.ExtendedAttribute attrib;
   List<Project.Tasks.Task.ExtendedAttribute> extendedAttributes = xml.getExtendedAttribute();

   for (TaskField mpxFieldID : getAllTaskExtendedAttributes())
   {
      Object value = mpx.getCachedValue(mpxFieldID);

      if (FieldTypeHelper.valueIsNotDefault(mpxFieldID, value))
      {
         m_extendedAttributesInUse.add(mpxFieldID);

         Integer xmlFieldID = Integer.valueOf(MPPTaskField.getID(mpxFieldID) | MPPTaskField.TASK_FIELD_BASE);

         attrib = m_factory.createProjectTasksTaskExtendedAttribute();
         extendedAttributes.add(attrib);
         attrib.setFieldID(xmlFieldID.toString());
         attrib.setValue(DatatypeConverter.printExtendedAttribute(this, value, mpxFieldID.getDataType()));
         attrib.setDurationFormat(printExtendedAttributeDurationFormat(value));
      }
   }
}
 
Example 2
Source File: PrimaveraPMFileWriter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Attempts to locate the activity type value extracted from an existing P6 schedule.
 * If necessary converts to the form which can be used in the PMXML file.
 * Returns "Resource Dependent" as the default value.
 *
 * @param task parent task
 * @return activity type
 */
private String extractAndConvertTaskType(Task task)
{
   String activityType = (String) task.getCachedValue(m_activityTypeField);
   if (activityType == null)
   {
      activityType = "Resource Dependent";
   }
   else
   {
      if (ACTIVITY_TYPE_MAP.containsKey(activityType))
      {
         activityType = ACTIVITY_TYPE_MAP.get(activityType);
      }
   }
   return activityType;
}
 
Example 3
Source File: TaskModel.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine if a task field contains data.
 *
 * @param task task instance
 * @param field target field
 * @return true if the field contains data
 */
@SuppressWarnings("unchecked") private boolean isFieldPopulated(Task task, TaskField field)
{
   boolean result = false;
   if (field != null)
   {
      Object value = task.getCachedValue(field);
      switch (field)
      {
         // We never write these fields to the task record.
         // We only write a predecessor entry rather than the successors entry
         // We write notes as a separate record
         case NOTES:
         case SUCCESSORS:
         {
            result = false;
            break;
         }

         case PREDECESSORS:
         {
            result = value != null && !((List<Relation>) value).isEmpty();
            break;
         }

         default:
         {
            result = value != null;
            break;
         }
      }
   }
   return result;
}
 
Example 4
Source File: PrimaveraPMFileWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Retrieve the Activity ID value for this task.
 * @param task Task instance
 * @return Activity ID value
 */
private String getActivityID(Task task)
{
   String result = null;
   if (m_activityIDField != null)
   {
      Object value = task.getCachedValue(m_activityIDField);
      if (value != null)
      {
         result = value.toString();
      }
   }
   return result;
}
 
Example 5
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);
}