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

resolves #4, resolves #9, resolves #10, resolves #11 #12

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ configure(moduleProjects) {
}

signing {
required { version.endsWith('SNAPSHOT') }
required { !version.endsWith('SNAPSHOT') }
sign publishing.publications.maven
}
}
2 changes: 1 addition & 1 deletion bundle-rest-embedded/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'net.corda.plugins.cordapp'

cordapp {
targetPlatformVersion 7
minimumPlatformVersion 7
minimumPlatformVersion 6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a comment explaining why it's the minimum version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated commit message

workflow {
// must be kept in sync with koin.properties
name "cordaptor-embedded-bundle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tech.b180.cordaptor.corda

import net.corda.core.flows.FlowLogic
import kotlin.reflect.KClass
import kotlin.reflect.full.allSupertypes

/**
* Unpacks reflection data about a flow class to determine its return type.
Expand All @@ -12,7 +13,7 @@ import kotlin.reflect.KClass
* FIXME log details of failed type discovery
*/
fun determineFlowResultClass(flowClass: KClass<out FlowLogic<Any>>): KClass<out Any> {
val flowLogicType = flowClass.supertypes.find { it.classifier == FlowLogic::class }
val flowLogicType = flowClass.allSupertypes.find { it.classifier == FlowLogic::class }
?: throw AssertionError("Flow class $flowClass does not seem to extend FlowLogic")

val flowLogicReturnType = flowLogicType.arguments.firstOrNull()?.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.math.BigDecimal
import java.math.RoundingMode
import java.security.PublicKey
import java.security.cert.X509Certificate
import java.time.Duration
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.*
Expand Down Expand Up @@ -208,6 +209,27 @@ class JavaInstantSerializer : CustomSerializer<Instant>,
}
}

/**
* Serializer for an [Duration] representing it as a JSON string value formatted as an ISO-8601 timestamp.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading comment about 'timestamp', it's actually ISO duration format

*
* @see DateTimeFormatter.ISO_INSTANT
*/
class JavaDurationSerializer : CustomSerializer<Duration>,
SerializationFactory.DelegatingSerializer<Duration, String>(
delegate = SerializationFactory.StringSerializer,
my2delegate = { this.toString() },
delegate2my = { Duration.parse(it) }
) {

override fun generateSchema(generator: JsonSchemaGenerator): JsonObject {
return mapOf(
"type" to "string",
"format" to "date-time"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is not date-time, but ISO duration

).asJsonObject()
}
}


/**
* Serializer for an [AbstractParty] representing it as a JSON object containing its X.500 name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ListSerializer private constructor(
when (parameterizedType.rawType) {
Collection::class.java -> ::newArrayList
List::class.java -> ::newArrayList
else -> throw AssertionError("Don't know how to make instances of ${parameterizedType.rawType}")
else -> ::instantiationNotSupported
}
} else {
throw AssertionError("Don't know how to make instances of ${collectionType.observedType}")
Expand All @@ -195,6 +195,9 @@ class ListSerializer private constructor(
// FIXME instantiate an array of a certain type via Java reflection
fun newArray(items: List<*>): Array<Any> = TODO("Deserialization of arrays is not supported yet")

//catch all for types that do not need to be created from JSON
fun instantiationNotSupported(items: Any) = SerializationException("Type not supported")

fun iteratorOfAnArray(c: Any?) = c?.let { (c as Array<*>).iterator() }
?: throw AssertionError("Null instead of an array - unsafe code in the parent serializer")
fun iteratorOfACollection(c: Any?) = c?.let { (c as Collection<*>).iterator() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class RestEndpointModuleProvider : ModuleProvider {
single { CordaTimeWindowSerializer(get()) } bind CustomSerializer::class
single { JsonObjectSerializer() } bind CustomSerializer::class
single { CordaOpaqueBytesSerializer() } bind CustomSerializer::class
single { JavaDurationSerializer() } bind CustomSerializer::class

single { CordaFlowInstructionSerializerFactory(get()) } bind CustomSerializerFactory::class
single { CordaAmountSerializerFactory(get()) } bind CustomSerializerFactory::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import tech.b180.cordaptor.corda.CordaNodeState
import tech.b180.cordaptor.kernel.lazyGetAll
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.Duration
import java.time.Instant
import java.util.*
import kotlin.reflect.full.allSuperclasses
Expand Down Expand Up @@ -275,6 +276,22 @@ class CordaTypesTest : KoinTest {
assertEquals(OpaqueBytes("TEST".toByteArray(Charsets.UTF_8)),
serializer.fromJson(""""VEVTVA=="""".asJsonValue()))
}

@Test
fun `test java duration serialization`() {
val serializer = getKoin().getSerializer(Duration::class)

assertEquals("""{"type":"string","format":"date-time"}""".asJsonObject(),
serializer.generateRecursiveSchema(getKoin().get()))

// "PT4H" is string for duration of 4 hours
assertEquals("PT4H",
serializer.toJsonString(Duration.ofHours(4)))

assertEquals(Duration.ofHours(4),
serializer.fromJson("PT4H".asJsonValue()))
}

}

data class TestFlowParam(val intParam: Int)
Expand Down
10 changes: 10 additions & 0 deletions tar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.apache.tools.ant.filters.*;
configurations {
// trimming down Corda's transitive dependencies not requried for Corda RPC client to work
implementation.exclude group: 'org.hibernate'
Expand Down Expand Up @@ -57,6 +58,15 @@ task dist(type: Tar, dependsOn: [ ':corda-rpc-client:jar', ':local-cache:jar', '
}
}

eachFile { file ->
// make sure scripts have UNIX endings
if (file.name.endsWith(".sh") || file.name.endsWith(".conf")) {
filter(FixCrLfFilter.class,
eol:FixCrLfFilter.CrLf.newInstance("lf"))
}
}


into "lib", {
from configurations.runtimeClasspath.files
}
Expand Down