From 4ee597b4ee70a64616cc474111cb1982ba5480a5 Mon Sep 17 00:00:00 2001 From: Andres Quast Date: Mon, 10 Oct 2022 15:37:19 +0200 Subject: [PATCH] start implementing usage of to.science.core --- app/helper/AmbMappingHelper.java | 63 ++++++ app/helper/LRMIMapper.java | 10 +- build.sbt | 3 +- pom.xml | 325 +++++++++++++++++++++++++++++++ 4 files changed, 397 insertions(+), 4 deletions(-) create mode 100644 app/helper/AmbMappingHelper.java create mode 100644 pom.xml diff --git a/app/helper/AmbMappingHelper.java b/app/helper/AmbMappingHelper.java new file mode 100644 index 00000000..cda05a0a --- /dev/null +++ b/app/helper/AmbMappingHelper.java @@ -0,0 +1,63 @@ +/** + * + */ +package helper; + +import java.io.BufferedReader; +import java.io.StringReader; + +import org.json.JSONObject; + +import actions.Read; +import models.Node; +import to.science.core.modelx.mapper.AmbMapperImpl; + +/** + * @author aquast + * + */ +public class AmbMappingHelper { + + AmbMapperImpl ambMapper = new AmbMapperImpl(); + + /** + * Get a to.science JSONObject from lrmiData within a specific node + * + * @param node + * @return + */ + public JSONObject getJSONObjectFromAmb(Node node) { + JSONObject tosModel = new JSONObject(); + + Read read = new Read(); + String currentLrmiContent = read.readLrmiData(node); + StringReader ambReader = new StringReader(currentLrmiContent); + JSONObject ambObject = parseReader(ambReader); + tosModel = ambMapper.getTosJSONObject(ambObject); + + return tosModel; + } + + /** + * @param ambReader + * @return + */ + private JSONObject parseReader(StringReader ambReader) { + JSONObject ambJSONObj = new JSONObject(); + + try { + BufferedReader bReader = new BufferedReader(ambReader); + StringBuilder jsonStringBuilder = new StringBuilder(); + + String inputStr; + while ((inputStr = bReader.readLine()) != null) + jsonStringBuilder.append(inputStr); + ambJSONObj = new JSONObject(jsonStringBuilder.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + + return ambJSONObj; + } + +} diff --git a/app/helper/LRMIMapper.java b/app/helper/LRMIMapper.java index 77b72755..dac13998 100644 --- a/app/helper/LRMIMapper.java +++ b/app/helper/LRMIMapper.java @@ -80,15 +80,19 @@ public String getLrmiAndLrmifyMetadata(Node n, RDFFormat format, /** * - hole den LRMI-Datenstrom (s. GET /lrmiData) */ - String oldContent = read.readLrmiData(node); + // get the current lrmiData as String + String currentLrmiContent = read.readLrmiData(node); + // String currentTosContent = read. + /** * - wandele ihn nach JsonObject (s. JsonMapper.getTosciencefyLrmi) */ // LRMI-Daten nach JSONObject wandeln JSONObject lrmiJsonContent = new JSONObject(); - if (oldContent != null) { - lrmiJsonContent = new JSONObject(oldContent); + if (currentLrmiContent != null) { + lrmiJsonContent = new JSONObject(currentLrmiContent); } + JSONArray arr = null; JSONObject obj = null; JSONObject subObj = null; diff --git a/build.sbt b/build.sbt index 89d556a1..db3718e6 100644 --- a/build.sbt +++ b/build.sbt @@ -45,7 +45,8 @@ libraryDependencies ++= Seq( "com.fasterxml.jackson.dataformat" %"jackson-dataformat-xml" %"2.6.3", "javax.mail" % "mail" % "1.4.2", "org.apache.lucene" % "lucene-core" % "4.7.2", - "mysql" % "mysql-connector-java" % "8.0.23" + "mysql" % "mysql-connector-java" % "8.0.23", + "io.github.hbz" % "to.science.core" % "1.1.3" ) val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean) diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..58d3ef14 --- /dev/null +++ b/pom.xml @@ -0,0 +1,325 @@ + + + 4.0.0 + de.nrw.hbz.to.science.api + Api + 1.0.0-SNAPSHOT + ToolboxOpenScience-Api + + + UTF-8 + UTF-8 + 1.8 + 1.8 + 1.8 + UTF-8 + 2.12.6 + 2.12 + 2.6.14 + 3.1.0 + 1.0.0 + 1.0.0-rc5 + 1.2.0 + 1.3.15 + + + + org.scala-lang + scala-library + ${scala.version} + + + org.scalatestplus.play + scalatestplus-play_${play2scala.version} + 4.0.1 + test + + + com.typesafe.play + play-server_${play2scala.version} + ${play2.version} + maven-plugin + + + com.typesafe.play + twirl-api_2.12 + ${twirl.version} + + + com.typesafe.play + play-java_${play2scala.version} + ${play2.version} + + + com.typesafe.play + filters-helpers_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-akka-http-server_${play2scala.version} + ${play2.version} + runtime + + + com.typesafe.play + play_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-logback_${play2scala.version} + ${play2.version} + runtime + + + com.typesafe.play + play-ws_${play2scala.version} + ${play2.version} + + + com.google.code.play2-maven-plugin + play2-provider-api + ${play2.plugin.version} + pom + + + com.typesafe.play + play-jdbc_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-jdbc-evolutions_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-test_${play2scala.version} + ${play2.version} + test + + + com.typesafe.play + play-java-forms_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-guice_${play2scala.version} + ${play2.version} + + + com.typesafe.play + play-json_2.12 + ${play2.version} + + + + + com.typesafe.play + play-ahc-ws_${play2scala.version} + ${play2.version} + + + javax.validation + validation-api + 1.1.0.Final + + + com.fasterxml.jackson.core + jackson-core + 2.3.3 + jar + + + com.fasterxml.jackson.core + jackson-databind + 2.3.3 + jar + + + org.eclipse.rdf4j + rdf4j-core + 2.2.2 + pom + + + org.eclipse.rdf4j + rdf4j-rio-api + 2.2.2 + + + javax.el + javax.el-api + 3.0.0 + + + xml-apis + xml-apis + 1.4.01 + + + + net.sf.supercsv + super-csv + 2.4.0 + + + commons-validator + commons-validator + 1.5.1 + + + com.github.jsonld-java + jsonld-java + 0.8.3 + + + javax.xml.bind + jaxb-api + 2.3.0 + + + com.sun.xml.bind + jaxb-core + 2.3.0 + + + com.sun.xml.bind + jaxb-impl + 2.3.0 + + + com.github.hbz.lobid-to-json + lobid-to-json + 0.1.1 + + + + com.wordnik + swagger-core_2.11 + 1.3.8 + + + org.json + json + 20220320 + + + io.github.hbz + to.science.core + 1.1.3 + + + + ${project.basedir}/app + ${project.basedir}/test + + + ${project.basedir}/conf + + + ${project.basedir}/public + public + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + true + true + + + + com.google.code.sbt-compiler-maven-plugin + sbt-compiler-maven-plugin + ${sbt-compiler.plugin.version} + + + default-sbt-compile + + compile + testCompile + + + + + + com.google.code.play2-maven-plugin + play2-maven-plugin + ${play2.plugin.version} + true + + injected + -Dplay.evolutions.db.default.autoApply=true + play.data._ + play.core.j.PlayFormsMagicForJava._ + + + + com.jakewharton.twirl + twirl-maven-plugin + ${twirl.plugin.version} + + ${project.basedir}/app + + + + generate-sources + + compile + + + + + + + + + eclipse + + + + m2e.version + + + + + ${project.basedir}/target-eclipse + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + true + true + 1.8 + 1.8 + + + + default-compile + + compile + + + + default-testCompile + + testCompile + + + + + + + + + \ No newline at end of file