How to read two elements from (XML) in App Engine Peoplecode - peoplesoft

Can't read two elements? I can read one element but I don't know how to read two.
&FieldL= &inXMLDoc.DocumentElement.GetElementsByTagName("ws:Name_Data");
For &a = 1 To &FieldL.Len
&pNode = &FieldL[&a];
&Name_Type = &pNode.GetElementsByTagName("ws:Name_Type");
&aName_Type = &Name_Type [1].NodeValue;
End-For;
Here is the XML file.
<ws:Name_Data>
<ws:Name_Type>Legal</ws:Name_Type>
<ws:First_Name></ws:First_Name>
</ws:Name_Data>
<ws:Name_Data>
<ws:Name_Type>Preferred</ws:Name_Type>
<ws:First_Name></ws:First_Name>
</ws:Name_Data>
Consider Solutions
For &a = 1 To &FieldL.Len
&pNode = &FieldL[1];
&pNode2 = &FieldL[2];
&Name_Type = &pNode.GetElementsByTagName("ws:Name_Type");
&aName_Type = &Name_Type [1].NodeValue;
&aName_Type2 = &pNode2.GetElementsByTagName("ws:Name_Type");
&aName_Type22 = &aName_Type2 [1].NodeValue;
End-For;

For &a = 1 To &FieldL.Len
[...]
&aName_Type = &Name_Type [1].NodeValue;
End-For;
If &a = 2, the value in &aName_Type will be overwritten. Make sure &aName_Type is an array, and use the index.
For &a = 1 To &FieldL.Len
[...]
&aName_Type[&a] = &Name_Type[1].NodeValue;
End-For;

Related

xcom value are overwritten by else statement in if/else loop

I'm looping through a folder with some sql files. For each file I want to push them as xcom value with specific value for each queries.
The code below is kind of working however not when adding else statement. not set value is overwriting everything.
directory = r'airflow_home/dags/sql'
for filename in os.listdir(directory):
with open(os.path.join(directory, filename), 'r') as file:
sqlFile = file.read()
file.close()
if filename == 'api_params.sql':
query = sqlFile.format(partitioned_key,execution_date_second,partitioned_key,next_execution_date_second)
if filename == 'create_fact_table.sql':
query = sqlFile.format(fact_table_dest)
if filename == 'create_geo_table.sql':
query = sqlFile.format(fact_table_dest)
if filename == f'{geo_type}'+'.sql':
query = sqlFile.format(execution_date)
filename = 'geo_query'
if filename == 'schema_' + f'{schema}' + '.sql':
query = sqlFile.format(fact_table_dest,raw_table_dest,execution_date,next_execution_date)
filename = 'production_query'
if filename == 'insert_key.sql':
query = sqlFile.format(raw_table_dest,execution_date,next_execution_date)
else:
query = 'not set'
task_instance.xcom_push(key=filename, value=query)
can someone explain me what's happening here?
You are using multiple if statements, which are executed one after the other. The else just referring to the last if statement and therefore overwriting previous set query parameter. What you are actually looking for is elif - see Python Docs.
directory = r'airflow_home/dags/sql'
for filename in os.listdir(directory):
with open(os.path.join(directory, filename), 'r') as file:
sqlFile = file.read()
file.close()
if filename == 'api_params.sql':
query = sqlFile.format(partitioned_key,execution_date_second,partitioned_key,next_execution_date_second)
elif filename == 'create_fact_table.sql':
query = sqlFile.format(fact_table_dest)
elif filename == 'create_geo_table.sql':
query = sqlFile.format(fact_table_dest)
elif filename == f'{geo_type}'+'.sql':
query = sqlFile.format(execution_date)
filename = 'geo_query'
elif filename == 'schema_' + f'{schema}' + '.sql':
query = sqlFile.format(fact_table_dest,raw_table_dest,execution_date,next_execution_date)
filename = 'production_query'
elif filename == 'insert_key.sql':
query = sqlFile.format(raw_table_dest,execution_date,next_execution_date)
else:
query = 'not set'
task_instance.xcom_push(key=filename, value=query)

putting letters with number inside lua variables

I have this Nginx lua code which is used to encrypt numbers from 0 to 9 with its equivalent encrypted code ... ( see the example below )
and its working great , but i want to make it also encrypt Letters from A to Z.
I'm not familiar with lua so i don't know what is the best way to make it works !
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
local cookie = ngx.var.token
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
Maybe something like that :
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[a] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf[b] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf[c] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
...................
...................
...................
...................
bf[z] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = ngx.var.token
for i=0, 9 and a, z do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
I tried to rewrite your code:
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf['a'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf['b'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf['c'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
--
--
--
bf['z'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = "01sdz" -- ngx.var.token
-- first example
local cookie = cookie:gsub ( '.', function (x)
local s = tonumber(x) or x
if bf[s] then return "'+".. bf[s] .."+'"
else return x
end
end )
print(cookie)
-- second example
cookie = "01sdz"
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+".. bf[i] .."+'")
-- may be use bf[i]:gsub( '([%%])', '%%%1') with escape escaping symbol %
end
for i= string.byte('a'), string.byte('z') do
local v = bf[string.char(i)]
if v then
cookie = cookie:gsub( string.char(i), "'+".. v:gsub( '([%%])', '%%%1') .."+'")
end
end
print(cookie)
result
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
I updated my code, anyway the second example will help you

openpyxl - How to preserve xlsx custom properties

How do I preserve custom properties from xlsx template which I am modifying with openpyxl? When I save() workbook using openpyxl these custom properties vanish!
Custom properties can be found here:-
On Mac -> Go to File Menu in Excel -> Properties ... -> Custom tab ->
Properties section
I am posting a pure python solution to reading and writing Workbook.CustomDocumentProperties just because I am currently also feeling the pain of not having this in openpyxl, and I needed a quick workaround for a personal automation project.
In fact, I will try to implement this feature (and hopefully later Worksheet.CustomProperties) into openpyxl myself if I can get my head around how to do all the plumbing the library needs: https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1003
Update: I pushed my contribution and it should be accepted and merged shortly :) https://foss.heptapod.net/openpyxl/openpyxl/-/merge_requests/384
So for now, here is a workaround, converting the .xlsx to .zip, then reading and writing the .xml files in the zip directly, and then renaming to .xlsx at the end.
To read Workbook.CustomDocumentProperties you can do this - only very slightly modified from this great answer: https://stackoverflow.com/a/46919795/9792594
from lxml import etree as ET
import zipfile
def get_custom_doc_properties(filename):
path_file = os.path.abspath(filename)
base, ext = os.path.splitext(path_file)
zip_filename = base + ".zip"
os.rename(path_file, zip_filename)
main_ns = "{http://schemas.openxmlformats.org/spreadsheetml/2006/main}"
docPr_ns = "{http://schemas.openxmlformats.org/officeDocument/2006/custom-properties}"
docPr_type = "{http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes}" #i4, r8, filetime, bool, lpwstr
r_ns = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}"
cusPr_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty"
with zipfile.ZipFile(zip_filename) as zip:
props = zip.open('docProps/custom.xml')
text = props.read()
xml = ET.fromstring(text)
workbook_props = {}
for child in XML:
if (child.tag == f"{docPr_ns}property"):
for cusPr in child:
workbook_props[child.attrib['name']] = cusPr.text
return workbook_props
#call like this:
get_custom_doc_properties(f'./example.xlsx')
And to add one prop to a document which already has custom doc props (and therefore already has a 'docProps/custom.xml' file), is pretty easy and we just append one more custom property to the xml.
(However, if the document had no current custom doc props, then we need to generate the 'docProps/custom.xml' file from scratch, as well as add a content override and a relationship - see code comments):
import os
from lxml import etree as ET
import zipfile
import shutil
import datetime
from tempfile import NamedTemporaryFile
def set_workbook_custom_document_properties(filename, cus_doc_prop_name, cus_doc_prop_val):
if not isinstance(cus_doc_prop_name, str):
print("you must supply a string as the 'cus_doc_prop_name'")
return
if isinstance(cus_doc_prop_val, str):
docPr_type_suffix = "lpwstr"
cus_doc_prop_str = cus_doc_prop_val
elif isinstance(cus_doc_prop_val, int):
docPr_type_suffix = "i4"
cus_doc_prop_str = str(cus_doc_prop_val)
elif isinstance(cus_doc_prop_val, float):
docPr_type_suffix = "r8"
cus_doc_prop_str = str(cus_doc_prop_val)
elif isinstance(cus_doc_prop_val, bool):
docPr_type_suffix = "bool"
cus_doc_prop_str = str(cus_doc_prop_val)
elif isinstance(cus_doc_prop_val, datetime.datetime):
docPr_type_suffix = "filetime"
cus_doc_prop_str = cus_doc_prop_val.strftime("%Y-%m-%dT%H:%M:%SZ")
else:
print("you must supply a string, int, float, bool, or date, as the 'cus_doc_prop_val'")
return
path_file = os.path.abspath(filename)
base, ext = os.path.splitext(path_file)
zip_filename = base + ".zip"
os.rename(path_file, zip_filename)
main = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
main_ns = "{%s}" % main
docPr = "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
docPr_ns = "{%s}" % docPr
docPr_type = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
docPr_type_ns = "{%s}" % docPr_type #i4, r8, filetime, bool, lpwstr
docPr_rel_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
docPr_content_type = "application/vnd.openxmlformats-officedocument.custom-properties+xml"
r_ns = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}"
cusPr_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty"
xml_declaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
base_xml = '{dec}<Properties xmlns="{docPr}" xmlns:vt="{docPr_type}"></Properties>'.format(dec=xml_declaration, docPr=docPr, docPr_type=docPr_type).encode('utf-8')
with NamedTemporaryFile() as tmp_file:
tmpname = os.path.basename(tmp_file.name)
with zipfile.ZipFile(zip_filename, 'r') as zip_in:
with zipfile.ZipFile(tmpname, 'w') as zip_out:
zip_out.comment = zip_in.comment # preserve the comment
custom_present = 'docProps/custom.xml' in zip_in.namelist()
for item in zip_in.infolist():
if item.filename == 'docProps/custom.xml':
custom_xml = ET.fromstring(zip_in.read(item.filename))
elif custom_present == False and item.filename == '_rels/.rels':
rels_xml = ET.fromstring(zip_in.read(item.filename))
elif custom_present == False and item.filename == '[Content_Types].xml':
content_types_xml = ET.fromstring(zip_in.read(item.filename))
else:
zip_out.writestr(item, zip_in.read(item.filename))
if custom_present:
# if custom.xml is already present we just need to append:
max_pid = 1
for node in custom_xml:
max_pid = max(int(node.attrib['pid']), max_pid)
else:
# if custom.xml is not present, we need to create it
# and also to add an override to [Content_Types].xml
# and also to add a relationship to _rels/.rels
custom_xml = ET.parse(BytesIO(base_xml)).getroot()
max_pid = 1
child_override = ET.SubElement(content_types_xml, "Override")
child_override.attrib['ContentType'] = docPr_content_type
child_override.attrib['PartName'] = '/docProps/custom.xml'
zip_out.writestr('[Content_Types].xml', ET.tostring(content_types_xml))
max_rid = 0
for node in rels_xml:
max_rid = max(int(node.attrib['Id'].replace("rId", "")), max_rid)
child_rel = ET.SubElement(rels_xml, "Relationship")
child_rel.attrib['Type'] = docPr_rel_type
child_rel.attrib['Target'] = 'docProps/custom.xml'
child_rel.attrib['Id'] = "rID" + str(max_rid + 1)
zip_out.writestr('_rels/.rels', ET.tostring(rels_xml))
child = ET.SubElement(custom_xml, "property")
child.attrib['name'] = cus_doc_prop_name
child.attrib['pid'] = str(max_pid + 1)
child.attrib['fmtid'] = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
val = ET.SubElement(child, f"{docPr_type_ns}{docPr_type_suffix}")
val.text = cus_doc_prop_str
print(ET.tostring(custom_xml, pretty_print=True))
zip_out.writestr('docProps/custom.xml', ET.tostring(custom_xml))
zip_out.close()
zip_in.close()
shutil.copyfile(tmpname, zip_filename)
os.rename(zip_filename, path_file)
#call it like this:
set_workbook_custom_document_properties(f'./example.xlsx', "testDocProp7", 2.5)

what is the pointer to pointer equivalent in lua

I know that you can use tables in a similar way to pointers in lua. That being said, what would pointers to pointers look like? Would they look something like dp = {p = {}}? if so what would the equivalent to the c code below be in lua?
void InsertItem(node **head, node *newp){
node **dp = head;
while((*dp) && (*dp)->value > newp->value
{
dp = &(*dp)->next;
}
newp->next = *dp;
*dp = newp;
}
Yes, double pointer may be translated to Lua as nested table.
local function InsertItem(head, newitem)
while head.next and head.next.value > newitem.value do
head = head.next
end
newitem.next = head.next
head.next = newitem
end
-- Typical Usage:
local head = {}
InsertItem(head, {value = 3.14})
InsertItem(head, {value = 42})
InsertItem(head, {value = 1})
-- Now the data is the following:
-- head = {next = elem1}
-- elem1 = {next = elem2, value = 42 }
-- elem2 = {next = elem3, value = 3.14}
-- elem3 = { value = 1 }
The big difference between C pointers and Lua tables is that in C, you can take the address of a variable and pass it to a function to modify it. You can't do that in Lua, but the function could always return the modified value.
Would they look something like dp = {p = {}}?
Yes, that's about as close as close as you can get to a pointer to a pointer in Lua.
if so what would the equivalent to the c code below be in lua?
Linked lists tend to work more smoothly with recursion:
local function InsertItem(head, newp)
if not head or head.value <= newp.value then
newp.next = head
return newp
end
head.next = InsertItem(head.next, newp)
return head
end

Oracle Stored Procedure unable to call from ASP.NET

I have written a code in ASP.NET to fetch data from Oracle stored procedure. But I get an error when trying to fetch the data:
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'USER_FEEDBACK' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
Procedure code is this:
create or replace PROCEDURE user_feedback(cv_results out sys_refcursor,start_date IN VARCHAR2)
IS
BEGIN
open cv_results for
select pi.first_name || ' ' || pi.last_name initiator
......
from request_workflow w inner join request_workflow_attribute waRating
on waRating.request_workflow_id = w.row_id
and waRating.attr_name = 'UserRating'
.............
where w.date_stamp_utc between start_date and '31-dec-2015'
order by waRating.attr_value desc, eform_name;
END ;
This is my ASP.NET code:
Oracle.DataAccess.Client.OracleCommand objCmd = new Oracle.DataAccess.Client.OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = "user_feedback";
objCmd.CommandType = CommandType.StoredProcedure;
Oracle.DataAccess.Client.OracleParameter oraP = new Oracle.DataAccess.Client.OracleParameter();
// System.Data.OracleClient.OracleParameter op = null;
oraP.OracleDbType = OracleDbType.RefCursor;
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;
oraP.ParameterName = "start_date";
oraP.OracleDbType = OracleDbType.Varchar2;
oraP.Value = "01-Dec-2015";
oraP.Direction = System.Data.ParameterDirection.Input;
objCmd.Parameters.Add(oraP);
objConn.Open();
objCmd.ExecuteReader();
objCmd.ExecuteNonQuery();
Please suggest how to make it work.
You're only creating/adding a single parameter but assigning it twice with different values resulting in just one parameter to the call.
Instead, create and add two separate parameters, something like;
var oraP1 = new Oracle.DataAccess.Client.OracleParameter();
oraP1.OracleDbType = OracleDbType.RefCursor;
oraP1.ParameterName = "cv_results";
oraP1.Direction = System.Data.ParameterDirection.Output;
objCmd.Parameters.Add(oraP1);
var oraP2 = new Oracle.DataAccess.Client.OracleParameter();
oraP2.ParameterName = "start_date";
oraP2.OracleDbType = OracleDbType.Varchar2;
oraP2.Value = "01-Dec-2015";
oraP2.Direction = System.Data.ParameterDirection.Input;
objCmd.Parameters.Add(oraP2);
It's probably because you don't Add the first parameter. Try something like this?
...
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;
objCmd.Parameters.Add(oraP);
oraP = new Oracle.DataAccess.Client.OracleParameter();
oraP.ParameterName = "start_date";
...
Though, it'd be better to declare another variable for the first param if you'll be reading from that refcursor later.

Resources