Skip to content

Warn when annotations placed on group definition#975

Merged
jadams-tresys merged 1 commit intoapache:mainfrom
jadams-tresys:DAFFODIL-2668
Mar 3, 2023
Merged

Warn when annotations placed on group definition#975
jadams-tresys merged 1 commit intoapache:mainfrom
jadams-tresys:DAFFODIL-2668

Conversation

@jadams-tresys
Copy link
Contributor

Annotations placed on group definitions will be ignored, so we should warn users that this is occurring.

DAFFODIL-2668

// Ensure that the group definition itself does not have any annotations.
// Annotations should only be on group references or children of the group
// definition
val found = defXML.child.map(_.label).contains("annotation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check that the annotation is specifically an appinfo annotation with source="http://www.ogf.org/dfdl/".
Those should create the warning.

You might want to tolerate not a perfect match on the source URI.

See annotatedSchemaComponent.scala

Look for lazy val dfdlAppInfos = { ... for this logic.

The common logic for finding a DFDL appinfo, tolerating small imperfections in the URI, should be shared between here and there. I'd suggest the common code belongs in XMLUtils, called from both places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will expect a new commit to check appinfo and fix formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the logic to XMLUtils via a getDFDLAppinfos function. However, it loses the ability to send schema definition warnings and I'm not sure what a good solution is to get that functionality back. Should there just be another pass through all the appinfos in AnnotatedSchemaComponent to issue warnings as needed? I thought about having my function return a list of warnings in addition to the list of appinfos and then doing SDW's back in AnnotatedSchemaComponent, but it felt very hacky to have a function returning a tuple with a list containing a tuple for WarnID, String.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest make dfdlAppInfos return a Either[Seq[(WarnID, String)], Seq[DFDLAppInfo]]
where Left is warnings to issue, Right is the appinfo object(s) if all goes well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another alternative, doesn't GlobalGroupDef implement AnnotatedSchemaComponet so it has access to dfdlAppInfos? Can the new check function just do something like:

if (dfdlAppInfos.length > 0) SDW(...)

So you reuse the existing dfdlAppInfos logic to find any dfdl annotations (which might warn), but then we can warn that they will be ignored in the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it does implement AnnotatedSchemaComponent, but only on the groupXML, which is just the group members I believe. It doesn't include the actual group definition, which is how the annotations for group definitions were getting ignored before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Maybe instead of making it an XMLUtils function it becomes a public function in AnnotatedMixin that accepts the XML node to look for annotations as a paramter? This way it could still create warnings like normal, and dfdlAppInfo could pass in xml while the GroupDef check could pass in defXML? Just trying to avoid having a complex return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this suggestion from Steve. Changes for it have been pushed up for review.

Copy link
Contributor

@mbeckerle mbeckerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

if (dais.nonEmpty)
SDW(
WarnID.InvalidAnnotationPoint,
"Annotations placed directly on a group definition will be ignored by DFDL. Any annotation expected to be processed by DFDL should instead be placed on the group reference",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to the group reference, could annotations also be placed on the model group (i.e. choice or sequence) of the group definition? I imagine if someone put an annotation on the group def that's maybe what they meant to do? Is it worth saying something like ... should be placed on the group reference or model group?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying "or model group" may confuse a user who isn't familiar with the meaning of "model group." I suggest either leaving the message the way it is now or changing it to ... should be placed on the group reference, choice, or sequence if we really want to list all the possible places.

@mbeckerle
Copy link
Contributor

+1. This is cleaner than what I was suggesting.

Copy link
Contributor

@tuxji tuxji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

if (dais.nonEmpty)
SDW(
WarnID.InvalidAnnotationPoint,
"Annotations placed directly on a group definition will be ignored by DFDL. Any annotation expected to be processed by DFDL should instead be placed on the group reference",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying "or model group" may confuse a user who isn't familiar with the meaning of "model group." I suggest either leaving the message the way it is now or changing it to ... should be placed on the group reference, choice, or sequence if we really want to list all the possible places.

DFDL Annotations placed on group definitions will be ignored,
so we should warn users that this is occurring.

DAFFODIL-2668
@jadams-tresys jadams-tresys merged commit 37f7e66 into apache:main Mar 3, 2023
@jadams-tresys jadams-tresys deleted the DAFFODIL-2668 branch March 3, 2023 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants