From 1673ca51382e5547ea866aff48730ada5c013cc7 Mon Sep 17 00:00:00 2001 From: Tobias Kuhn Date: Thu, 26 Nov 2026 10:15:40 +0100 Subject: [PATCH 1/3] chore(core-deps): update dependency org.nanopub:nanopub to v1.98.1 Co-Authored-By: Claude Opus 5.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9bd9bd82..49395409 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ org.nanopub nanopub - 1.97.1 + 1.98.1 io.github.openhtmltopdf From 594de216ea739d54ebbd55d91a01ab47cb1742f5 Mon Sep 17 00:00:00 2001 From: Tobias Kuhn Date: Thu, 26 Nov 2026 10:15:40 +0100 Subject: [PATCH 2/3] fix(publish): let the compliance check retrieve templates named by their node The compliance guard checks each nanopublication the form makes with nanopub-java's TemplateComplianceChecker, which asks the resolver for a template by the IRI the nanopublication names it with. A nanopublication made from a template with an identity of its own names it by its node (/templateVersion), and TemplateData.RESOLVER was Utils::getNanopub, which only takes a nanopublication URI or an artifact code. Every such nanopublication, among them every view made from the current view template, was therefore logged as not complying ("cannot be used: java.lang.IllegalArgumentException: Not a well-formed trusty URI"), and its assertion was not checked at all. Nothing visible was affected: the guard only logs, and the form strips the node itself before it loads a template. The resolver now strips an IRI within a nanopublication down to the nanopublication (Utils.stripToNanopubId) before retrieving it. Co-Authored-By: Claude Opus 5.5 --- docs/library-template-model.md | 5 ++- .../nanodash/template/TemplateData.java | 7 +++- .../template/TemplateComplianceGuardTest.java | 32 ++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/library-template-model.md b/docs/library-template-model.md index 4c0c341d..f78d305b 100644 --- a/docs/library-template-model.md +++ b/docs/library-template-model.md @@ -34,7 +34,10 @@ package are unchanged. ([nanopub-java#218](https://github.com/Nanopublication/nanopub-java/issues/218)). - **Retrieval goes through Nanodash.** A template gets its own nanopublication, and those that hold the values of a placeholder (`nt:possibleValuesFrom`), from `TemplateData.RESOLVER`, - which is `Utils.getNanopub` with its cache. The value lists are now loaded when first asked + which is `Utils.getNanopub` with its cache. It first strips an IRI within a nanopublication + down to the nanopublication (`Utils.stripToNanopubId`), as the compliance check asks for a + template by the IRI a nanopublication names it with, which can be its node + (`/templateVersion`). The value lists are now loaded when first asked for, not when the template is read. One difference in behaviour: a label the template itself gives to an IRI now wins over a label diff --git a/src/main/java/com/knowledgepixels/nanodash/template/TemplateData.java b/src/main/java/com/knowledgepixels/nanodash/template/TemplateData.java index 3e91bbb4..4fd36487 100644 --- a/src/main/java/com/knowledgepixels/nanodash/template/TemplateData.java +++ b/src/main/java/com/knowledgepixels/nanodash/template/TemplateData.java @@ -36,8 +36,13 @@ public class TemplateData implements Serializable { * How a template retrieves nanopublications: its own, and those that hold the values a * placeholder can take ({@code nt:possibleValuesFrom}). They come from where Nanodash * gets all its nanopublications, so that they are cached like the others. + *

+ * An IRI within a nanopublication retrieves that nanopublication. A nanopublication made + * from a template with an identity of its own names the template by its node + * ({@code /templateVersion}), and that is what the compliance check passes on, while + * {@link Utils#getNanopub(String)} only takes a nanopublication URI or an artifact code. */ - public static final NanopubResolver RESOLVER = Utils::getNanopub; + public static final NanopubResolver RESOLVER = id -> Utils.getNanopub(Utils.stripToNanopubId(id)); private static TemplateData instance; diff --git a/src/test/java/com/knowledgepixels/nanodash/template/TemplateComplianceGuardTest.java b/src/test/java/com/knowledgepixels/nanodash/template/TemplateComplianceGuardTest.java index ab0b1885..c2f14f8a 100644 --- a/src/test/java/com/knowledgepixels/nanodash/template/TemplateComplianceGuardTest.java +++ b/src/test/java/com/knowledgepixels/nanodash/template/TemplateComplianceGuardTest.java @@ -7,7 +7,9 @@ import org.eclipse.rdf4j.model.vocabulary.PROV; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.RDFS; +import com.knowledgepixels.nanodash.Utils; import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; import org.nanopub.Nanopub; import org.nanopub.NanopubCreator; import org.nanopub.templates.ComplianceIssue; @@ -20,6 +22,8 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mockStatic; /** * Tests for {@link TemplateComplianceGuard}: it reports what nanopub-java finds, and never @@ -73,11 +77,16 @@ private void registerTemplates() throws Exception { // A nanopublication as the form makes it from these templates, with the given assertion. private static Nanopub nanopub(IRI predicate) throws Exception { + return nanopub(predicate, ASSERTION_TEMPLATE); + } + + // The same, naming its assertion template with the given IRI. + private static Nanopub nanopub(IRI predicate, String assertionTemplateLink) throws Exception { NanopubCreator creator = new NanopubCreator(NP); creator.addAssertionStatement(THING, predicate, vf.createLiteral("A thing")); creator.addProvenanceStatement(PROV.WAS_ATTRIBUTED_TO, ME); creator.addPubinfoStatement(DCTERMS.CREATOR, ME); - creator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_TEMPLATE, vf.createIRI(ASSERTION_TEMPLATE)); + creator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_TEMPLATE, vf.createIRI(assertionTemplateLink)); creator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PROVENANCE_TEMPLATE, vf.createIRI(PROVENANCE_TEMPLATE)); creator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PUBINFO_TEMPLATE, vf.createIRI(PUBINFO_TEMPLATE)); return creator.finalizeNanopub(); @@ -101,6 +110,27 @@ void nanopublicationThatDoesNotFollowItsTemplatesIsReported() throws Exception { report.getErrors().stream().map(ComplianceIssue::kind).toList()); } + @Test + void templateNamedByItsNodeIsRetrievedThroughNanodash() throws Exception { + registerTemplates(); + // The check runs with Nanodash's resolver, as on the publish form. Utils.getNanopub is + // stood in for by one that, like the real one, takes only a nanopublication URI or an + // artifact code. + try (MockedStatic utils = mockStatic(Utils.class)) { + utils.when(() -> Utils.stripToNanopubId(anyString())).thenCallRealMethod(); + utils.when(() -> Utils.getNanopub(anyString())).thenAnswer(call -> { + String id = call.getArgument(0); + if (!id.matches("(.*[^A-Za-z0-9_-])?RA[A-Za-z0-9_-]{43}")) throw new IllegalArgumentException("Not a well-formed trusty URI"); + return templates.get(id); + }); + // A nanopublication made from a template with an identity of its own names the + // template by its node: + ComplianceReport report = TemplateComplianceGuard.check(nanopub(RDFS.LABEL, ASSERTION_TEMPLATE + "/templateVersion")); + assertNotNull(report); + assertEquals(List.of(), report.getIssues()); + } + } + @Test void templateThatCannotBeRetrievedIsAFindingNotAFailure() throws Exception { ComplianceReport report = TemplateComplianceGuard.check(nanopub(RDFS.LABEL), resolver); From 444780c6310f4df9df722506ddb9746735288b69 Mon Sep 17 00:00:00 2001 From: Tobias Kuhn Date: Thu, 26 Nov 2026 19:42:30 +0100 Subject: [PATCH 3/3] chore(core-deps): update dependency org.nanopub:nanopub to v1.98.2 1.98.2 waits for registries that answer 429 Too Many Requests instead of giving up on them at once. The public registries rate-limit the test suite's nanopub fetches, which made a different network-dependent test fail on each CI run since about 2026-11-23. Co-Authored-By: Claude Opus 5.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 49395409..2466242a 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ org.nanopub nanopub - 1.98.1 + 1.98.2 io.github.openhtmltopdf