Skip to content

Commit

Permalink
Improve primary resource methods (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
joniles authored Dec 4, 2024
1 parent 4198f23 commit c108c46
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<author email="jon@timephased.com">Jon Iles</author>
</properties>
<body>
<release date="unreleased" version="13.7.1">
<release date="unreleased" version="13.8.0">
<action dev="joniles" type="update">When writing PMXML files, improve handling of P6 schedules where activity code sequence numbers are missing.</action>
<action dev="joniles" type="update">Added an *experimental* feature to `MSPDIWriter` to allow the writer to generate timephased data when none is present. Disabled by default, call the `setGenerateMissingTimephasedData` and pass `true` to enable.</action>
<action dev="joniles" type="update">To improve consistency, the methods `Task.getPrimaryResourceID()` and `Task.setPrimaryResourceID()` have been marked as deprecated. Use the new `Task.getPrimaryResourceUniqueID()` and `Task.setPrimaryResourceUniqueID()` methods instead.</action>
<action dev="joniles" type="update">Added the methods `Task.getPrimaryResource()` and `Task.setPrimaryResource()`.</action>
</release>
<release date="2024-11-25" version="13.7.0">
<action dev="joniles" type="update">Update the MPXJ ruby gem to allow access to calendar data.</action>
Expand Down
46 changes: 44 additions & 2 deletions src/main/java/net/sf/mpxj/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -4809,8 +4809,9 @@ public LocalDateTime getSuspendDate()
* Set the primary resource ID.
*
* @param value primary resource ID
* @deprecated use the setPrimaryResourceUniqueID method
*/
public void setPrimaryResourceID(Integer value)
@Deprecated public void setPrimaryResourceID(Integer value)
{
set(TaskField.PRIMARY_RESOURCE_ID, value);
}
Expand All @@ -4819,12 +4820,53 @@ public void setPrimaryResourceID(Integer value)
* Retrieve the primary resource ID.
*
* @return primary resource ID
* @deprecated use the getPrimaryResourceUniqueID method
*/
public Integer getPrimaryResourceID()
@Deprecated public Integer getPrimaryResourceID()
{
return (Integer) get(TaskField.PRIMARY_RESOURCE_ID);
}

/**
* Set the primary resource unique ID.
*
* @param value primary resource unique ID
*/
public void setPrimaryResourceUniqueID(Integer value)
{
set(TaskField.PRIMARY_RESOURCE_ID, value);
}

/**
* Retrieve the primary resource unique ID.
*
* @return primary resource unique ID
*/
public Integer getPrimaryResourceUniqueID()
{
return (Integer) get(TaskField.PRIMARY_RESOURCE_ID);
}

/**
* Retrieve the primary resource for this task.
*
* @return primary resource
*/
public Resource getPrimaryResource()
{
return getParentFile().getResourceByUniqueID(getPrimaryResourceUniqueID());
}

/**
* Set the primary resource for this task.
*
* @param resource resource
*/
public void setPrimaryResource(Resource resource)
{
setPrimaryResourceUniqueID(resource == null ? null : resource.getUniqueID());
}

/**
* Set the activity ID.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/sf/mpxj/TaskField.java
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ public enum TaskField implements FieldType
PLANNED_DURATION(DataType.DURATION),
PLANNED_WORK(DataType.WORK),
SUSPEND_DATE(DataType.DATE),
// Deprecated: will be renamed PRIMARY_RESOURCE_UNIQUE_ID
PRIMARY_RESOURCE_ID(DataType.INTEGER),
ACTIVITY_ID(DataType.STRING),
PERCENT_COMPLETE_TYPE(DataType.PERCENT_COMPLETE_TYPE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ private void processTasks(List<WBSType> wbs, Map<Integer, Notes> wbsNotes, List<
task.setActivityID(row.getId());
task.setActivityType(ActivityTypeHelper.getInstanceFromXml(row.getType()));
task.setActivityStatus(ActivityStatusHelper.getInstanceFromXml(row.getStatus()));
task.setPrimaryResourceID(row.getPrimaryResourceObjectId());
task.setPrimaryResourceUniqueID(row.getPrimaryResourceObjectId());
task.setSuspendDate(row.getSuspendDate());
task.setResume(row.getResumeDate());
task.setType(TaskTypeHelper.getInstanceFromXml(row.getDurationType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ private void writeActivity(Task mpxj)
xml.setPlannedNonLaborUnits(getDurationInHours(WorkHelper.zeroIfNull(mpxj.getPlannedWorkNonlabor())));
xml.setPrimaryConstraintType(ConstraintTypeHelper.getXmlFromInstance(mpxj.getConstraintType()));
xml.setPrimaryConstraintDate(mpxj.getConstraintDate());
xml.setPrimaryResourceObjectId(mpxj.getPrimaryResourceID());
xml.setPrimaryResourceObjectId(mpxj.getPrimaryResourceUniqueID());
xml.setPlannedDuration(getDurationInHours(mpxj.getPlannedDuration() == null ? mpxj.getDuration() : mpxj.getPlannedDuration()));
xml.setPlannedFinishDate(plannedFinish);
xml.setPlannedStartDate(plannedStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ interface ExportFunction<T>
ACTIVITY_COLUMNS.put("status_code", t -> ActivityStatusHelper.getActivityStatus(t));
ACTIVITY_COLUMNS.put("task_code", t -> getActivityID(t));
ACTIVITY_COLUMNS.put("task_name", t -> StringHelper.stripControlCharacters(t.getName()));
ACTIVITY_COLUMNS.put("rsrc_id", t -> t.getPrimaryResourceID());
ACTIVITY_COLUMNS.put("rsrc_id", t -> t.getPrimaryResourceUniqueID());
ACTIVITY_COLUMNS.put("total_float_hr_cnt", t -> t.getActivityStatus() == ActivityStatus.COMPLETED ? null : t.getTotalSlack());
ACTIVITY_COLUMNS.put("free_float_hr_cnt", t -> t.getActivityStatus() == ActivityStatus.COMPLETED ? null : t.getFreeSlack());
ACTIVITY_COLUMNS.put("remain_drtn_hr_cnt", t -> t.getRemainingDuration());
Expand Down

0 comments on commit c108c46

Please sign in to comment.