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

knowledgepixels / nanopub-query / 17769786051

16 Sep 2025 02:48PM UTC coverage: 71.59%. Remained the same
17769786051

push

github

Ziroli Plutschow
Stop tests from waiting 120s

233 of 350 branches covered (66.57%)

Branch coverage included in aggregate %.

591 of 801 relevant lines covered (73.78%)

3.72 hits per line

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

86.67
src/main/java/com/knowledgepixels/query/LocalNanopubLoader.java
1
package com.knowledgepixels.query;
2

3
import org.eclipse.rdf4j.rio.RDFFormat;
4
import org.nanopub.MalformedNanopubException;
5
import org.nanopub.MultiNanopubRdfHandler;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

9
import java.io.BufferedReader;
10
import java.io.File;
11
import java.io.FileReader;
12
import java.io.IOException;
13

14
/**
15
 * Local loader left here in case it's needed for testing or when the Jelly loader breaks.
16
 */
17
public class LocalNanopubLoader {
18

19
    private static final Logger log = LoggerFactory.getLogger(LocalNanopubLoader.class);
3✔
20

21
    private LocalNanopubLoader() {
22
    }  // no instances allowed
23

24
    /**
25
     * File containing URIs of nanopubs to load.
26
     */
27
    public final static File loadUrisFile = new File("load/nanopub-uris.txt");
5✔
28

29
    /**
30
     * File containing nanopubs in TRIG format to load.
31
     */
32
    public final static File loadNanopubsFile = new File("load/nanopubs.trig.gz");
6✔
33

34
    private static final int DEFAULT_WAIT_SECONDS = 120;
35

36
    /**
37
     * Load nanopubs from local files.
38
     *
39
     * @return true if local nanopubs were found and loaded, false otherwise
40
     */
41
    public static boolean init() {
42
        if (!(loadNanopubsFile.exists() || loadUrisFile.exists())) {
6!
43
            log.info("No local nanopub files for loading found. Moving on to loading via Jelly...");
3✔
44
            return false;
2✔
45
        }
46
        log.info("Waiting {} seconds to make sure the triple store is up...", getWaitSeconds());
5✔
47
        try {
48
            for (int w = 0; w < getWaitSeconds(); w++) {
7✔
49
                log.info("Waited {} seconds...", w);
5✔
50
                Thread.sleep(1000);
2✔
51
            }
52
        } catch (InterruptedException ex) {
×
53
            // ignore
54
        }
1✔
55

56
        log.info("Loading the local list of nanopubs...");
3✔
57
        load();
1✔
58
        return true;
2✔
59
    }
60

61
    static void load() {
62
        if (!loadUrisFile.exists()) {
3✔
63
            log.info("No local nanopub URI file found.");
4✔
64
        } else {
65
            try (BufferedReader reader = new BufferedReader(new FileReader(loadUrisFile))) {
8✔
66
                String line = reader.readLine();
3✔
67
                while (line != null) {
2✔
68
                    NanopubLoader.load(line);
2✔
69
                    line = reader.readLine();
4✔
70
                }
71
            } catch (IOException ex) {
×
72
                log.info("Loading nanopubs failed.", ex);
×
73
            }
1✔
74
        }
75
        if (!loadNanopubsFile.exists()) {
3✔
76
            log.info("No local nanopub file found.");
4✔
77
        } else {
78
            try {
79
                MultiNanopubRdfHandler.process(RDFFormat.TRIG, loadNanopubsFile, np -> NanopubLoader.load(np, -1));
×
80
            } catch (IOException | MalformedNanopubException ex) {
1✔
81
                log.info("Loading nanopubs failed.", ex);
4✔
82
            }
×
83
        }
84
    }
1✔
85

86
    static int getWaitSeconds() {
87
        return Utils.getEnvInt("INIT_WAIT_SECONDS", DEFAULT_WAIT_SECONDS);
4✔
88
    }
89

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

© 2025 Coveralls, Inc