Skip to content

Commit

Permalink
emit taxonworks queries as they come in; related to globalbioticinter…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Aug 4, 2023
1 parent 909a50d commit b181cff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,14 @@ public RegistryReaderTaxonWorks(BlobStoreReadOnly blobStoreReadOnly, StatementsL
public void on(Quad statement) {
if (Seeds.TAXONWORKS.equals(statement.getSubject())
&& WAS_ASSOCIATED_WITH.equals(statement.getPredicate())) {
List<Quad> nodes = new ArrayList<>();
Stream.of(
toStatement(Seeds.TAXONWORKS, IS_A, ORGANIZATION),
toStatement(RegistryReaderTaxonWorks.TAXONWORKS_OPEN_PROJECTS,
DESCRIPTION,
toEnglishLiteral("Provides an index of open projects hosted via TaxonWorks."))
).forEach(nodes::add);
).forEach(this::emit);

emitPageRequest(new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, TAXONWORKS_OPEN_PROJECTS);
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
emitPageRequest(this, TAXONWORKS_OPEN_PROJECTS);
} else if (hasVersionAvailable(statement)
&& StringUtils.equals(getVersionSource(statement).toString(), TAXONWORKS_OPEN_PROJECTS.toString())) {
handleProjectIndex(statement);
Expand All @@ -93,79 +86,51 @@ public void emit(Quad statement) {


public void handleCitations(Quad statement) {
List<Quad> nodes = new ArrayList<>();
try {
IRI currentPage = (IRI) getVersion(statement);
InputStream is = get(currentPage);
if (is != null) {
parseCitations(currentPage, new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, is, getVersionSource(statement));
parseCitations(currentPage, this, is, getVersionSource(statement));
}
} catch (IOException e) {
LOG.warn("failed to handle [" + statement.toString() + "]", e);
}
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
}

public void handleBiologicalAssociation(Quad statement) {
List<Quad> nodes = new ArrayList<>();
try {
IRI currentPage = (IRI) getVersion(statement);
InputStream is = get(currentPage);
if (is != null) {
parseBiologicalAssociation(currentPage, new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, is, getVersionSource(statement));
parseBiologicalAssociation(currentPage, this, is, getVersionSource(statement));
}
} catch (IOException e) {
LOG.warn("failed to handle [" + statement.toString() + "]", e);
}
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
}

public void handleOTUs(Quad statement) {
List<Quad> nodes = new ArrayList<>();
try {
IRI currentPage = (IRI) getVersion(statement);
InputStream is = get(currentPage);
if (is != null) {
parseOTUs(currentPage, new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, is, getVersionSource(statement));
parseOTUs(currentPage, this, is, getVersionSource(statement));
}
} catch (IOException e) {
LOG.warn("failed to handle [" + statement.toString() + "]", e);
}
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
}

public void handleTaxonNames(Quad statement) {
List<Quad> nodes = new ArrayList<>();
try {
IRI currentPage = (IRI) getVersion(statement);
InputStream is = get(currentPage);
if (is != null) {
parseTaxonName(currentPage, new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, is, getVersionSource(statement));
parseTaxonName(currentPage, this, is, getVersionSource(statement));
}
} catch (IOException e) {
LOG.warn("failed to handle [" + statement.toString() + "]", e);
}
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
}

private void handleProjectIndex(Quad statement) {
Expand All @@ -174,17 +139,11 @@ private void handleProjectIndex(Quad statement) {
IRI currentPage = (IRI) getVersion(statement);
InputStream is = get(currentPage);
if (is != null) {
parseProjectIndex(new StatementsEmitterAdapter() {
@Override
public void emit(Quad statement) {
nodes.add(statement);
}
}, is, getVersionSource(statement));
parseProjectIndex(this, is, getVersionSource(statement));
}
} catch (IOException e) {
LOG.warn("failed to handle [" + statement.toString() + "]", e);
}
ActivityUtil.emitAsNewActivity(nodes.stream(), this, statement.getGraphName());
}

static void emitNextPage(int pageNumber, int pageSize, StatementsEmitter emitter, String versionSourceURI) {
Expand All @@ -199,6 +158,7 @@ static void emitNextPage(int pageNumber, int pageSize, StatementsEmitter emitter
emitPageRequest(emitter, nextPage);
}


private static void emitPageRequest(StatementsEmitter emitter, IRI nextPage) {
Stream.of(
toStatement(nextPage, CREATED_BY, Seeds.TAXONWORKS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.startsWith;


public class RegistryReaderTaxonWorksTest {
Expand Down Expand Up @@ -51,7 +50,7 @@ public InputStream get(IRI uri) throws IOException {
}, new StatementsListenerEmitterAdapter() {
@Override
public void emit(Quad statement) {

emitted.add(statement);
}

@Override
Expand All @@ -64,7 +63,7 @@ public void on(Quad statement) {
RefNodeFactory.toIRI("hash://sha256/abc"))
);

assertThat(emitted.size(), Is.is(254));
assertThat(emitted.size(), Is.is(253));

}

Expand Down Expand Up @@ -93,7 +92,7 @@ public void on(Quad statement) {
RefNodeFactory.toIRI("hash://sha256/abc"))
);

assertThat(emitted.size(), Is.is(7));
assertThat(emitted.size(), Is.is(6));

}

Expand All @@ -109,7 +108,7 @@ public InputStream get(IRI uri) throws IOException {
}, new StatementsListenerEmitterAdapter() {
@Override
public void emit(Quad statement) {

statements.add(statement);
}

@Override
Expand All @@ -122,25 +121,20 @@ public void on(Quad statement) {
RefNodeFactory.toIRI("hash://sha256/abc"))
);

assertThat(statements.size(), Is.is(4));

assertThat(statements.size(), Is.is(3));

Quad first = statements.get(0);
assertThat(first.getSubject().toString(), startsWith("<urn:uuid:"));
assertThat(first.getPredicate().toString(), Is.is("<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"));
assertThat(first.getObject().toString(), Is.is("<http://www.w3.org/ns/prov#Activity>"));

Quad second = statements.get(1);
Quad second = statements.get(0);
assertThat(second.getSubject().toString(), Is.is("<hash://sha256/abc>"));
assertThat(second.getPredicate().toString(), Is.is("<http://www.w3.org/ns/prov#hadMember>"));
assertThat(second.getObject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372119?project_token=ZEJhFp9sq8kBfks15qAbAg>"));

Quad third = statements.get(2);
Quad third = statements.get(1);
assertThat(third.getSubject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372119?project_token=ZEJhFp9sq8kBfks15qAbAg>"));
assertThat(third.getPredicate().toString(), Is.is("<http://purl.org/dc/elements/1.1/format>"));
assertThat(third.getObject().toString(), Is.is("\"application/json\""));

Quad forth = statements.get(3);
Quad forth = statements.get(2);
assertThat(forth.getSubject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372119?project_token=ZEJhFp9sq8kBfks15qAbAg>"));
assertThat(forth.getPredicate().toString(), Is.is("<http://purl.org/pav/hasVersion>"));
assertThat(forth.getObject() instanceof BlankNode, Is.is(true));
Expand Down Expand Up @@ -173,30 +167,24 @@ public void on(Quad statement) {
RefNodeFactory.toIRI("hash://sha256/abc"))
);

assertThat(statements.size(), Is.is(4));

Quad first = statements.get(0);
assertThat(first.getSubject().toString(), startsWith("<urn:uuid:"));
assertThat(first.getPredicate().toString(), Is.is("<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"));
assertThat(first.getObject().toString(), Is.is("<http://www.w3.org/ns/prov#Activity>"));
assertThat(statements.size(), Is.is(3));

Quad second = statements.get(1);
Quad second = statements.get(0);
assertThat(second.getSubject().toString(), Is.is("<hash://sha256/abc>"));
assertThat(second.getPredicate().toString(), Is.is("<http://www.w3.org/ns/prov#hadMember>"));
assertThat(second.getObject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372113?project_token=ZEJhFp9sq8kBfks15qAbAg>"));

Quad third = statements.get(2);
Quad third = statements.get(1);
assertThat(third.getSubject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372113?project_token=ZEJhFp9sq8kBfks15qAbAg>"));
assertThat(third.getPredicate().toString(), Is.is("<http://purl.org/dc/elements/1.1/format>"));
assertThat(third.getObject().toString(), Is.is("\"application/json\""));

Quad forth = statements.get(3);
Quad forth = statements.get(2);
assertThat(forth.getSubject().toString(), Is.is("<https://sfg.taxonworks.org/api/v1/taxon_names/372113?project_token=ZEJhFp9sq8kBfks15qAbAg>"));
assertThat(forth.getPredicate().toString(), Is.is("<http://purl.org/pav/hasVersion>"));
assertThat(forth.getObject() instanceof BlankNode, Is.is(true));



}

@Test
Expand Down Expand Up @@ -262,6 +250,7 @@ public void emit(Quad statement) {
assertThat(fifth.getObject() instanceof BlankNode, Is.is(true));

}

@Test
public void parseCitationObject() throws IOException {
List<Quad> statements = new ArrayList<>();
Expand Down

0 comments on commit b181cff

Please sign in to comment.