Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dspace harvester first version #4

Merged
merged 6 commits into from May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,7 +27,7 @@
/**
* Collection
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Collection {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Collection {
@JsonProperty("dspaceType")
private String dspaceType = "collection";

Expand Down
Expand Up @@ -28,7 +28,7 @@
/**
* Community
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Community {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Community {
@JsonProperty("dspaceType")
private String dspaceType = "community";

Expand Down
Expand Up @@ -22,7 +22,7 @@
/**
* Error
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Error {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Error {
@JsonProperty("code")
private Integer code = null;

Expand Down
Expand Up @@ -26,7 +26,7 @@
/**
* Item
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Item {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Item {
@JsonProperty("dspaceType")
private String dspaceType = "item";

Expand Down
Expand Up @@ -27,7 +27,7 @@
/**
* Repository
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Repository {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Repository {
@JsonProperty("dspaceType")
private String dspaceType = "repository";

Expand Down
Expand Up @@ -22,7 +22,7 @@
/**
* Statement
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class Statement {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class Statement {
@JsonProperty("dspaceType")
private String dspaceType = "statement";

Expand Down
Expand Up @@ -22,7 +22,7 @@
/**
* StatementLiteral
*/
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-07T06:06:42.412-04:00[America/New_York]")public class StatementLiteral {
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaJerseyServerCodegen", date = "2022-04-11T22:50:22.156-05:00[America/Guayaquil]")public class StatementLiteral {
@JsonProperty("dspaceType")
private String dspaceType = "statementLiteral";

Expand Down
165 changes: 90 additions & 75 deletions bundles/org.vivoweb.dspacevivo.transformation/pom.xml
@@ -1,77 +1,92 @@
<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>
<artifactId>org.vivoweb.dspacevivo.transformation</artifactId>
<licenses>
<license>
<name>BSD 3-Clause License</name>
<url>https://raw.githubusercontent.com/vivo-project/VIVO/develop/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Michel Héon</name>
<organization>Université du Québec à Montréal</organization>
<organizationUrl>http://uqam.ca/</organizationUrl>
<url>https://ca.linkedin.com/in/michelheon</url>
</developer>
</developers>
<properties>
</properties>
<build>
</build>
<parent>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.installer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../releng/org.vivoweb.dspacevivo.installer</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-cmds</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.model.ontologie</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.model.openapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
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>
<artifactId>org.vivoweb.dspacevivo.transformation</artifactId>
<licenses>
<license>
<name>BSD 3-Clause License</name>
<url>https://raw.githubusercontent.com/vivo-project/VIVO/develop/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Michel Héon</name>
<organization>Université du Québec à Montréal</organization>
<organizationUrl>http://uqam.ca/</organizationUrl>
<url>https://ca.linkedin.com/in/michelheon</url>
</developer>
</developers>
<properties>
</properties>
<build>
</build>
<parent>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.installer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../releng/org.vivoweb.dspacevivo.installer</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-cmds</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.model.ontologie</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.vivoweb.dspacevivo</groupId>
<artifactId>org.vivoweb.dspacevivo.model.openapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line at the end of file

@@ -0,0 +1,18 @@
package org.vivoweb.dspacevivo.transformation;

import java.io.IOException;
import org.vivoweb.dspacevivo.transformation.harvester.HarvesterRunner;

public class ConsoleApplication {

public static void main(String[] args) throws IOException {

HarvesterRunner runner = new HarvesterRunner();
runner.init();
//runner.harvest();
//runner.harvestCommunity();
//runner.harvestCollection();
runner.harvestRepository();
}

}
Expand Up @@ -49,7 +49,7 @@ public static void main(String[] args) throws JsonProcessingException {
Repository repo = new Repository();
repo.setId("123456789_0");
repo.setUri("http://localhost:8080/server/rdf/resource/123456789/0");
repo.addHasCommunityIdItem("123456789_1");
//repo.addHasCommunityIdItem("123456789_1");
Statement stmt = new Statement();
stmt.setSubjectUri("dspace:123456789_0");
stmt.setPredicateUri("dcterms:hasPart");
Expand Down
@@ -0,0 +1,31 @@
package org.vivoweb.dspacevivo.transformation.harvester;

import java.util.Iterator;
import java.util.Properties;
import org.vivoweb.dspacevivo.model.Collection;
import org.vivoweb.dspacevivo.model.Community;
import org.vivoweb.dspacevivo.model.Item;
import org.vivoweb.dspacevivo.model.Repository;

public abstract class DspaceHarvester {

protected Properties conf = null;

public DspaceHarvester(Properties conf) {
this.conf = conf;
}

public Properties getConf() {
return conf;
}

public abstract void connect();

public abstract Iterator<Item> harvestItems();

public abstract Iterator<Community> harvestCommunity();

public abstract Iterator<Collection> harvestCollection();

public abstract Iterator<Repository> harvestRepository();
}
@@ -0,0 +1,99 @@
package org.vivoweb.dspacevivo.transformation.harvester;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vivoweb.dspacevivo.model.Collection;
import org.vivoweb.dspacevivo.model.Community;
import org.vivoweb.dspacevivo.model.Item;
import org.vivoweb.dspacevivo.model.Repository;
import org.vivoweb.dspacevivo.transformation.harvester.config.HarvesterConfiguration;
import org.vivoweb.dspacevivo.transformation.harvester.oai.DspaceOAI;

public class HarvesterRunner {

private static Logger log = LoggerFactory.getLogger(HarvesterRunner.class);
private DspaceHarvester dh = null;

public void init() throws IOException {
Properties conf = HarvesterConfiguration.getConf();
switch (conf.getProperty("type")) {
case "RESTv7":
//dh = new Dspace7REST(conf);
break;
case "SPARQL":
//dh = new SPARQLHarvester(conf);
break;
case "OAI":
dh = new DspaceOAI(conf);
break;
}
dh.connect();
}

public void harvest() throws JsonProcessingException {
ObjectMapper mp = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
Iterator<Item> harvestItemsItr = dh.harvestItems();
int count = 0;
if (harvestItemsItr != null) {
while (harvestItemsItr.hasNext()) {
count++;
Item next = harvestItemsItr.next();
System.out.println("new Item harvested...");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use loggers instead of printing to console?

System.out.println(" " + count);
System.out.println(mp.writeValueAsString(next));
}
}
}

public void harvestCollection() throws JsonProcessingException {
ObjectMapper mp = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
Iterator<Collection> harvestCollection = dh.harvestCollection();
int count = 0;
if (harvestCollection != null) {
while (harvestCollection.hasNext()) {
count++;
Collection next = harvestCollection.next();
System.out.println("new Collection harvested...");
System.out.println(" " + count);
System.out.println(mp.writeValueAsString(next));
}
}
}

public void harvestCommunity() throws JsonProcessingException {
ObjectMapper mp = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
Iterator<Community> harvestCommunity = dh.harvestCommunity();
int count = 0;
if (harvestCommunity != null) {
while (harvestCommunity.hasNext()) {
count++;
Community next = harvestCommunity.next();
System.out.println("new Community harvested...");
System.out.println(" " + count);
System.out.println(mp.writeValueAsString(next));
}
}
}

public void harvestRepository() throws JsonProcessingException {
ObjectMapper mp = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
Iterator<Repository> harvestRepository = dh.harvestRepository();
int count = 0;
if (harvestRepository != null) {
while (harvestRepository.hasNext()) {
count++;
Repository next = harvestRepository.next();
System.out.println("new Repository harvested...");
System.out.println(" " + count);
System.out.println(mp.writeValueAsString(next));
}
}
}

}