Search in sources :

Example 1 with DatasetProxy

use of org.globalbioticinteractions.dataset.DatasetProxy in project eol-globi-data by jhpoelen.

the class DatasetProxyTest method getTestDataset.

public DatasetProxy getTestDataset(JsonNode config, JsonNode configProxy) {
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(config);
    DatasetProxy datasetProxy = new DatasetProxy(dataset);
    datasetProxy.setConfig(configProxy);
    return datasetProxy;
}
Also used : DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy)

Example 2 with DatasetProxy

use of org.globalbioticinteractions.dataset.DatasetProxy in project eol-globi-data by jhpoelen.

the class DatasetImporterForMetaTable method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    try {
        for (JsonNode tableConfig : collectTables(dataset)) {
            Dataset datasetProxy = new DatasetProxy(dataset);
            datasetProxy.setConfig(tableConfig);
            InteractionListener interactionListener = getInteractionListener();
            final InteractionListener listener = new TableInteractionListenerProxy(datasetProxy, interactionListener);
            importTable(listener, new TableParserFactoryImpl(), tableConfig, datasetProxy, getLogger());
        }
    } catch (IOException | NodeFactoryException e) {
        String msg = "problem importing from [" + getBaseUrl() + "]";
        LogUtil.logError(getLogger(), msg, e);
        throw new StudyImporterException(msg, e);
    }
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) Dataset(org.globalbioticinteractions.dataset.Dataset) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy)

Example 3 with DatasetProxy

use of org.globalbioticinteractions.dataset.DatasetProxy in project eol-globi-data by jhpoelen.

the class DatasetProxyTest method getMappedResource.

@Test
public void getMappedResource() throws IOException, URISyntaxException {
    URL original = getClass().getResource("/org/globalbioticinteractions/content/original.txt");
    URL proxied = getClass().getResource("/org/globalbioticinteractions/content/proxied.txt");
    JsonNode configProxy = new ObjectMapper().readTree("{ \"resources\": { \"archive\": \"" + proxied.toURI() + "\" } }");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(null);
    final String hashOfOriginal = "0682c5f2076f099c34cfdd15a9e063849ed437a49677e6fcc5b4198c76575be5";
    final String hashOfProxied = "b09f17ea1b5ca77b7a01a3ed62c84b38578817eddb34f827666c898a27504f67";
    DatasetProxy datasetProxy = new DatasetProxy(dataset);
    datasetProxy.setConfig(configProxy);
    DatasetProxy testDataset = datasetProxy;
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfProxied);
    JsonNode config = new ObjectMapper().readTree("{ \"resources\": { \"archive\": \"" + original.toURI() + "\" } }");
    testDataset = getTestDataset(config, configProxy);
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfProxied);
    testDataset = getTestDataset(config, null);
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfOriginal);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy) Test(org.junit.Test)

Example 4 with DatasetProxy

use of org.globalbioticinteractions.dataset.DatasetProxy in project eol-globi-data by jhpoelen.

the class DatasetImportUtilTest method getReferences.

public static List<Dataset> getReferences(Dataset dataset) {
    List<Dataset> referenceList = new ArrayList<>();
    final JsonNode config = dataset.getConfig();
    final JsonNode references = config.get("references");
    if (references != null && references.isArray()) {
        for (JsonNode reference : references) {
            final DatasetProxy datasetProxy = new DatasetProxy(dataset);
            datasetProxy.setConfig(reference);
            referenceList.add(datasetProxy);
        }
    }
    return referenceList;
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy)

Example 5 with DatasetProxy

use of org.globalbioticinteractions.dataset.DatasetProxy in project eol-globi-data by jhpoelen.

the class DatasetImporterForRSS method embeddedDatasetFor.

static Dataset embeddedDatasetFor(final Dataset datasetOrig, final String embeddedCitation, final URI embeddedArchiveURI, final Map<String, String> properties) {
    String hasDependencies = datasetOrig.getOrDefault(HAS_DEPENDENCIES, "false");
    ObjectNode config = new ObjectMapper().createObjectNode();
    config.put("citation", embeddedCitation);
    config.put("format", properties.getOrDefault("format", PropertyAndValueDictionary.MIME_TYPE_DWCA));
    config.put("url", embeddedArchiveURI.toString());
    config.put(HAS_DEPENDENCIES, hasDependencies);
    config.put("isDependency", properties.getOrDefault("isDependency", "false"));
    DatasetProxy dataset = new DatasetProxy(datasetOrig) {

        @Override
        public URI getArchiveURI() {
            return embeddedArchiveURI;
        }
    };
    dataset.setConfig(config);
    return dataset;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy)

Aggregations

DatasetProxy (org.globalbioticinteractions.dataset.DatasetProxy)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Dataset (org.globalbioticinteractions.dataset.Dataset)2 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 InteractionListener (org.eol.globi.process.InteractionListener)1 Test (org.junit.Test)1