Skip to content
Snippets Groups Projects
Commit 933cbc34 authored by Stefan E. Funk's avatar Stefan E. Funk
Browse files

Merge branch '293-implement-new-gitlab-workflow-and-do-some-code-formatting' into 'develop'

Resolve "Implement new GitLab workflow and do some code formatting"

Closes #293

See merge request !4
parents 4fd39455 fd302246
No related branches found
No related tags found
2 merge requests!5New RELEASE,!4Resolve "Implement new GitLab workflow and do some code formatting"
Pipeline #338553 canceled
......@@ -4,3 +4,5 @@ tgForms/
.classpath
.project
/node_modules/
/pom.xml.versionsBackup
......@@ -5,28 +5,32 @@
# Some variables
# TODO: Apply also as a template!
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
# Maven Settings
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
#MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
# Nexus Deployment settings, please use env vars in Settings -> CI/CD -> Variables.
# Maven deployment settings for Nexus, please use env vars in Settings -> CI/CD -> Variables.
MAVEN_SETTINGS_PATH: ".m2/settings.xml"
MAVEN_DEPLOY_OPTS: "--settings=$MAVEN_SETTINGS_PATH"
# Semantic versioning commit and push vars (the TOKEN name and user)
GIT_AUTHOR_EMAIL: ${GL_USER}@noreply.gitlab.gwdg.de
GIT_AUTHOR_NAME: ${GL_USER}
GIT_COMMITTER_EMAIL: ${GL_USER}@noreply.gitlab.gwdg.de
GIT_COMMITTER_NAME: ${GL_USER}
# Include Java settings from Gitlab templates repo.
include:
- project: 'dariah-de/gitlab-templates'
ref: 'main'
file: '/templates/.java.gitlab-ci.yml'
file:
- '/templates/.java.gitlab-ci.yml'
- '/templates/SBOM-Upload.gitlab-ci.yml'
# Stages...
stages:
- build_version
- deploy_java
- deploy_deb
- prepare
- test
- build
- deploy
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
......@@ -40,31 +44,62 @@ cache:
###
# Get the project version from main POM file and store it to artifact.
Get POM version:
get-pom-version:
stage: prepare
only:
- develop
- main
stage: build_version
- tags
extends:
- .get-pom-version-to-env
# Semantic versioning: Update POM and CHANGELOG RELEASE files, TAG a new RELEASE version!
prepare-release:
stage: prepare
rules:
# Only run if branch "main" AND commit title IS NOT "1.2.3" (main commit with tag) AND DOES NOT START WITH "Prepare next development iteration" (main commit with new version)
- if: $CI_COMMIT_REF_NAME == "main" && $CI_COMMIT_TITLE !~ /^[\d\.]+$/ && $CI_COMMIT_TITLE !~ /^Prepare next development iteration/
image: maven:3.8.3-jdk-8
extends:
- .prepare-semantic-release
# Build, validate, and package all the feature branches
validate-java:
stage: test
except:
- main
- develop
- tags
image: maven:3.8.3-jdk-8
script:
- mvn $MAVEN_OPTS $MAVEN_CLI_OPTS $MAVEN_DEPLOY_OPTS -U clean validate package
artifacts:
reports:
# Declare the JUnit reports (recursive pattern for multi-module projects)
junit:
- "**/target/*-reports/TEST-*.xml"
# Build and deploy all the JARs to GWDG Nexus, and build all the DEBs and store DEBs to artifacts.
Build and deploy JAR:
build-and-deploy-jars:
stage: build
image: maven:3.8.3-jdk-8
only:
- develop
- main
stage: deploy_java
- tags
script:
- 'mvn $MAVEN_OPTS $MAVEN_CLI_OPTS $MAVEN_DEPLOY_OPTS -U clean deploy -Pclassicmayan.deb'
- mvn $MAVEN_OPTS $MAVEN_CLI_OPTS $MAVEN_DEPLOY_OPTS -U clean validate deploy -Pclassicmayan.deb -Psbom
- cp target/bom.json .
artifacts:
name: WEBAPP_DEB_PACKAGES
paths:
- ./target/*.deb
- ./bom.json
reports:
# Declare the JUnit reports (recursive pattern for multi-module projects)
junit:
- "**/target/*-reports/TEST-*.xml"
# Deploy DEB files to APTLY repository.
Deploy SNAPSHOT DEB:
stage: deploy_deb
deploy-snapshot-deb:
stage: deploy
only:
- develop
variables:
......@@ -75,10 +110,10 @@ Deploy SNAPSHOT DEB:
extends:
- .deploy-deb
Deploy RELEASE DEB:
stage: deploy_deb
deploy-release-deb:
stage: deploy
only:
- main
- tags
variables:
PNAME: 'rdfDatabase'
PPATH: './target'
......
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
exec < /dev/tty && npx cz --hook || true
# RDF Database
# ClassicMayan RDF Database
> Database for persons and bibliographic references in the IDIOM project
RDF database is designed for the use with the [TextGrid](http://www.textgrid.de) RDF Object Editor. It uses [tgFormsMayaImpl](https://gitlab.gwdg.de/fe/classicmayan/tg-forms-classicmayan-impl), a JavaScript library to generate HTML forms from Turtle RDF representations.
RDF database is designed for the use with the [TextGrid](https://textgrid.de) RDF Object Editor. It uses [tgFormsMayaImpl](https://gitlab.gwdg.de/fe/classicmayan/tg-forms-classicmayan-impl), a JavaScript library to generate HTML forms from Turtle RDF representations.
Usage
-----
## Usage
If you have [node.js](http://nodejs.org), [Bower](http://bower.io) and [Apache Maven](http://maven.apache.org) installed, you can simply run the start script:
......
This diff is collapsed.
{
"private": true,
"name": "classicmayan-rdf-database",
"description": "The RDF Database for the ClassicMayan project.",
"repository": {
"type": "git",
"url": "https://gitlab.gwdg.de/fe/classicmayan/rdf-database"
},
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"@conveyal/maven-semantic-release": "^5.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^7.0.4",
"cz-conventional-changelog": "^3.0.1",
"husky": "^7.0.4",
"semantic-release": "^19.0.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"release": {
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
"@conveyal/maven-semantic-release",
[
"@semantic-release/gitlab",
{
"gitlabUrl": "https://gitlab.gwdg.de",
"assets": [
{
"path": "CHANGELOG.md",
"label": "Changelog"
}
]
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
]
}
]
]
},
"dependencies": {
"commitizen": "^4.2.4"
}
}
<project>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>bdnDatabase</name>
<groupId>org.classicmayan</groupId>
<artifactId>rdfDatabase</artifactId>
<packaging>war</packaging>
<version>1.4.14</version>
<version>1.4.14-SNAPSHOT</version>
<name>rdfDatabase</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<cxf.version>3.2.0</cxf.version>
<spring.version>4.0.2.RELEASE</spring.version>
<junit.version>4.8.1</junit.version>
<tgcrud.version>7.6.0</tgcrud.version>
<jena-core.version>3.4.0</jena-core.version>
<jena-arq.version>3.6.0</jena-arq.version>
<javax-mail.version>1.4.7</javax-mail.version>
<elasticsearch.version>1.7.5</elasticsearch.version>
<jaxws-api.version>2.2.6</jaxws-api.version>
<vafer.version>1.4</vafer.version>
<cyclonedx-maven-plugin.version>2.7.0</cyclonedx-maven-plugin.version>
<jaxws-api.version>2.2.6</jaxws-api.version>
<javax-mail.version>1.4.7</javax-mail.version>
<jdk.version>1.8</jdk.version>
<jetty-maven-plugin.version>9.2.11.v20150529</jetty-maven-plugin.version>
<jena-arq.version>3.6.0</jena-arq.version>
<jena-core.version>3.4.0</jena-core.version>
<junit.version>4.8.1</junit.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<jetty-maven-plugin.version>9.2.11.v20150529</jetty-maven-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<spring.version>4.0.2.RELEASE</spring.version>
<tgcrud.version>7.6.0</tgcrud.version>
<vafer.version>1.4</vafer.version>
</properties>
<dependencies>
<dependency>
......@@ -39,21 +41,11 @@
<artifactId>jena-core</artifactId>
<version>${jena-core.version}</version>
</dependency>
<!-- <exclusions> <exclusion> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId>
</exclusion> <exclusion> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId>
</exclusion> <exclusion> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId>
</exclusion> </exclusions> -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>${jena-arq.version}</version>
<!-- <exclusions> <exclusion> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> </exclusion> <exclusion> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId> </exclusion> <exclusion> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId> </exclusion> </exclusions> -->
</dependency>
<!-- <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId>
<version>2.13</version> </dependency> -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
......@@ -79,29 +71,22 @@
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId>
<version>1.0</version> </dependency> -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${javax-mail.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>${jaxws-api.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>${jaxws-api.version}</version>
</dependency>
</dependencies>
<build>
<finalName>rdfDatabase</finalName>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
......@@ -151,6 +136,29 @@
</repository>
</distributionManagement>
<profiles>
<profile>
<id>sbom</id>
<build>
<plugins>
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>${cyclonedx-maven-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>makeAggregateBom</goal>
</goals>
</execution>
</executions>
<configuration>
<outputFormat>JSON</outputFormat>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>classicmayan.deb</id>
<build>
......
......@@ -11,75 +11,83 @@ import org.apache.jena.query.DatasetAccessorFactory;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
/**
*
*/
class FusekiCRUD {
DatasetAccessor accessor;
List<String> artefactUriList = new ArrayList<String>();
List<String> allObjectUriList = new ArrayList<String>();
List<String> allUrisWithMissingCitation = new ArrayList<String>();
List<String> wrongZuriList = new ArrayList<String>();
String prefixes =
"prefix dct: <http://purl.org/dc/terms#>\n" +
"prefix dc: <http://purl.org/dc/elements/1.1/>\n" +
"prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"prefix owl: <http://www.w3.org/2002/07/owl#>\n" +
"prefix xsd: <http://www.w3.org/2001/XMLSchema#>\n" +
"prefix idiom: <http://idiom-projekt.de/schema/>\n" +
"prefix ecrm: <http://erlangen-crm.org/current#>\n" +
"prefix edm: <http://www.europeana.eu/schemas/edm#>\n" +
"prefix form: <http://rdd.sub.uni-goettingen.de/rdfform#>\n" +
"prefix crm: <http://erlangen-crm.org/current/>\n" +
"prefix tgforms: <http://www.tgforms.de/terms#>\n" +
"prefix textgrid: <http://textgridrep.de/>\n" +
"prefix schema: <http://schema.org/>\n" +
"prefix skos: <http://www.w3.org/2004/02/skos/core#>\n" +
"prefix wgs84pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n" +
"prefix rel: <http://purl.org/vocab/relationship/>\n" +
"prefix edm: <http://www.europeana.eu/schemas/edm/>\n" +
"prefix idiomcat: <http://idiom-projekt.de/catalogue/>\n" +
"\n";
public FusekiCRUD() {
accessor = DatasetAccessorFactory.createHTTP("http://localhost:3030/fuseki/metadata");
}
public void create(String tgURI, String rdfXML){
InputStream inStream = new ByteArrayInputStream(rdfXML.getBytes());
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "RDF/XML");
DatasetAccessor accessor;
List<String> artefactUriList = new ArrayList<String>();
List<String> allObjectUriList = new ArrayList<String>();
List<String> allUrisWithMissingCitation = new ArrayList<String>();
List<String> wrongZuriList = new ArrayList<String>();
accessor.add(tgURI, model);
}
String prefixes =
"prefix dct: <http://purl.org/dc/terms#>\n" +
"prefix dc: <http://purl.org/dc/elements/1.1/>\n" +
"prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"prefix owl: <http://www.w3.org/2002/07/owl#>\n" +
"prefix xsd: <http://www.w3.org/2001/XMLSchema#>\n" +
"prefix idiom: <http://idiom-projekt.de/schema/>\n" +
"prefix ecrm: <http://erlangen-crm.org/current#>\n" +
"prefix edm: <http://www.europeana.eu/schemas/edm#>\n" +
"prefix form: <http://rdd.sub.uni-goettingen.de/rdfform#>\n" +
"prefix crm: <http://erlangen-crm.org/current/>\n" +
"prefix tgforms: <http://www.tgforms.de/terms#>\n" +
"prefix textgrid: <http://textgridrep.de/>\n" +
"prefix schema: <http://schema.org/>\n" +
"prefix skos: <http://www.w3.org/2004/02/skos/core#>\n" +
"prefix wgs84pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n" +
"prefix rel: <http://purl.org/vocab/relationship/>\n" +
"prefix edm: <http://www.europeana.eu/schemas/edm/>\n" +
"prefix idiomcat: <http://idiom-projekt.de/catalogue/>\n" +
"\n";
public void update(String tgURI, String rdfXML){
/**
*
*/
public FusekiCRUD() {
this.accessor = DatasetAccessorFactory.createHTTP("http://localhost:3030/fuseki/metadata");
}
this.delete(tgURI);
this.create(tgURI, rdfXML);
/**
* @param tgURI
* @param rdfXML
*/
public void create(String tgURI, String rdfXML) {
}
InputStream inStream = new ByteArrayInputStream(rdfXML.getBytes());
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "RDF/XML");
public void delete(String tgURI) {
accessor.deleteModel(tgURI);
}
this.accessor.add(tgURI, model);
}
public void print() {
Model model = accessor.getModel("textgrid:2r45c");
String graph = model.toString();
InputStream stream = new ByteArrayInputStream(graph.getBytes(StandardCharsets.UTF_8));
model.read(stream, null, "RDF/XML");
}
}
/**
* @param tgURI
* @param rdfXML
*/
public void update(String tgURI, String rdfXML) {
this.delete(tgURI);
this.create(tgURI, rdfXML);
}
/**
* @param tgURI
*/
public void delete(String tgURI) {
this.accessor.deleteModel(tgURI);
}
/**
*
*/
public void print() {
Model model = this.accessor.getModel("textgrid:2r45c");
String graph = model.toString();
InputStream stream = new ByteArrayInputStream(graph.getBytes(StandardCharsets.UTF_8));
model.read(stream, null, "RDF/XML");
}
}
package com.github.hriebl.bdnDatabase;
import info.textgrid.namespaces.metadata.core._2010.GenericType;
import info.textgrid.namespaces.metadata.core._2010.MetadataContainerType;
import info.textgrid.namespaces.metadata.core._2010.ObjectType;
import info.textgrid.namespaces.metadata.core._2010.ProvidedType;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.RelationsExistFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.UpdateConflictFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.tgcrudclient.TGCrudClientUtilities;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......@@ -22,7 +8,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.util.ByteArrayDataSource;
......@@ -43,202 +28,238 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Holder;
import org.apache.cxf.helpers.IOUtils;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import info.textgrid.namespaces.metadata.core._2010.GenericType;
import info.textgrid.namespaces.metadata.core._2010.MetadataContainerType;
import info.textgrid.namespaces.metadata.core._2010.ObjectType;
import info.textgrid.namespaces.metadata.core._2010.ProvidedType;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.RelationsExistFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.UpdateConflictFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.tgcrudclient.TGCrudClientUtilities;
/**
*
*/
@Path("/")
public class Server {
private FusekiCRUD fusekiCRUD;
private TGCrudService tgCRUD;
public Server() throws MalformedURLException{
fusekiCRUD = new FusekiCRUD();
tgCRUD = TGCrudClientUtilities.getTgcrud("https://textgridlab.org/1.0/tgcrud/TGCrudService?wsdl");
}
@POST
@Path("/create")
@Produces("application/ld+json")
public String create(@FormParam("tgSID") String tgSID,
@FormParam("tgPID") String tgPID,
@FormParam("title") String title)
throws AuthFault,
IoFault,
MetadataParseFault,
ObjectNotFoundFault,
UnsupportedEncodingException {
System.out.println("I WANT TO CREATE");
ProvidedType providedMeta = new ProvidedType();
providedMeta.setFormat("text/tg.inputform+rdf+xml");
providedMeta.getTitle().add(title);
GenericType genericMeta = new GenericType();
genericMeta.setProvided(providedMeta);
ObjectType objectMeta = new ObjectType();
objectMeta.setGeneric(genericMeta);
MetadataContainerType metaContainer = new MetadataContainerType();
metaContainer.setObject(objectMeta);
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
tgMeta.value = metaContainer;
String string = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"/>";
DataSource dataSource = new ByteArrayDataSource(string.getBytes("UTF-8"), "UTF-8");
DataHandler tgData = new DataHandler(dataSource);
tgCRUD.create(tgSID, "", null, false, tgPID, tgMeta, tgData);
genericMeta = tgMeta.value.getObject().getGeneric();
String uri = genericMeta.getGenerated().getTextgridUri().getValue();
uri = uri.replaceFirst("\\.[0-9]*$", "");
return "{\"@id\": \"" + uri + "\"}";
private FusekiCRUD fusekiCRUD;
private TGCrudService tgCRUD;
/**
* @throws MalformedURLException
*/
public Server() throws MalformedURLException {
this.tgCRUD =
TGCrudClientUtilities.getTgcrud("https://textgridlab.org/1.0/tgcrud/TGCrudService?wsdl");
}
/**
* @param tgSID
* @param tgPID
* @param title
* @return
* @throws AuthFault
* @throws IoFault
* @throws MetadataParseFault
* @throws ObjectNotFoundFault
* @throws UnsupportedEncodingException
*/
@POST
@Path("/create")
@Produces("application/ld+json")
public String create(@FormParam("tgSID") String tgSID, @FormParam("tgPID") String tgPID,
@FormParam("title") String title) throws AuthFault, IoFault, MetadataParseFault,
ObjectNotFoundFault, UnsupportedEncodingException {
System.out.println("I WANT TO CREATE");
ProvidedType providedMeta = new ProvidedType();
providedMeta.setFormat("text/tg.inputform+rdf+xml");
providedMeta.getTitle().add(title);
GenericType genericMeta = new GenericType();
genericMeta.setProvided(providedMeta);
ObjectType objectMeta = new ObjectType();
objectMeta.setGeneric(genericMeta);
MetadataContainerType metaContainer = new MetadataContainerType();
metaContainer.setObject(objectMeta);
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
tgMeta.value = metaContainer;
String string = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"/>";
DataSource dataSource = new ByteArrayDataSource(string.getBytes("UTF-8"), "UTF-8");
DataHandler tgData = new DataHandler(dataSource);
this.tgCRUD.create(tgSID, "", null, false, tgPID, tgMeta, tgData);
genericMeta = tgMeta.value.getObject().getGeneric();
String uri = genericMeta.getGenerated().getTextgridUri().getValue();
uri = uri.replaceFirst("\\.[0-9]*$", "");
return "{\"@id\": \"" + uri + "\"}";
}
/**
* @param tgURI
* @param tgSID
* @return
* @throws AuthFault
* @throws IOException
* @throws IoFault
* @throws MetadataParseFault
* @throws ObjectNotFoundFault
* @throws ProtocolNotImplementedFault
*/
@GET
@Path("/read/{tgURI}")
@Produces("text/turtle")
public String read(@PathParam("tgURI") String tgURI, @QueryParam("tgSID") String tgSID)
throws AuthFault, IOException, IoFault, MetadataParseFault, ObjectNotFoundFault,
ProtocolNotImplementedFault {
System.out.println("I WANT TO READ");
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
Holder<DataHandler> tgData = new Holder<DataHandler>();
this.tgCRUD.read(tgSID, "", tgURI, tgMeta, tgData);
InputStream inStream = tgData.value.getInputStream();
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "RDF/XML");
OutputStream outStream = new ByteArrayOutputStream();
model.write(outStream, "TURTLE");
System.out.println("I WANT TO READ: " + tgURI);
return outStream.toString();
}
/**
* @param tgURI
* @param tgSID
* @param jsonLD
* @return
* @throws AuthFault
* @throws IOException
* @throws IoFault
* @throws MetadataParseFault
* @throws ObjectNotFoundFault
* @throws UpdateConflictFault
*/
@POST
@Path("/update/{tgURI}")
@Consumes("application/ld+json")
public Response write(@PathParam("tgURI") String tgURI, @QueryParam("tgSID") String tgSID,
String jsonLD) throws AuthFault, IOException, IoFault, MetadataParseFault,
ObjectNotFoundFault, UpdateConflictFault {
System.out.println("I WANT TO UPDATE: " + tgURI);
MetadataContainerType metaContainer = this.tgCRUD.readMetadata(tgSID, "", tgURI);
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
tgMeta.value = metaContainer;
InputStream inStream = new ByteArrayInputStream(jsonLD.getBytes());
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "JSON-LD");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
model.write(outStream, "RDF/XML");
byte[] byteArray = outStream.toByteArray();
String content = new String(outStream.toByteArray());
if (content.contains("idiom:Artefact")) {
tgMeta.value.getObject().getGeneric().getProvided().setNotes("ARTEFACT");
}
DataSource dataSource = new ByteArrayDataSource(byteArray, "UTF-8");
DataHandler tgData = new DataHandler(dataSource);
@GET
@Path("/read/{tgURI}")
@Produces("text/turtle")
public String read(@PathParam("tgURI") String tgURI,
@QueryParam("tgSID") String tgSID)
throws AuthFault,
IOException,
IoFault,
MetadataParseFault,
ObjectNotFoundFault,
ProtocolNotImplementedFault {
System.out.println("I WANT TO READ");
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
Holder<DataHandler> tgData = new Holder<DataHandler>();
tgCRUD.read(tgSID, "", tgURI, tgMeta, tgData);
InputStream inStream = tgData.value.getInputStream();
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "RDF/XML");
OutputStream outStream = new ByteArrayOutputStream();
model.write(outStream, "TURTLE");
System.out.println("I WANT TO READ: " + tgURI);
return outStream.toString();
this.tgCRUD.update(tgSID, "", tgMeta, tgData);
}
@POST
@Path("/update/{tgURI}")
@Consumes("application/ld+json")
public Response write(@PathParam("tgURI") String tgURI,
@QueryParam("tgSID") String tgSID,
String jsonLD)
throws AuthFault,
IOException,
IoFault,
MetadataParseFault,
ObjectNotFoundFault,
UpdateConflictFault {
System.out.println("I WANT TO UPDATE: " + tgURI);
MetadataContainerType metaContainer = tgCRUD.readMetadata(tgSID, "", tgURI);
Holder<MetadataContainerType> tgMeta = new Holder<MetadataContainerType>();
tgMeta.value = metaContainer;
InputStream inStream = new ByteArrayInputStream(jsonLD.getBytes());
Model model = ModelFactory.createDefaultModel();
model.read(inStream, null, "JSON-LD");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
model.write(outStream, "RDF/XML");
byte[] byteArray = outStream.toByteArray();
String content = new String(outStream.toByteArray());
if(content.contains("idiom:Artefact")) {
tgMeta.value.getObject().getGeneric().getProvided().setNotes("ARTEFACT");
}
DataSource dataSource = new ByteArrayDataSource(byteArray, "UTF-8");
DataHandler tgData = new DataHandler(dataSource);
tgCRUD.update(tgSID, "", tgMeta, tgData);
String tgPID = tgMeta.value.getObject().getGeneric().getGenerated().getProject().getId();
if (tgPID.equals("TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) {
String rdfXML = new String(byteArray, "UTF-8");
fusekiCRUD.update(tgURI, rdfXML);
}
return Response.ok().build();
String tgPID = tgMeta.value.getObject().getGeneric().getGenerated().getProject().getId();
if (tgPID.equals("TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) {
String rdfXML = new String(byteArray, "UTF-8");
this.fusekiCRUD.update(tgURI, rdfXML);
}
@DELETE
@Path("/delete/{tgURI}")
public Response delete(@PathParam("tgURI") String tgURI,
@QueryParam("tgSID") String tgSID)
throws AuthFault,
IoFault,
ObjectNotFoundFault,
RelationsExistFault{
tgCRUD.delete(tgSID, "", tgURI);
fusekiCRUD.delete(tgURI);
return Response.ok().build();
}
@GET
@Path("/swb")
@Produces("application/xml")
public String swb(@QueryParam("query") String query)
throws IOException,
MalformedURLException,
TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
query = query.replaceAll(" ", "+");
URL xmlURL = new URL("http://swb.bsz-bw.de/sru/DB=2.1/username=/" +
"password=/?maximumRecords=999&operation=searchRetrieve&" +
"recordSchema=marc21&query=pica.all%3D%22" + query + "%22");
String xmlString = IOUtils.toString(xmlURL.openStream());
xmlString = xmlString.replaceFirst("(srw:searchRetrieveResponse)",
"$1 xmlns=\"http://www.loc.gov/MARC21/slim\"");
InputStream xmlStream = new ByteArrayInputStream(xmlString.getBytes());
Source xmlSource = new StreamSource(xmlStream);
URL xslURL = new URL("http://localhost:9090/marc2mods.xsl");
Source xslSource = new StreamSource(xslURL.openStream());
Transformer transformer = factory.newTransformer(xslSource);
OutputStream stream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(stream);
transformer.transform(xmlSource, result);
return stream.toString();
}
return Response.ok().build();
}
/**
* @param tgURI
* @param tgSID
* @return
* @throws AuthFault
* @throws IoFault
* @throws ObjectNotFoundFault
* @throws RelationsExistFault
*/
@DELETE
@Path("/delete/{tgURI}")
public Response delete(@PathParam("tgURI") String tgURI, @QueryParam("tgSID") String tgSID)
throws AuthFault, IoFault, ObjectNotFoundFault, RelationsExistFault {
this.tgCRUD.delete(tgSID, "", tgURI);
this.fusekiCRUD.delete(tgURI);
return Response.ok().build();
}
/**
* @param query
* @return
* @throws IOException
* @throws MalformedURLException
* @throws TransformerException
*/
@GET
@Path("/swb")
@Produces("application/xml")
public String swb(@QueryParam("query") String query)
throws IOException, MalformedURLException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
query = query.replaceAll(" ", "+");
URL xmlURL = new URL("http://swb.bsz-bw.de/sru/DB=2.1/username=/" +
"password=/?maximumRecords=999&operation=searchRetrieve&" +
"recordSchema=marc21&query=pica.all%3D%22" + query + "%22");
String xmlString = IOUtils.toString(xmlURL.openStream());
xmlString = xmlString.replaceFirst("(srw:searchRetrieveResponse)",
"$1 xmlns=\"http://www.loc.gov/MARC21/slim\"");
InputStream xmlStream = new ByteArrayInputStream(xmlString.getBytes());
Source xmlSource = new StreamSource(xmlStream);
URL xslURL = new URL("http://localhost:9090/marc2mods.xsl");
Source xslSource = new StreamSource(xslURL.openStream());
Transformer transformer = factory.newTransformer(xslSource);
OutputStream stream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(stream);
transformer.transform(xmlSource, result);
return stream.toString();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment