joniles / mpxj

Primary repository for MPXJ library
http://www.mpxj.org/
GNU Lesser General Public License v2.1
240 stars 101 forks source link

MSPDIWriter: invalid Assignment/ResourceUID references #703

Closed alex-matatov closed 1 month ago

alex-matatov commented 1 month ago

Hi Jon,

This time I think it is a bug.

MSPDIWriter has a code to convert uniqueId to uid through these mappers:

private MicrosoftProjectUniqueIDMapper m_taskMapper;
private MicrosoftProjectUniqueIDMapper m_resourceMapper;
private MicrosoftProjectUniqueIDMapper m_calendarMapper;
private MicrosoftProjectUniqueIDMapper m_assignmentMapper;

MSPDIWriter.writeResource() sets Resource.UID like that: xml.setUID(m_resourceMapper.getUniqueID(mpx));

However, MSPDIWriter.writeAssignment() method sets reference to Resource.uniqueId without re-mapping, so MSP file has invalid references to Resources in <Assignment> sections:

xml.setResourceUID(mpx.getResource() == null ? BigInteger.valueOf(MicrosoftProjectConstants.ASSIGNMENT_NULL_RESOURCE_ID.intValue()) : BigInteger.valueOf(NumberHelper.getInt(mpx.getResourceUniqueID())));

The fix is very simple:

xml.setResourceUID(mpx.getResource() == null ? BigInteger.valueOf(MicrosoftProjectConstants.ASSIGNMENT_NULL_RESOURCE_ID.intValue()) : BigInteger.valueOf(NumberHelper.getInt(m_resourceMapper.getUniqueID(mpx.getResource()))));

Have a good day, Alex

joniles commented 1 month ago

Hi Alex, thanks for finding this. I've updated the code with your suggested change.

Jon