Need more complex custom mapping between Saga data and Saga message - nservicebus

Let's say I have message
public interface ISagaMessage
{
string Type1 { get; set; }
string Type2 { get; set; }
...
}
Is it possible to build Saga for Type1 values OR Type2 values being mutually interchangeable, so that all this 3 messages should work under the same Saga:
Message1: Type1 = AA, Type2 = null
Message2: Type1 = AA, Type2 = BB
Message3: Type1 = BB, Type2 = null
Desired scenario: First message creates Saga (AA,null), then Message2 get hooked on the same Saga because its pair of type (AA,BB) is overlapped with (AA,null) by element AA. Next Message3 is overlapped by BB value now. If new message Message4 comes in with Type1 = CC, Type2 = null, new Saga will be created.
Only 2 specific type values combination is possible, so that AA comes with BB always, CC always with DD, EE with FF etc. For example, AA will never come with CC. Saga does not know all this pairs of type values combinations upfront, so receiving (AA,null) it can't create Saga based on (AA,BB), BB is not known at this step
If I was able to build custom code to pick up right Saga I would come up with something like this (skipping null check):
public Saga GetSaga(ISagaMessage message)
{
IList<Saga> existibgSagas = GetExistingSagas();
return existibgSagas.FirstOrDefault(
s => s.Type1 == message.Type1 || s.Type1 == message.Type2 ||
s.Type2 == message.Type1 || s.Type2 == message.Type2))
}

That's not possible with the default saga finder implementation, but you can provide your own custom IFindSagas implementation. That will probably do the trick.
Check out documentation at https://docs.particular.net/nservicebus/sagas/saga-finding.
Samples at https://docs.particular.net/samples/saga/nh-custom-sagafinder/ and https://docs.particular.net/samples/saga/ravendb-custom-sagafinder/.

Related

How do i get the Specflow scenario outline example data to a table

Is there any way to get the scenario context outline example values i mean all the values in to a table
Scenario Outline: Create a Matter
Given I enter "< parameter1 >"
Then I enter "<parameter2>"
Then I enter "<parameter3>"
Then I enter "<parameter4>"
Then review all the parameters entered above in this final step
Examples:
| parameter1 | Paramter2|Parameter3|Parameter4|....|parameter14|
| value |value2 |value3 |value4 |....|value14|
in the above scenario is there any way to get all the example values in step4 to a table
I know I can set ScenarioContext.Current[parameter1] = value in each step
In my case I have 14 parameters which are used in each step but in the final step i need to use all the 14 parameters
is there any way I get the example values in to table.
I don't want to break in to smaller scenario
like below
Scenario: breaking in to smaller chunks
Given I enter the following
| parameter1 | Paramter2|
| value |value2|
Here is something I use that may help. Andreas is the expert though on this stuff and he probably has a better idea. Since your format was less than ideal, I used a basic scenario.
Change it to a "Scenario" and Drop the "Scenario Outline".
The feature looks like this:
Scenario: Validate Shipping Fees
When the user enters the State then we can verify the city and shipping fee
| City | State | Shipping |
| Boulder | Colorado | 6.00 |
| Houston | Texas | 8.00 |
Add the Table.
public class ShippingTable
{
public string City { get; set; }
public string State { get; set; }
public string Shipping { get; set; }
}
Then in your step:
[When(#"the user enters the State then we can verify the city and shipping fee")]
public void WhenTheUserEnterTheStateThenWeCanVerifyTheCityAndShippingFee(Table table)
{
var CityState = table.CreateSet<ShippingTable>();
foreach (var row in CityState)
{
try
{
Pages.CheckoutPage.SelectState(row.State);
Pages.CheckoutPage.SelectCity(row.City);
var recdPrice = Pages.CheckoutPage.GetShippingPrice;
Assert.AreEqual(row.shipping, recdPrice);
}
catch (Exception)
{
throw new Exception("This is jacked up");
}
}
}

Data class .copy only if nullable parameter is not null

I have a Front-End application that sends me Data to update my User (updatedUser). Since I don't want to send the whole Userdata, I'm only sending the data that has changed. Now I want to Update my Userdata with the changes provided, so I'd like to know if there is a more elegant way to do this than just a list of ifs/lets. I'm quite new to kotlin, so don't expect too much from me^^
Not so elegant way:
changeData.firstname?.let { updatedUser.firstname = it }
changeData.lastname?.let { updatedUser.lastname = it }
...
Expected (doesn't work - type mismatch):
updatedUser.copy(
firstname = changeData?.firstname,
lastname = changeData?.lastname,
...)
the reason you get a type mismatch is There is a string type and a string nullable type
var variableName:String = "myData" // if you want a non nullable
var variableName:String? = "myDataThatCouldBeNull" // if you want a string that could be null

Optionally copy values between EMF attributes

Question
Imagine following EMF-model based JFace-form
+-------------------------------------------------+
| My text field1 : __________________ |
+-------------------------------------------------+
| Inherit value from field1: [x] |
| My text field2 : __________________ |
+-------------------------------------------------+
Corresponding EMF-EClass
class Model {
String field1;
boolean inherit;
String field2;
}
Here the user should enter the value of the field1. Then he can
check the checkbox to copy the value from field1 to field2
uncheck the checkbox and enter a different value for the field2
My question:
How this kind of pattern should be properly implemented using JFace data-binding?
(The text field my be all kind of widgets including tables)
(I would like to leave the enabling/disabling field2 text box out of the scope of this question)
Dirty solution
IObservableValue value1Obs = EMFProperties.value(field1).observe(model);
IObservableValue value2Obs = EMFProperties.value(field2).observe(model);
IObservableValue inheritObs = EMFProperties.value(inherit).observe(model);
IObservableValue copyObs = new ComputedValue() {
#Override
protected Object calculate() {
if ((Boolean)inheritObs.getValue()) {
return value1Obs.getValue();
}
return value2Obs.getValue();
}
}
getBindingContext().bindValue(value2Obs, copyObs);
Don't use this
This works for simple attributes but don't work for lists/tables.
Also in case inherit=false I bind field2 to itself. This looks weird and may cause problems in the future.

HQL Query 2 sub classes with a property by the same name

I have 3 classes like:
public class Animal
{
... all sort of data ...
}
public class Cat : Animal
{
... more data ...
public virtual int Size { get; set; }
}
public class Dog : Animal
{
... other data ...
public virtual int Size { get; set; }
}
The classes are mapped using the "table per hierarchy" strategy in the hbm.xml mapping the Cat's Size property is mapped to a CatSize column and the Dog's property to DogSize
The following two queries work as expected:
From Cat o Where o.Size = 1
From Dog o Where o.Size = 1
Now I want to query Animal for all the cats where Size = 1 and all the dogs where size = 1, combining the two queries above I get:
From Animal Where o.Size = 1 Or o.Size = 1
That obviously doesn't do what I want, how can I tell NHibernate the first Size is Cat.Size and the second is Dog.Size (preferably without knowing the column names in the database).
Note: I understand the design is problematic an having two properties with the same name in different subclasses is not the smartest design decision ever made - but changing it now is even more problematic and I'd like to avoid it (the project should be delivered to the client in a few days and I really don't want to make design changes now).
I'm using NHibernate 2.0.1 (upgrading is not an option, the program does not work with later versions of NHibernate and we don't have time to fix it now).
Try this...
select a from Animal a where a in (select c from Cat c where c.Size = 1) or a in (select d from Dog d where d.Size = 1)
Why didn't you define the Size property on the Animal class ?
You can use a MultiQuery to execute the 2 queries in one roundtrip, and that will give you the results as well.
I think that this will be the best solution ...
IMultiQuery q = session.CreateMultiQuery();
q.Add("from Cat where Size = 1");
q.Add("from Dog where Size = 1");
var results = q.List();
var cats = (IList)results[0];
var dogs = (IList)results[1];

uniqueness of composite id with null component

I am running into problems using unique constraints.
The following combinations are allowed
A.name B.name
foo NULL
foo bar
foo bar1
foo1 bar
It should not be possible to create a new A with same name, only if it has a different B.
With the constraints below it is possible to create
A.name B.name
foo NULL
foo NULL
Because NULL seems not to have effect on unique.
Any hints how to fix this?
class A {
String name
static belongsTo = [b:B]
static constraints = {
name(unique:'b')
b(nullable:true)
}
}
class B {
String name
static hasMany = [as:A]
name(unique:true)
}
In the database structure, could you set the columns to NOT NULL DEFAULT 0 or similar, and then treat the zeros the same as you otherwise would the NULLs? Since the column is for names, there's likely to be no digits in the values anyway right?
I'm not entirely sure, but I think this will work:
name(unique:['b', 'name'])
Looking at the code for the unique constraint, it seems feasible. The constraint definitely lets you pass in a list of things to compare the uniqueness to. It calls this the uniquenessGroup. Then, when validating, it iterates over this list. Take a look starting at line 137 here: http://www.docjar.com/html/api/org/codehaus/groovy/grails/orm/hibernate/validation/UniqueConstraint.java.html
The code looks like this:
if(shouldValidate) {
Criteria criteria = session.createCriteria( constraintOwningClass )
.add( Restrictions.eq( constraintPropertyName, propertyValue ) );
if( uniquenessGroup != null ) {
for( Iterator it = uniquenessGroup.iterator(); it.hasNext(); ) {
String propertyName = (String) it.next();
criteria.add(Restrictions.eq( propertyName,
GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(target, propertyName)));
}
}
return criteria.list();
}
So it depends on whether the GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue call will retrieve a property in the same class. Which based on the name it seems like it should.
I'm curious to know if it works for you.