• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Nanopublication / nanopub-java / 24823925845

23 Apr 2026 07:59AM UTC coverage: 52.15% (+0.5%) from 51.675%
24823925845

push

github

web-flow
Merge pull request #71 from Nanopublication/add-fdo-schema-enrichment

feat(fdo): schema enrichment, handle URLs, referentName label

1133 of 3134 branches covered (36.15%)

Branch coverage included in aggregate %.

5429 of 9449 relevant lines covered (57.46%)

8.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/org/nanopub/fdo/FdoCreate.java
1
package org.nanopub.fdo;
2

3
import com.beust.jcommander.ParameterException;
4
import net.trustyuri.TrustyUriException;
5
import org.eclipse.rdf4j.rio.RDFFormat;
6
import org.nanopub.CliRunner;
7
import org.nanopub.MalformedNanopubException;
8
import org.nanopub.Nanopub;
9
import org.nanopub.NanopubAlreadyFinalizedException;
10
import org.nanopub.NanopubUtils;
11
import org.nanopub.extra.security.SignNanopub;
12
import org.nanopub.extra.security.TransformContext;
13
import org.nanopub.extra.server.PublishNanopub;
14

15
import java.io.IOException;
16
import java.net.URISyntaxException;
17
import java.security.InvalidKeyException;
18
import java.security.SignatureException;
19

20
/**
21
 * Create and optionally publish a nanopub for a handle-based FDO.
22
 */
23
public class FdoCreate extends CliRunner {
×
24

25
    @com.beust.jcommander.Parameter(description = "handle-id-or-url", required = true)
26
    private String handleId;
27

28
    @com.beust.jcommander.Parameter(names = "-u", description = "Unsigned, the Nanopub is not signed. Do not use with -p.")
29
    private boolean unsigned;
30

31
    @com.beust.jcommander.Parameter(names = "-p", description = "Directly publish the Nanopub.")
32
    private boolean publish;
33

34
    @com.beust.jcommander.Parameter(names = {"-s", "--enrich-from-schema"}, description = "Resolve the FDO profile's type registry entry and use property handles as predicates (with rdfs:label in pubinfo).")
35
    private boolean enrichFromSchema;
36

37
    /**
38
     * Main method to run the FdoCreate command-line tool.
39
     *
40
     * @param args command line arguments, expects a handle identifier
41
     */
42
    public static void main(String[] args) {
43
        try {
44
            FdoCreate obj = CliRunner.initJc(new FdoCreate(), args);
×
45
            obj.run();
×
46
        } catch (ParameterException ex) {
×
47
            System.exit(1);
×
48
        } catch (Exception ex) {
×
49
            ex.printStackTrace();
×
50
            System.exit(1);
×
51
        }
×
52
    }
×
53

54
    /**
55
     * Resolves the handle and creates a nanopub from it, then either prints or publishes it.
56
     *
57
     * @throws org.nanopub.MalformedNanopubException        if the nanopub is malformed
58
     * @throws java.io.IOException                          if there is an I/O error
59
     * @throws java.net.URISyntaxException                  if the handle identifier is not a valid URI
60
     * @throws java.lang.InterruptedException               if the thread is interrupted while resolving the handle
61
     * @throws net.trustyuri.TrustyUriException             if there is an issue with Trusty URI
62
     * @throws java.security.SignatureException             if there is an issue with signing the nanopub
63
     * @throws java.security.InvalidKeyException            if the signing key is invalid
64
     * @throws org.nanopub.NanopubAlreadyFinalizedException if the nanopub has already been finalized
65
     */
66
    public void run() throws MalformedNanopubException, IOException, URISyntaxException, InterruptedException,
67
            TrustyUriException, SignatureException, InvalidKeyException, NanopubAlreadyFinalizedException {
68

69
        if (unsigned && publish) {
×
70
            System.err.println("Do not use -u and -p together.");
×
71
            throw new ParameterException("Cannot use -u and -p together.");
×
72
        }
73

74
        String resolvedId = FdoUtils.extractHandleId(handleId);
×
75
        if (resolvedId == null) {
×
76
            System.err.println("Not a recognisable handle or handle/DOI URL: " + handleId);
×
77
            throw new ParameterException("Not a recognisable handle or handle/DOI URL: " + handleId);
×
78
        }
79

80
        Nanopub np = FdoNanopubCreator.createFromHandleSystem(resolvedId, enrichFromSchema);
×
81

82
        if (unsigned) {
×
83
            NanopubUtils.writeToStream(np, System.out, RDFFormat.TRIG);
×
84
        } else if (publish) {
×
85
            Nanopub signedNp = SignNanopub.signAndTransform(np, TransformContext.makeDefault());
×
86
            PublishNanopub.publish(signedNp);
×
87
        } else {
×
88
            Nanopub signedNp = SignNanopub.signAndTransform(np, TransformContext.makeDefault());
×
89
            NanopubUtils.writeToStream(signedNp, System.out, RDFFormat.TRIG);
×
90
        }
91
    }
×
92

93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc