076 instance_operation.resource_realm_id

This commit is contained in:
msyu
2025-04-06 11:16:02 +03:00
parent c6f9b72d9f
commit 080252cf2c
6 changed files with 86 additions and 83 deletions
@@ -186,12 +186,15 @@
/>
</cffunction>
<cffunction name="checkParam">
<cffunction name="checkParam" returnType="void">
<!--- проверка параметров по метаданным, независимо от семантики самого параметра --->
<cfargument name="svcOperationCfsParamId" type="numeric" required = true/>
<cfargument name="paramValue" required = true/>
<cfargument name="instanceOperationCfsParamUid" type="guid" required = false/><!--- передавать для существующего параметра - используется при проверке уникальности --->
<cfargument name="instanceOperationCfsParamUid" type="guid" default="00000000-0000-0000-0000-000000000000"/><!--- используется при проверке уникальности, чтобы не сравнивать с собой --->
<!--- *** Вероятно, стоит возвращать конкретную ругань --->
<!--- принадлежит ли параметр к данному сервису, проверяется выше --->
<!--- принадлежит ли параметр данному сервису, проверяется выше --->
<!--- получаем метаданные параметра --->
<cfquery name="qSvcOperationCfsParam">
select sop.svc_operation_cfs_param_id
,sop.svc_operation_cfs_param
@@ -211,7 +214,7 @@
<cfif qSvcOperationCfsParam.is_required GT 0 AND len(arguments.paramValue) EQ 0>
<!--- <cfreturn "Missing required parameter (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> --->
<cfthrow type="invalidParamValue" message="Missing required parameter (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/>
<cfelseif len(arguments.paramValue) AND NOT checkValue(arguments.paramValue,qSvcOperationCfsParam.data_type)>
<cfelseif len(arguments.paramValue) AND NOT validateDataType(arguments.paramValue,qSvcOperationCfsParam.data_type)>
<!--- <cfreturn "Invalid format (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> --->
<cfthrow type="invalidParamValue" message="Invalid format (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/>
</cfif>
@@ -244,7 +247,25 @@
<!--- ****** Внимание! Этот код сравнивает параметры одноименных операций, но уникальность должна быть и между create-modify и т.п. --->
<!--- *** при этом мы не исключаем уделенные инстансы, что неудобно --->
<cfset checkUniqueness(
qSvcOperationCfsParam.svc_operation_cfs_param_id, <!--- *** есть в аргументах, но было так - пока не меняю --->
arguments.svcOperationCfsParamId,
arguments.paramValue,
qSvcOperationCfsParam.unique_scope,
arguments.instanceOperationCfsParamUid
)/>
</cffunction>
<cffunction name="checkUniqueness" returnType="void">
<!--- использую void, потому что с исключением проще передавать информацию о конкретном характере ошибки. Чем возвращать объект ошибки - проше бросить исключение --->
<cfargument name="svcOperationCfsParamId" type="integer"/>
<cfargument name="svcOperationCfsParamName" type="string"/><!--- нужен только для формирования текста сообщения об ошибке --->
<cfargument name="paramValue" type="string"/>
<cfargument name="scope" type="string"/>
<cfargument name="instanceOperationCfsParamUid" type="guid"/>
<!--- request.usr_id passed implicitly --->
<cfswitch expression=#qSvcOperationCfsParam.unique_scope#>
<cfcase value="provider">
<cfquery name="qUnique">
@@ -253,18 +274,19 @@
join instance_operation o on (p.instance_operation_uid=o.instance_operation_uid)
join instance e on (o.instance_uid=e.instance_uid)
where p.param_value=<cfqueryparam cfsqltype="cf_sql_varchar" value=#arguments.paramValue#/>
AND p.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#qSvcOperationCfsParam.svc_operation_cfs_param_id#/>
<cfif structKeyExists(arguments,"instanceOperationCfsParamUid")>
AND p.instance_operation_cfs_param_uid <> <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationCfsParamUid#/><!--- null=#!isValid("guid",arguments.instanceOperationCfsParamUid)# --->
AND p.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.svcOperationCfsParamId#/>/*limit to the current svc param*/
<cfif arguments.instanceOperationCfsParamUid NEQ "00000000-0000-0000-0000-000000000000">
<!--- не решаюсь оставить эту проверку на БД, потому что наличие записи с 00000000-0000-0000-0000-000000000000 может все сломать --->
AND p.instance_operation_cfs_param_uid <> <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationCfsParamUid#/>/*exclude itself*/
</cfif>
AND (select cast(st.instance_data->>'isDeleted' as boolean) from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) IS NOT TRUE
</cfquery>
AND (select cast(st.instance_data->>'isDeleted' as boolean) from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) IS NOT TRUE /*ignore deleted instances*/
</cfquery><!--- ****** здесь может таиться трудно понимаемый баг с отсутствием записи --->
<!--- <cfdump var=#qUnique#/><cfabort/> --->
<cfif qUnique.cnt GT 0>
<!--- <cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the provider scope'/> --->
<cfthrow type="invalidParamValue" message='#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the provider scope'/>
<cfthrow type="invalidParamValue" message='#arguments.svcOperationCfsParamName# = "#arguments.paramValue#" is not unique in the provider scope'/>
</cfif>
</cfcase>
<cfcase value="tenant">
<cfquery name="qUnique">
select count(*) as cnt
@@ -277,29 +299,31 @@
join contragent k on (d.contragent_id=k.contragent_id)
join usr u on (k.contragent_id=u.contragent_id)
where p.param_value=<cfqueryparam cfsqltype="cf_sql_varchar" value=#arguments.paramValue#/>
AND svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#qSvcOperationCfsParam.svc_operation_cfs_param_id#/>
AND u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#request.usr_id#/>
<cfif structKeyExists(arguments,"instanceOperationCfsParamUid")>
AND p.instance_operation_cfs_param_uid <> <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationCfsParamUid#/> <!--- null=#!isValid("guid",arguments.instanceOperationCfsParamUid)# --->
AND svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.svcOperationCfsParamId#/>/*limit to the current svc param*/
AND u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#request.usr_id#/>/*limit to the contragent of current user*/
<cfif arguments.instanceOperationCfsParamUid NEQ "00000000-0000-0000-0000-000000000000">
<!--- не решаюсь оставить эту проверку на БД, потому что наличие записи с 00000000-0000-0000-0000-000000000000 может все сломать --->
AND p.instance_operation_cfs_param_uid <> <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationCfsParamUid#/>/*exclude itself*/
</cfif>
AND (select cast(st.instance_data->>'isDeleted' as boolean) from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) IS NOT TRUE
/*to ignore deleted instances*/
</cfquery>
AND (select cast(st.instance_data->>'isDeleted' as boolean) from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) IS NOT TRUE /*ignore deleted instances*/
</cfquery><!--- ****** здесь может таиться трудно понимаемый баг с отсутствием записи --->
<!--- <cfdump var=#qUnique#/> --->
<cfif qUnique.cnt GT 0>
<!--- <cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/> --->
<cfthrow type="invalidParamValue" message='#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/>
<cfthrow type="invalidParamValue" message='#arguments.svcOperationCfsParamName# = "#arguments.paramValue#" is not unique in the tenant scope'/>
</cfif>
</cfcase>
<cfdefaultcase></cfdefaultcase>
</cfswitch>
<!--- <cfreturn ""/> --->
</cffunction>
<cffunction name="checkValue" returnType="boolean">
<cffunction name="validateDataType" returnType="boolean">
<cfargument name="value" type="string"/>
<cfargument name="dataType" type="string"/>
<!--- Что возвращать-то?
<!--- Что возвращать-то?
Идею бросать исключение при некорректном вводе надо отринуть. Все введенные параметры надо обработать и не терять --->
<cfswitch expression=#arguments.dataType#>
@@ -322,7 +346,7 @@
<cfreturn isNumeric(arguments.value)/>
</cfcase>
<cfcase value="uuid">
<cfreturn isValid("guid",arguments.value)/><!--- *** или GUID? Или принимать оба формата и приводить к одному? А как быть с БД--->
<cfreturn isValid("guid",arguments.value)/><!--- *** или GUID? Или принимать оба формата GUID UUID и приводить к одному? А как быть с БД--->
</cfcase>
<cfdefaultcase><cfreturn true/>
<cfthrow type="custom" detail="unsupported CFS parameter value type (#arguments.dataType#)"/>