226 lines
11 KiB
Plaintext
226 lines
11 KiB
Plaintext
<cfcomponent extends="taffy.core.resource" taffy:uri="/instanceOperationCfsParams/{instanceOperationCfsParamUid}">
|
|
<!--- Вот здесь мы могли бы строить URI /instances/{instanceUid}/instanceOperations/{instanceOperationUid}/CfsParams, но это создает избыточность, у нас простые суррогатные первичные ключи. С другой стороны, контекст инстанса и операции у клиента всегда имеется. Но стоит ли передавать избыточную информацию? Это иногда провоцирует путаницу. Для POST мы можем передать необходимый контекст в теле запроса, а можем в URL.
|
|
В данном случае никакого смысла смотреть на все CFS параметры нет, только в рамках операции
|
|
Но: мы не хотели бы менять положение сущности в дереве. Либо она в корне, либо она ниже. И получится, когда мы выбираем один параметр, нам ни к чему контекст - мы к нему однозначно адресуемся.
|
|
Проголосуем за отсутстие избыточности?
|
|
--->
|
|
|
|
<cfsilent>
|
|
<cfimport prefix="m" taglib="../lib"/>
|
|
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
|
|
</cfsilent>
|
|
|
|
|
|
<cffunction name="get" hint="CFS параметр операции инстанса">
|
|
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
|
|
<cftry>
|
|
<cfset this.helper.validateField(arguments, "instanceOperationCfsParamUid", "guid")/>
|
|
<cfcatch type="invalidParamValue">
|
|
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
|
</cfcatch>
|
|
</cftry>
|
|
|
|
<cfset local={}/>
|
|
|
|
<cfquery name="local.qRead" result="local.result">
|
|
select
|
|
<m:field_set titleMapOut="local.titleMap" lengthOut="fieldCount">
|
|
<m:field>iop.instance_operation_cfs_param_uid::text as instance_operation_cfs_param_uid</m:field>
|
|
<m:field>iop.instance_operation_uid::text as instance_operation_uid</m:field>
|
|
<m:field>iop.svc_operation_cfs_param_id</m:field>
|
|
<!--- <m:field>iop.param_value</m:field> --->
|
|
<m:field>case when sop.is_sensitive then '********' else iop.param_value end as param_value </m:field><!--- внимание! если параметр типа MAP, то значение нужно разобрать и замаскировать секреты --->
|
|
<m:field>iop.note</m:field>
|
|
<m:field>to_char(iop.dt_created, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_created</m:field>
|
|
<m:field>iop.creator_id</m:field>
|
|
<m:field>sop.svc_operation_cfs_param</m:field>
|
|
<m:field>sop.data_type</m:field>
|
|
<m:field>null as data_descriptor</m:field>
|
|
<m:field>u.login as creator_login</m:field>
|
|
<m:field>u.shortname as creator_shortname</m:field>
|
|
<m:field formatter=#request.castToBool#>sop.is_sensitive</m:field>
|
|
</m:field_set>
|
|
from instance_operation_cfs_param iop
|
|
join svc_operation_cfs_param sop on (iop.svc_operation_cfs_param_id=sop.svc_operation_cfs_param_id)
|
|
join instance_operation io on (iop.instance_operation_uid=io.instance_operation_uid)
|
|
join instance e on (io.instance_uid=e.instance_uid)
|
|
join specification_item si on (e.specification_item_id=si.specification_item_id)
|
|
left outer join usr u on (iop.creator_id=u.usr_id)
|
|
where iop.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
|
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
|
|
</cfquery>
|
|
|
|
<cfif local.qRead.recordCount EQ 0>
|
|
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
|
|
</cfif>
|
|
|
|
|
|
<cfif local.qRead.data_type EQ "map">
|
|
<cfset var map={}/>
|
|
<cftry>
|
|
<cfset var map=deserializeJson(local.qRead.param_value)/>
|
|
<cfcatch type="any"><cfrethrow/></cfcatch>
|
|
</cftry>
|
|
|
|
<cfquery name="local.qSubparam">
|
|
select
|
|
sp.svc_operation_cfs_param_id
|
|
,sp.svc_operation_cfs_subparam_id
|
|
,sp.svc_operation_cfs_subparam
|
|
,sp.label
|
|
,sp.data_type
|
|
,sp.value_list
|
|
,sp.is_required
|
|
,sp.descr
|
|
,sp.man
|
|
,sp.default_value
|
|
,sp.minlength
|
|
,sp.maxlength
|
|
,sp.regex
|
|
,sp.sort
|
|
,sp.is_sensitive
|
|
from svc_operation_cfs_subparam sp
|
|
where sp.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#local.qRead.svc_operation_cfs_param_id#"/>
|
|
order by sp.sort
|
|
</cfquery>
|
|
|
|
<cfquery name="local.qInstSubparam">
|
|
select
|
|
sp.instance_operation_cfs_param_uid::text as instance_operation_cfs_param_uid
|
|
,sp.instance_operation_cfs_subparam
|
|
,sp.note
|
|
,sp.sort
|
|
,sp.is_sensitive
|
|
from instance_operation_cfs_subparam sp
|
|
where sp.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#local.qRead.instance_operation_cfs_param_uid#" null=#!isValid("guid",local.qRead.instance_operation_cfs_param_uid)#/>
|
|
order by sp.sort
|
|
</cfquery>
|
|
|
|
<cfset var mapDescriptor=structNew("linked")/>
|
|
|
|
<cfloop query="local.qSubparam">
|
|
<cfset structInsert(mapDescriptor, local.qSubparam.svc_operation_cfs_subparam,
|
|
{
|
|
"man":"#local.qSubparam.man#",
|
|
"isSensitive":#request.castToBool(local.qSubparam.is_sensitive)#
|
|
}, true
|
|
)
|
|
/>
|
|
<cfif local.qSubparam.is_sensitive AND structKeyExists(map,local.qSubparam.svc_operation_cfs_subparam)>
|
|
<cfset map["#local.qSubparam.svc_operation_cfs_subparam#"] = "********"/>
|
|
</cfif>
|
|
</cfloop>
|
|
|
|
<cfloop query="local.qInstSubparam">
|
|
<cfset structInsert(mapDescriptor, local.qInstSubparam.instance_operation_cfs_subparam,
|
|
{
|
|
"note":"#local.qInstSubparam.note#",
|
|
"isSensitive":#request.castToBool(local.qInstSubparam.is_sensitive)#
|
|
}, true
|
|
)
|
|
/>
|
|
<cfif local.qInstSubparam.is_sensitive AND structKeyExists(map,local.qInstSubparam.instance_operation_cfs_subparam)>
|
|
<cfset map["#local.qInstSubparam.instance_operation_cfs_subparam#"] = "********"/>
|
|
</cfif>
|
|
</cfloop>
|
|
|
|
<cfset local.qCfsParam.data_descriptor = mapDescriptor/>
|
|
<cfset local.qCfsParam.param_value = serializeJson(map)/>
|
|
</cfif><!---/map --->
|
|
|
|
<cfset var out=structNew("linked")/>
|
|
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
|
|
|
<cfset "out.instanceOperationCfsParam" = this.helper.appendRecord(
|
|
structNew("linked"), "", local.titleMap, local.qRead, this.helper.snake2camel
|
|
)/>
|
|
|
|
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
|
|
<cfreturn representationOf(out) />
|
|
</cffunction><!--- get --->
|
|
|
|
|
|
<cffunction name="delete" hint="Удаление CFS параметра операции по ключу.">
|
|
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
|
|
|
|
<cftry>
|
|
<cfset this.helper.validateField(arguments, "instanceOperationCfsParamUid", "guid")/>
|
|
<!--- *** Нужна проверка, что операция не была выполнена, иначе она становится архивной --->
|
|
|
|
<cfcatch type="invalidParamValue">
|
|
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
|
</cfcatch>
|
|
</cftry>
|
|
|
|
<cfset local={}/>
|
|
<cftry><!--- *** без проверок существования --->
|
|
|
|
<cfquery name="local.qCheck" result="local.result">
|
|
select
|
|
io.dt_submit, io.submit_result
|
|
from instance_operation_cfs_param iop
|
|
join instance_operation io on iop.instance_operation_uid=io.instance_operation_uid
|
|
where iop.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
|
</cfquery>
|
|
<cfif left(local.qCheck.submit_result,1) EQ "2"><!--- 201 etc --->
|
|
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter deletion disabled for started operation")).withStatus(422)/>
|
|
</cfif>
|
|
|
|
<cfquery name="local.qSave">
|
|
delete from instance_operation_cfs_param
|
|
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
|
</cfquery>
|
|
|
|
<cfcatch type="any">
|
|
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/><!--- это не нужно показывать в продуктиве --->
|
|
</cfcatch>
|
|
</cftry>
|
|
|
|
<cfreturn noData().withStatus(204, "No Content") />
|
|
</cffunction><!--- delete --->
|
|
|
|
<cffunction name="put" hint="запись CFS параметра операции инстанса">
|
|
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
|
|
<cfargument name="paramValue" type="string" required=true/>
|
|
<cfargument name="note" type="string" required=false default=""/>
|
|
|
|
<cfset var local={}/>
|
|
<cftry>
|
|
<cfset checkInstanceParam(arguments.instanceOperationCfsParamUid,arguments.paramValue)/>
|
|
<cfcatch type="invalidParamValue">
|
|
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
|
</cfcatch>
|
|
</cftry>
|
|
|
|
<cfquery name="local.qSave" result="local.result">
|
|
update instance_operation_cfs_param set
|
|
dt_created=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#" />
|
|
,creator_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#" />
|
|
,param_value=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.paramValue#" />
|
|
,note=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.note#" />
|
|
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
|
</cfquery>
|
|
<!--- *** проверить существование - 404 --->
|
|
<cfreturn noData().withStatus(204, "No Content") />
|
|
</cffunction><!--- put --->
|
|
|
|
|
|
|
|
<cffunction name="checkInstanceParam">
|
|
<cfargument name="instanceOperationCfsParamUid" type="guid" required=true/>
|
|
<cfargument name="paramValue" required=true/>
|
|
|
|
<cfset var local={}/>
|
|
<cfquery name="local.qCheck" result="local.result">
|
|
select svc_operation_cfs_param_id
|
|
from instance_operation_cfs_param
|
|
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
|
</cfquery>
|
|
<cfif local.qCheck.recordCount EQ 0>
|
|
<cfthrow type="invalidParamValue" message="Cannot find CFS parameter by instanceOperationCfsParamUid=#arguments.instanceOperationCfsParamUid#"/>
|
|
</cfif>
|
|
|
|
<cfset CreateObject("component", "instance_operation_cfs_param_ls").checkParam(local.qCheck.svc_operation_cfs_param_id, arguments.paramValue, arguments.instanceOperationCfsParamUid)/>
|
|
</cffunction>
|
|
|
|
</cfcomponent> |