diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java index e6921d2..e5e37ae 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java @@ -114,7 +114,7 @@ public void run() { new ResourceServiceLocalAndRemote(factory) ); - review("local", registryLocal, factory); + review(DatasetRegistryUtil.NAMESPACE_LOCAL, registryLocal, factory); } reviewCachedOrRemote(remoteNamespaces, factory); diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdStream.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdStream.java index 912ff03..ef72e04 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdStream.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdStream.java @@ -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; @@ -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) { diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java b/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java index 9a25abd..e84c570 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java @@ -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; @@ -22,9 +23,9 @@ public class DatasetRegistryFactoryImpl implements DatasetRegistryFactory { private static final Map> REGISTRY_LOOKUP = MapUtils.unmodifiableMap(new TreeMap>() {{ - 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; diff --git a/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java b/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java index 5a7c85b..0881a81 100644 --- a/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java +++ b/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java @@ -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, diff --git a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdLogTest.java b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdLogTest.java index e411972..7cfbfcb 100644 --- a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdLogTest.java +++ b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdLogTest.java @@ -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; @@ -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); diff --git a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateTest.java b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateTest.java index a260520..1ffb1cf 100644 --- a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateTest.java +++ b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateTest.java @@ -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; @@ -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");