Plugin to add metadata to projects and subjects

75 views
Skip to first unread message

Victor Ferat

unread,
Mar 6, 2023, 5:19:03 PM3/6/23
to xnat_discussion
Dear xnat community, dear developers, I am currently working on a xnat plugin, which would add metadata to projects and subjects. This metadata should be unique (like demographic for a subject). I can see two ways to do it: the first one would be to define new data types that would inherit from xnat:subjectAssessor and xnat:abstractProjectAsset respectively. The second would be to define new data types that define new types of subjects and projects, and that would inherit respectively from xnat:projectData and xnat:subjectData respectively. Having quickly explored both solutions, I realized that many elements of the API and web interface use xnat:projectData and xnat:subjectData as hardcoded values and that it would be extremely complicated to add new types of project/subject (solution 2). While for solution 1, I don't see how to enforce the fact that there is a unique asset per project/subject. It should also be possible to create it from the web interface, however, the turbine edit file doesn't seem to be able to handle the default creation case. Is there any way of proceeding that you would recommend ? Best, Victor

Rick Herrick

unread,
Mar 6, 2023, 7:43:10 PM3/6/23
to xnat_di...@googlegroups.com
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.

Next, in your new custom edit template, modify the form action to use your own class, e.g. ModifyProjectMetadata.

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 ------
From "Victor Ferat" <victor...@live.fr>
To "xnat_discussion" <xnat_di...@googlegroups.com>
Date 3/6/2023 11:07:12 AM
Subject [XNAT Discussion] Plugin to add metadata to projects and subjects

Dear xnat community, dear developers, I am currently working on a xnat plugin, which would add metadata to projects and subjects. This metadata should be unique (like demographic for a subject). I can see two ways to do it: the first one would be to define new data types that would inherit from xnat:subjectAssessor and xnat:abstractProjectAsset respectively. The second would be to define new data types that define new types of subjects and projects, and that would inherit respectively from xnat:projectData and xnat:subjectData respectively. Having quickly explored both solutions, I realized that many elements of the API and web interface use xnat:projectData and xnat:subjectData as hardcoded values and that it would be extremely complicated to add new types of project/subject (solution 2). While for solution 1, I don't see how to enforce the fact that there is a unique asset per project/subject. It should also be possible to create it from the web interface, however, the turbine edit file doesn't seem to be able to handle the default creation case. Is there any way of proceeding that you would recommend ? Best, Victor

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/45a4ad42-44f5-4e54-b808-01e04cfa1251n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages