blob: c51bb9de809a0c47218e5e301ec935f8003a3054 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_CLL_DsRestAPI_Filter_Functions
//
// Purpose:
// This module contains the functions of EPTF_CLL_DsRestAPI_Filter.
//
// Module depends on:
// <EPTF_CLL_Variable_Definitions>
// <EPTF_CLL_DataSource_Definitions>
// <EPTF_CLL_DataSource_Functions>
// <EPTF_CLL_Variable_Functions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_DsRestAPI_Filter_Definitions>
// <TCCConversion_Functions>
// <EPTF_CLL_Common_Definitions>
// <EPTF_CLL_FBQ_Functions>
//
// Current Owner:
// Tamas Kis (ekistam)
//
// Last Review Date:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////
module EPTF_CLL_DsRestAPI_Filter_Functions {
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_DataSource_Definitions all;
import from EPTF_CLL_DataSource_Functions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_DsRestAPI_Filter_Definitions all;
import from TCCConversion_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_FBQ_Functions all;
import from EPTF_CLL_Logging_Definitions all;
import from EPTF_CLL_Logging_Functions all;
import from EPTF_CLL_DsRestAPI_Storage_Definitions all;
import from EPTF_CLL_DsRestAPI_Storage_Functions all;
friend module EPTF_CLL_DsRestAPI_DSServer_Functions;
//=========================================================================
// Functions
//=========================================================================
friend external function ef_EPTF_DsRestAPI_replaceAllIfMatches(inout charstring pl_toReplace, in charstring pl_replaceTemplate, in charstring pl_replaceWith);
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Filter_init_CT
//
// Purpose:
// Initialize the DataSource Server for DsRestAPI
//
// Parameters:
// pl_selfName - *in* *charstring* - the name of the component
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Filter_init_CT(in charstring pl_selfName) runs on EPTF_DsRestAPI_Filter_CT {
if (not v_DsRestAPI_Filter_initialized) {
f_EPTF_Base_init_CT(pl_selfName);
f_EPTF_Var_init_CT(pl_selfName);
f_EPTF_DataSource_init_CT(pl_selfName);
f_EPTF_FBQ_init_CT(pl_selfName);
f_EPTF_Logging_init_CT(pl_selfName);
v_DsRestAPI_Filter_loggingMaskId := f_EPTF_Logging_registerComponentMasks(tsp_EPTF_DsRestAPI_Filter_loggingComponentMask, c_EPTF_DsRestAPI_Filter_loggingEventClasses, EPTF_Logging_CLL);
f_EPTF_FBQ_initFreeBusyQueue(v_DsRestAPI_Filter_filtersToBeEvaluatedQueue);
f_EPTF_FBQ_initFreeBusyQueue(v_DsRestAPI_Filter_outstandingFiltersQueue);
f_EPTF_Base_registerCleanup(refers(f_EPTF_DsRestAPI_Filter_cleanup_CT));
v_DsRestAPI_Filter_initialized := true;
}
}
friend function f_EPTF_DsRestAPI_Filter_debug(in @lazy charstring pl_msg) runs on EPTF_DsRestAPI_Filter_CT {
f_EPTF_Logging_debugV2(pl_msg, v_DsRestAPI_Filter_loggingMaskId, {cg_EPTF_DsRestAPI_Filter_loggingClassIdx_Debug});
}
friend function f_EPTF_DsRestAPI_Filter_warning(in @lazy charstring pl_msg) runs on EPTF_DsRestAPI_Filter_CT {
f_EPTF_Logging_warningV2(pl_msg, v_DsRestAPI_Filter_loggingMaskId, {cg_EPTF_DsRestAPI_Filter_loggingClassIdx_Warning});
}
private function f_EPTF_DsRestAPI_Filter_cleanup_CT() runs on EPTF_DsRestAPI_Filter_CT {
if (v_DsRestAPI_Filter_initialized) {
f_EPTF_FBQ_deleteFreeBusyQueue(v_DsRestAPI_Filter_filtersToBeEvaluatedQueue);
f_EPTF_FBQ_deleteFreeBusyQueue(v_DsRestAPI_Filter_outstandingFiltersQueue);
v_DsRestAPI_Filter_filtersToBeEvaluatedDB := {};
v_DsRestAPI_Filter_outstandingFiltersDB := {};
v_DsRestAPI_Filter_initialized := false;
}
}
private function f_EPTF_DsRestAPI_Filter_replaceFilterRequestParam(inout EPTF_DsRestAPI_Filter pl_filter, in charstring pl_replacement, in EPTF_IntegerList pl_filterPath, in integer pl_nextPathIndex) runs on EPTF_DsRestAPI_Filter_CT return EPTF_DsRestAPI_Filter {
if (pl_nextPathIndex < sizeof(pl_filterPath) - 1) {
return f_EPTF_DsRestAPI_Filter_replaceFilterRequestParam(pl_filter.request.params[pl_filterPath[pl_nextPathIndex]].paramValue, pl_replacement, pl_filterPath, pl_nextPathIndex + 1);
} else {
pl_filter.request.params[pl_filterPath[pl_nextPathIndex]].paramValue.dataValue := pl_replacement;
return pl_filter
}
}
private function f_EPTF_DsRestAPI_Filter_filterResponseArrived(in integer pl_errorCode, in EPTF_Var_DirectContent pl_dataValue, in EPTF_IntegerList pl_userData) runs on EPTF_DsRestAPI_Filter_CT {
var EPTF_IntegerList vl_filterPath := v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterPath;
var charstring vl_replacement := f_EPTF_Var_directContent2str(pl_dataValue);
if (pl_errorCode != 0) {
f_EPTF_DsRestAPI_Filter_warning("Error during filtering; error code: " & int2str(pl_errorCode) & ", error msg: " & vl_replacement);
vl_replacement := "false";
}
if (v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].storageKey != "") {
f_EPTF_DsRestAPI_Storage_storeItem(v_DsRestAPI_Filter_filtersToBeEvaluatedDB[v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterId].storageId, v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].storageKey, pl_dataValue);
}
if (vl_filterPath == {}) {
var EPTF_DsRestAPI_EvaluatedFilterHandlerItem vl_filterHandler := v_DsRestAPI_Filter_filtersToBeEvaluatedDB[v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterId];
if (vl_replacement != "true" and vl_replacement != "false") {
f_EPTF_DsRestAPI_Filter_warning("Root filter should evaluate to true or false, it is: " & vl_replacement);
}
vl_filterHandler.filterEvaluatedCallback.apply(vl_replacement == "true", vl_filterHandler.userData);
f_EPTF_FBQ_moveFromBusyToFreeTail(v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterId, v_DsRestAPI_Filter_filtersToBeEvaluatedQueue);
} else {
var EPTF_DsRestAPI_Filter vl_filterToSend := f_EPTF_DsRestAPI_Filter_replaceFilterRequestParam(v_DsRestAPI_Filter_filtersToBeEvaluatedDB[v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterId].filter, vl_replacement, vl_filterPath, 0);
if (f_EPTF_DsRestAPI_Filter_isFilterSendable(vl_filterToSend)) {
vl_filterPath := substr(vl_filterPath, 0, sizeof(vl_filterPath) - 1);
f_EPTF_DsRestAPI_Filter_sendFilterRequest(v_DsRestAPI_Filter_outstandingFiltersDB[pl_userData[0]].filterId, vl_filterPath, vl_filterToSend);
}
}
f_EPTF_FBQ_moveFromBusyToFreeTail(pl_userData[0], v_DsRestAPI_Filter_outstandingFiltersQueue);
}
private function f_EPTF_DsRestAPI_Filter_isFilterSendable(in EPTF_DsRestAPI_Filter pl_filter) return boolean {
var boolean vl_result := true;
if (ischosen(pl_filter.request) and ispresent(pl_filter.request.params)) {
var integer vl_paramsSize := sizeof(pl_filter.request.params);
for (var integer i := 0; i < vl_paramsSize; i := i + 1) {
if (ischosen(pl_filter.request.params[i].paramValue.request)) {
vl_result := false;
break;
}
}
}
return vl_result;
}
private function f_EPTF_DsRestAPI_Filter_sendFilterRequest(in integer pl_filterId, in EPTF_IntegerList pl_filterPath, in EPTF_DsRestAPI_Filter pl_filter) runs on EPTF_DsRestAPI_Filter_CT {
var integer vl_filterRequestId := f_EPTF_FBQ_getOrCreateFreeSlot(v_DsRestAPI_Filter_outstandingFiltersQueue);
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_DsRestAPI_Filter_outstandingFiltersQueue);
v_DsRestAPI_Filter_outstandingFiltersDB[vl_filterRequestId] := {pl_filterId, pl_filterPath, ""};
var EPTF_DataSource_Params vl_params := {};
if (ispresent(pl_filter.request.params)) {
var integer vl_paramsSize := sizeof(pl_filter.request.params);
for (var integer i := 0; i < vl_paramsSize; i := i + 1) {
vl_params[i] := {
paramName := pl_filter.request.params[i].paramName,
paramValue := pl_filter.request.params[i].paramValue.dataValue
}
}
pl_filter.request.params := {};
}
if (not ispresent(pl_filter.request.ptcname)) {
pl_filter.request.ptcname := "";
}
var EPTF_DataSource_Filter vl_filter := {rangeFilter := omit};
var charstring vl_storageKey := f_EPTF_DsRestAPI_Storage_getKey(pl_filter.request.source, pl_filter.request.ptcname, pl_filter.request.element, vl_params, vl_filter);
var EPTF_CLL_DsRestAPI_Storage_Item vl_itemInStorage;
if (f_EPTF_DsRestAPI_Storage_getStoredItem(v_DsRestAPI_Filter_filtersToBeEvaluatedDB[pl_filterId].storageId, vl_storageKey, vl_itemInStorage)) {
if (ischosen(vl_itemInStorage.content)) {
f_EPTF_DsRestAPI_Filter_filterResponseArrived(0, vl_itemInStorage.content, {vl_filterRequestId});
} else if (ischosen(vl_itemInStorage.preStoredItems)) {
f_EPTF_DsRestAPI_Storage_addContentArrivedHandler(v_DsRestAPI_Filter_filtersToBeEvaluatedDB[pl_filterId].storageId, vl_storageKey, {refers(f_EPTF_DsRestAPI_Filter_filterResponseArrived), {vl_filterRequestId}});
}
} else {
v_DsRestAPI_Filter_outstandingFiltersDB[vl_filterRequestId].storageKey := vl_storageKey;
f_EPTF_DsRestAPI_Storage_preStoreItem(v_DsRestAPI_Filter_filtersToBeEvaluatedDB[pl_filterId].storageId, vl_storageKey);
var integer vl_errorCode := f_EPTF_DataSource_getDataValue_nonblocking(pl_filter.request.source, pl_filter.request.ptcname, pl_filter.request.element, vl_params, vl_filter, {refers(f_EPTF_DsRestAPI_Filter_filterResponseArrived), {vl_filterRequestId}});
if (vl_errorCode != 0) {
f_EPTF_DsRestAPI_Filter_warning("Filtering: DataSource getDataValue_nonblocking returned with error code" & int2str(vl_errorCode));
}
}
}
private function f_EPTF_DsRestAPI_Filter_sendAllPossibleFilterRequests(in integer pl_filterId, in EPTF_IntegerList pl_filterPath, in EPTF_DsRestAPI_Filter pl_filter) runs on EPTF_DsRestAPI_Filter_CT {
if (ischosen(pl_filter.request)) {
if (f_EPTF_DsRestAPI_Filter_isFilterSendable(pl_filter)) {
f_EPTF_DsRestAPI_Filter_sendFilterRequest(pl_filterId, pl_filterPath, pl_filter);
}
if (ispresent(pl_filter.request.params)) {
var integer vl_paramsSize := sizeof(pl_filter.request.params);
var integer vl_nextIndex := sizeof(pl_filterPath);
for (var integer i := 0; i < vl_paramsSize; i := i + 1) {
pl_filterPath[vl_nextIndex] := i;
f_EPTF_DsRestAPI_Filter_sendAllPossibleFilterRequests(pl_filterId, pl_filterPath, pl_filter.request.params[i].paramValue);
}
}
}
}
private function f_EPTF_DsRestAPI_Filter_fillFilterParams(inout EPTF_DsRestAPI_Filter pl_filter, in EPTF_CharstringList pl_parentList, in EPTF_IntegerList pl_parentIndexList) {
var integer vl_parentListSize := sizeof(pl_parentList);
for (var integer i := 0; i < vl_parentListSize; i := i + 1) {
var charstring vl_parentN := "%Parent" & int2str(i) & "%";
var charstring vl_parentIdxN := "%Parent" & int2str(i) & "::idx%";
if (ischosen(pl_filter.dataValue)) {
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.dataValue, vl_parentIdxN, int2str(pl_parentIndexList[i]));
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.dataValue, vl_parentN, pl_parentList[i]);
} else /*if (ischosen(filter.request)*/ {
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.source, vl_parentIdxN, int2str(pl_parentIndexList[i]));
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.source, vl_parentN, pl_parentList[i]);
if (ispresent(pl_filter.request.ptcname)) {
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.ptcname, vl_parentIdxN, int2str(pl_parentIndexList[i]));
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.ptcname, vl_parentN, pl_parentList[i]);
}
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.element, vl_parentIdxN, int2str(pl_parentIndexList[i]));
ef_EPTF_DsRestAPI_replaceAllIfMatches(pl_filter.request.element, vl_parentN, pl_parentList[i]);
}
}
if (ispresent(pl_filter.request.params)) {
var integer vl_paramsLength := sizeof(pl_filter.request.params);
for (var integer j := 0; j < vl_paramsLength; j := j + 1) {
f_EPTF_DsRestAPI_Filter_fillFilterParams(pl_filter.request.params[j].paramValue, pl_parentList, pl_parentIndexList);
}
}
}
friend function f_EPTF_DsRestAPI_Filter_isPreFilterAllowed(in EPTF_DsRestAPI_Filter pl_filter, in integer pl_index) return boolean {
var charstring vl_parentN := "%Parent" & int2str(pl_index) & "%";
var charstring vl_parentIdxN := "%Parent" & int2str(pl_index) & "::idx%";
if (ischosen(pl_filter.dataValue)) {
if (f_strstr(pl_filter.dataValue, vl_parentN) != -1 or f_strstr(pl_filter.dataValue, vl_parentIdxN) != -1) {
return false
}
} else /*if (ischosen(filter.request)*/ {
if (f_strstr(pl_filter.request.source, vl_parentN) != -1 or f_strstr(pl_filter.request.source, vl_parentIdxN) != -1) {
return false;
}
if (ispresent(pl_filter.request.ptcname)) {
if (f_strstr(pl_filter.request.ptcname, vl_parentN) != -1 or f_strstr(pl_filter.request.ptcname, vl_parentIdxN) != -1) {
return false;
}
}
if (f_strstr(pl_filter.request.element, vl_parentN) != -1 or f_strstr(pl_filter.request.element, vl_parentIdxN) != -1) {
return false;
}
}
if (ispresent(pl_filter.request.params)) {
var integer vl_paramsLength := sizeof(pl_filter.request.params);
for (var integer j := 0; j < vl_paramsLength; j := j + 1) {
if (not f_EPTF_DsRestAPI_Filter_isPreFilterAllowed(pl_filter.request.params[j].paramValue, pl_index)) {
return false;
}
}
}
return true;
}
friend function f_EPTF_DsRestAPI_Filter_evaluateFilter(in EPTF_DsRestAPI_EvaluatedFilterHandlerItem pl_data, in EPTF_CharstringList pl_parentList, in EPTF_IntegerList pl_parentIndexList) runs on EPTF_DsRestAPI_Filter_CT {
// TODO if (not v_DsRestAPI_Filter_initialized)
f_EPTF_DsRestAPI_Filter_fillFilterParams(pl_data.filter, pl_parentList, pl_parentIndexList);
if (ischosen(pl_data.filter.dataValue)) {
pl_data.filterEvaluatedCallback.apply(pl_data.filter.dataValue == "true", pl_data.userData);
} else {
var integer vl_id := f_EPTF_FBQ_getOrCreateFreeSlot(v_DsRestAPI_Filter_filtersToBeEvaluatedQueue);
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_DsRestAPI_Filter_filtersToBeEvaluatedQueue);
v_DsRestAPI_Filter_filtersToBeEvaluatedDB[vl_id] := pl_data;
f_EPTF_DsRestAPI_Filter_sendAllPossibleFilterRequests(vl_id, {}, pl_data.filter);
}
}
} // ~ module EPTF_CLL_DsRestAPI_Filter_Functions