Commit 34c6346a authored by Stefan Funk's avatar Stefan Funk
Browse files

Merge branch 'release/3.5.5'

parents b45f19f7 57e98c29
......@@ -3,3 +3,4 @@
/.classpath
/.project
/bin/
/pom.xml.versionsBackup
......@@ -7,7 +7,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>common</artifactId>
<version>3.4.3</version>
<version>3.5.5</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>cli-tools</artifactId>
......
......@@ -3,3 +3,4 @@
/.classpath
/.project
/bin/
/pom.xml.versionsBackup
......@@ -7,7 +7,7 @@
<parent>
<artifactId>common</artifactId>
<groupId>info.textgrid.middleware</groupId>
<version>3.4.3</version>
<version>3.5.5</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>confclient</artifactId>
......
<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>
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>common</artifactId>
<version>3.5.5</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>const</artifactId>
<name>DARIAHDE :: Common :: Constants</name>
<packaging>jar</packaging>
</project>
/**
* This software is copyright (c) 2021 by
*
* TextGrid Consortium (https://textgrid.de)
*
* DAASI International GmbH (https://daasi.de)
*
* This is free software. You can redistribute it and/or modify it under the terms described in the
* GNU Lesser General Public License v3 of which you should have received a copy. Otherwise you can
* download it from
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright TextGrid Consortium (https://textgrid.de)
* @copyright DAASI International GmbH (https://daasi.de)
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License v3
* @author Stefan E. Funk (stefan.e.funk@daasi.de)
*/
package info.textgrid.middleware.common;
/**
* TODOLOG
*
**
* CHANGELOG
*
*/
/**
* <p>
* Some RDF constants for crud and publish and other services.
* </p>
*
* @author Stefan E. Funk, SUB Göttingen
* @version 2021-03-16
* @since 2021-03-16
*/
public final class RDFConstants {
// **
// STATIC FINALS
// **
public static final String RDF_XML = "RDF/XML";
public static final String TURTLE = "TURTLE";
public static final String NTRIPLES = "NTRIPLES";
public static final String RDF_JSON = "RDF/JSON";
public static final String JSON_LD = "JSON-LD";
public static final String MEDIATYPE_TURTLE = "text/turtle";
public static final String MEDIATYPE_NTRIPLES = "application/n-triples";
public static final String RDFXML_FILE_SUFFIX = ".rdf";
public static final String TTL_FILE_SUFFIX = ".ttl";
public static final String NTRIPLES_FILE_SUFFIX = ".nt";
public static final String RDFJSON_FILE_SUFFIX = ".rj";
public static final String JSONLD_FILE_SUFFIX = ".jsonld";
public static final String RDF_PREFIX = "rdf";
public static final String HDL_PREFIX = "hdl";
public static final String DOI_PREFIX = "doi";
public static final String DC_PREFIX = "dc";
public static final String DCTERMS_PREFIX = "dcterms";
public static final String DARIAH_PREFIX = "dariah";
public static final String DARIAHSTORAGE_PREFIX = "dariahstorage";
public static final String PREMIS_PREFIX = "premis";
public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public static final String HDL_NAMESPACE = "http://hdl.handle.net/";
public static final String DOI_NAMESPACE = "http://dx.doi.org/";
public static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
public static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
public static final String DARIAH_NAMESPACE = "http://de.dariah.eu/rdf/dataobjects/terms/";
public static final String DARIAHSTORAGE_NAMESPACE = "https://de.dariah.eu/storage/";
public static final String PREMIS_NAMESPACE = "http://www.loc.gov/premis/rdf/v1#";
public static final String ELEM_DARIAH_COLLECTION = "Collection";
public static final String ELEM_DARIAH_DATAOBJECT = "DataObject";
public static final String DARIAH_COLLECTION = DARIAH_NAMESPACE + "Collection";
public static final String DARIAH_DATAOBJECT = DARIAH_NAMESPACE + "DataObject";
public static final String ELEM_RDF_TYPE = "type";
public static final String ELEM_RDF_RESOURCE = "resource";
public static final String ELEM_RDF_ABOUT = "about";
public static final String ELEM_RDF_DESCRIPTION = "Description";
public static final String RDF_TYPE = RDF_NAMESPACE + ELEM_RDF_TYPE;
public static final String RDF_DESCRIPTION = RDF_NAMESPACE + ELEM_RDF_DESCRIPTION;
public static final String ELEM_DC_CONTRIBUTOR = "contributor";
public static final String ELEM_DC_COVERAGE = "coverage";
public static final String ELEM_DC_CREATOR = "creator";
public static final String ELEM_DC_DATE = "date";
public static final String ELEM_DC_DESCRIPTION = "description";
public static final String ELEM_DC_FORMAT = "format";
public static final String ELEM_DC_IDENTIFIER = "identifier";
public static final String ELEM_DC_LANGUAGE = "language";
public static final String ELEM_DC_PUBLISHER = "publisher";
public static final String ELEM_DC_RELATION = "relation";
public static final String ELEM_DC_RIGHTS = "rights";
public static final String ELEM_DC_SOURCE = "source";
public static final String ELEM_DC_SUBJECT = "subject";
public static final String ELEM_DC_TITLE = "title";
public static final String ELEM_DC_TYPE = "type";
public static final String ELEM_DCTERMS_HASPART = "hasPart";
public static final String ELEM_DCTERMS_MODIFIED = "modified";
public static final String ELEM_DCTERMS_CREATED = "created";
public static final String ELEM_DCTERMS_FORMAT = "format";
public static final String ELEM_DCTERMS_EXTENT = "extent";
public static final String ELEM_PREMIS_SIZE = "hasSize";
public static final String ELEM_PREMIS_MD = "hasMessageDigest";
public static final String ELEM_PREMIS_MDT = "hasMessageDigestType";
public static final String ELEM_PREMIS_MDO = "hasMessageDigestOriginator";
}
/**
* This software is copyright (c) 2021 by
*
* TextGrid Consortium (https://textgrid.de)
*
* DAASI International GmbH (https://daasi.de)
*
* This is free software. You can redistribute it and/or modify it under the terms described in the
* GNU Lesser General Public License v3 of which you should have received a copy. Otherwise you can
* download it from
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright TextGrid Consortium (https://textgrid.de)
* @copyright DAASI International GmbH (https://daasi.de)
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License v3
* @author Stefan E. Funk (stefan.e.funk@daasi.de)
*/
package info.textgrid.middleware.common;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* TODOLOG
*
* TODO Use Mimetypes from a general registry, where all types used in the TG-lab are gathered and
* registered. Problem: Every Eclipse plugin used in the TG-lab can define their own mimetypes.
*
**
* CHANGELOG
*
* 2017-08-30 - Funk - Added DARIAH-DE collection mimetype.
*
* 2014-06-24 - Funk - Changed Ubbo's and Max's special aggregations.
*
* 2014-04-29 - Funk - Added Ubbo's special Blumenbach aggregation.
*
* 2014-04-14 - Funk - Added Ubbo's special Blumenbach mimetype.
*
* 2013-09-27 - Funk - Added PLAINTEXT to original set.
*
* 2013-04-05 - Funk - Added GIF mimetype and image set.
*
* 2012-09-19 - Funk - Removed HTTP link to TextGrid mimetypes in the internal TextGrid wiki (was
* parsed at compile time).
*
* 2012-03-11 - Funk - Added OCTET_STREAM.
*
* 2012-02-01 - Funk - Added list for objects to put into the original eXist collection.
*
* 2011-02-03 - Funk - Added as maven module to tgcrud.
*
* 2011-01-04 - Funk - First version.
*/
/**
* <p>
* The collection of all mimetypes used in the TG-lab: The strings for the TextGrid content types,
* used for recognition of incoming data files, taken from
* info.textgrid.lab.core.model.contentTypes.
* </p>
*
* @author Stefan E. Funk, DAASI International GmbH
* @version 2021-03-16
* @since 2011-01-04
*/
public final class TextGridMimetypes {
// **
// STATIC FINALS
// **
// Mimetypes from TextGridLab Version 2.0.5, Revision: 201310011243
public static final String AGGREGATION = "text/tg.aggregation+xml";
public static final String EDITION = "text/tg.edition+tg.aggregation+xml";
public static final String COLLATION_SET = "text/collation-set+xml";
public static final String COLLATION_EQUIV = "text/collation-equivs+xml";
public static final String COLLECTION = "text/tg.collection+tg.aggregation+xml";
public static final String XSD = "text/xsd+xml";
public static final String CSS = "text/css";
public static final String PLAINTEXT = "text/plain";
public static final String IMPORT_EXPORT = "text/tg.imex+xml";
public static final String ZIP = "application/zip";
public static final String PROJECTFILE = "text/tg.projectfile+xml";
public static final String UNKNOWN = "unknown/unknown ";
public static final String UNKNOWN_IMAGE = "image/x-unknown";
public static final String WORK = "text/tg.work+xml";
public static final String LINKEDITOR = "text/linkeditorlinkedfile";
public static final String JPEG = "image/jpeg";
public static final String TIFF = "image/tiff";
public static final String PNG = "image/png";
public static final String GIF = "image/gif";
public static final String WORKFLOW = "text/tg.workflow+xml";
public static final String WORKFLOW_GWDL = "text/gwdl.workflow+xml";
public static final String SERVICE_DESCRIPTION = "text/tg.servicedescription+xml";
public static final String XML = "text/xml";
public static final String DTD = "application/xml-dtd";
public static final String XSLT = "text/xml+xslt";
public static final String MEI = "text/mei+xml";
// Vendor specific mimetypes.
public static final String INPUTFORM = "text/tg.inputform+rdf+xml";
public static final String INPUTFORM_AGGREGATION = "text/tg.inputform+tg.aggregation+xml";
// Mimetype for creating ByteArrayDataSources.
public static final String OCTET_STREAM = "application/octet-stream";
// DARIAH-DE Repository mimetypes.
public static final String DARIAH_COLLECTION = "text/vnd.dariah.dhrep.collection+turtle";
// Sets that contains all original, aggregation, and image types.
public static final Set<String> ORIGINAL_SET =
new HashSet<String>(Arrays.asList(XML, MEI, PLAINTEXT, INPUTFORM));
public static final Set<String> AGGREGATION_SET =
new HashSet<String>(Arrays.asList(AGGREGATION, EDITION, COLLECTION, INPUTFORM_AGGREGATION));
public static final Set<String> IMAGE_SET =
new HashSet<String>(Arrays.asList(UNKNOWN_IMAGE, JPEG, TIFF, PNG, GIF));
}
/.classpath
/.project
/.settings/
/pom.xml.versionsBackup
/target/
<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>
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>common</artifactId>
<version>3.5.5</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>dariah-storage-client</artifactId>
<name>DARIAHDE :: Common :: DARIAH-DE Storage Client</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>info.textgrid.middleware</groupId>
<artifactId>const</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
/**
* This software is copyright (c) 2021 by
*
* DARIAH-DE Consortium (https://de.dariah.eu)
*
* This is free software. You can redistribute it and/or modify it under the terms described in the
* download it from
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright DARIAH-DE Consortium (https://de.dariah.eu)
* @license Lesser General Public License v3 (http://www.gnu.org/licenses/lgpl-3.0.txt GNU)
* @author Stefan E. Funk (funk@sub.uni-goettingen.de)
*/
package info.textgrid.middleware.common;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.io.IOUtils;
/**
* @version 2021-03-17
*/
public class DariahStorageClient implements Serializable {
// **
// FINALS
// **
public static final String AUTH_TOKEN = "Authorization";
public static final String TRANSACTION_ID = "X-Transaction-ID";
public static final String BEARER = "bearer ";
public static final String LOCATION = "Location";
public static final String LIST_PATH = "list";
public static final String TOKENINFO_PATH = "auth/info";
public static final String PUBLISH_PATH = "publish";
public static final String UNPUBLISH_PATH = "unpublish";
public static final String CHECKACCESS_PATH = "checkAccess/";
public static final String CHECKACCESS_OPERATION_READ = "read";
public static final String CHECKACCESS_OPERATION_WRITE = "write";
public static final String CHECKACCESS_OPERATION_DELETE = "delete";
private static final long serialVersionUID = 6732445365684360629L;
private static final String LOG = " ";
private static final String STORAGE_SAYS = "Storage says: ";
private static final String ERROR_READING = "Error reading file! " + STORAGE_SAYS;
private static final String ERROR_CREATING = "Error creating file! " + STORAGE_SAYS;
private static final String ERROR_UPDATING = "Error updating file! " + STORAGE_SAYS;
private static final String ERROR_DELETING = "Error deleting file! " + STORAGE_SAYS;
private static final String ERROR_CHECKING_ACCESS = "Error checking access! " + STORAGE_SAYS;
private static final String ERROR_PUBLISHING = "Error publishing file! " + STORAGE_SAYS;;
private static final String ERROR_UNPUBLISING = "Error unpublishing file! " + STORAGE_SAYS;
private static final String ERROR_LISTING = "Error getting object list! " + STORAGE_SAYS;
private static final String ERROR_TOKENINFO = "Error getting token info! " + STORAGE_SAYS;
private static final String UTF8 = "UTF-8";
private static final Level LOGLEVEL = Level.WARNING;
// **
// CLASS
// **
private Client client;
private URI storageUri;
protected Logger defaultLogger;
/**
* @param storageTarget
*/
public DariahStorageClient() {
this.client = ClientBuilder.newClient().property("thread.safe.client", "true");
if (this.defaultLogger == null) {
this.defaultLogger = Logger.getLogger(DariahStorageClient.class.getName());
this.defaultLogger.setLevel(LOGLEVEL);
}
}
/**
* @param is
* @param mimetype
* @param token
* @return
* @throws IOException
*/
public String createFile(InputStream is, String mimetype, String token) throws IOException {
return createFile(is, mimetype, token, null);
}
/**
* @param is
* @param mimetype
* @param token
* @param logID
* @return
* @throws IOException
*/
public String createFile(InputStream is, String mimetype, String token, String logID)
throws IOException {
logID = "[" + logID + "] ";
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
headers = addTokenToHeader(token, headers);
headers = addLogIDToHeader(logID, headers);
this.defaultLogger.log(Level.INFO, logID + headers);
this.defaultLogger.log(Level.INFO, logID + mimetype);
Response response = this.client.target(this.storageUri).request().headers(headers)
.post(Entity.entity(is, mimetype));
this.defaultLogger.log(Level.INFO, logID + response.getStatus());
this.defaultLogger.log(Level.INFO, logID + response.getEntity());
this.defaultLogger.log(Level.INFO, logID + response.readEntity(String.class));
if (response.getStatus() != Status.CREATED.getStatusCode()) {
String message = logID + ERROR_CREATING + response.getStatus() + " "
+ response.getStatusInfo().getReasonPhrase();
this.defaultLogger.log(Level.SEVERE, message);
throw new IOException(message);
}
String location = response.getHeaderString("Location");
this.defaultLogger.log(Level.INFO, logID + location);
return location.substring(location.lastIndexOf("/") + 1);
}
/**
* @param id
* @return
* @throws IOException
*/
public InputStream readFile(String id) throws IOException {
return readFile(id, null, null);
}
/**
* @param id
* @param token
* @return
* @throws IOException
*/
public InputStream readFile(String id, String token) throws IOException {
return readFile(id, token, null);
}
/**
* @param id
* @param token
* @param logID
* @return
* @throws IOException
*/
public InputStream readFile(String id, String token, String logID) throws IOException {
return (InputStream) readResponse(id, token, logID).getEntity();
}
/**
* @param id
* @return
* @throws IOException
*/
public Response readResponse(String id) throws IOException {
return readResponse(id, null, null);
}
/**
* @param id
* @param token
* @return
* @throws IOException
*/
public Response readResponse(String id, String token) throws IOException {
return readResponse(id, token, null);
}
/**
* @param id
* @param token
* @param logID
* @return
* @throws IOException
*/
public Response readResponse(String id, String token, String logID) throws IOException {
Response result = null;
logID = "[" + logID + "] ";
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
headers = addTokenToHeader(token, headers);
headers = addLogIDToHeader(logID, headers);
result = this.client.target(this.storageUri).path(id).request().headers(headers).get();
this.defaultLogger.log(Level.INFO, logID + id + LOG + result.getStatus());
if (result.getStatus() != Status.OK.getStatusCode()) {
String message = logID + id + LOG + ERROR_READING + result.getStatus() + " "
+ result.getStatusInfo().getReasonPhrase();
this.defaultLogger.log(Level.SEVERE, message);
throw new IOException(message);
}
return result;
}
/**
* @param id
* @param is