Reputation: 277
I am trying to use flexible search with restriction. I have a session attribute (?session.userGroups) and want to filter using this list of groups.
I've seen in SAP documentation how to do this if the given table you are trying to filter contains the object you are wanting to filter on. For example {country} IN (?session.countries}. Where {country} exists in the table.
But how would I do something like filter on the country table directly.
Or in my case I want to filter the UserGroup table directly.
What property can I use. Thought maybe the {pk} but the session attribute contains objects themselves not just PKs.
{pk} IN (?session.usergroups} --not sure this is correct
{what goes here} IN (?session.usergroups}
Upvotes: 0
Views: 4199
Reputation: 5430
Assuming you are saving list of UserGroup Objects in session
For example :
Set<UserGroupModel> usergroups = userService.getAllUserGroupsForUser(user);
sessionService.setAttribute("userGroups", usergroups);
Now there are two way :
Using SearchRestriction/Personalization - (Search Restriction will impact everywhere in site for customergroup)
INSERT_UPDATE SearchRestriction;code[unique=true];name[lang=en];query;principal(UID);restrictedType(code);active;generate
;usergroup_restriction;Restrict UserGroups visibility;{item:PK} IN (?session.userGroups);customergroup;UserGroup;true;true;
Apply Search Condition directly in FlexibleSearchQuery -
FlexibleSearchQuery ->
String queryString = "Select {PK} from {UserGroup} where {PK} in (?usergroups)"
final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
query.addQueryParameter("usergroups", sessionService.getAttribute("userGroups"));
return flexibleSearchService.search(query);
Upvotes: 1