diff --git a/build.sbt b/build.sbt index 1b896fe..800db95 100644 --- a/build.sbt +++ b/build.sbt @@ -31,7 +31,7 @@ val common = crossProject(JSPlatform, JVMPlatform) .settings(commonSettings) .settings( name := "doi-common", - version := "0.4.0", + version := "0.4.1", cpDeploy := { sys.error("Please switch to project doiJVM for deployment") } @@ -46,7 +46,7 @@ lazy val core = project .settings( name := "doi-core", libraryDependencies ++= Seq("io.spray" %% "spray-json" % "1.3.6"), - version := "0.4.1" + version := "0.4.2" ) //the DOI minting web app itself @@ -56,7 +56,7 @@ lazy val doi = crossProject(JSPlatform, JVMPlatform) .settings( name := "doi", version := "0.3.0", - libraryDependencies += "com.typesafe.play" %%% "play-json" % "2.10.0-RC6", + libraryDependencies += "com.typesafe.play" %%% "play-json" % "2.10.0-RC7", ) .jsSettings( name := "doi-js", @@ -74,7 +74,7 @@ lazy val doi = crossProject(JSPlatform, JVMPlatform) "com.typesafe.akka" %% "akka-slf4j" % "2.6.19" cross CrossVersion.for3Use2_13, "ch.qos.logback" % "logback-classic" % "1.1.3", "com.sun.mail" % "jakarta.mail" % "1.6.7", - "se.lu.nateko.cp" %% "views-core" % "0.6.5", + "se.lu.nateko.cp" %% "views-core" % "0.6.7", "se.lu.nateko.cp" %% "cpauth-core" % "0.8.0", ), reStart / baseDirectory := { diff --git a/common/src/main/scala/se/lu/nateko/cp/doi/Doi.scala b/common/src/main/scala/se/lu/nateko/cp/doi/Doi.scala index 743e4a9..5b716dd 100644 --- a/common/src/main/scala/se/lu/nateko/cp/doi/Doi.scala +++ b/common/src/main/scala/se/lu/nateko/cp/doi/Doi.scala @@ -83,7 +83,7 @@ case class DoiMeta( ) } -case class DoiWrapper(attributes: DoiMeta) +case class DoiWrapper(id: Doi, `type`: String, attributes: DoiMeta) case class SingleDoiPayload(data: DoiWrapper) case class DoiListMeta(total: Int, totalPages: Int, page: Int) case class DoiListPayload(data: Seq[DoiWrapper], meta: DoiListMeta) diff --git a/core/src/main/scala/se/lu/nateko/cp/doi/core/DoiClient.scala b/core/src/main/scala/se/lu/nateko/cp/doi/core/DoiClient.scala index 00ca27c..9b0acb1 100644 --- a/core/src/main/scala/se/lu/nateko/cp/doi/core/DoiClient.scala +++ b/core/src/main/scala/se/lu/nateko/cp/doi/core/DoiClient.scala @@ -65,9 +65,9 @@ class DoiClient(conf: DoiClientConfig, doiHttp: DoiHttp)(using ExecutionContext) ) def putMetadata(meta: DoiMeta): Future[Unit] = http - .putPayload( - metaUrl(meta.doi), - SingleDoiPayload(DoiWrapper(meta)).toJson.compactPrint, + .putPayload( + new URL(s"$metaBase"), + SingleDoiPayload(DoiWrapper(id = meta.doi, `type` = "dois", attributes = meta)).toJson.compactPrint, "application/vnd.api+json" ).flatMap(analyzeResponse{ case 200 | 201 => Future.successful(()) diff --git a/core/src/main/scala/se/lu/nateko/cp/doi/core/JsonSupport.scala b/core/src/main/scala/se/lu/nateko/cp/doi/core/JsonSupport.scala index 8ecafac..4a71e76 100644 --- a/core/src/main/scala/se/lu/nateko/cp/doi/core/JsonSupport.scala +++ b/core/src/main/scala/se/lu/nateko/cp/doi/core/JsonSupport.scala @@ -159,7 +159,7 @@ object JsonSupport extends DefaultJsonProtocol{ given RootJsonFormat[DoiMeta] = jsonFormat18(DoiMeta.apply) - given RootJsonFormat[DoiWrapper] = jsonFormat1(DoiWrapper.apply) + given RootJsonFormat[DoiWrapper] = jsonFormat3(DoiWrapper.apply) given RootJsonFormat[SingleDoiPayload] = jsonFormat1(SingleDoiPayload.apply) given RootJsonFormat[DoiListMeta] = jsonFormat3(DoiListMeta.apply) given RootJsonFormat[DoiListPayload] = jsonFormat2(DoiListPayload.apply) diff --git a/core/src/main/scala/se/lu/nateko/cp/doi/core/PlainJavaDoiHttp.scala b/core/src/main/scala/se/lu/nateko/cp/doi/core/PlainJavaDoiHttp.scala index dc33d36..54109f2 100644 --- a/core/src/main/scala/se/lu/nateko/cp/doi/core/PlainJavaDoiHttp.scala +++ b/core/src/main/scala/se/lu/nateko/cp/doi/core/PlainJavaDoiHttp.scala @@ -31,7 +31,7 @@ class PlainJavaDoiHttp( val conn = getConnection(url) conn.setDoOutput(true) conn.setRequestProperty("Content-Type", contentType) - conn.setRequestMethod("PUT") + conn.setRequestMethod("POST") try{ val out = conn.getOutputStream() diff --git a/jvm/src/main/scala/se/lu/nateko/cp/doi/Playground.scala b/jvm/src/main/scala/se/lu/nateko/cp/doi/Playground.scala index bf75993..ec9074e 100644 --- a/jvm/src/main/scala/se/lu/nateko/cp/doi/Playground.scala +++ b/jvm/src/main/scala/se/lu/nateko/cp/doi/Playground.scala @@ -1,12 +1,16 @@ -package se.lu.nateko.cp.doi +// package se.lu.nateko.cp.doi import java.net.URL +import se.lu.nateko.cp.doi.* import akka.actor.ActorSystem import se.lu.nateko.cp.doi.core.DoiClient import se.lu.nateko.cp.doi.core.JsonSupport.given import se.lu.nateko.cp.doi.meta._ import spray.json.* +import se.lu.nateko.cp.doi.core.PlainJavaDoiHttp +import scala.concurrent.Await +import scala.concurrent.duration.Duration @@ -16,12 +20,17 @@ object Playground { import system.dispatcher val config = DoiConfig.getConfig.client - val http = new AkkaDoiHttp(config.member.symbol, config.member.password) - val client = new DoiClient(config, http) + val akkaHttp = new AkkaDoiHttp(config.member.symbol, config.member.password) + val javaHttp = new PlainJavaDoiHttp(Some(config.member.symbol), Some(config.member.password)) + + val akkaClient = new DoiClient(config, akkaHttp) + val javaClient = new DoiClient(config, javaHttp) + + val testDoi = akkaClient.doi("carbonportal") + val testDoi2 = javaClient.doi("MJAP-FD4W") - val testDoi = client.doi("carbonportal") val example = DoiMeta( - doi = testDoi, + doi = testDoi2, creators = Seq( Creator( name = GenericName("ICOS CP"), @@ -40,9 +49,9 @@ object Playground { url = Some("https://www.icos-cp.eu/") ) - val testDoi2 = client.doi("icosdocs") + val testDoi3 = akkaClient.doi("icosdocs") val example2 = DoiMeta( - doi = testDoi2, + doi = testDoi3, creators = Seq( Creator( name = PersonalName("Oleg", "Mirzov"), @@ -61,13 +70,22 @@ object Playground { url = Some("https://docs.icos-cp.eu/") ) - def testCreate = client.putMetadata(example) - def testCreate2 = client.putMetadata(example2) - def testMeta = client.getMetadata(testDoi) + def testCreate = + println("---------------- akka client --------------------------") + Await.ready(akkaClient.putMetadata(example).andThen(res => println(res)), Duration.Inf) + + println("---------------- java client --------------------------") + Await.ready(javaClient.putMetadata(example).map(res => println(res)), Duration.Inf) + + // fut foreach println + // fut.failed.foreach(err => println(err.getMessage)) + + def testCreate2 = akkaClient.putMetadata(example2) + def testMeta = Await.ready(javaClient.getMetadata(testDoi2).andThen(res => println(res)), Duration.Inf) def printPrettyJson(suffix: String): Unit = { - val doi = client.doi(suffix) - val fut = client.getMetadata(doi).map{_ + val doi = akkaClient.doi(suffix) + val fut = akkaClient.getMetadata(doi).map{_ .getOrElse(throw new Exception(s"doi not found: $doi")) .toJson .prettyPrint