Commit 9fbee8e7 authored by Stefan Funk's avatar Stefan Funk 🐧
Browse files

Merge branch 'release/10.3.0.34-DH' into main

parents 0d5b8663 ed5f4fb3
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>crud-base</artifactId>
<name>DARIAHDE :: CrudService :: Base</name>
......
......@@ -162,11 +162,20 @@ public interface CrudServiceIdentifier {
boolean unlockInternal(URI theUri) throws IoFault;
/**
* @param theUri
* @param theType
* @return
* @throws IoFault
* @throws MetadataParseFault
* <p>
* Example, if existing (CREATED):
* {"responseCode":1,"handle":"21.T11991/0000-001B-4222-2","values":[{"index":17,"type":"PUBLISHED","data":{"format":"string","value":"true"},"ttl":86400,"timestamp":"2021-04-19T12:21:08Z"}]}
* </p>
* <p>
* Example, if not existing (DELETED):
* {"responseCode":200,"values":[],"handle":"21.T11991/0000-001B-48B5-6"}
* </p>
*
* @param theUri The PID of the resource.
* @param theType Any Handle metadata type (such as BAG, DELETED, PUBLISHED, or CREATOR)
* @return The JSON string value of the given type metadata, if existing.
* @throws IoFault If something went wrong.
* @throws MetadataParseFault If Handle metadata of given type is NOT existing.
*/
abstract String getHandleMetadata(final URI theUri, final String theType)
throws IoFault, MetadataParseFault;
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</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.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>crudclient-online</artifactId>
<name>DARIAHDE :: CrudClient :: Online Tests</name>
......
......@@ -18,6 +18,7 @@ package info.textgrid.namespaces.middleware.tgcrud.clients.crudclient.dhtest;
import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
......@@ -79,8 +80,8 @@ public class TestDHCrudServiceOnline {
// STATIC FINALS
// **
// private static final String propertiesFile = "dhcrud.test.properties";
private static final String propertiesFile = "dhcrud.test.trep-de-dariah-eu.properties";
private static final String propertiesFile = "dhcrud.test.properties";
// private static final String propertiesFile = "dhcrud.test.trep-de-dariah-eu.properties";
// private static final String propertiesFile =
// "dhcrud.test.dhrepworkshop-de-dariah-eu.properties";
// private static final String propertiesFile = "dhcrud.test.repository-de-dariah-eu.properties";
......@@ -121,10 +122,12 @@ public class TestDHCrudServiceOnline {
// **
/**
* @throws IOException
* @throws FileNotFoundException
* @throws Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
public static void setUpBeforeClass() throws FileNotFoundException, IOException {
System.out.println("System's default charset: " + Charset.defaultCharset().displayName());
......@@ -320,11 +323,11 @@ public class TestDHCrudServiceOnline {
// Test DOI.
URI doiURI = URI.create(doiPrefix + "/" + xmlObjectSuffix);
readMetadata(name, doiURI, path, MediaType.TEXT_PLAIN);
readMetadata(name, doiURI, path, MediaType.TEXT_XML);
// Test HDL.
URI hdlURI = URI.create(hdlPrefix + "/" + xmlObjectSuffix);
readMetadata(name, hdlURI, path, MediaType.TEXT_PLAIN);
readMetadata(name, hdlURI, path, MediaType.TEXT_XML);
}
/**
......@@ -440,11 +443,11 @@ public class TestDHCrudServiceOnline {
// Test DOI.
URI doiURI = URI.create(doiPrefix + "/" + xmlObjectSuffix);
readAdministrativeMetadata(name, doiURI, path, MediaType.TEXT_PLAIN);
readAdministrativeMetadata(name, doiURI, path, MediaType.TEXT_XML);
// Test HDL.
URI hdlURI = URI.create(hdlPrefix + "/" + xmlObjectSuffix);
readAdministrativeMetadata(name, hdlURI, path, MediaType.TEXT_PLAIN);
readAdministrativeMetadata(name, hdlURI, path, MediaType.TEXT_XML);
}
/**
......@@ -1106,7 +1109,7 @@ public class TestDHCrudServiceOnline {
if (thePath.equals("/metadata")) {
r = dhcrud.readMetadata(theURI, LOGID);
} else if (thePath.equals("/metadata/xml")) {
r = dhcrud.readMetadata(theURI, LOGID);
r = dhcrud.readMetadataRDF(theURI, LOGID);
} else if (thePath.equals("/metadata/ttl")) {
r = dhcrud.readMetadataTTL(theURI, LOGID);
} else if (thePath.equals("/metadata/json")) {
......@@ -1157,7 +1160,7 @@ public class TestDHCrudServiceOnline {
if (thePath.equals("/adm")) {
r = dhcrud.readAdmMD(theURI, LOGID);
} else if (thePath.equals("/adm/xml")) {
r = dhcrud.readAdmMD(theURI, LOGID);
r = dhcrud.readAdmMDRDF(theURI, LOGID);
} else if (thePath.equals("/adm/ttl")) {
r = dhcrud.readAdmMDTTL(theURI, LOGID);
} else if (thePath.equals("/adm/json")) {
......@@ -1435,6 +1438,8 @@ public class TestDHCrudServiceOnline {
private static void testGeneralHTTPHeaders(MultivaluedMap<String, Object> theHeaders,
String theExpectedContentType) {
System.out.println("\tAll HTTP headers: " + theHeaders);
if (theExpectedContentType != null) {
String type = theHeaders.get(HttpHeaders.CONTENT_TYPE).get(0).toString();
......@@ -1450,8 +1455,8 @@ public class TestDHCrudServiceOnline {
if (!theExpectedContentType.equals(type.toString())) {
assertTrue(type + " is NOT the expected one: " + theExpectedContentType, false);
}
System.out.println("\tContent-Type: " + theHeaders.get("Content-Type"));
System.out.println("\tContent-Length: " + theHeaders.get("Content-Length"));
System.out.println("\tContent-Type: " + theHeaders.get(HttpHeaders.CONTENT_TYPE));
System.out.println("\tContent-Length: " + theHeaders.get(HttpHeaders.CONTENT_LENGTH));
}
if (!theHeaders.toString().contains(HttpHeaders.LAST_MODIFIED)
......@@ -1463,24 +1468,7 @@ public class TestDHCrudServiceOnline {
// anyhow! Server-side headers are ok!
System.out.println("\tX-Clacks-Overhead: " + theHeaders.get("X-Clacks-Overhead"));
// System.out.println("\tGeneral HTTP headers OK: " + theHeaders);
}
/**
* @param theStream
* @throws IOException
*/
private static void doReadNPrint(final Response theR) throws IOException {
InputStream i = theR.readEntity(InputStream.class);
byte[] b = new byte[256];
System.out.print("\t");
while (i.available() > 0) {
i.read(b);
System.out.print(".");
}
i.close();
System.out.println();
System.out.println("\tHTTP headers OK");
}
}
......@@ -123,7 +123,7 @@ public class TestTGCrudServiceOnline {
// ** SET PROPERTIES FILE BELOW!
//
private static final String PROPERTIES_FILE = "tgcrud.test.dev-textgridlab-org.properties";
private static final String PROPERTIES_FILE = "tgcrud.test.test-textgridlab-org.properties";
//
// ** SET PROPERTIES FILE ABOVE!
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>dhcrud-api</artifactId>
<name>DARIAHDE :: DHCrudService :: API</name>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>dhcrud-base</artifactId>
<name>DARIAHDE :: DHCrudService :: Base</name>
......
......@@ -21,6 +21,7 @@ package info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice;
import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -29,6 +30,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.codehaus.jettison.json.JSONException;
import info.textgrid.middleware.common.LTPUtils;
import info.textgrid.middleware.pid.api.TGPidService;
......@@ -236,18 +238,21 @@ public class DHCrudServiceIdentifierPidImpl extends CrudServiceIdentifierAbs {
result =
thePidService.getHandleMetadata(uriWithoutPrefix, this.conf.getIDsERVICEpASS(), theType);
if (result != null) {
// Look for type metadata, throw error if not existing.
boolean typeExisting = DHCrudServiceUtilities.checkTypeInHandleMetadata(result, theType);
if (typeExisting) {
return result;
} else {
String message = "No Handle metadata type=" + theType + " existing for " + theUri;
throw new MetadataParseFault(message);
}
} catch (AuthenticationException | WebApplicationException | IOException e) {
} catch (AuthenticationException | WebApplicationException | IOException | JSONException
| ParseException e) {
String message = "Error checking PID metadata type=" + theType + " for " + theUri.toString()
+ " due to a " + e.getClass().getName() + ": " + e.getMessage();
// TGCrudServiceUtilities.serviceLog(CrudService.ERROR, meth, message);
TGCrudServiceUtilities.serviceLog(CrudService.ERROR, meth, message);
throw new IoFault(message);
}
......
......@@ -818,7 +818,7 @@ public class DHCrudServiceStorageDariahImpl extends CrudStorageAbs<Model> {
*/
protected static Response getBagResponsePublic(final URI thePid, URL theHandleResolverUrl,
String theLogID) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException,
IoFault, IOException, URISyntaxException, ParseException {
IoFault, URISyntaxException, ParseException, IOException {
// Get relocated object response.
Response result =
......@@ -1054,10 +1054,8 @@ public class DHCrudServiceStorageDariahImpl extends CrudStorageAbs<Model> {
* @param theLocation
* @param theLogID
* @return
* @throws IOException
*/
private static Response getPublicStorageBagResponse(URI theLocation, String theLogID)
throws IOException {
private static Response getPublicStorageBagResponse(URI theLocation, String theLogID) {
return storageClient
.setStorageUri(URI.create(theLocation.getScheme() + "://" + theLocation.getHost()))
.readResponse(theLocation.getPath(), NO_TOK, theLogID);
......@@ -1350,7 +1348,7 @@ public class DHCrudServiceStorageDariahImpl extends CrudStorageAbs<Model> {
URI location = getBagURL(thePid, theConf.getPIDrESOLVER(), theLogID);
DHCrudServiceImpl.log(DHCrudServiceImpl.DEBUG, theMethodInfo,
"Downloading temp ZIP bag to " + zipTempFile.getCanonicalPath());
"Downloading temp ZIP bag to " + zipTempFile.getCanonicalPath(), theLogID);
FileOutputStream out = new FileOutputStream(zipTempFile);
InputStream in = DHCrudServiceStorageDariahImpl.getBagStreamPublic(location, theLogID);
......
......@@ -1073,12 +1073,12 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
}
/**
* @param thePid
* @param theJSONDeletedMetadata
* @return
* @throws JSONException
* @throws ParseException
*/
protected static Date getTimestampFromHandleMetadata(String theJSONDeletedMetadata)
protected static Date getTimestampFromHandleMetadata(final String theJSONDeletedMetadata)
throws JSONException, ParseException {
Date result = null;
......@@ -1101,12 +1101,12 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
}
/**
* @param thePid
* @param theJSONDeletedMetadata
* @return
* @throws JSONException
* @throws ParseException
*/
protected static String getCitationFromHandleMetadata(String theJSONDeletedMetadata)
protected static String getCitationFromHandleMetadata(final String theJSONDeletedMetadata)
throws JSONException, ParseException {
String result = null;
......@@ -1126,4 +1126,31 @@ public class DHCrudServiceUtilities extends CrudServiceUtilities {
return result;
}
/**
* @param theJSONDeletedMetadata
* @param theType
* @return
* @throws JSONException
* @throws ParseException
*/
protected static boolean checkTypeInHandleMetadata(final String theJSONTypeMetadata,
final String theType) throws JSONException, ParseException {
boolean result = false;
JSONObject jsonTypeMetadata = new JSONObject(theJSONTypeMetadata);
if (jsonTypeMetadata.has("values")) {
JSONArray values = jsonTypeMetadata.getJSONArray("values");
for (int i = 0; i < values.length(); i++) {
JSONObject o = values.getJSONObject(i);
if (o.has("type") && o.getString("type").equals(theType)) {
result = true;
break;
}
}
}
return result;
}
}
......@@ -12,7 +12,6 @@ import org.apache.cxf.helpers.IOUtils;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.lang.extra.javacc.ParseException;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.junit.Test;
import info.textgrid.middleware.common.RDFConstants;
import info.textgrid.middleware.common.RDFUtils;
......
......@@ -638,4 +638,39 @@ public class TestDHCrudServiceUtilities {
}
}
/**
* @throws JSONException
* @throws ParseException
*/
@Test
public void testCheckTypeInHandleMetadataNotExisting() throws JSONException, ParseException {
String emptyJSONString =
"{\"responseCode\":200,\"values\":[],\"handle\":\"21.T11991/0000-001B-48B5-6\"}";
String type = "DELETED";
boolean typeExisting = DHCrudServiceUtilities.checkTypeInHandleMetadata(emptyJSONString, type);
if (typeExisting) {
assertTrue(false);
}
}
/**
* @throws JSONException
* @throws ParseException
*/
@Test
public void testCheckTypeInHandleMetadataExisting() throws JSONException, ParseException {
String publishedTypeJSONString =
"{\"responseCode\":1,\"handle\":\"21.T11991/0000-001B-4222-2\",\"values\":[{\"index\":17,\"type\":\"PUBLISHED\",\"data\":{\"format\":\"string\",\"value\":\"true\"},\"ttl\":86400,\"timestamp\":\"2021-04-19T12:21:08Z\"}]}";
String type = "PUBLISHED";
boolean typeExisting =
DHCrudServiceUtilities.checkTypeInHandleMetadata(publishedTypeJSONString, type);
if (!typeExisting) {
assertTrue(false);
}
}
}
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>dhcrud-webapp-public</artifactId>
<name>DARIAHDE :: DHCrudService :: Public Web Application</name>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>dhcrud-webapp</artifactId>
<name>DARIAHDE :: DHCrudService :: Web Application</name>
......
......@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
<packaging>pom</packaging>
<name>DARIAHDE :: CrudService</name>
<properties>
......@@ -21,7 +21,7 @@
<log4j.version>1.2.16</log4j.version>
<surefire.version>2.13</surefire.version>
<elasticsearch.version>1.7.5</elasticsearch.version>
<common.version>3.5.5</common.version>
<common.version>3.6.2</common.version>
<pid.version>5.3.0</pid.version>
<tgauth.version>1.9.10</tgauth.version>
<wildfly.version>8.1.0.Final</wildfly.version>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>tgcrud-adaptormanager</artifactId>
<name>DARIAHDE :: TGCrudService :: AdaptorManager</name>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>tgcrud-api</artifactId>
<name>DARIAHDE :: TGCrudService :: API</name>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>crud</artifactId>
<version>10.3.0.32-DH</version>
<version>10.3.0.34-DH</version>
</parent>
<artifactId>tgcrud-client</artifactId>
<name>DARIAHDE :: TGCrudService :: Client</name>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment