Are there any possible ways to ignore all paths of JPA Example Matcher - spring

I'm new to Spring JPA.
I has two questions about Example and ExampleMatcher API.
Are there any ways to ignore all paths except some paths which I set matchers. Or are there any ways to ignore all paths if Example object's path has null value. It is quite annoying to set all path names like below:
ExampleMatcher<Product> matcher =ExampleMatcher.matching().ignorePaths("field_a", "field_b");
How to match joined column using Example. For example. Product entity has User entity field as #ManyToOne relation. User entity has several fields but my Example object has User field only filled with userId field. In this case I want to find product data which has user_id foreign key column matching userId field value included in user object included in product Example object.
Sorry for poor English... Actually this is my first question at Stack Overflow.
Thanks for attention.
I'm looking forward for great answers.

Spring Data by default will ignore null values in properties. So you need not ignore paths for null values. We could also use the withIgnoreNullValues() (docs) method call on the matcher to explicitly tell it to ignore null values.
Note primitive values(int,double,etc) if not set will still be used since primitives can't have nulls and use default values instead so you should ignore the primitive properties if not used for matching.
For your second question, you could do something like the below
Product product = new Product();
User user = new User();
user.setId(5); // Id to be matched
product.setUser(user); // Associate User object with Product
Example<Product> example = Example.of(product,matcher);

Related

How to use Get Record to lookup a related record on another object when I don't have the schema Entity Name - Just the LogicalName

All,
I am building a Power Flow. I am returning an object that has a relationship to another entity.
I want to get some values from the related entity.
I am attemping to use the "Get Record" connector. The returning object returns just the logicalEntityName (in this case "opportunities") but Get Record wants an Entity Name that is the Schema Name ("Working Opportunities").
Big Question: What's the secret to use CDS to get information from a related record in another object?
Little Question: How do I do get the Schema Name?
The logical name will be the same as schema name except some casing difference, ie schema name will have camel casing (first letter of first/second word with capitals, you can notice it clearly in custom entity which will have publisher prefix like new_entityname) and logical name will have pascal casing (all lower case).
You can find the details in XrmToolBox metadata browser or in Solution.
In the below snip, (Logical) Name = Opportunity and Schema Name = Opportunity, also Display Name can be anything and can be changed anytime.
Regarding the related entities, you should use List Records: GetItems_V2 and you can use filter by passing parent record to get related child records. Read more
Could you please share flow screenshot and response to help you with your requirement?
As suggested by Arun you could use List Record and filter query to pass parent record id which will be available from dynamic content.
see below link.
https://crmkeeper.com/2019/08/31/cds-list-records-filter-query-using-flow/
Please mark my answer verified if i were helpful

laravel collection merge didn't work as I expected

I have similar but slightly different Eloquent Model classes named Exam, Type, Custom.
$recent = Exam::orderBy('updated_at', 'desc')->take(3)->get();
$recent = $recent->merge(Type::orderBy('updated_at', 'desc')->take(3)->get());
$recent = $recent->merge(Custom::orderBy('updated_at', 'desc')->take(3)->get());
Above is what I've tried and it doesn't work. Final $recent collection contains Custom items only. Other items like Exam, Type are disappeared.
Currently, I'm replace this part with push method. It works fine but even after saw the source code of merge method, I cannot find the reason why my previous code doesn't work.
Its because your keys are almost similar (as you mentioned in the question). Values of string keys from the original collection will be replaced by the new collection values if key matches. So merge is not a better approach if you want values from three different models having same keys. Like same id from Exam model will be replaced by the Type model id and then it will be replaced by the Custom model id. push is ok as it doesn't replace the matched key values rather push it as a new item in the collection. So use push instead of merge
Laravel Docs

Passing an element of a collection in the query builder

I would like to make a second request with the id obtained in the previous request.
I have 3 tables:
organization
users
follow_organization (relationship table)
I would like to obtain the number of occurrences in the follow_organization table by passing the id of the organization previously obtained.
$organization = DB::table('organizations')->where('name', $name)->first();
$followers = DB::table('follow_organizations')->where('organization_id', $organization)->count();
Unfortunately, I get the following error message:
Object of class stdClass could not be converted to string.
I understood the problem, I pass a table while the query builder waits for a string.
But I can't find the solution to this problem despite the tons of answers I've read on the internet.
Currently you are passing the whole organization object into the where clause, but you only need the id.
To access the id property you can use $organization->id
DB::table('follow_organizations')->where('organization_id', $organization->id)->count();
Setting and Getting Property Values

FetchXML to filter by name of E-mail's RegardingObjectId

I have a query that starts at the QueueItem and, if the entity that Queue Item references is an E-mail, adds some additional filter conditions. One of those conditions is the primary field value of whatever that e-mail, in turn, is "Regarding". I don't really care what type of entity the E-mail references, I just need to allow the user to filter by the "Name" of that entity. Is this possible, and if so, how?
This depends somewhat from where the query is performed from.
With a basic FetchXML query, in around about sort of a way this is possible, you need to do joins on the relationship and see if there is a record there. Its not perfect but it might work.
If you are running the query from code, then its a bit easier as you can examine the entity type in code. For example:
EntityReference e = entity.GetAttributeValue("regardingobjectid");
string entityName = e.LogicalName;

How do I use Spring Roo for referenced data

I’m new to Spring Roo and looking to build an application. I need to have combo boxes to select values into string fields – a fairly common requirement. The Spring Roo Pizza example shows this using enumerated data types enum constant, but I require the source values to be editable by an admin (ie in a table) so we can change the values in the future. Further, my preference would be to use a single table to contain all these lists for easier maintenance.
I know the SQL I want to generate the list would be something like:
Select listvals FROM listTable WHERE listtype = “status”;
Then, my dropdown box would show something like: Active, Inactive. The user would select one, and the string “Active” would be stored in the target field.
And in a second example, we might use:
Select listvals FROM listTable WHERE listtype = “State”;
The second dropdown box would show something like: Alaska, California, Florida. The user would select one, and the string “Florida” would be stored in the target field.
My CORE question is how does one achieve this sort of function in Roo?
Using the Pizza Shop quick start as a sandbox I have tried defining the target fields such as:
I changed: field reference --fieldName base --type ~.domain.Base to:
field reference --fieldName base --type ~.domain.Base --referencedColumnName name
Which returned this error:
#JoinColumn name is required if specifying a referencedColumnName
The initial problem is that at this point roo has yet to create the row ID columns for the db, so I don’t know the name of the join column on the Base table. But, if I wait until after I run the script with a 1:M join, the column pizza.base will be defined as an integer, and not the string that I want.
So, I ran the vanilla pizza shop roo script and interrogated the vanilla db. (Does roo generate an SQL script for db creation that I could look at?)
As it turns out, roo names the row id column “id” as a BigInt. (I also note that it doesn't seem to make use of the SEQUENCE feature that postgres recommends for primary indices / row Ids.)
So now I run:
field reference --fieldName base --type ~.domain.Base --referencedColumnName name --joinColumnName id
Roo likes this!
Until I perform tests where it throws out a number of undecipherable errors in the Surefire reports.
I note that solving this problem is only step 1 to meeting my overall requrement described above. Step 2 will be to try to inject some sort of filter or where clause into the reference statement. I suspect that this has to do with the --fetch option (Roo support docs (http://docs.spring.io/autorepo/docs/spring-roo/1.2.5.RELEASE/reference/html/command-index.html#command-index-finder-commands - The fetch semantics at a JPA level; no default value)
But, I can’t find an example of this to see if I’m on the right track or to model my ‘fetch semantics’ – whatever those are.
Another possibility might be to use field list to define a class containing my list of dropdown values. This has a similar modifier --fetch, but again I can’t find any examples.
I’d really appreciate some help in answering my CORE question above.
THANKS!
Fetch parameter indicates whether the association should be lazily loaded or must be eagerly fetched (https://docs.oracle.com/javaee/6/api/javax/persistence/ManyToOne.html#fetch()).
Maybe the error of tests can be because you try to find, create, delete or update elements with related elements that not exists. Check this first of all.
You can see an example of application created with gvNIX (distribution of Spring Roo) that contains relationships between some entities on https://github.com/DISID/gvnix-samples/blob/master/quickstart-app/quickstart.roo

Resources