ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SAP C4C基于自定义BO开发的OWL UI,如何实现动态访问控制

2020-08-30 18:02:37  阅读:385  来源: 互联网

标签:OWL 自定义 BO field step var new


My series of Cloud Application Studio Blogs

Suppose I have a testBO with the following fields:

import AP.Common.GDT as apCommonGDT;
import AP.FO.BusinessPartner.Global;

businessobject TestBO {
[Label("Agreement ID")] [AlternativeKey] element AgreementID:ID;
		[Label("Start Date")] element StartDate:Date;
		[Label("Close Date")] element CloseDate:Date;
		[Label("Duration")] element Duration:NumberValue;
		[Label("IsOverDue")] element IsOverDue:Indicator;
		[Label("Quantity")] element Quantity: Quantity;
		[Label("ProductName")] element ProductName: LANGUAGEINDEPENDENT_EXTENDED_Text;
		[Label("DepartmentName")] [Transient] element DepartmentName:LANGUAGEINDEPENDENT_EXTENDED_Text;
		[DependentObject(AttachmentFolder)] node Attachment;
}

And here is some test data displayed in OWL:

Now I would like to achieve the dynamic access control below:
Suppose the currently logged on user has been assigned to an organization unit which is only allowed to sell product with name “Laptop”, then this business user SHOULD ONLY see those entries whose value in ProductName equals to Laptop as well. That is to say, the last two entries in above picture with ProductName Monitor should be filtered out.

How the restriction that only Laptop is allowed to sell for employees within a given Organization Unit

For demonstration purpose I just reuse the standard field “Department Name” to store the name of sellable product.

And I assign myself to this organization unit, which means Employee Jerry Wang is only allowed to sell Laptop.

Now I implement this dynamic access control into a new OWL named TestBORestricted_OWL.

Below is the achievement: I have put this new OWL into a new tab in Thing Inspector and once launched, only entries whose ProductName equal to Laptop are displayed. Other entries are filtered out due to the fact that this employee is not allowed to sell them.

Implementation Detail

Here below is step by step implementation detail:
(1) Create an AfterLoading event in TestBO with mass enabled checkbox unselected,

And implement the following ABSL code to fill the transient field with product name which is allowed to sell for current logged on user.

import ABSL;
import AP.PC.IdentityManagement.Global;
import AP.FO.BusinessPartner.Global;

var queryByIdentityUUID = Identity.QueryByElements;
var queryByIdentityUUIDParameter = queryByIdentityUUID.CreateSelectionParams();
var queryByEmployeeBPUUID = Employee.QueryByIdentification;
var queryByEmployeeBPUUIDParameter = queryByEmployeeBPUUID.CreateSelectionParams();


if ( this.DepartmentName.IsInitial()){

	var id = Context.GetCurrentIdentityUUID().content;
	queryByIdentityUUIDParameter.Add( queryByIdentityUUID.UUID.content, "I", "EQ", id.ToString() );
	var result = queryByIdentityUUID.Execute(queryByIdentityUUIDParameter);
	var first = result.GetFirst(); // points to identity instance
	var person = first.Person;
	var bpUUId = person.UUID.content;
	queryByEmployeeBPUUIDParameter.Add( queryByEmployeeBPUUID.UUID.content, "I", "EQ", bpUUId.ToString());
	var employeeQueryResult = queryByEmployeeBPUUID.Execute(queryByEmployeeBPUUIDParameter);
	var EmployeeQueryResultCurrent = employeeQueryResult.GetFirst();
	if( EmployeeQueryResultCurrent.OrganisationalUnitAssignment.Count() > 0 ){
		var assignedOrg = EmployeeQueryResultCurrent.OrganisationalUnitAssignment.GetFirst();
		var org = assignedOrg.ToRoot;
	    // readOnly in AfterLoading event
	   this.DepartmentName  = org.NameAndAddress.AddressSnapshot.NameSuitableForLogonLanguage.GetFirst().Name.SecondLineName;
	}
}

(2) In new TestBORestricted_OWL, create a new field ProductName under search structure SearchParameters.

Bind the query to QueryByElements modelled in TestBO and bind the query parameter ProductName to the field ProductName under SearchParameters.

Create a new inport and bind the parameter to the field mentioned above as well.

(3) Create a new outport in Thing Inspector, bind the parameter productName with the transient field DepartmentName filled in step 1.

Create a new tab in Thing Inspector and drag the new OWL into it. Click Bind button:

Bind the parameter of outport defined in TI with the one in inport of new OWL.

With all the steps above done, the sellable product name calculated by ABSL is passed from TI to new OWL via parameter passing during navigation, and could be considered during the query of new OWL is executed. As a result the restriction takes effect due to this ProductName search parameter.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

标签:OWL,自定义,BO,field,step,var,new
来源: https://www.cnblogs.com/sap-jerry/p/13585967.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有