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 c01e7c1..52926ea 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 @@ -16,11 +16,11 @@ class DoiClient(config: DoiClientConfig, http: DoiHttp)(implicit ctxt: Execution val metaBase: URL = new URL(config.restEndpoint, "dois") def clientDois(query: String, page: Int): URL = new URL( //TODO Move page size into the API, too - s"${config.restEndpoint}dois?query=${URLEncoder.encode(query, "UTF-8")}&client-id=${config.symbol.toLowerCase()}&page[size]=25&page[number]=$page" + s"${config.restEndpoint}dois?query=${URLEncoder.encode(query, "UTF-8")}&client-id=${config.symbol.toLowerCase()}&page[size]=25&page[number]=$page&affiliation=true" ) def doi(suffix: String): Doi = Doi(config.doiPrefix, suffix) - def metaUrl(doi: Doi) = new URL(s"$metaBase/$doi") + def metaUrl(doi: Doi) = new URL(s"$metaBase/${doi}?affiliation=true") def listDoisMeta(query: Option[String] = None, page: Option[Int]): Future[String] = http .getJson(clientDois(query.getOrElse(""), page.getOrElse(1))).flatMap( 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 ecf311b..b785cf7 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 @@ -80,20 +80,7 @@ object JsonSupport extends DefaultJsonProtocol{ } } - implicit val affiliationFormat = new JsonFormat[Affiliation]{ - def write(affiliation: Affiliation) = JsObject( - "name" -> JsString(affiliation.name) - ) - - def read(json: JsValue): Affiliation = json match { - case JsObject(fields) => fields.get("name") match { - case Some(JsString(name)) => Affiliation(name) - case _ => deserializationError("Expected affiliation name") - } - case JsString(name) => Affiliation(name) - case _ => deserializationError("Expected affiliation") - } - } + implicit val affiliationFormat = jsonFormat1(Affiliation) implicit val creatorFormat = fieldConflatingFormat(jsonFormat3(Creator), "name") implicit val contributorFormat = fieldConflatingFormat(jsonFormat4(Contributor), "name") implicit val titleFormat = jsonFormat3(Title) diff --git a/core/src/test/resources/productionDois.json b/core/src/test/resources/productionDois.json index a0a56f7..9ea2cee 100644 --- a/core/src/test/resources/productionDois.json +++ b/core/src/test/resources/productionDois.json @@ -476,7 +476,9 @@ "givenName": "Christoph", "familyName": "Gerbig", "affiliation": [ - "Max Planck Institute for Biogeochemistry, Jena, Germany" + { + "name": "Max Planck Institute for Biogeochemistry, Jena, Germany" + } ], "nameIdentifiers": [ { @@ -516,7 +518,9 @@ "givenName": "Christoph", "familyName": "Gerbig", "affiliation": [ - "Max Planck Institute for Biogeochemistry, Jena, Germany" + { + "name": "Max Planck Institute for Biogeochemistry, Jena, Germany" + } ], "contributorType": "Producer", "nameIdentifiers": [ @@ -532,7 +536,9 @@ "givenName": "Frank-Thomas", "familyName": "Koch", "affiliation": [ - "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + { + "name": "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + } ], "contributorType": null, "nameIdentifiers": [ @@ -548,7 +554,9 @@ "givenName": "Ute", "familyName": "Karstens", "affiliation": [ - "ICOS Carbon Portal, Lund University, Lund, Sweden" + { + "name": "ICOS Carbon Portal, Lund University, Lund, Sweden" + } ], "contributorType": "DataCurator", "nameIdentifiers": [ @@ -641,7 +649,9 @@ "givenName": "Christoph", "familyName": "Gerbig", "affiliation": [ - "Max Planck Institute for Biogeochemistry, Jena, Germany" + { + "name": "Max Planck Institute for Biogeochemistry, Jena, Germany" + } ], "nameIdentifiers": [ { @@ -656,7 +666,9 @@ "givenName": "Frank-Thomas", "familyName": "Koch", "affiliation": [ - "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + { + "name": "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + } ], "nameIdentifiers": [ { @@ -693,7 +705,9 @@ "givenName": "Christoph", "familyName": "Gerbig", "affiliation": [ - "Max Planck Institute for Biogeochemistry, Jena, Germany" + { + "name": "Max Planck Institute for Biogeochemistry, Jena, Germany" + } ], "contributorType": "Producer", "nameIdentifiers": [ @@ -709,7 +723,9 @@ "givenName": "Frank-Thomas", "familyName": "Koch", "affiliation": [ - "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + { + "name": "Deutscher Wetterdienst (DWD), Meteorologisches Observatorium Hohenpeißenberg, Germany" + } ], "contributorType": "ProjectMember", "nameIdentifiers": [ @@ -725,7 +741,9 @@ "givenName": "Ute", "familyName": "Karstens", "affiliation": [ - "ICOS Carbon Portal, Lund University, Lund, Sweden" + { + "name": "ICOS Carbon Portal, Lund University, Lund, Sweden" + } ], "contributorType": "DataCurator", "nameIdentifiers": [ diff --git a/js/src/main/scala/se/lu/nateko/cp/doi/gui/JsonSupport.scala b/js/src/main/scala/se/lu/nateko/cp/doi/gui/JsonSupport.scala index 07a8c14..ab770de 100644 --- a/js/src/main/scala/se/lu/nateko/cp/doi/gui/JsonSupport.scala +++ b/js/src/main/scala/se/lu/nateko/cp/doi/gui/JsonSupport.scala @@ -78,15 +78,7 @@ object JsonSupport{ } } - implicit val affiliationFormat = new Format[Affiliation]{ - def writes(affiliation: Affiliation): JsValue = Json.obj( - "name" -> JsString(affiliation.name) - ) - def reads(json: JsValue): JsResult[Affiliation] = (json \ "name") match { - case JsDefined(JsString(name)) => JsSuccess(Affiliation(name)) - case _ => json.validate[String].map(Affiliation) - } - } + implicit val affiliationFormat = Json.format[Affiliation] implicit val creatorFormat = fieldConflatingFormat(Json.format[Creator], "name") implicit val contributorFormat = fieldConflatingFormat(Json.format[Contributor], "name") implicit val titleFormat = Json.format[Title]