IATI / IATI-Schemas

Schema development for the International Aid Transparency Initiative.
Other
15 stars 9 forks source link

Fix schemas to work with xjc #425

Closed nvioli closed 5 years ago

nvioli commented 5 years ago

My organization's method of generating IATI data files is to process the schemas with xjc, then use the generated java classes to build the organization and activity objects, and marshal that object back into an xml file that complies with the schema.

Unfortunately in the process of upgrading our files from 1.x to 2.03, I notice that xjc throws errors when using the latest versions of the schema files. The command I'm using is:

xjc iati-organisations-schema.xsd iati-activities-schema.xsd

There appear to be two problems:

I will open a PR shortly with the changes I made which allow me to run xjc successfully and to create valid files.

andylolz commented 5 years ago
  • The elements currency and currencyType are present in both the activities and organisations schema, which causes an error. I suggest they be moved to the iati-common file.

This part of the fix seems fine to me, though if you run xjc for each schema separately, you won’t run into this. I.e.:

$ xjc iati-activities-schema.xsd
$ xjc iati-organisations-schema.xsd

UPDATE: Actually, my approach looks like it will mess up ObjectFactory, so you’re right – it’s probably preferable to move stuff to iati-common.

  • There is a conflict in the documentLinkWithReceipientCountry element which manifests as the following error:

Oh, interesting. This doesn’t happen on the version-2.02 branch, so this issue was introduced at version-2.03 (when a lot of stuff was refactored into complexTypes, including documentLinkWithReceipientCountry [sic]). I can’t exactly tell what the problem is either, but I think you’re right – I think L796 of iati-organisations-schema.xsd may be a duplicate of L251 of iati-common.xsd, so it can probably be safely removed. https://github.com/IATI/IATI-Schemas/blob/a96c582f2f6873aa46b42df2d24d69f3128b24e4/iati-organisations-schema.xsd#L796 https://github.com/IATI/IATI-Schemas/blob/a96c582f2f6873aa46b42df2d24d69f3128b24e4/iati-common.xsd#L251

nvioli commented 5 years ago

if you run xjc for each schema separately, you won’t run into this

That's true, not sure why I thought that wouldn't work. Still probably best to DRY it up.

I think L796 of iati-organisations-schema.xsd may be a duplicate of L251 of iati-common.xsd, so it can probably be safely removed.

Yes, that was my thought too.

Let me know if I can do anything else to help!

andylolz commented 5 years ago

Still probably best to DRY it up.

Agreed!

nvioli commented 5 years ago

if you run xjc for each schema separately, you won’t run into this

I just tried again and realized this won't work because each of the xjc commands creates an ObjectFactory which is responsible for creating the rest of the objects. The ObjectFactory created by the second command will only contain methods to create the objects in the second schema, so I wouldn't be able to create any objects from the first schema.

Possible workarounds would be to change the classname of the generated factory (OrganisationObjectFactory and ActivitiesObjectFactory), or manually merge the two generated classes, but it's much easier just to pass both schemas to xjc so all classes and methods are created at once.

andylolz commented 5 years ago

Yeah, I spotted that too:

UPDATE: Actually, my approach looks like it will mess up ObjectFactory, so you’re right – it’s probably preferable to move stuff to iati-common.

nvioli commented 5 years ago

Merged https://github.com/IATI/IATI-Schemas/pull/426