From 9286278f59f746202d1c690e022bbef2a8c13aa1 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Tue, 15 Jan 2019 21:02:02 +0000 Subject: [PATCH] CORDA-2442: Added wither methods to the vault query classes (#4585) (cherry picked from commit 498db538d7c755cefe8aa5b0b99d21241818f2b5) --- .../core/node/services/vault/QueryCriteria.kt | 115 +++++++++++------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt index dca8c935f2..83490d874f 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt @@ -88,61 +88,63 @@ sealed class QueryCriteria : GenericQueryCriteria>? = null, val stateRefs: List? = null, val notary: List? = null, val softLockingCondition: SoftLockingCondition? = null, - val timeCondition: TimeCondition? = null + val timeCondition: TimeCondition? = null, + override val relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL, + override val constraintTypes: Set = emptySet(), + override val constraints: Set = emptySet(), + override val participants: List? = null ) : CommonQueryCriteria() { - // These extra fields are handled this way to preserve Kotlin wire compatibility wrt additional parameters with default values. + // V3 c'tors + // These have to be manually specified as @JvmOverloads for some reason causes declaration clashes constructor( status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, contractStateTypes: Set>? = null, stateRefs: List? = null, notary: List? = null, softLockingCondition: SoftLockingCondition? = null, - timeCondition: TimeCondition? = null, - relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL, - constraintTypes: Set = emptySet(), - constraints: Set = emptySet(), - participants: List? = null - ) : this(status, contractStateTypes, stateRefs, notary, softLockingCondition, timeCondition) { - this.relevancyStatus = relevancyStatus - this.constraintTypes = constraintTypes - this.constraints = constraints - this.participants = participants - } - - override var relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL - private set - - override var constraintTypes: Set = emptySet() - private set - - override var constraints: Set = emptySet() - private set - - override var participants: List? = null - private set + timeCondition: TimeCondition? = null + ) : this(status, contractStateTypes, stateRefs, notary, softLockingCondition, timeCondition, participants = null) + constructor(status: Vault.StateStatus) : this(status, participants = null) + constructor(status: Vault.StateStatus, contractStateTypes: Set>?) : this(status, contractStateTypes, participants = null) + constructor(status: Vault.StateStatus, contractStateTypes: Set>?, stateRefs: List?) : this( + status, contractStateTypes, stateRefs, participants = null + ) + constructor(status: Vault.StateStatus, contractStateTypes: Set>?, stateRefs: List?, notary: List?) : this( + status, contractStateTypes, stateRefs, notary, participants = null + ) + constructor(status: Vault.StateStatus, contractStateTypes: Set>?, stateRefs: List?, notary: List?, softLockingCondition: SoftLockingCondition?) : this( + status, contractStateTypes, stateRefs, notary, softLockingCondition, participants = null + ) override fun visit(parser: IQueryCriteriaParser): Collection { super.visit(parser) return parser.parseCriteria(this) } + fun withStatus(status: Vault.StateStatus): VaultQueryCriteria = copy(status = status) + fun withContractStateTypes(contractStateTypes: Set>): VaultQueryCriteria = copy(contractStateTypes = contractStateTypes) + fun withStateRefs(stateRefs: List): VaultQueryCriteria = copy(stateRefs = stateRefs) + fun withNotary(notary: List): VaultQueryCriteria = copy(notary = notary) + fun withSoftLockingCondition(softLockingCondition: SoftLockingCondition): VaultQueryCriteria = copy(softLockingCondition = softLockingCondition) + fun withTimeCondition(timeCondition: TimeCondition): VaultQueryCriteria = copy(timeCondition = timeCondition) + fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): VaultQueryCriteria = copy(relevancyStatus = relevancyStatus) + fun withConstraintTypes(constraintTypes: Set): VaultQueryCriteria = copy(constraintTypes = constraintTypes) + fun withConstraints(constraints: Set): VaultQueryCriteria = copy(constraints = constraints) + fun withParticipants(participants: List): VaultQueryCriteria = copy(participants = participants) + fun copy( status: Vault.StateStatus = this.status, contractStateTypes: Set>? = this.contractStateTypes, stateRefs: List? = this.stateRefs, notary: List? = this.notary, softLockingCondition: SoftLockingCondition? = this.softLockingCondition, - timeCondition: TimeCondition? = this.timeCondition, - relevancyStatus: Vault.RelevancyStatus = this.relevancyStatus, - constraintTypes: Set = this.constraintTypes, - constraints: Set = this.constraints, - participants: List? = this.participants + timeCondition: TimeCondition? = this.timeCondition ): VaultQueryCriteria { return VaultQueryCriteria( status, @@ -201,6 +203,13 @@ sealed class QueryCriteria : GenericQueryCriteria): LinearStateQueryCriteria = copy(participants = participants) + fun withUuid(uuid: List): LinearStateQueryCriteria = copy(uuid = uuid) + fun withExternalId(externalId: List): LinearStateQueryCriteria = copy(externalId = externalId) + fun withStatus(status: Vault.StateStatus): LinearStateQueryCriteria = copy(status = status) + fun withContractStateTypes(contractStateTypes: Set>): LinearStateQueryCriteria = copy(contractStateTypes = contractStateTypes) + fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): LinearStateQueryCriteria = copy(relevancyStatus = relevancyStatus) + fun copy( participants: List? = this.participants, uuid: List? = this.uuid, @@ -233,12 +242,18 @@ sealed class QueryCriteria : GenericQueryCriteria): FungibleStateQueryCriteria = copy(participants = participants) + fun withQuantity(quantity: ColumnPredicate): FungibleStateQueryCriteria = copy(quantity = quantity) + fun withStatus(status: Vault.StateStatus): FungibleStateQueryCriteria = copy(status = status) + fun withContractStateTypes(contractStateTypes: Set>): FungibleStateQueryCriteria = copy(contractStateTypes = contractStateTypes) + fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): FungibleStateQueryCriteria = copy(relevancyStatus = relevancyStatus) } /** * FungibleStateQueryCriteria: provides query by attributes defined in [VaultSchema.VaultFungibleStates] */ - data class FungibleAssetQueryCriteria constructor( + data class FungibleAssetQueryCriteria( override val participants: List? = null, val owner: List? = null, val quantity: ColumnPredicate? = null, @@ -248,7 +263,8 @@ sealed class QueryCriteria : GenericQueryCriteria>? = null, override val relevancyStatus: Vault.RelevancyStatus ) : CommonQueryCriteria() { - @JvmOverloads constructor( + @JvmOverloads + constructor( participants: List? = null, owner: List? = null, quantity: ColumnPredicate? = null, @@ -263,6 +279,15 @@ sealed class QueryCriteria : GenericQueryCriteria): FungibleAssetQueryCriteria = copy(participants = participants) + fun withOwner(owner: List): FungibleAssetQueryCriteria = copy(owner = owner) + fun withQuantity(quantity: ColumnPredicate): FungibleAssetQueryCriteria = copy(quantity = quantity) + fun withIssuer(issuer: List): FungibleAssetQueryCriteria = copy(issuer = issuer) + fun withissuerRef(issuerRef: List): FungibleAssetQueryCriteria = copy(issuerRef = issuerRef) + fun withStatus(status: Vault.StateStatus): FungibleAssetQueryCriteria = copy(status = status) + fun withContractStateTypes(contractStateTypes: Set>): FungibleAssetQueryCriteria = copy(contractStateTypes = contractStateTypes) + fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): FungibleAssetQueryCriteria = copy(relevancyStatus = relevancyStatus) + fun copy( participants: List? = this.participants, owner: List? = this.owner, @@ -293,13 +318,14 @@ sealed class QueryCriteria : GenericQueryCriteria constructor( + data class VaultCustomQueryCriteria( val expression: CriteriaExpression, override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, override val contractStateTypes: Set>? = null, override val relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL ) : CommonQueryCriteria() { - @JvmOverloads constructor( + @JvmOverloads + constructor( expression: CriteriaExpression, status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, contractStateTypes: Set>? = null @@ -310,6 +336,11 @@ sealed class QueryCriteria : GenericQueryCriteria): VaultCustomQueryCriteria = copy(expression = expression) + fun withStatus(status: Vault.StateStatus): VaultCustomQueryCriteria = copy(status = status) + fun withContractStateTypes(contractStateTypes: Set>): VaultCustomQueryCriteria = copy(contractStateTypes = contractStateTypes) + fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): VaultCustomQueryCriteria = copy(relevancyStatus = relevancyStatus) + fun copy( expression: CriteriaExpression = this.expression, status: Vault.StateStatus = this.status, @@ -376,13 +407,13 @@ sealed class AttachmentQueryCriteria : GenericQueryCriteria) = copy(uploaderCondition = uploaderPredicate) - fun withFilename(filenamePredicate: ColumnPredicate) = copy(filenameCondition = filenamePredicate) - fun withUploadDate(uploadDatePredicate: ColumnPredicate) = copy(uploadDateCondition = uploadDatePredicate) - fun withContractClassNames(contractClassNamesPredicate: ColumnPredicate>) = copy(contractClassNamesCondition = contractClassNamesPredicate) - fun withSigners(signersPredicate: ColumnPredicate>) = copy(signersCondition = signersPredicate) - fun isSigned(isSignedPredicate: ColumnPredicate) = copy(isSignedCondition = isSignedPredicate) - fun withVersion(versionPredicate: ColumnPredicate) = copy(versionCondition = versionPredicate) + fun withUploader(uploaderPredicate: ColumnPredicate): AttachmentsQueryCriteria = copy(uploaderCondition = uploaderPredicate) + fun withFilename(filenamePredicate: ColumnPredicate): AttachmentsQueryCriteria = copy(filenameCondition = filenamePredicate) + fun withUploadDate(uploadDatePredicate: ColumnPredicate): AttachmentsQueryCriteria = copy(uploadDateCondition = uploadDatePredicate) + fun withContractClassNames(contractClassNamesPredicate: ColumnPredicate>): AttachmentsQueryCriteria = copy(contractClassNamesCondition = contractClassNamesPredicate) + fun withSigners(signersPredicate: ColumnPredicate>): AttachmentsQueryCriteria = copy(signersCondition = signersPredicate) + fun isSigned(isSignedPredicate: ColumnPredicate): AttachmentsQueryCriteria = copy(isSignedCondition = isSignedPredicate) + fun withVersion(versionPredicate: ColumnPredicate): AttachmentsQueryCriteria = copy(versionCondition = versionPredicate) } class AndComposition(override val a: AttachmentQueryCriteria, override val b: AttachmentQueryCriteria): AttachmentQueryCriteria(), GenericQueryCriteria.ChainableQueryCriteria.AndVisitor