Skip to content

Commit

Permalink
only log archive provenance for namespace once; #52
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Nov 30, 2023
1 parent 3fd598b commit 0ca2f7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/main/java/org/globalbioticinteractions/elton/cmd/CmdLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

@CommandLine.Command(
name = "log",
Expand Down Expand Up @@ -88,6 +89,7 @@ private static class LoggingResourceService implements ResourceService {
private final PrintStream out;
private HashType sha256;
private final ResourceService local;
private final AtomicReference<IRI> archiveContentId = new AtomicReference<>(null);

public LoggingResourceService(PrintStream out, ResourceService resourceService) {
this.out = out;
Expand Down Expand Up @@ -119,17 +121,20 @@ private URI getLocationInDataset(URI uri, Dataset dataset) throws IOException {
if (CacheUtil.isLocalDir(archiveURI)) {
resourceLocation = ResourceUtil.getAbsoluteResourceURI(archiveURI, uri);
} else {
IRI archiveContentId = Hasher.calcHashIRI(local.retrieve(archiveURI), NullOutputStream.NULL_OUTPUT_STREAM, sha256);
Quad quad = RefNodeFactory.toStatement(
RefNodeFactory.toIRI(archiveURI),
RefNodeConstants.HAS_VERSION,
archiveContentId
);
out.println(quad.toString());
if (this.archiveContentId.get() == null) {
IRI archiveContentId = Hasher.calcHashIRI(local.retrieve(archiveURI), NullOutputStream.NULL_OUTPUT_STREAM, sha256);
this.archiveContentId.set(archiveContentId);
Quad quad = RefNodeFactory.toStatement(
RefNodeFactory.toIRI(archiveURI),
RefNodeConstants.HAS_VERSION,
archiveContentId
);
out.println(quad.toString());
}

String localDatasetRoot = DatasetFinderUtil.getLocalDatasetURIRoot(local.retrieve(archiveURI));

URI localArchiveRoot = URI.create("zip:" + archiveContentId.getIRIString() + "!/" + localDatasetRoot);
URI localArchiveRoot = URI.create("zip:" + archiveContentId.get().getIRIString() + "!/" + localDatasetRoot);
resourceLocation = ResourceUtil.getAbsoluteResourceURI(localArchiveRoot, uri);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public void logTemplate() throws URISyntaxException {
PrintStream out = new PrintStream(out1);
cmd.run(out);
String[] split = out1.toString().split("\n");
assertThat(split.length, is(4));
assertThat(split.length, is(3));
assertThat(split[0], is("<https://zenodo.org/record/207958/files/globalbioticinteractions/template-dataset-0.0.2.zip> <http://purl.org/pav/hasVersion> <hash://sha256/631d3777cf83e1abea848b59a6589c470cf0c7d0fd99682c4c104481ad9a543f> ."));
assertThat(split[1], is("<zip:hash://sha256/631d3777cf83e1abea848b59a6589c470cf0c7d0fd99682c4c104481ad9a543f!/globalbioticinteractions-template-dataset-e68f448/globi.json> <http://purl.org/pav/hasVersion> <hash://sha256/1cc8eff62af0e6bb3e7771666e2e4109f351b7dfc6fc1dc8314e5671a8eecb80> ."));
assertThat(split[2], is("<https://zenodo.org/record/207958/files/globalbioticinteractions/template-dataset-0.0.2.zip> <http://purl.org/pav/hasVersion> <hash://sha256/631d3777cf83e1abea848b59a6589c470cf0c7d0fd99682c4c104481ad9a543f> ."));
assertThat(split[3], is("<zip:hash://sha256/631d3777cf83e1abea848b59a6589c470cf0c7d0fd99682c4c104481ad9a543f!/globalbioticinteractions-template-dataset-e68f448/interactions.tsv> <http://purl.org/pav/hasVersion> <hash://sha256/c1b37add5ee5f30916f19811c59c2960e3b68ecf1a3846afe1776014c4c96271> ."));
assertThat(split[2], is("<zip:hash://sha256/631d3777cf83e1abea848b59a6589c470cf0c7d0fd99682c4c104481ad9a543f!/globalbioticinteractions-template-dataset-e68f448/interactions.tsv> <http://purl.org/pav/hasVersion> <hash://sha256/c1b37add5ee5f30916f19811c59c2960e3b68ecf1a3846afe1776014c4c96271> ."));

}

Expand Down

0 comments on commit 0ca2f7f

Please sign in to comment.