Skip to content

Commit

Permalink
upgrade to globi-libs v0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Nov 8, 2024
1 parent 3cd80e8 commit fde6653
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 88 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<description>Discover, access, and review, species interaction data</description>

<properties>
<globi.version>0.26.6</globi.version>
<globi.version>0.27.0</globi.version>
<preston.version>0.7.8</preston.version>
<slf4j.version>1.7.30</slf4j.version>
<picocli.version>4.6.3</picocli.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.globalbioticinteractions.elton.cmd;


import org.globalbioticinteractions.dataset.Dataset;
import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.dataset.DatasetRegistryException;
Expand Down Expand Up @@ -51,7 +52,9 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
createInputStreamFactory());
createInputStreamFactory(),
getContentPathFactory(),
getProvenancePathFactory());

try {
CmdUtil.handleNamespaces(registry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.globalbioticinteractions.elton.cmd;

import org.globalbioticinteractions.cache.ContentPathFactory;
import org.globalbioticinteractions.cache.ContentPathFactoryDepth0;
import org.globalbioticinteractions.cache.ProvenancePathFactory;
import org.globalbioticinteractions.cache.ProvenancePathFactoryImpl;
import org.globalbioticinteractions.elton.util.ProgressCursor;
import org.globalbioticinteractions.elton.util.ProgressCursorFactory;
import org.globalbioticinteractions.elton.util.ProgressCursorRotating;
Expand All @@ -13,36 +17,41 @@
import java.util.List;

abstract class CmdDefaultParams implements Runnable {
@CommandLine.Option (names = {"--cache-dir", "-c"},
@CommandLine.Option(names = {"--cache-dir", "-c"},
description = "Cache directory"
)
private String cacheDir = "./datasets";

@CommandLine.Option (names = {"--work-dir", "-w"},
@CommandLine.Option(names = {"--work-dir", "-w"},
description = "Work directory"
)
private String workDir = ".";

@CommandLine.Option (names = {"--no-progress"},
@CommandLine.Option(names = {"--no-progress"},
description = "Do not show progress indicator"
)
private boolean noProgress = false;


public void setNamespaces(List<String> namespaces) {
this.namespaces = namespaces;
}

@CommandLine.Parameters (
@CommandLine.Parameters(
description = "[namespace1] [namespace2] ..."
)
private List<String> namespaces = new ArrayList<>();

private ContentPathFactory contentPathFactory = new ContentPathFactoryDepth0();
private ProvenancePathFactory provenancePathFactory = new ProvenancePathFactoryImpl();

private PrintStream stderr = System.err;
private PrintStream stdout = System.out;
private InputStream stdin = System.in;

final private ProgressCursorFactory cursorFactory = new ProgressCursorFactory() {
private final ProgressCursor cursor = new ProgressCursorRotating(stderr);

@Override
public ProgressCursor createProgressCursor() {
return cursor;
Expand Down Expand Up @@ -92,19 +101,29 @@ public void setCacheDir(String cacheDir) {
this.cacheDir = cacheDir;
}


public ContentPathFactory getContentPathFactory() {
return (this.contentPathFactory);
}


public void setWorkDir(String workingDir) {
this.workDir = workingDir;
}

public ProgressCursorFactory getProgressCursorFactory() {
return noProgress
? () -> () -> {}
: cursorFactory;
? () -> () -> {
}
: cursorFactory;
}

public InputStreamFactoryLogging createInputStreamFactory() {
return new InputStreamFactoryLogging(getProgressCursorFactory());
}


public ProvenancePathFactory getProvenancePathFactory() {
return provenancePathFactory;
}
}
26 changes: 4 additions & 22 deletions src/main/java/org/globalbioticinteractions/elton/cmd/CmdGet.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
package org.globalbioticinteractions.elton.cmd;

import bio.guoda.preston.HashType;
import bio.guoda.preston.Hasher;
import bio.guoda.preston.RefNodeConstants;
import bio.guoda.preston.RefNodeFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
import org.eol.globi.data.NodeFactory;
import org.eol.globi.service.CacheService;
import org.eol.globi.service.ResourceService;
import org.eol.globi.tool.NullImportLogger;
import org.globalbioticinteractions.dataset.Dataset;
import org.globalbioticinteractions.dataset.DatasetProxy;

import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.dataset.DatasetRegistryException;
import org.globalbioticinteractions.dataset.DatasetRegistryProxy;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.globalbioticinteractions.elton.util.NamespaceHandler;
import org.globalbioticinteractions.elton.util.NodeFactoryNull;
import org.nanopub.Run;
import picocli.CommandLine;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URI;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -61,7 +41,9 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
createInputStreamFactory()
createInputStreamFactory(),
getContentPathFactory(),
getProvenancePathFactory()
);

final List<String> actualNamespaces = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.eol.globi.data.ImportLogger;
import org.eol.globi.data.NodeFactory;
import org.eol.globi.domain.LogContext;

import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.globalbioticinteractions.elton.util.ProgressUtil;
Expand All @@ -29,7 +30,9 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
createInputStreamFactory());
createInputStreamFactory(),
getContentPathFactory(),
getProvenancePathFactory());

NodeFactory nodeFactory = WriterUtil.nodeFactoryForInteractionWriting(!shouldSkipHeader(), out);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.globalbioticinteractions.elton.cmd;

import org.eol.globi.util.ResourceServiceRemote;

import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.dataset.DatasetRegistryException;
import org.globalbioticinteractions.dataset.DatasetRegistryGitHubArchive;
Expand Down Expand Up @@ -28,7 +29,7 @@ public void run() {

public void run(PrintStream out) {
InputStreamFactoryLogging inputStreamFactory = createInputStreamFactory();
DatasetRegistry registryLocal = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), inputStreamFactory);
DatasetRegistry registryLocal = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), inputStreamFactory, getContentPathFactory(), getProvenancePathFactory());

File cacheDir = new File(getCacheDir());
List<DatasetRegistry> registries =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.eol.globi.data.NodeFactory;
import org.eol.globi.service.ResourceService;
import org.eol.globi.tool.NullImportLogger;

import org.globalbioticinteractions.dataset.Dataset;
import org.globalbioticinteractions.dataset.DatasetProxy;
import org.globalbioticinteractions.dataset.DatasetRegistry;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void run() {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
createInputStreamFactory()
createInputStreamFactory(),
getContentPathFactory(), getProvenancePathFactory()
);

IRI softwareAgent = RefNodeFactory.toIRI("https://zenodo.org/doi/10.5281/zenodo.998263");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.eol.globi.data.NodeFactory;
import org.eol.globi.tool.NullImportLogger;

import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import picocli.CommandLine;
Expand All @@ -23,7 +24,7 @@ public void run() {

void run(PrintStream out) {

DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), createInputStreamFactory());
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), createInputStreamFactory(), getContentPathFactory(), getProvenancePathFactory());

NodeFactory nodeFactory = WriterUtil.nodeFactoryForTaxonWriting(!shouldSkipHeader(), out);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.globalbioticinteractions.elton.cmd;

import org.eol.globi.tool.NullImportLogger;

import org.globalbioticinteractions.dataset.DatasetRegistry;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.globalbioticinteractions.elton.util.IdGenerator;
Expand Down Expand Up @@ -43,7 +44,8 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
createInputStreamFactory());
createInputStreamFactory(),
getContentPathFactory(), getProvenancePathFactory());

InteractionWriter serializer = createSerializer(out);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eol.globi.util.InputStreamFactory;
import org.eol.globi.util.ResourceServiceLocal;
import org.eol.globi.util.ResourceServiceLocalAndRemote;

import org.globalbioticinteractions.dataset.CitationUtil;
import org.globalbioticinteractions.dataset.Dataset;
import org.globalbioticinteractions.dataset.DatasetConstant;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class CmdReview extends CmdTabularWriterParams {
private String reviewId = UUID.randomUUID().toString();



@Override
public void run() {
try {
Expand All @@ -111,7 +113,8 @@ public void run() {
DatasetRegistry registryLocal = DatasetRegistryUtil.forLocalDir(
localNamespace,
getCacheDir(),
new ResourceServiceLocalAndRemote(factory, new File(getCacheDir()))
new ResourceServiceLocalAndRemote(factory, new File(getCacheDir())),
getContentPathFactory()
);

review(DatasetRegistryUtil.NAMESPACE_LOCAL, registryLocal, factory, shouldSkipHeader());
Expand All @@ -129,7 +132,9 @@ private void reviewCachedOrRemote(List<String> namespaces, InputStreamFactory in
review(namespace,
DatasetRegistryUtil.forCacheDir(
getCacheDir(),
new ResourceServiceLocal(inputStreamFactory)
new ResourceServiceLocal(inputStreamFactory),
getContentPathFactory(),
getProvenancePathFactory()
),
inputStreamFactory,
shouldSkipHeader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eol.globi.data.NodeFactory;
import org.eol.globi.domain.LogContext;
import org.eol.globi.tool.NullImportLogger;

import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.globalbioticinteractions.elton.util.ProgressCursor;
import org.globalbioticinteractions.elton.util.ProgressCursorFactory;
Expand Down Expand Up @@ -69,7 +70,9 @@ public void run() {
this.getStderr(),
this.createInputStreamFactory(),
new NodeFactoryFactoryImpl(shouldWriteHeader, recordType, loggerFactory.createImportLogger()),
loggerFactory
loggerFactory,
getContentPathFactory(),
getProvenancePathFactory()
);
namespaceHandler.onNamespace(namespace);
isFirst.set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.eol.globi.data.NodeFactory;
import org.eol.globi.data.StudyImporterException;
import org.eol.globi.util.DatasetImportUtil;

import org.globalbioticinteractions.dataset.Dataset;
import org.globalbioticinteractions.dataset.DatasetFactory;
import org.globalbioticinteractions.dataset.DatasetRegistry;
Expand Down Expand Up @@ -65,11 +66,15 @@ public void run() {
registryProxy,
namespace,
getCacheDir(),
inputStreamFactory);
inputStreamFactory,
getContentPathFactory(),
getProvenancePathFactory()
);

Dataset dataset =
new DatasetFactory(registry, createInputStreamFactory())
.datasetFor(namespace);

NodeFactory factory = new NodeFactoryNull();
factory.getOrCreateDataset(dataset);
try {
Expand Down
Loading

0 comments on commit fde6653

Please sign in to comment.