Skip to content

Commit

Permalink
move exporters into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Jan 8, 2015
1 parent b0ebcb2 commit 42fd73e
Show file tree
Hide file tree
Showing 45 changed files with 111 additions and 274 deletions.
28 changes: 28 additions & 0 deletions eol-globi-data-export/pom.xml
@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>eol-globi-parent</artifactId>
<groupId>org.eol</groupId>
<version>0.6-SNAPSHOT</version>
<relativePath>../eol-globi-parent/pom.xml</relativePath>
</parent>

<artifactId>eol-globi-data-export</artifactId>
<name>EOL's Global Biotic Interaction Data Exporters</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eol-globi-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>${mapdb.version}</version>
</dependency>
</dependencies>

</project>
@@ -1,5 +1,6 @@
package org.eol.globi.export;

import org.apache.commons.lang.StringUtils;
import org.eol.globi.data.CharsetConstant;
import org.eol.globi.domain.PropertyAndValueDictionary;
import org.eol.globi.domain.Study;
Expand All @@ -18,10 +19,6 @@
import java.util.List;
import java.util.Map;

import static org.apache.commons.lang.StringUtils.join;
import static org.apache.commons.lang.StringUtils.split;
import static org.apache.commons.lang.StringUtils.trim;

/**
* Exports an expanded taxon list. Rolls up to taxonomic rank "order".
* <p/>
Expand All @@ -38,22 +35,22 @@ public class ExporterTaxaRollup extends ExporterTaxa {
public static List<Map<String, Object>> expandTaxonResult(Map<String, Object> result) {
List<Map<String, Object>> expandedResults = new ArrayList<Map<String, Object>>();

String[] pathNames = split((String) result.get("pathNames"), CharsetConstant.SEPARATOR_CHAR);
String[] pathIds = split((String) result.get("pathIds"), "|");
String[] path = split((String) result.get("path"), "|");
String[] pathNames = StringUtils.split((String) result.get("pathNames"), CharsetConstant.SEPARATOR_CHAR);
String[] pathIds = StringUtils.split((String) result.get("pathIds"), "|");
String[] path = StringUtils.split((String) result.get("path"), "|");
if (pathNames != null && pathIds != null && path != null
&& pathNames.length == pathIds.length && pathNames.length == path.length) {
for (int i = 0; i < pathNames.length; i++) {
String rank = trim(pathNames[i]);
String rank = StringUtils.trim(pathNames[i]);
if (EXPANDABLE_RANKS.contains(rank)) {
Map<String, Object> taxon = new HashMap<String, Object>();
taxon.put("scientificName", trim(path[i]));
taxon.put("taxonId", trim(pathIds[i]));
taxon.put("scientificName", StringUtils.trim(path[i]));
taxon.put("taxonId", StringUtils.trim(pathIds[i]));
taxon.put("rank", rank);
String[] partialPathNames = Arrays.copyOfRange(pathNames, 0, i + 1);
String[] partialPath = Arrays.copyOfRange(path, 0, i + 1);
taxon.put("path", trim(join(partialPath, CharsetConstant.SEPARATOR_CHAR)));
taxon.put("pathNames", trim(join(partialPathNames, CharsetConstant.SEPARATOR_CHAR)));
taxon.put("path", StringUtils.trim(StringUtils.join(partialPath, CharsetConstant.SEPARATOR_CHAR)));
taxon.put("pathNames", StringUtils.trim(StringUtils.join(partialPathNames, CharsetConstant.SEPARATOR_CHAR)));
expandedResults.add(taxon);
}
}
Expand Down Expand Up @@ -89,7 +86,7 @@ private void exportRollupTaxa(Writer writer, GraphDatabaseService graphDatabase)

Map<String, String> row = new HashMap<String, String>();
for (Map<String, Object> taxon : taxonMap.values()) {
resultsToRow(row, taxon);
ExporterTaxa.resultsToRow(row, taxon);
writeProperties(writer, row);
row.clear();
}
Expand Down
Expand Up @@ -7,9 +7,9 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eol.globi.data.NodeFactoryImpl;
import org.eol.globi.data.StudyImporterException;
import org.eol.globi.domain.Study;
import org.eol.globi.util.NodeUtil;
import org.neo4j.graphdb.GraphDatabaseService;

import java.io.BufferedOutputStream;
Expand All @@ -33,10 +33,9 @@ public void export(GraphDatabaseService graphService, String baseDir) throws Stu
} catch (IOException e) {
throw new StudyImporterException("failed to create output dir [" + baseDir + "]", e);
}
List<Study> studies = NodeFactoryImpl.findAllStudies(graphService);
List<Study> studies = NodeUtil.findAllStudies(graphService);
exportDataOntology(studies, baseDir);
exportUnmatchedTaxa(studies, baseDir);
//exportGoMexSI(studies, baseDir);
exportDarwinCoreAggregatedByStudy(baseDir, studies);
exportDarwinCoreAll(baseDir, studies);
}
Expand All @@ -55,21 +54,6 @@ private void exportUnmatchedTaxa(List<Study> studies, String baseDir) throws Stu
}
}

// Provide simple data representation
private void exportGoMexSI(List<Study> studies, String baseDir) throws StudyImporterException {
try {
FileUtils.forceMkdir(new File(baseDir));
OutputStreamWriter writer = openStream(baseDir + "GoMexSIInteractionsTaxa.csv");
for (Study importedStudy : studies) {
boolean includeHeader = studies.indexOf(importedStudy) == 0;
new ExporterGoMexSI().exportStudy(importedStudy, writer, includeHeader);
}
closeStream(baseDir + "GoMexSIInteractionsTaxa.csv", writer);
} catch (IOException e) {
throw new StudyImporterException("failed to export GoMexSI", e);
}
}

private void exportDarwinCoreAggregatedByStudy(String baseDir, List<Study> studies) throws StudyImporterException {
exportDarwinCoreArchive(studies,
baseDir + "aggregatedByStudy/", new HashMap<String, DarwinCoreExporter>() {
Expand Down
10 changes: 0 additions & 10 deletions eol-globi-data-sources/pom.xml
Expand Up @@ -30,16 +30,6 @@
<version>${project.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.swizzle</groupId>
<artifactId>swizzle-stream</artifactId>
Expand Down
14 changes: 4 additions & 10 deletions eol-globi-data-tool/pom.xml
Expand Up @@ -13,21 +13,21 @@
<name>EOL's Global Biotic Interaction Data Import/Export Tool</name>

<dependencies>
<dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eol-globi-lib</artifactId>
<artifactId>eol-globi-enrich</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eol-globi-enrich</artifactId>
<artifactId>eol-globi-data-sources</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eol-globi-data-sources</artifactId>
<artifactId>eol-globi-data-export</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down Expand Up @@ -58,12 +58,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>


Expand Down

This file was deleted.

Expand Up @@ -83,16 +83,6 @@ public NodeFactoryImpl(GraphDatabaseService graphDb, TaxonIndex taxonIndex) {

}

public static List<Study> findAllStudies(GraphDatabaseService graphService) {
List<Study> studies = new ArrayList<Study>();
Index<Node> studyIndex = graphService.index().forNodes("studies");
IndexHits<Node> hits = studyIndex.query("title", "*");
for (Node hit : hits) {
studies.add(new Study(hit));
}
return studies;
}

public GraphDatabaseService getGraphDb() {
return graphDb;
}
Expand Down

This file was deleted.

Expand Up @@ -5,6 +5,7 @@
import org.eol.globi.domain.Specimen;
import org.eol.globi.domain.Study;
import org.eol.globi.domain.TaxonNode;
import org.eol.globi.util.NodeUtil;
import org.junit.Test;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -94,7 +95,7 @@ public boolean shouldImportRecord(Long recordNumber) {
});
studyImporterForBarnes.importStudy();

List<Study> studies = NodeFactoryImpl.findAllStudies(getGraphDb());
List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
assertTrue(studies.size() > 0);
for (Study study : studies) {
assertThat(study.getTitle(), is(notNullValue()));
Expand Down
@@ -1,6 +1,7 @@
package org.eol.globi.data;

import org.eol.globi.domain.Study;
import org.eol.globi.util.NodeUtil;
import org.junit.Test;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
Expand All @@ -18,7 +19,7 @@ public class StudyImporterForBellTest extends GraphDBTestCase {
public void importAll() throws StudyImporterException, NodeFactoryException {
StudyImporter importer = new StudyImporterForBell(new ParserFactoryImpl(), nodeFactory);
importer.importStudy();
List<Study> allStudies = NodeFactoryImpl.findAllStudies(getGraphDb());
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
assertThat(allStudies.size(), is(6));
ExecutionResult execute = new ExecutionEngine(getGraphDb()).execute("START taxon = node:taxons('*:*') RETURN taxon.name");
String actual = execute.dumpToString();
Expand Down
Expand Up @@ -7,6 +7,7 @@
import org.eol.globi.domain.Specimen;
import org.eol.globi.domain.Study;
import org.eol.globi.domain.TaxonNode;
import org.eol.globi.util.NodeUtil;
import org.junit.Test;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void importAll() throws StudyImporterException {
StudyImporterForBrose studyImporterForBrose = new StudyImporterForBrose(new ParserFactoryImpl(), nodeFactory);
studyImporterForBrose.importStudy();

List<Study> studies = NodeFactoryImpl.findAllStudies(getGraphDb());
List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
assertThat(studies.size(), is(20));
for (Study study : studies) {
assertThat(study.getTitle(), is(notNullValue()));
Expand Down
@@ -1,6 +1,7 @@
package org.eol.globi.data;

import org.eol.globi.domain.Study;
import org.eol.globi.util.NodeUtil;
import org.junit.Test;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
Expand Down Expand Up @@ -28,7 +29,7 @@ public void importAll() throws StudyImporterException, NodeFactoryException {

List<String> citationList = new ArrayList<String>();
Set<String> citations = new HashSet<String>();
List<Study> studies = NodeFactoryImpl.findAllStudies(getGraphDb());
List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
assertTrue(studies.size() > 0);
for (Study study : studies) {
assertThat(study.getTitle(), is(notNullValue()));
Expand Down

0 comments on commit 42fd73e

Please sign in to comment.