Hi Victor,
Re: "I don't see how to enforce the fact that there is a unique asset per project/subject…” I think you mean that you want to have one and only one instance of your metadata data type per project or subject so that if a user created one instance of project metadata for project A then tried to create a second instance of project metadata for project A there would be an error.
Presuming that’s the case, you can enforce this in code by adding a custom modify action to your plugin. The
XNAT template plugin includes an example of this. First, copy the default generated edit screen for your data type into your main code repository, e.g. copy this:
build/xnat-generated/src/main/resources/META-INF/resources/base-templates/screens/XDATScreen_edit_your_datatype.vm
To something like this:
src/main/resources/META-INF/resources/templates/screens/XDATScreen_edit_your_datatype.vm
Note that you’ll probably want to do this anyway: the generated report and edit screens try hard but generally they’re not super usable.
Now create a class in the folder src/main/java/org/apache/turbine/app/xnat/modules/actions (there’s almost no flexibility on this: that’s basically where you need to put the class) with the same name you specified for the form action. Again, the template plugin provides a useful example here with the
ModifyTemplateSample action class. Note that that class extends ModifySubjectAssessorData, which would be useful for your subject demographics data type. For your project demographics data type you’ll probably just want to extend
ModifyItem.
That’s the basic approach you’ll want for this sort of thing.
All that said… an upcoming XNAT release (probably 1.8.8) will include a new feature called custom forms, which is intended to replace and improve on XNAT’s current custom variables functionality. Supporting custom metadata at the project and subject levels is one of the primary purposes for the custom forms work, so you may want to look into that functionality and see if it might address your needs without requiring your own custom data types. You can read a bit about them
here but also feel free to ask about that functionality here to see if you think it might do what you need.
Rick Herrick
Senior Software Developer
------ Original Message ------
Date 3/6/2023 11:07:12 AM
Subject [XNAT Discussion] Plugin to add metadata to projects and subjects