-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote changes to BETA Bug Fixes: * Pivotal ID # 176052254: JSON Submission Attributes Validation (#310) * Pivotal ID # 176052264: Inner Folder Mapping (#311) * Pivotal ID # 172671360: Ignore Empty Value Attributes (#314)
- Loading branch information
1 parent
91c3a8b
commit 64b7017
Showing
29 changed files
with
395 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Dependencies.KotlinLogging | ||
import Dependencies.KotlinStdLib | ||
import Dependencies.Log4J | ||
import TestDependencies.BaseTestCompileDependencies | ||
import TestDependencies.BaseTestRuntimeDependencies | ||
|
||
dependencies { | ||
api(project(":client:bio-webclient")) | ||
implementation(KotlinStdLib) | ||
implementation(Log4J) | ||
implementation(KotlinLogging) | ||
|
||
BaseTestCompileDependencies.forEach { testImplementation(it) } | ||
BaseTestRuntimeDependencies.forEach { testImplementation(it) } | ||
} |
53 changes: 53 additions & 0 deletions
53
...webclient-demo/src/main/kotlin/ac/uk/ebi/biostd/client/demo/SimpleSubmissionDslExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ac.uk.ebi.biostd.client.demo | ||
|
||
import ac.uk.ebi.biostd.client.integration.web.SecurityWebClient | ||
import ebi.ac.uk.dsl.attribute | ||
import ebi.ac.uk.dsl.file | ||
import ebi.ac.uk.dsl.link | ||
import ebi.ac.uk.dsl.section | ||
import ebi.ac.uk.dsl.submission | ||
import ebi.ac.uk.model.Attribute | ||
import ebi.ac.uk.model.extensions.title | ||
import mu.KotlinLogging | ||
import java.nio.file.Files | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
/** | ||
* Demonstrate how to submit a simple submission using bio-studies client and kotlin submission dsl. Note that | ||
* | ||
* 1. Client Serialization service is used to serialize class representation into json. | ||
* 2. Files are uploaded into user file directory first. | ||
*/ | ||
fun main(args: Array<String>) { | ||
val client = SecurityWebClient | ||
.create(baseUrl = args[0]) | ||
.getAuthenticatedClient(args[1], args[2]) | ||
|
||
val directory = Files.createTempDirectory("submission-files") | ||
val submissionFile = Files.createTempFile(directory, "sub-file-", ".tmp").toFile() | ||
|
||
client.uploadFiles(listOf(submissionFile)) | ||
val response = client.submitSingle(submission { | ||
title = "my-submission example" | ||
attribute("Attribute", "Attr Value 1") | ||
attribute("Another-Attribute", "Another-Attribute Value") | ||
section("study") { | ||
attributes = listOf(Attribute("attribute-1", "attributeValue")) | ||
link("AF069309") { | ||
attribute("type", "gen") | ||
} | ||
|
||
file(submissionFile.name) { | ||
size = 0 | ||
attribute("Description", "Data File 1") | ||
} | ||
|
||
section("Author") { | ||
attribute("Name", "Mr Doctor") | ||
} | ||
} | ||
}) | ||
|
||
logger.info { "successfully created submission ${response.body.accNo}" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../src/main/kotlin/ac/uk/ebi/biostd/json/deserialization/AttributeDetailJsonDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ac.uk.ebi.biostd.json.deserialization | ||
|
||
import ac.uk.ebi.biostd.json.deserialization.AttributeJsonDeserializerHelper.deserializeNameValue | ||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer | ||
import ebi.ac.uk.model.AttributeDetail | ||
|
||
internal class AttributeDetailJsonDeserializer : StdDeserializer<AttributeDetail>(AttributeDetail::class.java) { | ||
override fun deserialize(jp: JsonParser, ctxt: DeserializationContext): AttributeDetail { | ||
val mapper = jp.codec as ObjectMapper | ||
val node: JsonNode = mapper.readTree(jp) | ||
val (name, value) = deserializeNameValue(node) | ||
|
||
return AttributeDetail(name, value) | ||
} | ||
} |
10 changes: 2 additions & 8 deletions
10
...zation/src/main/kotlin/ac/uk/ebi/biostd/json/deserialization/AttributeJsonDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../src/main/kotlin/ac/uk/ebi/biostd/json/deserialization/AttributeJsonDeserializerHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ac.uk.ebi.biostd.json.deserialization | ||
|
||
import ac.uk.ebi.biostd.common.NAME | ||
import ac.uk.ebi.biostd.common.VALUE | ||
import ac.uk.ebi.biostd.json.exception.NoAttributeValueException | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.node.TextNode | ||
import uk.ac.ebi.serialization.extensions.getNode | ||
|
||
internal object AttributeJsonDeserializerHelper { | ||
fun deserializeNameValue(node: JsonNode): Pair<String, String> { | ||
val name = node.getNode<TextNode>(NAME).textValue() | ||
val value = node.getNode<TextNode>(VALUE).textValue() | ||
require(value.isNotBlank()) { throw NoAttributeValueException(name) } | ||
|
||
return name to value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../src/test/kotlin/ac/uk/ebi/biostd/json/deserialization/AttributeDetailDeserializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ac.uk.ebi.biostd.json.deserialization | ||
|
||
import ac.uk.ebi.biostd.json.JsonSerializer | ||
import ac.uk.ebi.biostd.json.exception.NoAttributeValueException | ||
import ebi.ac.uk.model.AttributeDetail | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import uk.ac.ebi.serialization.extensions.deserialize | ||
|
||
class AttributeDetailDeserializerTest { | ||
private val testInstance = JsonSerializer.mapper | ||
|
||
@Test | ||
fun `deserialize attribute detail`() { | ||
val result = testInstance.deserialize<AttributeDetail>("""{ | ||
|"name": "attr name", | ||
|"value": "attr value" | ||
|}""".trimMargin()) | ||
|
||
assertThat(result.name).isEqualTo("attr name") | ||
assertThat(result.value).isEqualTo("attr value") | ||
} | ||
|
||
@Test | ||
fun `deserialize empty`() { | ||
val exception = assertThrows<IllegalStateException> { testInstance.deserialize<AttributeDetail>("{}") } | ||
assertThat(exception.message).isEqualTo("Expecting to find property with 'name' in node '{}'") | ||
} | ||
|
||
@Test | ||
fun `deserialize with no value property`() { | ||
val exception = assertThrows<IllegalStateException> { testInstance.deserialize<AttributeDetail>("""{ | ||
|"name": "attr name" | ||
|}""".trimMargin()) | ||
} | ||
|
||
assertThat(exception.message).isEqualTo( | ||
"Expecting to find property with 'value' in node '{\"name\":\"attr name\"}'") | ||
} | ||
|
||
@Test | ||
fun `deserialize no value`() { | ||
val exception = assertThrows<NoAttributeValueException> { testInstance.deserialize<AttributeDetail>("""{ | ||
|"name": "attr name", | ||
|"value": "" | ||
|}""".trimMargin()) } | ||
|
||
assertThat(exception.message).isEqualTo("The value for the attribute 'attr name' can't be empty") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.