CORDA-2442: Added wither methods to the vault query classes (#4585)

(cherry picked from commit 498db538d7)
This commit is contained in:
Shams Asari 2019-01-15 21:02:02 +00:00 committed by Katelyn Baker
parent f5148e8b6c
commit 9286278f59

View File

@ -88,61 +88,63 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
/** /**
* VaultQueryCriteria: provides query by attributes defined in [VaultSchema.VaultStates] * VaultQueryCriteria: provides query by attributes defined in [VaultSchema.VaultStates]
*/ */
data class VaultQueryCriteria @JvmOverloads constructor( data class VaultQueryCriteria(
override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED,
override val contractStateTypes: Set<Class<out ContractState>>? = null, override val contractStateTypes: Set<Class<out ContractState>>? = null,
val stateRefs: List<StateRef>? = null, val stateRefs: List<StateRef>? = null,
val notary: List<AbstractParty>? = null, val notary: List<AbstractParty>? = null,
val softLockingCondition: SoftLockingCondition? = 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<Vault.ConstraintInfo.Type> = emptySet(),
override val constraints: Set<Vault.ConstraintInfo> = emptySet(),
override val participants: List<AbstractParty>? = null
) : CommonQueryCriteria() { ) : 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( constructor(
status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED,
contractStateTypes: Set<Class<out ContractState>>? = null, contractStateTypes: Set<Class<out ContractState>>? = null,
stateRefs: List<StateRef>? = null, stateRefs: List<StateRef>? = null,
notary: List<AbstractParty>? = null, notary: List<AbstractParty>? = null,
softLockingCondition: SoftLockingCondition? = null, softLockingCondition: SoftLockingCondition? = null,
timeCondition: TimeCondition? = null, timeCondition: TimeCondition? = null
relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL, ) : this(status, contractStateTypes, stateRefs, notary, softLockingCondition, timeCondition, participants = null)
constraintTypes: Set<Vault.ConstraintInfo.Type> = emptySet(), constructor(status: Vault.StateStatus) : this(status, participants = null)
constraints: Set<Vault.ConstraintInfo> = emptySet(), constructor(status: Vault.StateStatus, contractStateTypes: Set<Class<out ContractState>>?) : this(status, contractStateTypes, participants = null)
participants: List<AbstractParty>? = null constructor(status: Vault.StateStatus, contractStateTypes: Set<Class<out ContractState>>?, stateRefs: List<StateRef>?) : this(
) : this(status, contractStateTypes, stateRefs, notary, softLockingCondition, timeCondition) { status, contractStateTypes, stateRefs, participants = null
this.relevancyStatus = relevancyStatus )
this.constraintTypes = constraintTypes constructor(status: Vault.StateStatus, contractStateTypes: Set<Class<out ContractState>>?, stateRefs: List<StateRef>?, notary: List<AbstractParty>?) : this(
this.constraints = constraints status, contractStateTypes, stateRefs, notary, participants = null
this.participants = participants )
} constructor(status: Vault.StateStatus, contractStateTypes: Set<Class<out ContractState>>?, stateRefs: List<StateRef>?, notary: List<AbstractParty>?, softLockingCondition: SoftLockingCondition?) : this(
status, contractStateTypes, stateRefs, notary, softLockingCondition, participants = null
override var relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL )
private set
override var constraintTypes: Set<Vault.ConstraintInfo.Type> = emptySet()
private set
override var constraints: Set<Vault.ConstraintInfo> = emptySet()
private set
override var participants: List<AbstractParty>? = null
private set
override fun visit(parser: IQueryCriteriaParser): Collection<Predicate> { override fun visit(parser: IQueryCriteriaParser): Collection<Predicate> {
super.visit(parser) super.visit(parser)
return parser.parseCriteria(this) return parser.parseCriteria(this)
} }
fun withStatus(status: Vault.StateStatus): VaultQueryCriteria = copy(status = status)
fun withContractStateTypes(contractStateTypes: Set<Class<out ContractState>>): VaultQueryCriteria = copy(contractStateTypes = contractStateTypes)
fun withStateRefs(stateRefs: List<StateRef>): VaultQueryCriteria = copy(stateRefs = stateRefs)
fun withNotary(notary: List<AbstractParty>): 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<Vault.ConstraintInfo.Type>): VaultQueryCriteria = copy(constraintTypes = constraintTypes)
fun withConstraints(constraints: Set<Vault.ConstraintInfo>): VaultQueryCriteria = copy(constraints = constraints)
fun withParticipants(participants: List<AbstractParty>): VaultQueryCriteria = copy(participants = participants)
fun copy( fun copy(
status: Vault.StateStatus = this.status, status: Vault.StateStatus = this.status,
contractStateTypes: Set<Class<out ContractState>>? = this.contractStateTypes, contractStateTypes: Set<Class<out ContractState>>? = this.contractStateTypes,
stateRefs: List<StateRef>? = this.stateRefs, stateRefs: List<StateRef>? = this.stateRefs,
notary: List<AbstractParty>? = this.notary, notary: List<AbstractParty>? = this.notary,
softLockingCondition: SoftLockingCondition? = this.softLockingCondition, softLockingCondition: SoftLockingCondition? = this.softLockingCondition,
timeCondition: TimeCondition? = this.timeCondition, timeCondition: TimeCondition? = this.timeCondition
relevancyStatus: Vault.RelevancyStatus = this.relevancyStatus,
constraintTypes: Set<Vault.ConstraintInfo.Type> = this.constraintTypes,
constraints: Set<Vault.ConstraintInfo> = this.constraints,
participants: List<AbstractParty>? = this.participants
): VaultQueryCriteria { ): VaultQueryCriteria {
return VaultQueryCriteria( return VaultQueryCriteria(
status, status,
@ -201,6 +203,13 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
return parser.parseCriteria(this) return parser.parseCriteria(this)
} }
fun withParticipants(participants: List<AbstractParty>): LinearStateQueryCriteria = copy(participants = participants)
fun withUuid(uuid: List<UUID>): LinearStateQueryCriteria = copy(uuid = uuid)
fun withExternalId(externalId: List<String>): LinearStateQueryCriteria = copy(externalId = externalId)
fun withStatus(status: Vault.StateStatus): LinearStateQueryCriteria = copy(status = status)
fun withContractStateTypes(contractStateTypes: Set<Class<out ContractState>>): LinearStateQueryCriteria = copy(contractStateTypes = contractStateTypes)
fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): LinearStateQueryCriteria = copy(relevancyStatus = relevancyStatus)
fun copy( fun copy(
participants: List<AbstractParty>? = this.participants, participants: List<AbstractParty>? = this.participants,
uuid: List<UUID>? = this.uuid, uuid: List<UUID>? = this.uuid,
@ -233,12 +242,18 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
super.visit(parser) super.visit(parser)
return parser.parseCriteria(this) return parser.parseCriteria(this)
} }
fun withParticipants(participants: List<AbstractParty>): FungibleStateQueryCriteria = copy(participants = participants)
fun withQuantity(quantity: ColumnPredicate<Long>): FungibleStateQueryCriteria = copy(quantity = quantity)
fun withStatus(status: Vault.StateStatus): FungibleStateQueryCriteria = copy(status = status)
fun withContractStateTypes(contractStateTypes: Set<Class<out ContractState>>): FungibleStateQueryCriteria = copy(contractStateTypes = contractStateTypes)
fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): FungibleStateQueryCriteria = copy(relevancyStatus = relevancyStatus)
} }
/** /**
* FungibleStateQueryCriteria: provides query by attributes defined in [VaultSchema.VaultFungibleStates] * FungibleStateQueryCriteria: provides query by attributes defined in [VaultSchema.VaultFungibleStates]
*/ */
data class FungibleAssetQueryCriteria constructor( data class FungibleAssetQueryCriteria(
override val participants: List<AbstractParty>? = null, override val participants: List<AbstractParty>? = null,
val owner: List<AbstractParty>? = null, val owner: List<AbstractParty>? = null,
val quantity: ColumnPredicate<Long>? = null, val quantity: ColumnPredicate<Long>? = null,
@ -248,7 +263,8 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
override val contractStateTypes: Set<Class<out ContractState>>? = null, override val contractStateTypes: Set<Class<out ContractState>>? = null,
override val relevancyStatus: Vault.RelevancyStatus override val relevancyStatus: Vault.RelevancyStatus
) : CommonQueryCriteria() { ) : CommonQueryCriteria() {
@JvmOverloads constructor( @JvmOverloads
constructor(
participants: List<AbstractParty>? = null, participants: List<AbstractParty>? = null,
owner: List<AbstractParty>? = null, owner: List<AbstractParty>? = null,
quantity: ColumnPredicate<Long>? = null, quantity: ColumnPredicate<Long>? = null,
@ -263,6 +279,15 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
return parser.parseCriteria(this) return parser.parseCriteria(this)
} }
fun withParticipants(participants: List<AbstractParty>): FungibleAssetQueryCriteria = copy(participants = participants)
fun withOwner(owner: List<AbstractParty>): FungibleAssetQueryCriteria = copy(owner = owner)
fun withQuantity(quantity: ColumnPredicate<Long>): FungibleAssetQueryCriteria = copy(quantity = quantity)
fun withIssuer(issuer: List<AbstractParty>): FungibleAssetQueryCriteria = copy(issuer = issuer)
fun withissuerRef(issuerRef: List<OpaqueBytes>): FungibleAssetQueryCriteria = copy(issuerRef = issuerRef)
fun withStatus(status: Vault.StateStatus): FungibleAssetQueryCriteria = copy(status = status)
fun withContractStateTypes(contractStateTypes: Set<Class<out ContractState>>): FungibleAssetQueryCriteria = copy(contractStateTypes = contractStateTypes)
fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): FungibleAssetQueryCriteria = copy(relevancyStatus = relevancyStatus)
fun copy( fun copy(
participants: List<AbstractParty>? = this.participants, participants: List<AbstractParty>? = this.participants,
owner: List<AbstractParty>? = this.owner, owner: List<AbstractParty>? = this.owner,
@ -293,13 +318,14 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
* Params * Params
* [expression] refers to a (composable) type safe [CriteriaExpression] * [expression] refers to a (composable) type safe [CriteriaExpression]
*/ */
data class VaultCustomQueryCriteria<L : StatePersistable> constructor( data class VaultCustomQueryCriteria<L : StatePersistable>(
val expression: CriteriaExpression<L, Boolean>, val expression: CriteriaExpression<L, Boolean>,
override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED,
override val contractStateTypes: Set<Class<out ContractState>>? = null, override val contractStateTypes: Set<Class<out ContractState>>? = null,
override val relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL override val relevancyStatus: Vault.RelevancyStatus = Vault.RelevancyStatus.ALL
) : CommonQueryCriteria() { ) : CommonQueryCriteria() {
@JvmOverloads constructor( @JvmOverloads
constructor(
expression: CriteriaExpression<L, Boolean>, expression: CriteriaExpression<L, Boolean>,
status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED, status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED,
contractStateTypes: Set<Class<out ContractState>>? = null contractStateTypes: Set<Class<out ContractState>>? = null
@ -310,6 +336,11 @@ sealed class QueryCriteria : GenericQueryCriteria<QueryCriteria, IQueryCriteriaP
return parser.parseCriteria(this) return parser.parseCriteria(this)
} }
fun withExpression(expression: CriteriaExpression<L, Boolean>): VaultCustomQueryCriteria<L> = copy(expression = expression)
fun withStatus(status: Vault.StateStatus): VaultCustomQueryCriteria<L> = copy(status = status)
fun withContractStateTypes(contractStateTypes: Set<Class<out ContractState>>): VaultCustomQueryCriteria<L> = copy(contractStateTypes = contractStateTypes)
fun withRelevancyStatus(relevancyStatus: Vault.RelevancyStatus): VaultCustomQueryCriteria<L> = copy(relevancyStatus = relevancyStatus)
fun copy( fun copy(
expression: CriteriaExpression<L, Boolean> = this.expression, expression: CriteriaExpression<L, Boolean> = this.expression,
status: Vault.StateStatus = this.status, status: Vault.StateStatus = this.status,
@ -376,13 +407,13 @@ sealed class AttachmentQueryCriteria : GenericQueryCriteria<AttachmentQueryCrite
) )
} }
fun withUploader(uploaderPredicate: ColumnPredicate<String>) = copy(uploaderCondition = uploaderPredicate) fun withUploader(uploaderPredicate: ColumnPredicate<String>): AttachmentsQueryCriteria = copy(uploaderCondition = uploaderPredicate)
fun withFilename(filenamePredicate: ColumnPredicate<String>) = copy(filenameCondition = filenamePredicate) fun withFilename(filenamePredicate: ColumnPredicate<String>): AttachmentsQueryCriteria = copy(filenameCondition = filenamePredicate)
fun withUploadDate(uploadDatePredicate: ColumnPredicate<Instant>) = copy(uploadDateCondition = uploadDatePredicate) fun withUploadDate(uploadDatePredicate: ColumnPredicate<Instant>): AttachmentsQueryCriteria = copy(uploadDateCondition = uploadDatePredicate)
fun withContractClassNames(contractClassNamesPredicate: ColumnPredicate<List<ContractClassName>>) = copy(contractClassNamesCondition = contractClassNamesPredicate) fun withContractClassNames(contractClassNamesPredicate: ColumnPredicate<List<ContractClassName>>): AttachmentsQueryCriteria = copy(contractClassNamesCondition = contractClassNamesPredicate)
fun withSigners(signersPredicate: ColumnPredicate<List<PublicKey>>) = copy(signersCondition = signersPredicate) fun withSigners(signersPredicate: ColumnPredicate<List<PublicKey>>): AttachmentsQueryCriteria = copy(signersCondition = signersPredicate)
fun isSigned(isSignedPredicate: ColumnPredicate<Boolean>) = copy(isSignedCondition = isSignedPredicate) fun isSigned(isSignedPredicate: ColumnPredicate<Boolean>): AttachmentsQueryCriteria = copy(isSignedCondition = isSignedPredicate)
fun withVersion(versionPredicate: ColumnPredicate<Int>) = copy(versionCondition = versionPredicate) fun withVersion(versionPredicate: ColumnPredicate<Int>): AttachmentsQueryCriteria = copy(versionCondition = versionPredicate)
} }
class AndComposition(override val a: AttachmentQueryCriteria, override val b: AttachmentQueryCriteria): AttachmentQueryCriteria(), GenericQueryCriteria.ChainableQueryCriteria.AndVisitor<AttachmentQueryCriteria, AttachmentsQueryCriteriaParser, AttachmentSort> class AndComposition(override val a: AttachmentQueryCriteria, override val b: AttachmentQueryCriteria): AttachmentQueryCriteria(), GenericQueryCriteria.ChainableQueryCriteria.AndVisitor<AttachmentQueryCriteria, AttachmentsQueryCriteriaParser, AttachmentSort>