Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
72ecfb6
Merge pull request #423 from hbz/EDOZWO-1133
inkuss Sep 6, 2023
b804f42
created new Helper Class RdfHelper & methode RdfHelper.getRdfAsMap()
hadoud Oct 16, 2023
aaebbdf
typo0
hadoud Oct 16, 2023
879e7b7
Added neu methods to class Modify for persisting the new data stream …
hadoud Oct 16, 2023
c49074f
typo1
hadoud Oct 16, 2023
87a8efb
extended of class Node
hadoud Oct 16, 2023
1f656c3
Minimal Changes of classes Modify & Node
hadoud Oct 16, 2023
fccafe6
Added neu methods to class Utils
hadoud Oct 16, 2023
d3494e0
added more debugs
hadoud Oct 20, 2023
ea43f2c
Changed dataType of Resource.updateMetadata() to Object
hadoud Oct 20, 2023
00d9c7c
Changed dataType of Resource.updateMetadata() to Object!
hadoud Oct 20, 2023
9b319df
added more debugs-2
hadoud Oct 20, 2023
98dd48e
converted rdf-map to JsonObject
hadoud Oct 24, 2023
9d4c49f
Persistence of real tosciecne data stream (no dummy)
hadoud Oct 24, 2023
ce7c290
For monographs, the data stream toscience should also be persisted
hadoud Oct 25, 2023
84f6524
Edited Method DataciteClient.mintDoiAtDatacite() so that URL of datac…
hadoud Oct 25, 2023
1430f34
Edited Method DataciteClient.registerMetadataAtDatacite()
hadoud Oct 31, 2023
646ba5e
added debugs to code
hadoud Oct 31, 2023
fde99f0
added neu Repo for Doi-Registration
hadoud Nov 3, 2023
c6a1d62
Correction of the post request at DataciteClient.mintDoiAtDatacite()
hadoud Nov 7, 2023
6b12efb
Merge pull request #424 from hbz/DoiRegistration
hadoud Nov 8, 2023
a07f43e
The DoiResolver should be loaded from the application.conf file
hadoud Nov 8, 2023
114a4de
typo0
hadoud Nov 9, 2023
02c4a7a
Merge pull request #425 from hbz/resolveDOIs
inkuss Nov 9, 2023
4b03927
added new helper class ToscienceHelper & resolved the prefLabels in t…
hadoud Nov 14, 2023
1575293
Method keySet() replaced by names() because keySet() is not available…
hadoud Nov 14, 2023
fc8f332
typo0
hadoud Nov 14, 2023
80e778a
added import to class ToscienceHelper
hadoud Nov 14, 2023
b52ba07
typo1
hadoud Nov 14, 2023
f644489
typo2
hadoud Nov 14, 2023
fd881e0
typo3
hadoud Nov 14, 2023
855cceb
added try catch block to ToscienceHelper.getPrefLabelsResolved()
hadoud Nov 14, 2023
8b9a67b
added debugs to code
hadoud Nov 14, 2023
99bb141
added debugs-2
hadoud Nov 14, 2023
f0e4d60
added debugs-3
hadoud Nov 15, 2023
c2e9fcb
typo4
hadoud Nov 15, 2023
76e05f8
typo5
hadoud Nov 15, 2023
42f9786
Extending the MyLabelMaker.getLabelFromLabelWs() method so that geoc…
hadoud Nov 15, 2023
61cd1f8
typo6
hadoud Nov 16, 2023
5116f62
Revert "typo6"
hadoud Nov 16, 2023
c421843
Revert " Extending the MyLabelMaker.getLabelFromLabelWs() method so t…
hadoud Nov 16, 2023
f41dafe
Labels of geocoordinates should temporarily not be resolved
hadoud Nov 17, 2023
42db895
typo7
hadoud Nov 21, 2023
6c22748
Merge pull request #426 from hbz/persistToscienceDatastreamByMaster
hadoud Nov 21, 2023
777c880
added new helper class KTBLMapperHelper.java
hadoud Nov 22, 2023
8e1e27d
Implement Resource.updateKtbl() & Refactor Code
hadoud Nov 24, 2023
82e9a0f
added required statement to Resource.createObjectWithMetadata()
hadoud Nov 24, 2023
08486df
added try catch blocks to methods in KTBLMapperHelper
hadoud Nov 24, 2023
9513e9a
closed BufferedReader in KTBLMapperHelper.getStringContentFromJsonFile()
hadoud Nov 24, 2023
f87a68d
added IOException to KTBLMapperHelper.getStringContentFromJsonFile()
hadoud Nov 24, 2023
f30acb0
added try catch block to close Bufferedreader in KTBLMapperHelper.get…
hadoud Nov 24, 2023
e206bf1
typo1
hadoud Nov 24, 2023
3ce6e16
parameter correction of the endpoint updateKtbl
hadoud Nov 24, 2023
104b5d3
added debugs
hadoud Nov 27, 2023
3704914
Only the KTBL-Data-Stream should be persisted.
hadoud Nov 27, 2023
d598598
Merge pull request #427 from hbz/persistKtblDatastreamByMaster
inkuss Nov 28, 2023
4ac8c08
Refactor get and set Metadata: Using HashMap for metadataTypes
inkuss Nov 29, 2023
d2f3feb
Refactor get set metadata: Delete & Enrich
inkuss Nov 29, 2023
0431f21
Merge pull request #430 from hbz/refactorGetSetMetadata
inkuss Dec 5, 2023
b17b9a9
Persist the data stream toscience beside data stream ktbl in the endp…
hadoud Dec 8, 2023
018ee59
persist data stream metadata2 beside toscience and ktbl in the endpoi…
hadoud Dec 12, 2023
7f651b2
typo1
hadoud Dec 12, 2023
2b55cc3
added new helper class Metadata2Helper
hadoud Dec 15, 2023
e2a8120
added fileName + ContentType and mapping correction of title by title…
hadoud Dec 15, 2023
bdb197c
Call of enrichMetadata2() in the endpoint Resource.updateKtblAndTos()
hadoud Jan 3, 2024
445bde6
KTBLMapperHelper.getToPersistKtblMetadata() has been optimised
hadoud Jan 5, 2024
397feb8
typo2
hadoud Jan 5, 2024
679e9c3
added resource_id to Data Streams KTBL, Toscience and Metadata2
hadoud Jan 12, 2024
84ce0b2
edited Metadata2Helper.getRdfFromToscience()
hadoud Jan 12, 2024
b85cd7a
mapping of institution (FRL-Sammlung) at metadata2
hadoud Jan 16, 2024
ad9d325
Merge branch 'persistKtblAndTosDatastreamByMasterSles' into persistKt…
inkuss Feb 9, 2024
35e7a7e
Merge pull request #436 from hbz/persistKtblAndTosDatastreamsByMaster
inkuss Feb 9, 2024
f495de9
added id to dataorigin
hadoud Mar 8, 2024
c39d961
Added New path to routes file for updateKtblAndTos-Endpoint
hadoud Mar 8, 2024
b7a054c
Mapping of fields issued & rdfType
hadoud Mar 12, 2024
a69ebb4
Mapping correction of the field issued
hadoud Mar 12, 2024
91e1176
added new class KtblService.java
hadoud Mar 18, 2024
7e362d0
typo1
hadoud Mar 18, 2024
0a1d2dd
added AdHocUriProvider.java
hadoud Mar 20, 2024
f7fe07f
typo2
hadoud Mar 20, 2024
0a8b4e5
added adhocURIs to creators and contributors
hadoud Mar 21, 2024
04c13ff
typo3
hadoud Mar 22, 2024
fed96ae
added usageManual(Hinweise zur Nutzung)
hadoud Mar 22, 2024
1d0f769
redefine Metadata2Helper.cleanString() for usageManual&description
hadoud Mar 22, 2024
e9a7958
redefine Metadata2Helper.cleanString() version_2
hadoud Mar 22, 2024
80e2012
typo3
hadoud Mar 22, 2024
f8b2f7c
Revert "typo3"
hadoud Mar 22, 2024
4b5d176
Revert "redefine Metadata2Helper.cleanString() version_2"
hadoud Mar 22, 2024
9d170dc
redefine Metadata2Helper.cleanString() version_3
hadoud Mar 25, 2024
2e92cc8
redefine Metadata2Helper.cleanString() version_4
hadoud Mar 25, 2024
9fb405a
fundingId will be mapped based on the new structure
hadoud Mar 25, 2024
026a29e
Load the fundigID-Uri in Etiket-DB if required
hadoud Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/actions/Enrich.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static String enrichMetadata2(Node node) {
try {
play.Logger.info("Enrich 2 " + node.getPid());
String metadata = node.getMetadata2();
play.Logger.debug("metadata2 " + metadata);
if (metadata == null || metadata.isEmpty()) {
play.Logger.info("No metadata2 to enrich " + node.getPid());
return "No metadata2 to enrich " + node.getPid();
Expand Down
3 changes: 2 additions & 1 deletion app/actions/Modify.java
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,9 @@ private static List<String> getType(Node node) {
}
}

private String rdfToString(Map<String, Object> result, RDFFormat format) {
public String rdfToString(Map<String, Object> result, RDFFormat format) {
try {
play.Logger.debug("result=" + result.toString());
String rdf = RdfUtils.readRdfToString(
new ByteArrayInputStream(json(result).getBytes("utf-8")),
RDFFormat.JSONLD, format, "");
Expand Down
7 changes: 4 additions & 3 deletions app/archive/fedora/XmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
*
*/
public class XmlUtils {
String doiResolver = Globals.doiResolver;

public static XmlSchemaValidator validator = new XmlSchemaValidator();

Expand Down Expand Up @@ -489,8 +490,8 @@ public Map<String, Object> getLd2Lobidify2DeepGreen(
String doi = node.getTextContent();
play.Logger.debug("DOI: " + doi);
Map<String, Object> publisherVersionDoi = new TreeMap<>();
publisherVersionDoi.put("@id", "https://doi.org/" + doi);
publisherVersionDoi.put("prefLabel", "https://doi.org/" + doi);
publisherVersionDoi.put("@id", doiResolver + "/" + doi);
publisherVersionDoi.put("prefLabel", doiResolver + "/" + doi);
publisherVersions.add(publisherVersionDoi);
}
if (attrib.getNodeValue().equalsIgnoreCase("pmcid")) {
Expand Down Expand Up @@ -922,7 +923,7 @@ else if (elemListCopStatement.getLength() > 0) {
int indexOpen = text.indexOf("(");
int indexClose = text.indexOf(")");
if (indexOpen == -1)
licenseId = "https://doi.org/10.1027/a000001";
licenseId = doiResolver + "/10.1027/a000001";
if (indexOpen >= 0)
licenseId = text.substring(indexOpen + 1, indexClose);
break;
Expand Down
67 changes: 44 additions & 23 deletions app/controllers/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -60,6 +61,7 @@
import authenticate.BasicAuth;
import helper.HttpArchiveException;
import helper.KTBLMapperHelper;
import helper.Metadata2Helper;
import helper.RdfHelper;
import helper.ToscienceHelper;
import helper.WebgatherUtils;
Expand Down Expand Up @@ -546,31 +548,33 @@ public static Promise<Result> updateDeepGreen(@PathParam("pid") String pid,
@ApiOperation(produces = "application/json", nickname = "updateKtbl", value = "updateKtbl", notes = "Updates the ktbl datastream of a resource.", response = Message.class, httpMethod = "PUT")
@ApiImplicitParams({
@ApiImplicitParam(name = "data", value = "data", dataType = "file", required = true, paramType = "body") })
public static Promise<Result> updateKtbl(@PathParam("pid") String pid) {

public static Promise<Result> updateKtblAndTos(@PathParam("pid") String pid) {
return new ModifyAction().call(pid, node -> {
try {

play.Logger.debug("Starting KTBL Mapping");

LinkedHashMap<String, Object> rdf = null;
Node readNode = new Read().readNode(pid);

MultipartFormData body = request().body().asMultipartFormData();
FilePart data = body.getFile("data");

String name = data.getFilename();
play.Logger.debug("FileName=" + name);

if (data == null) {
return (Result) JsonMessage(new Message("Missing File.", 400));
}

/**
* 1.KTBL(Json)***************************************
*/
play.Logger.debug("Starting KTBL Mapping");

String contentOfFile =
KTBLMapperHelper.getStringContentFromJsonFile(data);
play.Logger.debug("contentOfFile=" + contentOfFile);

String ktblMetadata =
KTBLMapperHelper.getToPersistKtblMetadata(contentOfFile);
play.Logger.debug("ktblMetadata=" + ktblMetadata);
String ktblMetadata = KTBLMapperHelper
.getToPersistKtblMetadata(contentOfFile, readNode.getPid());

String result1 = modify.updateMetadata("ktbl", readNode, ktblMetadata);

Expand All @@ -579,25 +583,42 @@ public static Promise<Result> updateKtbl(@PathParam("pid") String pid) {
/**
* 2. TOSCIENCE(Json)***************************************
*/
play.Logger.debug("Starting TOSCIENCE Mapping");

String toscienceMetadata = ToscienceHelper
.getToPersistTosMetadata(contentOfFile, readNode.getPid());

play.Logger.debug("toscienceMetadata=" + toscienceMetadata);

String result2 =
modify.updateMetadata("toscience", readNode, toscienceMetadata);

// String result2 =
// modify.updateMetadata("toscience", readNode, ktblMetadata);
play.Logger.debug("Done TOSCIENCE Mapping");

/**
* 3. METADATA2(rdf)***************************************
* 3. METADATA2(rdf)****************************************
*/
// JSONObject ktblJson = new JSONObject(ktblMetadata);
// Map<String, Object> rdf =
// KTBLMapperHelper.getMapFromJSONObject(ktblJson);
//
// String contentRewrite = modify.rewriteContent(rdf.toString(), pid);
//
// String result3 =
// modify.updateMetadata("metadata2", readNode, contentRewrite);

Globals.fedora.updateNode(readNode);

return JsonMessage(new Message(result1));

play.Logger.debug("Starting METADATA2 Mapping");

rdf = Metadata2Helper
.getRdfFromToscience(new JSONObject(toscienceMetadata), readNode);

play.Logger.debug("rdf=" + rdf.toString());

String rdfContent = modify.rdfToString(
(Map<String, Object>) rdf.get("metadata2"), RDFFormat.NTRIPLES);

play.Logger.debug("rdfContent=" + rdfContent);

String result3 =
modify.updateMetadata("metadata2", readNode, rdfContent);

play.Logger.debug("Done METADATA2 Mapping");

Enrich.enrichMetadata2(readNode);

return JsonMessage(new Message(result1 + result2 + result3));
} catch (Exception e) {
throw new HttpArchiveException(500, e);
}
Expand Down
1 change: 1 addition & 0 deletions app/de/hbz/lobid/helper/JsonConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private Map<String, Object> convert(String subject, Object context,
mainSubjectOfTheResource = subject;
collect(g);
Map<String, Object> result = createMap(g);
play.Logger.debug("result=" + result.toString());
result.put("@context", context);
return result;
}
Expand Down
87 changes: 87 additions & 0 deletions app/helper/AdHocUriProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package helper;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.common.io.Closeables;

import models.Globals;
import play.libs.ws.WSResponse;

/**
* @author aquast
*
* The Class provides a simplified way to create an adHocUri based on a
* new to.science.label Object (formely known as "regal etikett") which
* is required for the lobid metadata format.
*
* Class is based on the method code of Enrich.java
* enrichLRMIData-method simplified in comparisation to this by reducing
* functionality and variables
*/
public class AdHocUriProvider {

private String labelValue = null;

private InputStream inStream;

/**
* @param LabelValue the value for which we like to create an AdHocUri
* @return a AdHocUri representing a newly created to.science.label
*/
public String getAdhocUri(String LabelValue) {

String adHocUri = null;
this.labelValue = LabelValue;

adHocUri = generateNewAdHocUri();

return adHocUri;
}

private String generateNewAdHocUri() {
String adHocUri = null;

play.Logger.debug("Start AdHocUri generation for " + labelValue);

// String encodedValue = labelValue.replace(" ", "+");
try {
String encodedValue =
URLEncoder.encode(labelValue, StandardCharsets.UTF_8.toString())
.replaceAll("\\+", "%20").replaceAll("%21", "!")
.replaceAll("%27", "'").replaceAll("%28", "(")
.replaceAll("%29", ")").replaceAll("%7E", "~");
WSResponse response = play.libs.ws.WS
.url(Globals.zettelUrl + "/localAutocomplete" + "?q=" + encodedValue)
.setFollowRedirects(true).get().get(2000);
inStream = response.getBodyAsStream();
String formsResponseBody =
CharStreams.toString(new InputStreamReader(inStream, Charsets.UTF_8));
Closeables.closeQuietly(inStream);
// fetch annoying errors from to.science.forms service
if (response.getStatus() != 200) {
play.Logger.error(
"to.science.forms service request localAutocomplete fails for "
+ encodedValue + "\nUse URI for setting Label now!");
} else {
// Parse out uri value from JSON structure
JSONArray jFormsResponse = new JSONArray(formsResponseBody);
JSONObject jFormsObject = jFormsResponse.getJSONObject(0);
adHocUri = new String(jFormsObject.getString("value"));
play.Logger.debug("Found adHoc-URI: " + adHocUri);
}
} catch (Exception e) {
play.Logger.error("Content could not be enriched!", e);
throw new RuntimeException("LRMI.json could not be enriched", e);
}

return adHocUri;
}
}
25 changes: 18 additions & 7 deletions app/helper/DataciteClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.sun.jersey.client.urlconnection.HTTPSProperties;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.impl.MultiPartWriter;
import com.typesafe.config.ConfigFactory;

/**
* @author Jan Schnasse
Expand All @@ -45,14 +46,16 @@ public class DataciteClient {
Client webclient = null;
boolean testMode = false;
int status = 200;
String user = Globals.dataCiteUser;
String password = Globals.dataCitePasswd;
// URL of Datacite-Repository(Prod | Test)
String dataciteURL = Globals.datCiteUrl;

/**
* The DataciteClient can mint and register dois via the datacite api
*/
public DataciteClient() {
status = 200;
String user = Globals.dataCiteUser;
String password = Globals.dataCitePasswd;
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
cc.getClasses().add(FormDataMultiPart.class);
Expand Down Expand Up @@ -103,14 +106,18 @@ public void setTestMode(boolean t) {
*/
public String mintDoiAtDatacite(String doi, String objectUrl) {
try {
play.Logger.debug("mintDoiAtDatacite is called");
play.Logger.debug("objectUrl=" + objectUrl);
status = 200;
String url = testMode ? "https://mds.datacite.org/doi?testMode=true"
: "https://mds.datacite.org/doi";
String url =
testMode ? dataciteURL + "/doi?testMode=true" : dataciteURL + "/doi";
WebResource resource = webclient.resource(url);
play.Logger.debug("resource=" + resource.toString());
String postBody = "doi=" + doi + "\nurl=" + objectUrl + "\n";
play.Logger.info("PostBody:\n" + postBody);
play.Logger.debug("PostBody=" + postBody);
String response =
resource.type("application/xml").post(String.class, postBody);
play.Logger.debug("response" + response);
return response;
} catch (UniformInterfaceException e) {
setStatus(e.getResponse().getStatus());
Expand All @@ -125,9 +132,13 @@ public String mintDoiAtDatacite(String doi, String objectUrl) {
*/
public String registerMetadataAtDatacite(Node node, String xml) {
try {
play.Logger.debug("registerMetadataAtDatacite is called");
play.Logger.debug("dataciteURL=" + dataciteURL);
status = 200;
String url = testMode ? "https://mds.datacite.org/metadata?testMode=true"
: "https://mds.datacite.org/metadata";
String url = testMode ? dataciteURL + "/metadata?testMode=true"
: dataciteURL + "/metadata";

play.Logger.debug("url=" + url);
WebResource resource = webclient.resource(url);
String response = resource.type("application/xml;charset=UTF-8")
.post(String.class, xml);
Expand Down
32 changes: 24 additions & 8 deletions app/helper/KTBLMapperHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import play.mvc.Http.MultipartFormData.FilePart;
import org.json.JSONException;
import java.io.IOException;
import models.Globals;

/**
*
Expand Down Expand Up @@ -64,22 +65,37 @@ static public String getStringContentFromJsonFile(FilePart fp) {
* @param allKtblMetadata
* @return required KTBL metadata, which must be persisted
*/
static public String getToPersistKtblMetadata(String contentJsFile) {
static public String getToPersistKtblMetadata(String contentJsFile,
String pid) {

JSONObject wantedKtblMetadata = null;
JSONObject allKtblMetadata = null;

try {
String resource_id =
new String(Globals.protocol + Globals.server + "/resource/" + pid);

allKtblMetadata = new JSONObject(contentJsFile);
wantedKtblMetadata = new JSONObject();
play.Logger.debug("resource_id= " + resource_id);
if (resource_id != null) {
wantedKtblMetadata.put("id", resource_id);
}

wantedKtblMetadata.put("recordingPeriod",
allKtblMetadata.getJSONArray("recordingPeriod"));
wantedKtblMetadata.put("relatedDatasets",
allKtblMetadata.getJSONArray("relatedDatasets"));
wantedKtblMetadata.put("info", allKtblMetadata.get("info"));
if (allKtblMetadata.has("recordingPeriod")) {
wantedKtblMetadata.put("recordingPeriod",
allKtblMetadata.getJSONArray("recordingPeriod"));
}
if (allKtblMetadata.has("relatedDatasets")) {
wantedKtblMetadata.put("relatedDatasets",
allKtblMetadata.getJSONArray("relatedDatasets"));
}
if (allKtblMetadata.has("info")) {
wantedKtblMetadata.put("info", allKtblMetadata.get("info"));
}

} catch (JSONException e) {
play.Logger.debug("JSONException:getToPersistKtblMetadata()");
} catch (Exception e) {
play.Logger.debug("Unable to create JSONObject");
}

return wantedKtblMetadata.toString();
Expand Down
Loading