102 cleaning

This commit is contained in:
msyu
2025-04-30 12:27:10 +03:00
parent 063474d704
commit 7b9e811cce
10 changed files with 51 additions and 113 deletions
+1 -1
View File
@@ -51,7 +51,7 @@
//variables.framework.docs={};
variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.101";
variables.framework.docs.APIVersion="0.102";
variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
+2 -6
View File
@@ -2,12 +2,8 @@
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
</cfsilent>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/>
</cfsilent>
<cffunction name="patch">
<cfargument name="bookmarkUid" type="string" required=true hint="type:guid"/>
+1 -8
View File
@@ -115,16 +115,12 @@
<cffunction name="post" hint="Создание нового букмарка.">
<!--- <cfargument name="bookmarkUid" type="string" required=true hint="type:guid"/> --->
<!--- <cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/> --->
<cfargument name="bookmark" type="string" required=true hint="type:string description: заголовок"/><!--- чистить против XSS --->
<cfargument name="descr" type="string" required=false default="" hint="type:boolean description: пользовательское примечание"/>
<cfargument name="url" type="string" required=false default="" hint="type:string description: url"/><!--- чистить против XSS --->
<cfargument name="iconUrl" type="string" required=false default="" hint="type:string description: url иконки"/><!--- чистить против XSS --->
<cfargument name="sort" type="string" required=false default="100" hint="type:integer description: целое число для сортировки"/>
<cfargument name="isEnabled" type="string" required=false default="1" hint="type:boolean description: вкл"/>
<!--- arguments.contragentId injected implicitly --->
<!--- arguments.usrId injected implicitly --->
<cftry>
<cfset this.helper.validateField(arguments, "bookmarkUid", "guid")/>
@@ -140,7 +136,6 @@
<cfset local.bookmarkUid=#createGUID()#/>
<cftry>
<cfquery name="local.qSave">
insert into bookmark (
bookmark_uid,contragent_id, bookmark,url,icon_url,descr,sort,is_enabled,dt_created,creator_id
@@ -157,9 +152,7 @@
,<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#" />
);
</cfquery>
<!--- <cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch> --->
<cfcatch type="any">
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/>
</cfcatch>
+2 -2
View File
@@ -47,9 +47,9 @@
when
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
when
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
(select st.instance_data->>'isSuspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
when
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select coalesce(st.instance_data->>'suspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select coalesce(st.instance_data->>'isSuspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
when
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
when
+1 -8
View File
@@ -37,14 +37,7 @@
<cfset "out.instance.descr"="#local.qSvc.descr#"/>
<cfset "out.instance.man"="#local.qSvc.man#"/>
<!--- <cfset var out = structCopy(svc)/> ---><!--- *** иначе, видимо, циклическая ссылка, если мы еще скопируем это внутрь структуры --->
<!--- <cfset "out.instance" = instance/> --->
<!--- <cfset "out.instance.availableResourceRealms"=[]/>
<cfloop query=#local.qAvailableResourceRealm#>
<cfset arrayAppend(out.instance.availableResourceRealms, this.helper.appendRecord(structNew("linked"), "", local.realmTitleMap, local.qAvailableResourceRealm, this.helper.snake2camel))/>
</cfloop> --->
<!--- <cfset var out = structCopy(svc)/> ---><!--- *** иначе, видимо, циклическая ссылка, если мы еще скопируем это внутрь структуры ---><!--- <cfset "out.instance" = instance/> --->
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
+27 -76
View File
@@ -120,24 +120,10 @@
<cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch>
</cftry>
<!--- *********** 2DO ShortList --->
<!---
<cfdump var=#order#/>
<cfdump var=#local.fieldsToQueryFor#/>
<cfdump var=#local.fieldsToOutput#/>
<cfabort/>--->
</cftry>
<cftry><!--- *** времянка, пока глотается ошибка 500 --->
<!--- <cfset var maxrows=arguments.pageSize*arguments.page/> --->
<!--- <cfset var startrow=arguments.pageSize*(arguments.page-1)+1/> --->
<!--- Такая бодяга. Кастомные сериализаторы не умеют вложенных структур (поразительно, или я не нашел как). Стандартный сериализатор не умеет выводить дату в ISO 8601. Приходится колхозить и форматировать на стороне БД (насилу подобрал формат). Также на стороне БД приходится конвертировать GUID, потому что драйвер pg jdbc его представляет как структуру из 2 чисел.
И то сказать, jsonb как-то странно сериализуется, в 3 поля, вместо одного Value
--->
@@ -151,8 +137,6 @@
<m:field>e.instance_uid::text as instance_uid</m:field>
<m:field>e.display_name</m:field>
<m:field>e.service_id</m:field>
<!--- <m:field>e.resource_realm_id</m:field> --->
<!--- <m:field>r.resource_realm</m:field> --->
<m:field>e.specification_item_id</m:field>
<m:field formatter=#request.castToBool#>e.is_auxiliary</m:field>
<m:field>d.contract_id</m:field>
@@ -176,14 +160,22 @@
<m:field>(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_finish</m:field>
<m:field>(select round(extract('epoch' from coalesce(io.dt_finish,CURRENT_TIMESTAMP)- io.dt_start),1) from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as duration</m:field>
<m:field>(select case when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/ when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP)) else 0 end from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as uptime</m:field>/* *** это вообще неправильно, некоторые операции заканчиваются состоянием running, а некоторые нет, переделать */
<m:field>(select case
when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/
when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP))
else 0 end
from instance_operation io
where io.instance_uid=e.instance_uid
order by dt_submit desc
limit 1)
as uptime</m:field>
<m:field>(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid AND io.is_successful AND io.operation='create' order by dt_submit desc limit 1) as dt_deploy</m:field>
<m:field formatter=#function(x){return (deserializeJson(x))}#>(select instance_data::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_data</m:field><!--- *** операция выглядит очень накладно, но можно это поле в дельнейшем не выводить --->
<m:field>(select st.instance_state_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_state_uid</m:field>
<m:field formatter=#request.castToBool#>(select st.is_test from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_test</m:field>
<m:field formatter=#request.castToBool#>coalesce((select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1),'false') as is_deleted</m:field><!--- attention it is not bool in state --->
<m:field formatter=#request.castToBool#>(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended</m:field>
<m:field formatter=#request.castToBool#>(select st.instance_data->>'isSuspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended</m:field>
<m:field>(select cast(st.instance_data->>'params' as json)->>'resourceRealm' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as resource_realm</m:field>
<m:field>(select to_char(st.dt_state, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as dt_state</m:field>
<m:field>
@@ -191,9 +183,12 @@
when
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
when
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
(select st.instance_data->>'isSuspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
when
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select coalesce(st.instance_data->>'suspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false'
AND
(select coalesce(st.instance_data->>'isSuspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false'
then 'running'
when
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
when
@@ -204,7 +199,7 @@
<m:field>(select max(version) from instance_state st where st.instance_uid=e.instance_uid) as version</m:field>
</m:field_set>
<!--- <cfdump var=#definedInstanceFields#/><cfabort/> --->
<!--- <cfdump var=#definedInstanceFields#/><cfabort/> --->
<cfquery name="local.qCnt" result="local.result">
select count(*) as cnt
@@ -233,8 +228,6 @@
) inr
where 1=1 <m:filter_build filter=#filter#/>
</cfquery>
<!--- <cfdump var=#url#/>
<cfdump var=#local.qCnt#/><cfabort/> --->
<cfquery name="local.qRead" result="local.result">
@@ -266,8 +259,6 @@
limit #arguments.pageSize#
offset #arguments.pageSize*(arguments.page-1)#
</cfquery>
<!--- <cfdump var=#local.qRead#/><cfabort/> --->
<!--- formatter=#function(x){if (isNull(x)) {return x} else {return (x NEQ 0)}}# --->
<cfquery name="local.qTotal">
select count(*) as cnt
@@ -308,7 +299,7 @@
<cfreturn representationOf(cfcatch).withStatus(500)/>
</cfcatch>
</cftry>
</cffunction>
</cffunction><!--- get --->
<cffunction name="post" hint="(ТЕСТИРОВАНИЕ) ВНИМАНИЕ! У текущего контрагента должна быть спецификация, в которую будет вписан создаваемый экземпляр. Новая пустая запись экземпляра. Фактическое развертывание выполняется отдельно,асинхронной операцией create сконфигурированного экземпляра. Одновременно мы создаем строку в спецификации по умолчанию и связываем экземпляр с этой строкой. Первичный ключ генерируется. Текущий пользователь, контракт, спецификация получаются из контекста.">
@@ -316,19 +307,14 @@
<cfargument name="serviceId" type="string" required=true hint="type:integer"/>
<cfargument name="descr" type="string" required=false default="" hint="type:varchar (no cleanup here!)"/>
<cfargument name="resourceRealmId" type="string" required=false default="-1" hint="type:integer"/>
<!--- <cfargument name="instanceUid" type="string" required=false default="" hint="type:guid)"/> --->
<!--- <cfargument name="usrUid" type="string" required=true hint="type:guid"/>
<!--- <cfargument name="instanceUid" type="string" required=false default="" hint="type:guid)"/>
<cfargument name="usrUid" type="string" required=true hint="type:guid"/>
<cfargument name="companyUid" type="string" required=true hint="type:guid"/> --->
<!--- оказывается, их можно и не декларировать --->
<cfset local={}/>
<!--- <cfif structKeyExists(arguments,"instanceUid")>
<cfset local.instanceUid=arguments.instanceUid/>
<cfelse> --->
<cfset local.instanceUid=#createGUID()#/>
<!--- </cfif> --->
<cfset var local={}/>
<cfset local.instanceUid=#createGUID()#/>
<cftry>
<cfset this.helper.keyExistsAndValid(arguments, "serviceId", "integer")/>
@@ -377,11 +363,8 @@
<cfreturn noData()
.withHeaders({location: "./#local.instanceUid#"})
.withStatus(201, "Created")
/>
</cffunction>
/>
</cffunction><!--- post --->
@@ -459,35 +442,3 @@
</cfcomponent>
<!--- select
*
from (
select
to_char(e.dt_created, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as instance_config_dt_created,to_char(e.dt_updated, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as instance_config_dt_updated,e.instance_uid::text as instance_uid,e.display_name,e.service_id,e.specification_item_id,e.is_auxiliary,d.contract_id,i.specification_id,s.specification,i.quantity,i.price,v.svc,v.code,e.updater_id,u.login as updater_login,u.shortname as updater_shortname,(select io.operation from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation,(select io.instance_operation_uid::text from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation_uid,(select io.submit_result from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as submit_result,(select to_char(io.dt_start, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_start,(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_finish,(select round(extract('epoch' from coalesce(io.dt_finish,CURRENT_TIMESTAMP)- io.dt_start),1) from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as duration,(select case when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/ when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP)) else 0 end from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as uptime,(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid AND io.is_successful AND io.operation='create' order by dt_submit desc limit 1) as dt_deploy,(select instance_data::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_data,(select st.instance_state_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_state_uid,(select st.is_test from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_test,(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_deleted,(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended,(select to_char(st.dt_state, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as dt_state,
(case
when
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
when
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
when
(select COALESCE(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select COALESCE(st.instance_data->>'suspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
when
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
when
not exists (select * from instance_state st where st.instance_uid=e.instance_uid) then 'not created'
else null end
) as explained_status
,(select max(version) from instance_state st where st.instance_uid=e.instance_uid) as version
from instance e
join specification_item i on (e.specification_item_id=i.specification_item_id)
join specification s on (i.specification_id=s.specification_id)
join contract d on (s.contract_id=d.contract_id)
join contragent k on (d.contragent_id=k.contragent_id)
join svc v on (e.service_id=v.svc_id)
left outer join usr u on (e.updater_id=u.usr_id)
where s.specification_id=2
) inr
where 1=1
order by 1 desc
limit 3
offset 18 --->
+1 -1
View File
@@ -194,7 +194,7 @@
AND a.is_enabled)
join svc s on r.resource_realm_type_id=s.resource_realm_type_id
where s.svc_id=<cfqueryparam cfsqltype="CF_SQL_INTEGER" value=#arguments.svcId# null=#!isValid("integer", arguments.svcId)#/>
order by r.sort
order by r.sort, r.resource_realm
</cfquery> <!--- <cfdump var=#arguments#/> cfdump здесь провоцирует NPE --->
<cfreturn valueList(local.qAvailableResourceRealm.resource_realm)/>
</cffunction>
@@ -59,7 +59,7 @@
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
<cfreturn representationOf(out) />
</cffunction>
</cffunction><!--- get --->
<cffunction name="delete" hint="Удаление CFS параметра операции по ключу.">
@@ -99,7 +99,7 @@
</cftry>
<cfreturn noData().withStatus(204, "No Content") />
</cffunction>
</cffunction><!--- delete --->
<cffunction name="put" hint="запись CFS параметра операции инстанса">
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
@@ -124,7 +124,9 @@
</cfquery>
<!--- *** проверить существование - 404 --->
<cfreturn noData().withStatus(204, "No Content") />
</cffunction>
</cffunction><!--- put --->
<cffunction name="checkInstanceParam">
<cfargument name="instanceOperationCfsParamUid" type="guid" required=true/>
@@ -13,7 +13,11 @@
<!---спецификация полей, пригодных для фильтрации --->
<cfset this.fieldsSpec={
dt_created={prefix="iop", type="date"},
svc_operation_cfs_param={prefix="sop", type="string"}
svc_operation_cfs_param={prefix="sop", type="string"},
login={prefix="iop", type="string"},
creator_id={prefix="iop", type="integer"},
sort={prefix="sop", type="integer"},
is_sensitive={prefix="sop", type="boolean"}
<!--- ,
dt_updated={prefix="e", type="date"},
service_id={prefix="e", type="integer"},
@@ -105,8 +109,7 @@
<cfset "out.runDurationMs"=getTickCount()-request.startTickCount/>
<!---<cfset "out.sql"=#local.result.sql#/>--->
<cfreturn representationOf(out)/>
</cffunction>
</cffunction><!--- get --->
<cffunction name="post" hint="Создание нового CFS параметра операции.">
@@ -185,7 +188,9 @@
.withHeaders({location: "./#local.instanceOperationCfsParamUid#"})
.withStatus(201, "Created")
/>
</cffunction>
</cffunction><!--- post --->
<cffunction name="checkParam" returnType="void">
<!--- проверка параметров по метаданным, независимо от семантики самого параметра --->
@@ -241,15 +246,13 @@
<!--- ****** Внимание! Этот код сравнивает параметры одноименных операций, но уникальность должна быть и между create-modify и т.п. --->
<cfset checkUniqueness(
arguments.svcOperationCfsParamId,
qSvcOperationCfsParam.svc_operation_cfs_param,
arguments.paramValue,
qSvcOperationCfsParam.unique_scope,
arguments.instanceOperationCfsParamUid
)/>
)/>
</cffunction>
<cffunction name="checkUniqueness" returnType="void">
+1 -1
View File
@@ -187,7 +187,7 @@
AND a.is_enabled)
join svc s on r.resource_realm_type_id=s.resource_realm_type_id
where s.svc_id=<cfqueryparam cfsqltype="CF_SQL_INTEGER" value=#arguments.svcId# null=#!isValid("integer", arguments.svcId)#/>
order by r.sort
order by r.sort, r.resource_realm
</cfquery> <!--- <cfdump var=#arguments#/> cfdump здесь провоцирует NPE --->
<cfreturn valueList(local.qAvailableResourceRealm.resource_realm)/>
</cffunction>