Scope that includes subflows of a flow, but not its "parent flow"? - spring-webflow

Suppose that flow A has subflow B, which in turn has subflow C. Is there a scope that would be visible in B and C, but not in A?

If you just want an obj to be visible in Subflow C (from subflow B) You could just pass the pojo/obj DIRECTLY from Subflow B -> Subflow C via params using 'input' and 'output' tags and avoid using scopes all together.
See this post for an example:
Spring Flow: Pass object back and forth from between Main WebFlow and Subflow

Related

Can I have an account on a node and trade with that account without the state staying on the account node?

I'm working with corda accounts.
In my scenario the account is created on node M and shared with node D.
Node D runs a state creation flow, where the account is a participant.
By modeling the solution, the transaction must be registered on node D, but not on node M.
The problem is that when using the account belonging to node M, session of node M is required. And when I don't execute a ReceiveFinalityFlow on Responder Flow, an UnexpectedFlowEndException exception is generated.
And I need to be able to make a vaultquery through accountId.
The question is, can I have an account on a node and trade with that account without the state staying on the account node?
FinalityFlow will throw an error if you don't provide a FlowSession for each participant (see here), and in your case the account is a participant; so you need to provide a FlowSession for node M.
Since you pass a FlowSession for node M, then there should be a responder flow where node M calls ReceiveFinalityFlow; otherwise your initiator flow will hang because FinalityFlow will execute a send() to send the transaction to M, while M doesn't have a receive() call (which ReceiveFinalityFlow executes).
You can achieve the requirement that you're asking for by calling ReceiveFinalityFlow and set the input parameter statesToRecord to NONE; by default, that parameter is set to ONLY_RELEVANT (see flow definition here). The various types of StatesToRecord are explained here.
Your responder flow must have an if statement, if getOurIdentity() is node M, then call ReceiveFinalityFlow with statesToRecord == NONE (because you don't want M to record the state), if it's node D then call ReceiveFinalityFlow with statesToRecord == RELEVANT (because you want D to record the state).
Please note that just because you wrote a responder a certain way, doesn't guarantee that node M will execute your version; writing a responder flow is usually the responsibility of the other node; their developers can write their own version of the responder in which they call ReceiveFinalityFlow with statesToRecord == RELEVANT (meaning node M will register the resulting state). Read the first This is not true in this article.
Once you implement the above, please write a flow test that checks that node M:
Didn't register the resulting transaction in its transaction storage
Didn't register the resulting state in its vault
The reason I'm asking you to do this is because I noticed in Corda's code the following:
ReceiveFinalityFlow calls ReceiveTransactionFlow here
ReceiveTransactionFlow calls ResolveTransactionFlow here
ResolveTransactionFlow overrides statesToRecord from NONE to RELEVANT here and this statement has me worried; I just want to make sure that when you set statesToRecord to NONE in ReceiveFinalityFlow for node M, it doesn't record the transaction or the state
Let me know how things go.
Also to query by account, read in my article the below 2 sections:
Search for Finally, how do you query the vault by account?
Also read This is very important!

Can 3rd party check the state that he does not know, and add this state in a flow as a input state?

Here is my deliverydemo source code on github.
My scenario:
A issues tokens to B
B makes an order with C
C delivers the goods to B, and try to start a flow for retrieving token from B.
My question:
Can C know the state of the token state which B has?
Can C add this token state in a "retrieving" flow as a input state?
As Joel's suggestion, I try to send some request and receive the StateAndRef from PartyB on PartyC in my OrderDeliveredFlow.
Unfortunately, seems like JAVA does not support "unwrap", but Kotlin does.
After I add a small segment for send and receive Java.String and unwarp it in a workable flow - my token issue flow, this flow going to rise this error - "missing parameter name at index 0 {}".
An possible solution that I think, is create a new flow in Kotlin just like "CollectSignaturesFlow".
Otherwise, I have to translate my Java code into Kotlin.
C isn't aware of the existence of the token states, so can't add them to the transaction herself.
Instead, C should ask B to send over the token states she wants to spend, and add them to a transaction.
The flow code would look something like:
val otherPartySession = initiateFlow(otherParty)
val tokenState = otherPartySession.receive<StateAndRef<Cash.State>>().unwrap { it }
txBuilder.addInputState(tokenState)
As an alternative to Joel's answer. You could look into adding C as a participant of the token state.
e.g. in Kotlin, where other would be set as C
override val participants: List<AbstractParty> get() = listOf(issuer, owner, other)
C would then know about the state of the token that B has. However, you can see that this would require the issuer or B to know about C beforehand.
Naturally, the route you take all depends on your privacy model.

Conditional commands

I have three main views in my application: A, B and C. Each of these views contain a view called X. Clicking a button in the X view dispatches a FooEvent to the event pool.
I would like to map multiple commands to the FooEvent and execute one of them depending on which main view (A, B or C) is currentry visible. I would have to add an if clause to every command mapped to FooEvent checking if the correct view is visible and I don't like this. Distributing logic across commands makes them hard to manage.
What is the best way to conditionally call commands in the context my application?
Inside X mediator you can create a listener for a FooEvent.
and then based on X parent you dispatch new Event.
Or inside A,B and C you listen for FooEvent, and when you catch it you mediate it from A,B or C mediator to specific command.
The goal is to keep view events inside views, and to mediate new communication further
You can also use Signals

Interception messages in Squeak

I am trying to understand better reflection in Smalltalk. I am using the latest version of Squeak (v4.3). I want to intercept every message sent to instances of one of my classes. I assumed that I could override the method ProtoObject>>withArgs:executeMethod but Stéphane Ducasse explained me that for performance reason, this method is not used (this is my own summary of his answer). Which method should I override / how could intercept sent messages?
Here is the code of my attempt:
Object subclass: #C
instanceVariableNames: 'i'
classVariableNames: ''
poolDictionaries: ''
category: 'CSE3009'.
C class compile: 'newWithi: anInt
^(self new) i: anInt ; yourself.'.
C compile: 'withArgs: someArgs executeMethod: aMethod
Transcript show: ''Caught: ''.
^ super withArgs: someArgs executeMethod aMethod.'.
C compile: 'foo: aText
Transcript show: aText.
Transcript show: i.
Transcript cr.'.
C compile: 'i: anInt
i := anInt.'.
o := C newWithi: 42.
o foo: 'This is foo: '.
Executing this entire piece of code yields:
This is foo: 42
When I would like to have:
Caught: This is foo: 42
There's no build-in way to intercept messages to objects like that. There are two ways we commonly use to do this kind of trick.
First, you can create a wrapper object which responds to doesNotUnderstand:. This object usually has nil for the superclass so it doesn't inherit any instance methods from Object. The doesNotUnderstand: handler would delegate all its messages to the target object. It has the option of performing code before and after the call. All references to the original object would now point to the new "proxy" object. Messages to self wouldn't be intercepted and the proxy would need to test for objects that return self and change the returned object to be the proxy instead.
The second approach is to use a mechanism called Method Wrappers. Method Wrappers allows you to replace all of the methods in a set of classes with methods that do some other operations before and after calling the original method. This approach can provide fairly seemless results and intercepts all messages including those send to self.
MethodWrappers is available for VisualWorks and VASmalltalk. I believe it's also available for Squeak and Pharo but I'm not positive.
The three main techniques are:
Dynamic proxies
Method wrapper
Bytecode instrumentation
For a good comparision of all possible approaches, have a look at "Evaluating Message Passing Control Techniques in Smalltalk" by Stephane Ducasse (you already know him, apparently).
Of interest is also "Smalltalk: A Reflective Langauge" by F. Rivard, that shows how to implement pre- and post-conditions using bytecode rewriting. This is also a form of interception.

accessing the property of a child from the parent and passing such property to another component in flex

I have a component A which has two components B and C. Now, component B has a child component D which has an XML property. The task now is how can i pass the XML property from D to the C component?
You can either say C.xmlProperty = D.xmlProperty in your A component or you can dispatch a custom event with data from your D component and listen for that event in your C component.
If you want more specifics, please show me some example code so that i can help you more.
all the best,
blz
You should create and dispatch a custom event which contains that XML. You can read more about custom events here. So D dispatches your event to B. B can process data and finally redispatches it to A. Or you can use event bubbling and listen to this event from D directly in A. The disadvantage of the second way with bubbling is impossibility to declare a contract (using metatags) and impossibility to handle events in MXML.

Resources