Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joniles committed Dec 12, 2024
1 parent 3de0c60 commit c1f2495
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 683 deletions.
683 changes: 1 addition & 682 deletions mkdocs/docs/field-guide.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/java/net/sf/mpxj/LocaleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ public static final String[] getStringArray(Locale locale, String key)
RESOURCE_COLUMNS_ARRAY[ResourceField.SHIFT_UNIQUE_ID.getValue()] = "Shift Unique ID";
RESOURCE_COLUMNS_ARRAY[ResourceField.PRIMARY_ROLE_UNIQUE_ID.getValue()] = "Primary Role Unique ID";
RESOURCE_COLUMNS_ARRAY[ResourceField.RESOURCE_CODE_VALUES.getValue()] = "Resource Code Values";
RESOURCE_COLUMNS_ARRAY[ResourceField.ROLE_CODE_VALUES.getValue()] = "Role Code Values";

ASSIGNMENT_COLUMNS_ARRAY[AssignmentField.START.getValue()] = "Start";
ASSIGNMENT_COLUMNS_ARRAY[AssignmentField.ASSIGNMENT_UNITS.getValue()] = "Assignment Units";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/sf/mpxj/ProjectFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ public ResourceCodeContainer getResourceCodes()
return m_shared.getResourceCodes();
}

/**
* Retrieves the role code configuration for this project.
*
* @return role codes
*/
public RoleCodeContainer getRoleCodes()
{
return m_shared.getRoleCodes();
}

/**
* Retrieves the shifts for this project.
*
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/sf/mpxj/ProjectFileSharedData.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public ResourceCodeContainer getResourceCodes()
return m_resourceCodes;
}

/**
* Retrieves the role code configuration for this project.
*
* @return role codes
*/
public RoleCodeContainer getRoleCodes()
{
return m_roleCodes;
}

/**
* Retrieves the shifts for this project.
*
Expand Down Expand Up @@ -198,6 +208,7 @@ public static boolean contains(Class<?> c)
private final ActivityCodeContainer m_activityCodes = new ActivityCodeContainer(this);
private final ProjectCodeContainer m_projectCodes = new ProjectCodeContainer(this);
private final ResourceCodeContainer m_resourceCodes = new ResourceCodeContainer(this);
private final RoleCodeContainer m_roleCodes = new RoleCodeContainer(this);
private final ShiftContainer m_shifts = new ShiftContainer(this);
private final ShiftPeriodContainer m_shiftPeriods = new ShiftPeriodContainer(this);
private final Map<String, ObjectSequence> m_uniqueIdObjectSequences = new HashMap<>();
Expand All @@ -217,6 +228,8 @@ public static boolean contains(Class<?> c)
ProjectCodeValue.class.getName(),
ResourceCode.class.getName(),
ResourceCodeValue.class.getName(),
RoleCode.class.getName(),
RoleCodeValue.class.getName(),
Shift.class.getName(),
ShiftPeriod.class.getName()));
}
31 changes: 31 additions & 0 deletions src/main/java/net/sf/mpxj/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,26 @@ public void setPrimaryRole(Resource role)
((Map<ResourceCode, ResourceCodeValue>) get(ResourceField.RESOURCE_CODE_VALUES)).put(value.getResourceCode(), value);
}

/**
* Retrieve the role code values associated with this resource.
*
* @return map of role code values
*/
@SuppressWarnings("unchecked") public Map<RoleCode, RoleCodeValue> getRoleCodeValues()
{
return (Map<RoleCode, RoleCodeValue>) get(ResourceField.ROLE_CODE_VALUES);
}

/**
* Assign a role code value to this resource.
*
* @param value resoroleurce code value
*/
@SuppressWarnings("unchecked") public void addRoleCodeValue(RoleCodeValue value)
{
((Map<RoleCode, RoleCodeValue>) get(ResourceField.ROLE_CODE_VALUES)).put(value.getRoleCode(), value);
}

/**
* Maps a field index to a ResourceField instance.
*
Expand Down Expand Up @@ -2874,6 +2894,16 @@ private Map<ResourceCode, ResourceCodeValue> defaultResourceCodeValues()
return new HashMap<>();
}

/**
* Supply a default value for the role code values.
*
* @return default value for role code values
*/
private Map<RoleCode, RoleCodeValue> defaultRoleCodeValues()
{
return new HashMap<>();
}

private Double calculateSV()
{
Double variance = null;
Expand Down Expand Up @@ -3029,6 +3059,7 @@ private LocalDateTime calculateAvailableTo()
CALCULATED_FIELD_MAP.put(ResourceField.ACTIVE, Resource::defaultActive);
CALCULATED_FIELD_MAP.put(ResourceField.DEFAULT_UNITS, Resource::defaultDefaultUnits);
CALCULATED_FIELD_MAP.put(ResourceField.RESOURCE_CODE_VALUES, Resource::defaultResourceCodeValues);
CALCULATED_FIELD_MAP.put(ResourceField.ROLE_CODE_VALUES, Resource::defaultRoleCodeValues);
}

private static final Map<FieldType, List<FieldType>> DEPENDENCY_MAP = new HashMap<>();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/mpxj/ResourceField.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ public enum ResourceField implements FieldType
SHIFT_UNIQUE_ID(DataType.INTEGER),
PRIMARY_ROLE_UNIQUE_ID(DataType.INTEGER),
FINISH(DataType.DATE),
RESOURCE_CODE_VALUES(DataType.CODE_VALUES);
RESOURCE_CODE_VALUES(DataType.CODE_VALUES),
ROLE_CODE_VALUES(DataType.CODE_VALUES);

/**
* Constructor.
Expand Down
215 changes: 215 additions & 0 deletions src/main/java/net/sf/mpxj/RoleCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* file: RoleCode.java
* author: Jon Iles
* date: 2024-12-12
*/

/*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* Role code type definition, contains a list of the valid
* values for this role code.
*/
public final class RoleCode implements Code
{
/**
* Constructor.
*
* @param builder builder
*/
private RoleCode(Builder builder)
{
m_uniqueID = builder.m_sequenceProvider.getUniqueIdObjectSequence(RoleCode.class).syncOrGetNext(builder.m_uniqueID);
m_sequenceNumber = builder.m_sequenceNumber;
m_name = builder.m_name;
m_secure = builder.m_secure;
m_maxLength = builder.m_maxLength;
}

@Override public Integer getUniqueID()
{
return m_uniqueID;
}

@Override public Integer getSequenceNumber()
{
return m_sequenceNumber;
}

@Override public String getName()
{
return m_name;
}

@Override public boolean getSecure()
{
return m_secure;
}

@Override public Integer getMaxLength()
{
return m_maxLength;
}

public List<RoleCodeValue> getValues()
{
return m_values;
}

public List<RoleCodeValue> getChildValues()
{
return m_values.stream().filter(v -> v.getParentValue() == null).collect(Collectors.toList());
}

public void addValue(RoleCodeValue value)
{
m_values.add(value);
}

public RoleCodeValue getValueByUniqueID(Integer id)
{
if (id == null)
{
return null;
}

// I'd prefer a map-based lookup, but this will do for now and the list of values will typically be fairly short
return m_values.stream().filter(v -> v.getUniqueID().intValue() == id.intValue()).findFirst().orElse(null);
}

private final Integer m_uniqueID;
private final Integer m_sequenceNumber;
private final String m_name;
private final boolean m_secure;
private final Integer m_maxLength;
private final List<RoleCodeValue> m_values = new ArrayList<>();

/**
* RoleCode builder.
*/
public static class Builder
{
/**
* Constructor.
*
* @param sequenceProvider parent file
*/
public Builder(UniqueIdObjectSequenceProvider sequenceProvider)
{
m_sequenceProvider = sequenceProvider;
}

/**
* Initialise the builder from an existing RoleCode instance.
*
* @param value RoleCode instance
* @return builder
*/
public Builder from(RoleCode value)
{
m_uniqueID = value.m_uniqueID;
m_sequenceNumber = value.m_sequenceNumber;
m_name = value.m_name;
m_secure = value.m_secure;
m_maxLength = value.m_maxLength;
return this;
}

/**
* Add unique ID.
*
* @param value unique ID
* @return builder
*/
public Builder uniqueID(Integer value)
{
m_uniqueID = value;
return this;
}

/**
* Add sequence number.
*
* @param value sequence number
* @return builder
*/
public Builder sequenceNumber(Integer value)
{
m_sequenceNumber = value;
return this;
}

/**
* Add name.
*
* @param value name
* @return builder
*/
public Builder name(String value)
{
m_name = value;
return this;
}

/**
* Add secure flag.
*
* @param value secure flag
* @return builder
*/
public Builder secure(boolean value)
{
m_secure = value;
return this;
}

/**
* Add max length.
*
* @param value max length
* @return builder
*/
public Builder maxLength(Integer value)
{
m_maxLength = value;
return this;
}

/**
* Build an RoleCode instance.
*
* @return RoleCode instance
*/
public RoleCode build()
{
return new RoleCode(this);
}

private final UniqueIdObjectSequenceProvider m_sequenceProvider;
private Integer m_uniqueID;
private Integer m_sequenceNumber;
private String m_name;
private boolean m_secure;
private Integer m_maxLength;
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/sf/mpxj/RoleCodeContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* file: RoleCodeContainer.java
* author: Jon Iles
* date: 2024-12-11
*/

/*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

package net.sf.mpxj;

/**
* Container for role code definitions.
*/
public class RoleCodeContainer extends ProjectEntityContainer<RoleCode>
{
/**
* Constructor.
*
* @param sequenceProvider sequence provider
*/
public RoleCodeContainer(UniqueIdObjectSequenceProvider sequenceProvider)
{
super(sequenceProvider);
}
}
Loading

0 comments on commit c1f2495

Please sign in to comment.