Härzlig willkome zue minere Bocksnip Code-Gallerie um alli Arte vo Code z'teile.

API Export - Rep Script

Avaloq · August 31, 2016 11:20 am

0 0 401

En Task zum exportiere vom API nach XML

[Report 2.0]

report task_script_ddic.rbsc$xml
/*
-------------------------------------------------------------------------------------------------------------
Bank: Coutts & Co Ltd.
Business Area: TEC
Description: Used to extract the Avaloq API
-------------------------------------------------------------------------------------------------------------
ID Date Name, Company Issue Affected BUs, Description
-------------------------------------------------------------------------------------------------------------
001
-------------------------------------------------------------------------------------------------------------
*/

----------------------------------------------------------------------------
naming
dfltlang "Export DDIC XML"

user_id "XML"

----------------------------------------------------------------------------
-- DATAMART
----------------------------------------------------------------------------
datamart

connect dtm_script_ddic as dd
where [dd.fld_is_active = '+']

group by
tab [dd.tab_id]
order by [dd.tab_name]
fld_type [decode(dd.fld_name, '##new##', 1, decode(dd.fld_domn, 'action', 2, 3))]
fld [dd.fld_id]
order by [dd.fld_name || ' ' || dd.parent_level]

consolidate
on top
item_ref text assign [dd.item_ref]
base_tab script_tab connect [task_exec.param('script_tab_id').id_val]
msg_buf text assign [null]
filename text assign [null]
sub_dir text assign [null]
on tab inherit script_tab
prev_fld_name text assign [null]
parent_tab script_tab connect [dd.parent_tab_id]
on fld_type
tag text assign [
case when dd.fld_name = '##new##' then ''
when dd.fld_domn = 'action' then 'actionlist'
else 'fieldlist'
end
]

on fld inherit script_fld
tag text assign [
case when dd.fld_name = '##new##' then 'constructor'
when dd.fld_domn = 'action' then 'action'
else 'field'
end
]

end datamart

----------------------------------------------------------------------------
-- LAYOUT
----------------------------------------------------------------------------
script layout

import text_list;
import rbsc$xml_util;
import native script_ddic#;
import native rbsc$api_exp#;

--------------------------------------------------------------------------
on report head

declare
l_rel_path text;
begin
if task_exec.task_descn is not null then
top.sub_dir := task_exec.task_descn||rbsc$api_exp#.get_ddic_path(top.base_tab.name);
l_rel_path := regexp_replace(regexp_replace(top.sub_dir, '([^/]+/)', '../'), '/[^/]*$', '/');
end if;
top.filename := top.base_tab.name || '.xml';

with new buf(keep_buf=>"+") as b do
top.msg_buf := b;
end with;

buf(top.msg_buf).put('<?xml version="1.0" encoding="ISO-8859-1"?>'||chr(10));
buf(top.msg_buf).put('<!DOCTYPE avq_api SYSTEM "'||l_rel_path||'avq_api.dtd">
<?xml-stylesheet type="text/xsl" href="'||l_rel_path||'avq_api.xsl" ?>'||chr(10));
end;

--------------------------------------------------------------------------
on report foot
rbsc$api_exp#.store_buf(top.filename, top.sub_dir, top.msg_buf);


--------------------------------------------------------------------------
on tab head

---- DDIC HEAD ----
buf(top.msg_buf).put('<ddic id="'||tab.id||'" type="'||tab.tab_type||'" name="'||tab.name||'" ');
if tab.label is not null then
buf(top.msg_buf).put('label="'||rbsc$xml_util.encode(session.text(tab.label))||'" ');
end if;
if tab.is_abstr = '+' then
buf(top.msg_buf).put('abstract="true" ');
end if;
if tab.is_obsolete = '+' then
buf(top.msg_buf).put('obsolete="true" substitute="'||rbsc$xml_util.encode(tab.subst)||'" ');
end if;
with src(lookup.fld("meta_script_tab", tab.id, "gen_src_id")) as s do
if s is not null then
buf(top.msg_buf).put('generated="true" ');
if s.name is not null then
buf(top.msg_buf).put('generatorSource="'||rbsc$xml_util.encode(s.name)||'" ');
buf(top.msg_buf).put('generatorSourceType="'||rbsc$xml_util.encode(s.src_type.user_id)||'" ');
end if;
end if;
end with;
buf(top.msg_buf).put('>'||chr(10));
if tab.descn is not null then
buf(top.msg_buf).put(' '||rbsc$xml_util.get_xml_element('descn', tab.descn)||chr(10));
end if;

---- INHERITANCE ----
declare
l_is_first boolean := true;
l_hira text;
begin
-- DDICs this one inherits from
for tab_parent in tab.parent_list(1) loop
l_hira := tab_parent.name;
if l_hira is not null then
if l_is_first then
buf(top.msg_buf).put(' <inheritlist>'||chr(10));
l_is_first := false;
end if;
buf(top.msg_buf).put(' <parent>'||l_hira||'</parent>'||chr(10));
end if;
end loop;
if not l_is_first then
buf(top.msg_buf).put(' </inheritlist>'||chr(10));
end if;
end;

--------------------------------------------------------------------------
on tab foot

---- DDIC FOOT ----
buf(top.msg_buf).put('</ddic>'||chr(10));

--------------------------------------------------------------------------
on fld_type head
if fld_type.tag is not null then
buf(top.msg_buf).put(' <'||fld_type.tag||'>'||chr(10));
end if;

--------------------------------------------------------------------------
on fld_type foot
if fld_type.tag is not null then
buf(top.msg_buf).put(' </'||fld_type.tag||'>'||chr(10));
end if;

--------------------------------------------------------------------------
on fld head

---- SUMMARIES DATA: Constructor, Methods, Fields ----
declare
l_name text;
l_get_val text;
l_label text;
l_descn text;
l_idx number;
l_stmt_list text;
begin
l_name := fld.name;

---- SUPPRESS ROOT FIELDS AND DUPLICATES ----
if fld_type.id != 1 and l_name = script_ddic#.c_root_fld_name then
return;
elsif l_name = tab.prev_fld_name then
return;
end if;
tab.prev_fld_name := l_name;

-- Field basics
buf(top.msg_buf).put(' <'||fld.tag||' id="'||fld.id||'" name="'||l_name||'" domain="'||fld.domn||'" type="'||fld.type||'" ');

-- Get the "ID" value hidden behind the get statement
for s in fld.stmt_list loop
if s.name = 'get' then
l_get_val := is_number(s.val);
end if;
end loop;

l_label := fld.label;

-- No label? For code tables there are OUT_TEXT entries with appropriate name!
if l_label is null and top.base_tab.name like '%code%' and l_get_val is not null then
l_label := upper(replace(tab.name, "code_")||"."||l_get_val);
end if;
-- Translate label to text
if l_label is not null then
l_label := session.text(l_label);
end if;
-- Still no label?
if l_label is null then
-- Code tables have a NAME column
if top.base_tab.name like '%code%' then
l_label := rbsc$api_exp#.script#fld_name(tab.name, fld.name);

-- EXTN DDICs sometimes are badly generated => get name from CODE_OBJ_ADD
elsif top.base_tab.name like '%obj_extn%' then
l_label := rbsc$api_exp#.script#fld_name('code_obj_add', fld.name);

-- EXTN DDICs sometimes are badly generated => get name from CODE_OBJ_ADD
elsif top.base_tab.name like '%extn%' then
l_label := rbsc$api_exp#.script#fld_name('code_obj_add', fld.name);
end if;
end if;

-- For inactive fields: trim the ! from the label
if fld.is_active = '-' and l_label like '!%' then
l_label := substr(l_label, 2);
end if;

if l_label is not null then
buf(top.msg_buf).put('label="'||rbsc$xml_util.encode(l_label)||'" ');
end if;

if fld.is_obsolete = '+' then
buf(top.msg_buf).put('obsolete="true" substitute="'||rbsc$xml_util.encode(fld.subst)||'" ');
end if;

---- PARENT ----
if fld.tab_id != tab.id then
buf(top.msg_buf).put('inherited="'||session.fld('meta_script_tab', fld.tab_id)||'" ');
end if;

---- LIST ----
if fld.is_list = '+' then
buf(top.msg_buf).put('list="true" ');
end if;
if fld.constr is not null then
buf(top.msg_buf).put('constraint="'||rbsc$xml_util.encode(fld.constr)||'" ');
end if;
if fld.is_calc = '+' then
buf(top.msg_buf).put('calculated="true" ');
end if;

---- STATEMENT LIST ----
for s in fld.stmt_list loop
l_stmt_list := iff(l_stmt_list is not null, l_stmt_list || ', ') || s.name;
end loop;
if l_stmt_list is not null then
buf(top.msg_buf).put('statements="'||rbsc$xml_util.encode(l_stmt_list)||'" ');
end if;

l_descn := fld.descn;
if l_descn is null and top.base_tab.name like '%code%' and l_get_val is not null then
l_descn := rbsc$api_exp#.script#fld_descn(tab.name, fld.name);
end if;

if fld.par_cnt = 0 and l_descn is null then
buf(top.msg_buf).put('/>'||chr(10));
else
buf(top.msg_buf).put('>'||chr(10));
if l_descn is not null then
buf(top.msg_buf).put(' '||rbsc$xml_util.get_xml_element('descn', l_descn)||chr(10));
end if;

---- FIELD PARAMETER ----
l_idx := 1;
while fld.par_cnt >= l_idx loop
with fld.par(l_idx) as par do
buf(top.msg_buf).put(' <param id="'||par.fld_id||'" name="'||par.name||'" domain="'||par.domn||'" type="'||par.type||'" ');
if par.constr is not null then
buf(top.msg_buf).put('constraint="'||rbsc$xml_util.encode(par.constr)||'" ');
end if;
if par.is_mand = '+' then
buf(top.msg_buf).put('mandatory="true" ');
end if;
if par.is_obsolete = '+' then
buf(top.msg_buf).put('obsolete="true" substitute="'||rbsc$xml_util.encode(par.subst)||'" ');
end if;
if par.dflt is not null then
buf(top.msg_buf).put('default="'||rbsc$xml_util.encode(par.dflt)||'" ');
end if;
if par.descn is not null then
buf(top.msg_buf).put('>
'||rbsc$xml_util.get_xml_element('descn', par.descn)||'
</param>'||chr(10));
else
buf(top.msg_buf).put('/>'||chr(10));
end if;
end with;
l_idx := l_idx + 1;
end loop;
buf(top.msg_buf).put(' </'||fld.tag||'>'||chr(10));
end if;
end;

end layout

end report

Besprich das Bocksnip
    Kei Kommentar zur Diskussion gfunde

    Du muesch igloggt si, um über das Bocksnip z'diskutiere
boecki

boecki

Nimmt teil
August 13, 2016

  • 64 Bocksnipa
    gschriebe
  • 0 Likes
    verteilt
  • 1 Kommentär gmacht
Bocksnip Tags
Teil din Code

Organisier und teil all dini Code Snips a eim Platz.