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

Nanopublication / nanopub-java / 24826025182

23 Apr 2026 08:49AM UTC coverage: 52.16% (+0.01%) from 52.15%
24826025182

push

github

web-flow
Merge pull request #72 from Nanopublication/fdo-label-on-np-and-doi-iri

Attach FDO label to nanopub; preserve DOI URL as FDO IRI

1135 of 3138 branches covered (36.17%)

Branch coverage included in aggregate %.

5433 of 9454 relevant lines covered (57.47%)

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
        if (FdoUtils.extractHandleId(handleId) == null) {
×
75
            System.err.println("Not a recognisable handle or handle/DOI URL: " + handleId);
×
76
            throw new ParameterException("Not a recognisable handle or handle/DOI URL: " + handleId);
×
77
        }
78

79
        Nanopub np = FdoNanopubCreator.createFromHandleSystem(handleId, enrichFromSchema);
×
80

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

92
}
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