CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
SAP Commerce has Special Logic written to Export Access Rights available in the System. The below script is responsible for Exporting Access Rights -
"#% impex.setTargetFile(""UserRight.csv"",true,0,0);"
#SPECIAL CASE: Type UserRight will be exported with special logic (without header definition), see https://wiki.hybris.com/x/PIFvAg
"#% impex.exportItems(""UserRight"", false);"


Problem Statement:


Since this special logic export access rights of all the UserGroups & Users including its child items as well such as B2BUnit, Employee, Customer, B2BCustomer etc.

In Production System, there can be millions of B2BUnits and Customers are available which makes the whole Export Script drastically Slow to provide the final result.

Generally Access Rights relevant for UserGroup & Employee only then there is no point of looking these irrelevant items as well and to make the whole Export Process Slow.

What if i only Export Access Rights of UserGroup & Employee only, will that make if Fast, and the answer if YES 🙂

Special Logic:


Before we jump to the Solution, let's first understand what this Special Logic is and where it is written.



Exporter Class -



package de.hybris.platform.impex.jalo.exp;

public class Exporter implements LocationProvider {

public void exportItems(String typecode, int count, boolean inclSubTypes) throws ImpExException
{
if (typecode.equals(TypeManager.getInstance().getComposedType(UserRight.class).getCode()))
{
this.exportUserRights(); //Special Logic
}
else
{
int start = 0;
int range = count;
Collection items = null;

do {
items = this.getAllItems(typecode, start, range, inclSubTypes);
start += range;
this.exportItems(items);

} while(items != null && items.size() == range);
}
}

Whenever we Export UserRights, this if condition matched, and exportUserRights() method is being called. This method uses one Helper class - ImportExportUserRightsHelper which ultimately export the permissions.


ImportExportUserRightsHelper - 


public void exportSecurity() 
{
Set allUserAndUserGroups = new HashSet();
allUserAndUserGroups.addAll(UserManager.getInstance().getAllUserGroups()); //Fetch all UserGroups including child one as well
allUserAndUserGroups.addAll(UserManager.getInstance().getAllUsers()); //Fetch all users including child one as well
this.exportSecurity(allUserAndUserGroups);
}

This method fetches all UserGroups & Users including its child items as well.

We are interested in Export Access Rights of only UserGroups & Employees without any child items.


 

Solution:


The Solution is pretty simple. This can be achieved using Personalization (or SearchRestriction).

Step 1- 


Create new Backoffice Role e.g. SecurityGroup which should have Access of Export Permission in Backoffice.



Step 2-


Create Two new SearchRestriction for our newly created Backoffice Role e.g. SecurityGroup
INSERT_UPDATE SearchRestriction;code[unique=true];name[lang=en];query;principal(UID);restrictedType(code);active;generate

;Export_UserGroup_Permission_Restriction;Restrict SecurityGroup to export only UserGroup Permissions;{itemtype} in ({{select {PK} from {ComposedType} where {code}='UserGroup'}});SecurityGroup;UserGroup;true;true

;Export_Employee_Permission_Restriction;Restrict SecurityGroup to export only Employee Permissions;{itemtype} in ({{select {PK} from {ComposedType} where {code}='Employee'}});SecurityGroup;User;true;true

The first one will apply on UserGroup and another one on User Type and filter query make sure only item with UserGroup and Employee ComposedType shall be considered.


Step 3-


Now create any test employee e.g. testSecurityGroup for SecurityGroup role and login with that employee in Backoffice.


 

Step 4-


Click on Export node, one popup window shall be open. Paste UserRights export script there.


 

Step 5-


Validate the script and click on Save button. As soon as we save the script, a new Impex Media created for the same. Select Mode - Export (No re-import)


 

Step 6-


Click on Next button and Start the Export


 

Conclusion:


This way we can improve the Performance of Exporting UserRights in Production and get the meaningful result as we want.

 

Thank You

Shreshtt Bhatt
2 Comments