Commit ffc1d7a2 authored by Stefan Funk's avatar Stefan Funk 🐧
Browse files

Merge branch 'release/10.3.0.37-TG' into main

parents 9fbee8e7 91108a32
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.34-DH</version>
<version>10.3.0.37-TG</version>
</parent>
<artifactId>crud-base</artifactId>
<name>DARIAHDE :: CrudService :: Base</name>
......
/*******************************************************************************
* This software is copyright (c) 2020 by
/**
* This software is copyright (c) 2021 by
*
* TextGrid Consortium (http://www.textgrid.de)
* TextGrid Consortium (https://textgrid.de)
*
* DAASI International GmbH (http://www.daasi.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
......@@ -11,11 +11,11 @@
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright TextGrid Consortium (http://www.textgrid.de)
* @copyright DAASI International GmbH (http://www.daasi.de)
* @copyright TextGrid Consortium (https://textgrid.de)
* @copyright DAASI International GmbH (https://daasi.de)
* @license GNU Lesser General Public License v3 (http://www.gnu.org/licenses/lgpl-3.0.txt)
* @author Stefan E. Funk (stefan.e.funk@daasi.de)
******************************************************************************/
*/
package info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice;
......@@ -56,6 +56,8 @@ import info.textgrid.namespaces.middleware.tgcrud.common.CrudOperations;
**
* CHANGELOG
*
* 2021-06-25 - Funk - Fix bugs #35593 and #31709 (from feature/elastic6).
*
* 2020-04-06 - Funk - Using new (and much faster) EXIF extraction method now.
*
* 2014-12-22 - Funk - Removed extra structure handling, messaging is taking care of that now!
......@@ -258,12 +260,16 @@ public class TGCrudServiceAdaptorManager {
// If an image is ingested, do extract some mandatory EXIF metadata and put it into the
// relations metadata as relations.RDF.Description.
//
// NOTE We do omit all existing RDF part here, because only TG-crud is allowed to put RDF data
// in here, and it is always written from scratch, if applicable!
//
// --------------------------------------------------------------------------------------------
//
else if (TextGridMimetypes.IMAGE_SET.contains(format)) {
// Add all EXIF data we need to the relations metadata RDF type.
try {
// Extract the EXIF data with LTPUtils.
List<String> exifData =
LTPUtils.extractExifImageData(theObject.getData().getInputStream(), theUri, format);
......@@ -275,38 +281,13 @@ public class TGCrudServiceAdaptorManager {
TGCrudServiceExceptions.ioFault("Metadata not omitted");
}
// Get the RDF element from the metadata, if existing, create Jena RDF model.
// Create Jena RDF model for RDF metadata part, put prefixes into the model.
Model model = ModelFactory.createDefaultModel();
RelationType relations = theObject.getMetadata().getObject().getRelations();
// Put prefixes into the model.
model.setNsPrefix(EXIF_NAMESPACE_PREFIX, RELATION_EXIF_NAMESPACE);
model.setNsPrefix(DC_NAMESPACE_PREFIX, RELATION_DC_NAMESPACE);
// If an RDF type is existing in the metadata, read the relations into the model.
if (relations != null) {
JAXBElement<RdfType> rdfType =
new JAXBElement<RdfType>(new QName(TGCrudServiceUtilities.RDF_NAMESPACE, "RDF"),
RdfType.class, relations.getRDF());
StringWriter rdfWriter = new StringWriter();
JAXB.marshal(rdfType, rdfWriter);
String rdfWriterString = rdfWriter.toString();
rdfWriter.close();
// Read the existing RDF into the model.
TGCrudServiceUtilities.serviceLog(CrudService.DEBUG, METH,
READING_INTO_MODEL + " (existing RDF): " + rdfWriterString);
try {
model.read(new StringReader(rdfWriterString), null, RDFConstants.RDF_XML);
} catch (Exception e) {
e.printStackTrace();
}
}
// Create and set new relation type here, if not existing yet.
else {
theObject.getMetadata().getObject().setRelations(new RelationType());
}
// Add relation RDF part to metadata.
theObject.getMetadata().getObject().setRelations(new RelationType());
// Create StringWriter.
StringWriter exifWriter = new StringWriter();
......@@ -322,7 +303,7 @@ public class TGCrudServiceAdaptorManager {
model.read(new StringReader(exifString), null, RDFConstants.NTRIPLES);
// Write model as RDF/XML into the StringWriter.
// Write model as RDF/XML into an RDF StringWriter.
StringWriter rdfWriter = new StringWriter();
model.write(rdfWriter, RDFConstants.RDF_XML, null);
String rdfWriterString = rdfWriter.toString();
......@@ -347,6 +328,10 @@ public class TGCrudServiceAdaptorManager {
// If an XML file is ingested, let the AdaptorManager extract the namespace and the root element
// of the file and put it into the relations metadata as relations.RDF.Description.
//
//
// NOTE Same here: We do omit all existing RDF part here, because only TG-crud is allowed to put
// RDF data in here, and it is always written from scratch, if applicable!
//
// --------------------------------------------------------------------------------------------
//
else if (TextGridMimetypes.XML.equals(format)) {
......@@ -376,39 +361,12 @@ public class TGCrudServiceAdaptorManager {
TGCrudServiceExceptions.ioFault("Metadata not omitted");
}
// Get the RDF element from the metadata, if existing, create Jena RDF model.
// Create Jena RDF model, put prefix into the model.
Model model = ModelFactory.createDefaultModel();
RelationType relations = theObject.getMetadata().getObject().getRelations();
// Put prefix into the model.
model.setNsPrefix(TG_NAMESPACE_PREFIX, RELATION_TEXTGRID_NAMESPACE);
// If an RDF type is existing in the metadata, and not null, read its relations into the
// model.
if (relations != null) {
if (relations.getRDF() != null) {
JAXBElement<RdfType> rdfType =
new JAXBElement<RdfType>(new QName(TGCrudServiceUtilities.RDF_NAMESPACE, "RDF"),
RdfType.class, relations.getRDF());
StringWriter rdfWriter = new StringWriter();
JAXB.marshal(rdfType, rdfWriter);
String rdfWriterString = rdfWriter.toString();
rdfWriter.close();
// Read the existing RDF into the model.
model.read(new StringReader(rdfWriterString), null, RDFConstants.RDF_XML);
TGCrudServiceUtilities.serviceLog(CrudService.DEBUG, METH,
"RDF/XML read into Jena model: " + rdfWriter.toString());
} else {
TGCrudServiceUtilities.serviceLog(CrudService.DEBUG, METH,
"No RDF types existing in relations metadata.");
}
}
// Create and set new relation type here, if not existing yet.
else {
theObject.getMetadata().getObject().setRelations(new RelationType());
}
// Create and set new relation type here.
theObject.getMetadata().getObject().setRelations(new RelationType());
// Create StringWriter.
StringWriter n3Writer = new StringWriter();
......@@ -434,14 +392,12 @@ public class TGCrudServiceAdaptorManager {
RdfType rdf = JAXB.unmarshal(new StringReader(rdfWriterString), RdfType.class);
theObject.getMetadata().getObject().getRelations().setRDF(rdf);
TGCrudServiceUtilities.serviceLog(CrudService.INFO, METH,
"Added QName to relations");
TGCrudServiceUtilities.serviceLog(CrudService.INFO, METH, "Added QName to relations");
} catch (Exception e) {
addWarning("Extracting QName from XML data failed: " + e.getMessage(), warningList);
e.printStackTrace();
}
}
//
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.34-DH</version>
<version>10.3.0.37-TG</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud-common</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.34-DH</version>
<version>10.3.0.37-TG</version>
</parent>
<artifactId>crudclient-online</artifactId>
<name>DARIAHDE :: CrudClient :: Online Tests</name>
......
......@@ -69,7 +69,7 @@ import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.DHCrudS
* </p>
*
* @author Stefan E. Funk, SUB Göttingen
* @version 2021-04-16
* @version 2021-05-21
* @since 2018-04-27
**/
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.34-DH</version>
<version>10.3.0.37-TG</version>
</parent>
<artifactId>dhcrud-api</artifactId>
<name>DARIAHDE :: DHCrudService :: API</name>
......
/**
* This software is copyright (c) 2021 by
*
* DARIAH-DE Consortium (https://de.dariah.eu)
*
......@@ -92,6 +91,12 @@ public interface DHCrudService {
public static final String SEAFILE_TOKEN = "X-Seafile-Token";
public static final String TRANSACTION_ID = "X-Transaction-ID";
public static final String APPLICATION_ZIP = "application/x-zip-compressed";
// General PID and DOI syntax.
public static final String PID_AND_DOI_REGEXP =
"[0-9]{2}\\.[a-zA-Z0-9]+\\/[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{1}";
// The GWDG Handle PID syntax, using institution ID 21.
public static final String GWDG_HANDLE_PID_REGEXP =
"^21\\.[a-zA-Z0-9]+\\/[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{1}$";
// **
// METHOD DECLARATIONS
......@@ -169,7 +174,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.WILDCARD)
@Path("/{pid: .+}/data")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/data")
public Response read(final @PathParam(PARAM_PID) URI pid,
final @QueryParam(PARAM_OFFSET) long offset, final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -183,8 +188,8 @@ public interface DHCrudService {
* @return HTTP response with DC metadata TURTLE.
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/metadata")
@Produces(MediaType.TEXT_PLAIN)
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata")
public Response readMetadata(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -199,7 +204,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/metadata/xml")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata/xml")
public Response readMetadataRDF(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -214,7 +219,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/{pid: .+}/metadata/ttl")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata/ttl")
public Response readMetadataTTL(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -229,7 +234,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/{pid: .+}/metadata/ntriples")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata/ntriples")
public Response readMetadataNTRIPLES(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -244,7 +249,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{pid: .+}/metadata/json")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata/json")
public Response readMetadataJSON(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -259,7 +264,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{pid: .+}/metadata/jsonld")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/metadata/jsonld")
public Response readMetadataJSONLD(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -274,7 +279,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/adm")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm")
public Response readAdmMD(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -289,7 +294,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/{pid: .+}/adm/ttl")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm/ttl")
public Response readAdmMDTTL(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -304,7 +309,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/adm/xml")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm/xml")
public Response readAdmMDRDF(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -319,7 +324,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{pid: .+}/adm/json")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm/json")
public Response readAdmMDJSON(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -334,7 +339,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/{pid: .+}/adm/ntriples")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm/ntriples")
public Response readAdmMDNTRIPLES(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -349,7 +354,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{pid: .+}/adm/jsonld")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/adm/jsonld")
public Response readAdmMDJSONLD(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -364,7 +369,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/tech")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/tech")
public Response readTechMD(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -379,7 +384,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("/{pid: .+}/prov")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/prov")
public Response readProvMD(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -394,7 +399,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/{pid: .+}/index")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/index")
public Response readIndex(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -409,7 +414,7 @@ public interface DHCrudService {
*/
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/{pid: .+}/landing")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/landing")
public Response readLanding(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -424,7 +429,7 @@ public interface DHCrudService {
*/
@GET
@Produces(APPLICATION_ZIP)
@Path("/{pid: .+}/bag")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/bag")
public Response readBag(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -439,7 +444,7 @@ public interface DHCrudService {
*/
@GET
@Produces(APPLICATION_ZIP)
@Path("/{pid: .+}/bag/pack")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/bag/pack")
public Response readBagPack(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -457,7 +462,7 @@ public interface DHCrudService {
* @return HTTP response with the object as Bagit Bag ZIP.
*/
@GET
@Path("/{pid: .+}")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}")
public Response readRoot(final @PathParam(PARAM_PID) URI pid,
final @HeaderParam("Accept") String accept, final @HeaderParam(TRANSACTION_ID) String logID);
......@@ -484,7 +489,7 @@ public interface DHCrudService {
* @return HTTP response of the update message sending call.
*/
@GET
@Path("/{pid: .+}/recache")
@Path("/{pid: " + PID_AND_DOI_REGEXP + "}/recache")
public Response recache(@PathParam(PARAM_PID) URI pid,
final @HeaderParam(TRANSACTION_ID) String logID);
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.34-DH</version>
<version>10.3.0.37-TG</version>
</parent>
<artifactId>dhcrud-base</artifactId>
<name>DARIAHDE :: DHCrudService :: Base</name>
......@@ -23,6 +23,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-openapi-v3</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>info.textgrid.middleware</groupId>
<artifactId>dhcrud-api</artifactId>
......@@ -46,6 +51,13 @@
<dependency>
<groupId>info.textgrid.middleware</groupId>
<artifactId>dariah-storage-client</artifactId>
<exclusions>
<!-- Remove all the old jackson 2.4 things! -->
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
<version>${common.version}</version>
</dependency>
<dependency>
......@@ -97,10 +109,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>io.swagger.core.v3</groupId> <artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version> </dependency> <dependency> <groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId> <version>${swagger.version}</version>
</dependency> -->
</dependencies>
<build>
<plugins>
......
......@@ -105,7 +105,6 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
public static final String ORCID_PREFIX = "orcid:";
public static final String GND_PREFIX = "gnd:";
public static final String PND_PREFIX = "pnd:";
public static final String PID_REGEXP = "^21.[a-zA-Z0-9]+/[-a-zA-Z0-9]+$";
public static final String DEPRECATED_DOI_PREFIX = "10.5072";
public static final int ORCID_NAME_HASHMAP_MAX_SIZE = 111;
public static final String HANDLE_DELETED_TYPE = "DELETED";
......@@ -540,9 +539,9 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
}
// Else throw exception.
else {
String message = "WRONG PREFIX! " + theUri
+ " is not a HDL or DOI of this service. Please check your prefixes to be " + thePidPrefix
+ " or " + theDoiPrefix + ".";
String message =
"WRONG PID PREFIX! " + theUri + " is not a HDL or DOI of this service, only prefixes "
+ thePidPrefix + " or " + theDoiPrefix + " are served here!";
throw new ParseException(message, 42);
}
......@@ -553,31 +552,38 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
}
// Check if the given Handle URI has got the syntax: 21.T11991/0000-0008-BB04-1.
if (!checkHandlePIDSyntax(result)) {
String message = "WRONG PID SYNTAX! " + theUri + " is not a valid Handle PID!";
throw new ParseException(message, 43);
}
// FIXME Can safely be removed --> PIDs and DOIs are checked via regexp in DHCrudService REST
// API!
// if (!checkHandlePIDSyntax(result)) {
// String message = "WRONG PID SYNTAX! " + theUri + " is not a valid Handle PID!";
// throw new ParseException(message, 43);
// }
return result;
}
/**
* <p>
* Test the PID for correct Handle PID syntax as following: 21.T11991/0000-0008-BB04-1.
* Test the PID for correct GWDG Handle PID syntax as following: 21.T11991/0000-0008-BB04-1
* </p>
*
* @param thePid
* @return
*/
public static boolean checkHandlePIDSyntax(URI thePid) {
return thePid.toString().matches(DHCrudService.GWDG_HANDLE_PID_REGEXP);
}
boolean result = false;
if (thePid.toString().matches(PID_REGEXP)) {
result = true;
}
return result;
/**
* <p>
* Test the DOI for correct syntax as following: 10.20375/0000-0008-BB04-1
* </p>
*
* @param thePid
* @return
*/
public static boolean checkPIDAndDOISyntax(URI thePid) {
return thePid.toString().matches(DHCrudService.PID_AND_DOI_REGEXP);
}
/**
......
......@@ -388,6 +388,11 @@ public class TestDHCrudServiceUtilities {
}
}
String[] ids = {
"21.T11991/0000-000E-F1B4-6", "10.5072/0000-000E-F1B4-6",
"21.11113/0000-000B-CAC4-4", "10.20375/0000-000B-CAC4-4"};
/**
*
*/
......@@ -402,7 +407,6 @@ public class TestDHCrudServiceUtilities {
assertTrue(false);
}
// Lowercase Handle.
handlePID = URI.create("21.t11991/0000-0008-bb04-1");
correct = DHCrudServiceUtilities.checkHandlePIDSyntax(handlePID);
......@@ -411,11 +415,60 @@ public class TestDHCrudServiceUtilities {
assertTrue(false);
}
// DOI.
// Uppercase DOI.
URI doiPID = URI.create("10.20375/0000-0008-BB04-1");
correct = DHCrudServiceUtilities.checkHandlePIDSyntax(doiPID);