cancel
Showing results for 
Search instead for 
Did you mean: 

Is Java needed when implementing Search Restrictions?

Former Member
0 Kudos
254

Hy experts, I have one doubt about search restrictions. I've read documentation about restriction but I have this doubt:

If I create a new search restriction by impex there it's no need to implement java code?

I just execute the impex with the restriction and works, or I have to activate restrictions by java. If i have to activate it by java, what class should I implement, or what do I need to do. I've no idea.

Thanxs.

Accepted Solutions (1)

Accepted Solutions (1)

former_member620692
Active Contributor
0 Kudos

You do not need to implement a Java class. The ImpEx script is sufficient. However, you can also create and manage restrictions using Java code.

Please refer https://help.hybris.com/1808/hcd/8c428f8286691014970ceee87aa01605.html for more information. This page says,

Restrictions are rules obeyed by FlexibleSearch which allow to limit search results depending on which type is searched and which user is currently logged in.

This happens transparently and does not require any code adjustment on business layer.

This page also has sections, Creating Restrictions via the SAP Commerce API and Creating Restrictions via the ImpEx Extension which you can go through to understand the options.

You can also refer my answer, https://answers.sap.com/questions/12770249/role-specific-categories-display-in-back-office-pr.html?c... for an example.
Former Member
0 Kudos

Hy Arvind. Thanx again for your support. As you manage a lot hybris, one thing:

A restriction, as I read it must be applied to a type or group. Is right no? It's because client wants: "In order not to use user group, will add to employee entity an enum to define the type of user." Depending of the enum values user has, it will apply restriction or not. But as I read we must apply restriction to a group. To do that, if possible, I will have to create a new class or samething like that but I have no idea where to start. I think if anyway need a group it will be better to do this byimpex.

former_member620692
Active Contributor
0 Kudos

Please note that restrictions work on FlexibleSearch queries only and is basically just a fragment of the WHERE clause which gets added to a FlexibleSearch query. So, whatever restriction criteria you are going to define must fit with WHERE clause of a FlexibleSearch query. Since the restriction affects all members of the applicable UserGroup, you can create hierarchy of sub groups and then use the required user group (level) in the restriction.

I hope it helps.
Best Regards.

Former Member
0 Kudos

Ok. It's just that in documentation I saw restriction can be created by java too.

Employe will have a boolean property: useRestriction. When data is loaded if user property is true then will apply a restriction for this user. But in the image it only sais service we must use but no what class we have to create/extends/implements.....

Do you know if I want to implement this by java what class I need to create or your advise is to use impex.

Thanx again and sorry, but I'm new in hybris and it's quite difficult first.

former_member620692
Active Contributor
0 Kudos

Please check my answer again. I had already mentioned that you can create and manage the restrictions using Java too 🙂

You can use the code wherever you want. You can refer hybris/bin/platform/ext/core/testsrc/de/hybris/platform/servicelayer/internal/i18n/impl/DefaultLocalizationServiceTest.java as an example.

Former Member
0 Kudos

I saw your answer (https://answers.sap.com/questions/12770249/role-specific-categories-display-in-back-office-pr.html?c...) but I see you use an impex to add a restriction. Or when you launch an impex it automatically creates all java clases?

former_member620692
Active Contributor
0 Kudos

No, my ImpEx will not create any Java class. It will simply add the restriction to the database so that when any business logic (hybris code) which will try to execute the Flexible Search query, SELECT {PK} FROM {Category} for TestProductManager, will be given the following modified query by hybris:

 SELECT {PK} FROM {Category} 
 WHERE
 {PK} IN ( {{SELECT {cat.PK} FROM {Category as cat JOIN Catalog as c ON {cat.catalog} = {c.PK}} WHERE {c.id} = 'electronicsProductCatalog' AND {cat.code} = '577'}})
Former Member
0 Kudos

Can you give me a hint of how to create it by java. I've read the answer but can't find out how to create it.

Thanx.

former_member620692
Active Contributor
0 Kudos

I had already mentioned in the previous comment that you can refer hybris/bin/platform/ext/core/testsrc/de/hybris/platform/servicelayer/internal/i18n/impl/DefaultLocalizationServiceTest.java as an example.

Former Member
0 Kudos

Hy Arvind. I've seen the example. Sorry but first time I didn't see it.

I studied similar examples but all are java test class. I coundn't see any example of a class that is not a test class to take it as a reference.

Do you know any example? Like a tutorial. What class to create, if bean declaration is needed or item.xml modify (I saw an example where in item.xml is defined an attribute searchAllRestriction but none of how to create a new one).

I've searched tutorials but nothing; all examples I've find in project are javatest........

Thanxs again 😉 Regards.

former_member620692
Active Contributor
0 Kudos

I do not see any use case except a test class where you should write Java code to create a restriction. Since you already have SearchRestriction itemtype for which you just need to insert search restriction query in the DB (which you do using ImpEx) and the rest is all taken care by Hybris, why do you bother to reinvent the wheel?

Answers (0)