Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt draft DOI request to Datacite API #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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 := {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/se/lu/nateko/cp/doi/Doi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions core/src/main/scala/se/lu/nateko/cp/doi/core/DoiClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
42 changes: 30 additions & 12 deletions jvm/src/main/scala/se/lu/nateko/cp/doi/Playground.scala
Original file line number Diff line number Diff line change
@@ -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



Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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
Expand Down