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

The following examples show how to use net.sf.mpxj.Task#addResourceAssignment() . 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: ConceptDrawProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read resource assignments.
 *
 * @param task Parent task
 * @param assignment ConceptDraw PROJECT resource assignment
 */
private void readResourceAssignment(Task task, Document.Projects.Project.Task.ResourceAssignments.ResourceAssignment assignment)
{
   Resource resource = m_projectFile.getResourceByUniqueID(assignment.getResourceID());
   if (resource != null)
   {
      ResourceAssignment mpxjAssignment = task.addResourceAssignment(resource);
      mpxjAssignment.setUniqueID(assignment.getID());
      mpxjAssignment.setWork(Duration.getInstance(assignment.getManHour().doubleValue() * m_workHoursPerDay, TimeUnit.HOURS));
      mpxjAssignment.setUnits(assignment.getUse());
   }
}
 
Example 2
Source File: TurboProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read resource assignment data from a PEP file.
 */
private void readResourceAssignments()
{
   for (MapRow row : getTable("USGTAB"))
   {
      Task task = m_projectFile.getTaskByUniqueID(row.getInteger("TASK_ID"));
      Resource resource = m_projectFile.getResourceByUniqueID(row.getInteger("RESOURCE_ID"));
      if (task != null && resource != null)
      {
         ResourceAssignment assignment = task.addResourceAssignment(resource);
         m_eventManager.fireAssignmentReadEvent(assignment);
      }
   }
}
 
Example 3
Source File: GanttProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an individual GanttProject resource assignment.
 *
 * @param gpAllocation GanttProject resource assignment.
 */
private void readResourceAssignment(Allocation gpAllocation)
{
   Integer taskID = Integer.valueOf(NumberHelper.getInt(gpAllocation.getTaskId()) + 1);
   Integer resourceID = Integer.valueOf(NumberHelper.getInt(gpAllocation.getResourceId()) + 1);
   Task task = m_projectFile.getTaskByUniqueID(taskID);
   Resource resource = m_projectFile.getResourceByUniqueID(resourceID);
   if (task != null && resource != null)
   {
      ResourceAssignment mpxjAssignment = task.addResourceAssignment(resource);
      mpxjAssignment.setUnits(gpAllocation.getLoad());
      m_eventManager.fireAssignmentReadEvent(mpxjAssignment);
   }
}
 
Example 4
Source File: MerlinReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read assignment data.
 */
private void processAssignments() throws SQLException
{
   List<Row> rows = getRows("select * from zscheduleitem where zproject=? and z_ent=? order by zorderinactivity", m_projectID, m_entityMap.get("Assignment"));
   for (Row row : rows)
   {
      Task task = m_project.getTaskByUniqueID(row.getInteger("ZACTIVITY_"));
      Resource resource = m_project.getResourceByUniqueID(row.getInteger("ZRESOURCE"));
      if (task != null && resource != null)
      {
         ResourceAssignment assignment = task.addResourceAssignment(resource);
         assignment.setGUID(row.getUUID("ZUNIQUEID"));
         assignment.setActualFinish(row.getTimestamp("ZGIVENACTUALENDDATE_"));
         assignment.setActualStart(row.getTimestamp("ZGIVENACTUALSTARTDATE_"));

         assignment.setWork(assignmentDuration(task, row.getWork("ZGIVENWORK_")));
         assignment.setOvertimeWork(assignmentDuration(task, row.getWork("ZGIVENWORKOVERTIME_")));
         assignment.setActualWork(assignmentDuration(task, row.getWork("ZGIVENACTUALWORK_")));
         assignment.setActualOvertimeWork(assignmentDuration(task, row.getWork("ZGIVENACTUALWORKOVERTIME_")));
         assignment.setRemainingWork(assignmentDuration(task, row.getWork("ZGIVENREMAININGWORK_")));

         assignment.setLevelingDelay(row.getDuration("ZLEVELINGDELAY_"));

         if (assignment.getRemainingWork() == null)
         {
            assignment.setRemainingWork(assignment.getWork());
         }

         if (resource.getType() == ResourceType.WORK)
         {
            assignment.setUnits(Double.valueOf(NumberHelper.getDouble(row.getDouble("ZRESOURCEUNITS_")) * 100.0));
         }
      }
   }
}
 
Example 5
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read a single resource assignment.
 *
 * @param resource MPXJ resource
 * @param assignment Phoenix assignment
 */
private void readAssignment(Resource resource, Assignment assignment)
{
   Task task = m_activityMap.get(assignment.getActivity());
   if (task != null)
   {
      task.addResourceAssignment(resource);
   }
}
 
Example 6
Source File: PrimaveraPMFileReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process resource assignments.
 *
 * @param project xml container
 */
private void processAssignments(ProjectType project)
{
   List<ResourceAssignmentType> assignments = project.getResourceAssignment();
   for (ResourceAssignmentType row : assignments)
   {
      Task task = m_projectFile.getTaskByUniqueID(mapTaskID(row.getActivityObjectId()));
      Resource resource = m_projectFile.getResourceByUniqueID(row.getResourceObjectId());
      if (task != null && resource != null)
      {
         ResourceAssignment assignment = task.addResourceAssignment(resource);

         assignment.setUniqueID(row.getObjectId());
         assignment.setRemainingWork(getDuration(row.getRemainingUnits()));
         assignment.setBaselineWork(getDuration(row.getPlannedUnits()));
         assignment.setActualWork(getDuration(row.getActualUnits()));
         assignment.setRemainingCost(row.getRemainingCost());
         assignment.setBaselineCost(row.getPlannedCost());
         assignment.setActualCost(row.getActualCost());
         assignment.setActualStart(row.getActualStartDate());
         assignment.setActualFinish(row.getActualFinishDate());
         assignment.setBaselineStart(row.getPlannedStartDate());
         assignment.setBaselineFinish(row.getPlannedFinishDate());
         assignment.setGUID(DatatypeConverter.parseUUID(row.getGUID()));

         task.setActualCost(Double.valueOf(NumberHelper.getDouble(task.getActualCost()) + NumberHelper.getDouble(assignment.getActualCost())));
         task.setRemainingCost(Double.valueOf(NumberHelper.getDouble(task.getRemainingCost()) + NumberHelper.getDouble(assignment.getRemainingCost())));
         task.setBaselineCost(Double.valueOf(NumberHelper.getDouble(task.getBaselineCost()) + NumberHelper.getDouble(assignment.getBaselineCost())));

         populateField(assignment, AssignmentField.WORK, AssignmentField.ACTUAL_WORK, AssignmentField.BASELINE_WORK);
         populateField(assignment, AssignmentField.COST, AssignmentField.ACTUAL_COST, AssignmentField.BASELINE_COST);
         populateField(assignment, AssignmentField.START, AssignmentField.ACTUAL_START, AssignmentField.BASELINE_START);
         populateField(assignment, AssignmentField.FINISH, AssignmentField.ACTUAL_FINISH, AssignmentField.BASELINE_FINISH);

         readUDFTypes(assignment, row.getUDF());

         m_eventManager.fireAssignmentReadEvent(assignment);
      }
   }
}
 
Example 7
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read resource assignments.
 */
private void readResourceAssignments()
{
   for (MapRow row : m_tables.get("RES"))
   {
      Task task = m_activityMap.get(row.getString("ACTIVITY_ID"));
      Resource resource = m_resourceMap.get(row.getString("RESOURCE_ID"));
      if (task != null && resource != null)
      {
         task.addResourceAssignment(resource);
      }
   }
}
 
Example 8
Source File: P3DatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read resource assignments.
 */
private void readResourceAssignments()
{
   for (MapRow row : m_tables.get("RES"))
   {
      Task task = m_activityMap.get(row.getString("ACTIVITY_ID"));
      Resource resource = m_resourceMap.get(row.getString("RESOURCE_ID"));
      if (task != null && resource != null)
      {
         task.addResourceAssignment(resource);
      }
   }
}
 
Example 9
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process a resource assignment.
 *
 * @param row resource assignment data
 */
protected void processAssignment(Row row)
{
   Resource resource = m_project.getResourceByUniqueID(row.getInteger("RES_UID"));
   Task task = m_project.getTaskByUniqueID(row.getInteger("TASK_UID"));

   if (task != null)
   {
      ResourceAssignment assignment = task.addResourceAssignment(resource);
      m_assignmentMap.put(row.getInteger("ASSN_UID"), assignment);

      assignment.setActualCost(row.getCurrency("ASSN_ACT_COST"));
      assignment.setActualFinish(row.getDate("ASSN_ACT_FINISH"));
      assignment.setActualOvertimeCost(row.getCurrency("ASSN_ACT_OVT_COST"));
      assignment.setActualOvertimeWork(row.getDuration("ASSN_ACT_OVT_WORK"));
      assignment.setActualStart(row.getDate("ASSN_ACT_START"));
      assignment.setActualWork(row.getDuration("ASSN_ACT_WORK"));
      assignment.setACWP(row.getCurrency("ASSN_ACWP"));
      assignment.setBaselineCost(row.getCurrency("ASSN_BASE_COST"));
      assignment.setBaselineFinish(row.getDate("ASSN_BASE_FINISH"));
      assignment.setBaselineStart(row.getDate("ASSN_BASE_START"));
      assignment.setBaselineWork(row.getDuration("ASSN_BASE_WORK"));
      assignment.setBCWP(row.getCurrency("ASSN_BCWP"));
      assignment.setBCWS(row.getCurrency("ASSN_BCWS"));
      assignment.setCost(row.getCurrency("ASSN_COST"));
      assignment.setCostRateTableIndex(row.getInt("ASSN_COST_RATE_TABLE"));
      //assignment.setCostVariance();
      //assignment.setCreateDate(row.getDate("ASSN_CREATION_DATE")); - not present in some MPD files?
      //assignment.setCV();
      assignment.setDelay(row.getDuration("ASSN_DELAY"));
      assignment.setFinish(row.getDate("ASSN_FINISH_DATE"));
      assignment.setFinishVariance(MPDUtility.getAdjustedDuration(m_project, row.getInt("ASSN_FINISH_VAR"), TimeUnit.DAYS));

      //assignment.setGUID();
      assignment.setLevelingDelay(MPDUtility.getAdjustedDuration(m_project, row.getInt("ASSN_LEVELING_DELAY"), MPDUtility.getDurationTimeUnits(row.getInt("ASSN_DELAY_FMT"))));
      assignment.setLinkedFields(row.getBoolean("ASSN_HAS_LINKED_FIELDS"));
      //assignment.setOvertimeCost();
      assignment.setOvertimeWork(row.getDuration("ASSN_OVT_WORK"));
      //assignment.setPercentageWorkComplete();
      assignment.setRemainingCost(row.getCurrency("ASSN_REM_COST"));
      assignment.setRemainingOvertimeCost(row.getCurrency("ASSN_REM_OVT_COST"));
      assignment.setRemainingOvertimeWork(row.getDuration("ASSN_REM_OVT_WORK"));
      assignment.setRegularWork(row.getDuration("ASSN_REG_WORK"));
      assignment.setRemainingWork(row.getDuration("ASSN_REM_WORK"));
      assignment.setResponsePending(row.getBoolean("ASSN_RESPONSE_PENDING"));
      assignment.setStart(row.getDate("ASSN_START_DATE"));
      assignment.setStartVariance(MPDUtility.getAdjustedDuration(m_project, row.getInt("ASSN_START_VAR"), TimeUnit.DAYS));

      //assignment.setSV();
      assignment.setTeamStatusPending(row.getBoolean("ASSN_TEAM_STATUS_PENDING"));
      assignment.setUniqueID(row.getInteger("ASSN_UID"));
      assignment.setUnits(Double.valueOf(row.getDouble("ASSN_UNITS").doubleValue() * 100.0d));
      assignment.setUpdateNeeded(row.getBoolean("ASSN_UPDATE_NEEDED"));
      //assignment.setVAC(v);
      assignment.setWork(row.getDuration("ASSN_WORK"));
      assignment.setWorkContour(WorkContour.getInstance(row.getInt("ASSN_WORK_CONTOUR")));
      //assignment.setWorkVariance();

      String notes = row.getString("ASSN_RTF_NOTES");
      if (notes != null)
      {
         if (m_preserveNoteFormatting == false)
         {
            notes = RtfHelper.strip(notes);
         }
         assignment.setNotes(notes);
      }

      m_eventManager.fireAssignmentReadEvent(assignment);
   }
}
 
Example 10
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process assignment data.
 *
 * @param rows assignment data
 */
public void processAssignments(List<Row> rows)
{
   for (Row row : rows)
   {
      Task task = m_project.getTaskByUniqueID(mapTaskID(row.getInteger("task_id")));
      Resource resource = m_project.getResourceByUniqueID(row.getInteger("rsrc_id"));
      if (task != null && resource != null)
      {
         ResourceAssignment assignment = task.addResourceAssignment(resource);
         processFields(m_assignmentFields, row, assignment);

         populateField(assignment, AssignmentField.START, AssignmentField.BASELINE_START, AssignmentField.ACTUAL_START);
         populateField(assignment, AssignmentField.FINISH, AssignmentField.BASELINE_FINISH, AssignmentField.ACTUAL_FINISH);

         // include actual overtime work in work calculations
         Duration remainingWork = row.getDuration("remain_qty");
         Duration actualOvertimeWork = row.getDuration("act_ot_qty");
         Duration actualRegularWork = row.getDuration("act_reg_qty");
         Duration actualWork = Duration.add(actualOvertimeWork, actualRegularWork, m_project.getProjectProperties());
         Duration totalWork = Duration.add(actualWork, remainingWork, m_project.getProjectProperties());
         assignment.setActualWork(actualWork);
         assignment.setWork(totalWork);

         // include actual overtime cost in cost calculations
         Double remainingCost = row.getDouble("remain_cost");
         Double actualOvertimeCost = row.getDouble("act_ot_cost");
         Double actualRegularCost = row.getDouble("act_reg_cost");
         double actualCost = NumberHelper.getDouble(actualOvertimeCost) + NumberHelper.getDouble(actualRegularCost);
         double totalCost = actualCost + NumberHelper.getDouble(remainingCost);
         assignment.setActualCost(NumberHelper.getDouble(actualCost));
         assignment.setCost(NumberHelper.getDouble(totalCost));

         double units;
         if (resource.getType() == ResourceType.MATERIAL)
         {
            units = (totalWork == null) ? 0 : totalWork.getDuration() * 100;
         }
         else // RT_Labor & RT_Equip
         {
            units = NumberHelper.getDouble(row.getDouble("target_qty_per_hr")) * 100;
         }
         assignment.setUnits(NumberHelper.getDouble(units));

         // Add User Defined Fields
         populateUserDefinedFieldValues("TASKRSRC", FieldTypeClass.ASSIGNMENT, assignment, assignment.getUniqueID());

         m_eventManager.fireAssignmentReadEvent(assignment);
      }
   }

   updateTaskCosts();
}
 
Example 11
Source File: MPP8Reader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method extracts and collates resource assignment data.
 *
 * @throws IOException
 */
private void processAssignmentData() throws IOException
{
   DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
   FixFix assnFixedData = new FixFix(204, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixFix   0"))));
   if (assnFixedData.getDiff() != 0 || (assnFixedData.getSize() % 238 == 0 && testAssignmentTasks(assnFixedData) == false))
   {
      assnFixedData = new FixFix(238, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixFix   0"))));
   }

   int count = assnFixedData.getItemCount();
   FixDeferFix assnVarData = null;

   for (int loop = 0; loop < count; loop++)
   {
      if (assnVarData == null)
      {
         assnVarData = new FixDeferFix(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixDeferFix   0"))));
      }

      byte[] data = assnFixedData.getByteArrayValue(loop);

      //
      // Check that the deleted flag isn't set
      //
      if (MPPUtility.getByte(data, 168) != 0x02)
      {
         Task task = m_file.getTaskByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 16)));
         Resource resource = m_file.getResourceByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 20)));

         if (task != null && resource != null)
         {
            ResourceAssignment assignment = task.addResourceAssignment(resource);
            assignment.setActualCost(NumberHelper.getDouble(((double) MPPUtility.getLong6(data, 138)) / 100));
            assignment.setActualWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 96)) / 100, TimeUnit.HOURS));
            assignment.setCost(NumberHelper.getDouble(((double) MPPUtility.getLong6(data, 132)) / 100));
            //assignment.setDelay(); // Not sure what this field maps on to in MSP
            assignment.setFinish(MPPUtility.getTimestamp(data, 28));
            assignment.setOvertimeWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 90)) / 100, TimeUnit.HOURS));
            //assignment.setPlannedCost(); // Not sure what this field maps on to in MSP
            //assignment.setPlannedWork(); // Not sure what this field maps on to in MSP
            assignment.setRemainingWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 114)) / 100, TimeUnit.HOURS));
            assignment.setStart(MPPUtility.getTimestamp(data, 24));
            assignment.setUniqueID(Integer.valueOf(MPPUtility.getInt(data, 0)));
            assignment.setUnits(Double.valueOf(((double) MPPUtility.getShort(data, 80)) / 100));
            assignment.setWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 84)) / 100, TimeUnit.HOURS));

            m_eventManager.fireAssignmentReadEvent(assignment);
         }
      }
   }
}
 
Example 12
Source File: SynchroReader.java    From mpxj with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Extract data for a single resource assignment.
 *
 * @param task parent task
 * @param row Synchro resource assignment
 */
private void processResourceAssignment(Task task, MapRow row)
{
   Resource resource = m_resourceMap.get(row.getUUID("RESOURCE_UUID"));
   task.addResourceAssignment(resource);
}