Files
svc-api-x/v1/resources/svc_operation.cfc
T

107 lines
4.6 KiB
Plaintext

<cfcomponent extends="taffy.core.resource" taffy:uri="/serviceOperation/{svcOperationId}">
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/>
</cfsilent>
<cffunction name="get" hint="Операция сервиса"><!--- *** TODO проверка принадлежности тенанту --->
<cfargument name="svcOperationId" type="string" required=true hint="type:integer"/>
<cftry>
<cfset this.helper.validateField(arguments, "svcOperationId", "integer")/>
<cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch>
</cftry>
<cfquery name="local.qSvcOperation" result="local.result">
select
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
<m:field title="ID" cfSqlType="CF_SQL_INTEGER">o.svc_operation_id</m:field>
<m:field title="operation">o.operation</m:field>
<m:field title="URL">o.url</m:field>
<m:field title="Описание">o.descr</m:field>
<m:field title="Руководство">o.man</m:field>
</m:field_set>
from svc_operation o
where o.svc_operation_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcOperationId#" null=#!isValid('integer',arguments.svcOperationId)#/>
</cfquery>
<cfquery name="local.qCfsParam" result="local.result">
select
<m:field_set titleMapOut="local.cfsParamMap" lengthOut="local.fieldCount">
<m:field title="ID" cfSqlType="CF_SQL_INTEGER">p.svc_operation_cfs_param_id</m:field>
<!--- <m:field cfSqlType="CF_SQL_INTEGER">p.svc_operation_id</m:field> --->
<m:field>p.svc_operation_cfs_param</m:field>
<m:field>p.label</m:field>
<m:field>p.data_type</m:field>
<m:field formatter=#function(x){return listToArray(x);}# type="list">p.value_list</m:field>
<m:field>p.ref_svc_id</m:field>
<m:field formatter=#request.castToBool#>p.is_required</m:field>
<m:field>p.default_value</m:field><!--- can be overridden bu default_compute --->
<m:field>p.default_compute</m:field>
<m:field>p.func</m:field>
<m:field>p.regex</m:field>
<m:field>p.unique_scope</m:field>
<m:field>p.maxlength</m:field>
<m:field>p.minlength</m:field>
<m:field>p.maxvalue</m:field>
<m:field>p.minvalue</m:field>
<m:field>p.descr</m:field>
<m:field>p.man</m:field>
<m:field>p.sort</m:field>
<m:field>p.depends_on_cfs_params</m:field>
<m:field formatter=#request.castToBool#>(
select 1 from svc_operation_cfs_param m
join svc_operation om on (m.svc_operation_id=om.svc_operation_id)
join svc_operation oc on (om.svc_id=oc.svc_id AND om.operation='modify' AND oc.operation='create')
join svc_operation_cfs_param c on (oc.svc_operation_id=c.svc_operation_id AND m.svc_operation_cfs_param=c.svc_operation_cfs_param)
where c.svc_operation_cfs_param_id=p.svc_operation_cfs_param_id
order by c.svc_operation_cfs_param_id
limit 1
) as is_modifiable</m:field>
<m:field formatter=#request.castToBool#>p.is_sensitive</m:field>
</m:field_set>
from svc_operation_cfs_param p
where p.svc_operation_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcOperationId#" null=#!isValid('integer',arguments.svcOperationId)#/>
AND p.is_actual
order by p.sort, p.svc_operation_cfs_param_id
</cfquery>
<cfif local.qSvcOperation.recordCount EQ 0>
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
</cfif>
<cfset var out=structNew("linked")/>
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
<cfset "out.svcOperation" = this.helper.appendRecord(
structNew("linked"), "", local.titleMap, local.qSvcOperation, this.helper.snake2camel
)/>
<cfset "out.svcOperation.cfsParams"=[]/>
<cfloop query=#local.qCfsParam#>
<cfset arrayAppend(out.svcOperation.cfsParams, this.helper.appendRecord(structNew("linked"), "", local.cfsParamMap, local.qCfsParam, this.helper.snake2camel))/>
</cfloop>
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
<cfreturn representationOf(out) />
</cffunction>
<!--- *** выглядит ужасно, но красивый вариант не придумывается ряд месяцев --->
<cffunction name="computeDefault">
<cfargument name="defaultCompute"/>
<cfargument name="original"/>
<cfswitch expression=#arguments.defaultCompute#>
<cfcase value="display_name">
</cfcase>
<cfdefaultcase>
<cfreturn #arguments.original#/>
</cfdefaultcase>
</cfswitch>
</cffunction>
</cfcomponent>