Skip to content

Commit

Permalink
introduce default namespace for streaming globi.json; refactor namesp…
Browse files Browse the repository at this point in the history
…ace constants
  • Loading branch information
Jorrit Poelen committed Jul 29, 2024
1 parent 07f5bcc commit 516a43e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void run() {
new ResourceServiceLocalAndRemote(factory)
);

review("local", registryLocal, factory);
review(DatasetRegistryUtil.NAMESPACE_LOCAL, registryLocal, factory);
}

reviewCachedOrRemote(remoteNamespaces, factory);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/globalbioticinteractions/elton/cmd/CmdStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand Down Expand Up @@ -39,25 +40,23 @@ public void run() {
while ((line = reader.readLine()) != null) {
try {
JsonNode jsonNode = new ObjectMapper().readTree(line);
if (jsonNode.has("namespace")) {
String namespace = jsonNode.get("namespace").asText();
if (StringUtils.isNotBlank(namespace)) {
try {
StreamingNamespaceConfigHandler namespaceHandler = new StreamingNamespaceConfigHandler(
jsonNode,
this.createInputStreamFactory(),
this.getCacheDir(),
this.getStderr(),
this.getStdout()
);
namespaceHandler.setShouldWriteHeader(isFirst.get());
namespaceHandler.onNamespace(namespace);
isFirst.set(false);
} catch (Exception e) {
LOG.error("failed to add dataset associated with namespace [" + namespace + "]", e);
} finally {
FileUtils.forceDelete(new File(this.getCacheDir()));
}
String namespace = jsonNode.at("/namespace").asText(DatasetRegistryUtil.NAMESPACE_LOCAL);
if (StringUtils.isNotBlank(namespace)) {
try {
StreamingNamespaceConfigHandler namespaceHandler = new StreamingNamespaceConfigHandler(
jsonNode,
this.createInputStreamFactory(),
this.getCacheDir(),
this.getStderr(),
this.getStdout()
);
namespaceHandler.setShouldWriteHeader(isFirst.get());
namespaceHandler.onNamespace(namespace);
isFirst.set(false);
} catch (Exception e) {
LOG.error("failed to add dataset associated with namespace [" + namespace + "]", e);
} finally {
FileUtils.forceDelete(new File(this.getCacheDir()));
}
}
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.globalbioticinteractions.dataset.DatasetRegistryGitHubArchive;
import org.globalbioticinteractions.dataset.DatasetRegistryZenodo;
import org.globalbioticinteractions.elton.util.DatasetRegistrySingleDir;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;

import javax.annotation.Resource;
import java.lang.reflect.Constructor;
Expand All @@ -22,9 +23,9 @@

public class DatasetRegistryFactoryImpl implements DatasetRegistryFactory {
private static final Map<String, Class<? extends DatasetRegistry>> REGISTRY_LOOKUP = MapUtils.unmodifiableMap(new TreeMap<String, Class<? extends DatasetRegistry>>() {{
put("local", DatasetRegistrySingleDir.class);
put("zenodo", DatasetRegistryZenodo.class);
put("github", DatasetRegistryGitHubArchive.class);
put(DatasetRegistryUtil.NAMESPACE_LOCAL, DatasetRegistrySingleDir.class);
put(DatasetRegistryUtil.NAMESPACE_ZENODO, DatasetRegistryZenodo.class);
put(DatasetRegistryUtil.NAMESPACE_GITHUB, DatasetRegistryGitHubArchive.class);
}});

private final InputStreamFactory inputStreamFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
public class DatasetRegistryUtil {

public static final String NAMESPACE_LOCAL = "local";
public static final String NAMESPACE_ZENODO = "zenodo";
public static final String NAMESPACE_GITHUB = "github";

public static DatasetRegistry forLocalDir(final URI localArchiveDir,
final String cacheDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bio.guoda.preston.HashType;
import bio.guoda.preston.RefNodeConstants;
import org.apache.commons.lang3.StringUtils;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -50,12 +51,12 @@ public void logRSSTemplate() throws URISyntaxException, IOException {
CmdUpdate pull = new CmdUpdate();
pull.setCacheDir(cacheDir);
pull.setWorkDir(new File(getClass().getResource("/dataset-rss-cache/globi.json").toURI()).getParent());
pull.setRegistryNames(Collections.singletonList("local"));
pull.setRegistryNames(Collections.singletonList(DatasetRegistryUtil.NAMESPACE_LOCAL));
pull.run();

CmdLog cmd = new CmdLog();
cmd.setCacheDir(cacheDir);
cmd.setNamespaces(Collections.singletonList("local"));
cmd.setNamespaces(Collections.singletonList(DatasetRegistryUtil.NAMESPACE_LOCAL));
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
PrintStream out = new PrintStream(out1);
cmd.setStdout(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -36,12 +37,12 @@ public void updateLocalDataset() throws IOException, URISyntaxException {
File file = tmpDir.newFolder();
cmd.setCacheDir(file.getAbsolutePath());
cmd.setWorkDir(localWorkDir.getAbsolutePath());
cmd.setRegistryNames(Arrays.asList("local"));
cmd.setNamespaces(Collections.singletonList("local"));
cmd.setRegistryNames(Arrays.asList(DatasetRegistryUtil.NAMESPACE_LOCAL));
cmd.setNamespaces(Collections.singletonList(DatasetRegistryUtil.NAMESPACE_LOCAL));

cmd.run();

File local = new File(file, "local");
File local = new File(file, DatasetRegistryUtil.NAMESPACE_LOCAL);
assertThat(local.exists(), is(true));

File provenanceLog = new File(local, "access.tsv");
Expand Down

0 comments on commit 516a43e

Please sign in to comment.