Two collections in for each - foreach

How to specify two collection variables in foreach scope in mule?
<foreach collection="#[flowVars.ar] && #[flowVars.md]" doc:name="For Each" counterVariableName="i">
<db:select config-ref="Generic_Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT a.tempocode AS tempocode
FROM Referencelookup a WITH (NOLOCK)
JOIN ReferenceLookup r WITH (NOLOCK) ON r.Metadatatype = 'ServicerCode' AND r.TempoCode = a.AccountName
WHERE a.metadatatype =#[flowVars.md[counter-1]]
AND a.lookuptype = 'fiserv' AND r.refcode =#[flowVars.srvcode] AND a.refcode =#[flowVars.ar[counter-1]]]]></db:parameterized-query>
</db:select>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</foreach>

Related

XQuery: How to get a specific value out of a tag?

Suppose we have this xml:
<question>
<test id="1">
<tag k="a" v="1"/>
<tag k="a" v="2"/>
<tag k="b" v="3"/>
</test>
<test id="2">
<tag k="a" v="1"/>
<tag k="a" v="4"/>
<tag k="b" v="5"/>
</test>
<test id="3">
<tag k="a" v="2"/>
<tag k="a" v="6"/>
<tag k="b" v="7"/>
</test>
</question>
I would like to return all values v of test, if k = "a" AND v = "1", like this:
v="3"
v="5"
So far my approach:
for $i in //test
where ($i/tag[#k = 'a' and #v = '1'])
return $i/tag/#v
But this is not correct because thats the return:
v="1"
v="2"
v="3"
v="1"
v="4"
v="5"
Thank you for your help :)
You are probably looking for something like
for $i in //test
where ($i/tag[#k = 'a'][#v="1"])
return $i/tag[#k="b"]/#v
Your criteria for selection was not exactly clear, but this returns what you expected:
for $i in //test
where $i/tag[#k = 'a' and #v = '1']
return $i/tag[not(#k = 'a' or #v = '1')]/#v
You could simplify and do this in a single XPath expression:
//test/tag[#k = 'a' and #v = '1']/tag[not(#k = 'a' or #v = '1')]/#v

unable to parse xml with groovy

I can't read the xml and parse the items because it's always returning an error of
groovy.lang.MissingPropertyException: No such property: method for
class: Script1
def xmlText = new XmlSlurper().parse('myxml.xml')
def skipped = 0
def failed = 0
def total = 0
def passed = 0
xmlText.suite.test.class.test-method.each{
if(it['#is-config'] == "true"){
}
else{
if(it['#status']=="PASS"){
passed = passed + 1
total = total + 1
}
if(it['#status']=="FAIL"){
failed = failed + 1
total = total + 1
}
if(it['#status']=="SKIP"){
skipped = skipped + 1
total = total + 1
}
}
}
the xml file is
<?xml version="1.0" encoding="UTF-8"?>
<testng-results skipped="3" failed="0" total="3" passed="0">
<reporter-output>
</reporter-output>
<suite name="DinamicTestSuite" duration-ms="24" started-at="2018-07-16T13:26:48Z" finished-at="2018-07-16T13:26:48Z">
<groups>
</groups>
<test name="Device:null" duration-ms="24" started-at="2018-07-16T13:26:48Z" finished-at="2018-07-16T13:26:48Z">
<class name="com.automation.venues.stg.VenuesSuite">
<test-method status="PASS" signature="login(org.testng.ITestContext, java.lang.String)[pri:0, instance:com.automation.venues.stg.VenuesSuite#71454b9d]" name="login" is-config="true" duration-ms="11" started-at="2018-07-16T16:26:48Z" finished-at="2018-07-16T16:26:48Z">
</test-method>
<test-method status="PASS" signature="beforeMethod(java.lang.reflect.Method)[pri:0, instance:com.automation.venues.stg.VenuesSuite#71454b9d]" duration-ms="0" started-at="2018-07-16T16:26:48Z" finished-at="2018-07-16T16:26:48Z">
</test-method>
</class> <!-- com.automation.venues.stg.VenuesSuite -->
</test> <!-- Device:null -->
</suite> <!-- DinamicTestSuite -->
</testng-results>
how can I parse the list ?
You need to put quotes round the attribute with a - in it
xmlText.suite.test.class.'test-method'.each{
An alternative to your each approach would be:
def xmlText = new XmlSlurper().parse('myxml.xml')
def totals = xmlText.suite.test.class.'test-method'.countBy { it.#status.text() }
def skipped = totals.SKIP
def failed = totals.FAIL
def passed = totals.PASS
def total = totals.values().sum()

XPATH in Nokogiri

I have an XML + SOAP with Nokogiri and I want only the body to appear but I have some errors.
The XML SOAP is:
data = <SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">
<SOAP:Header><header xmlns=\"xmlapi_1.0\">
<requestID>aquiroga:0001</requestID>
<requestTime>Mar 14, 2018 11:33:27 PM</requestTime>
<responseTime>Mar 14, 2018 11:33:27 PM</responseTime>
</header>
</SOAP:Header>
<SOAP:Body>
<findResponse xmlns=\"xmlapi_1.0\">
<result>
<service.SapEgrQosQueueStatsLogRecord>
<queueId>2</queueId>
<droppedInProfOctets>0</droppedInProfOctets>
<droppedOutProfOctets>0</droppedOutProfOctets>
<timeCaptured>1521072355115</timeCaptured>
<periodicTime>0</periodicTime>
<displayedName>eNodo_B-HOTELPUERTOPALMERA-S1UX2</displayedName>
<monitoredObjectSiteName>SMT-TRS-AN01</monitoredObjectSiteName>
</service.SapEgrQosQueueStatsLogRecord>
<service.SapEgrQosQueueStatsLogRecord>
<queueId>1</queueId>
<droppedInProfOctets>0</droppedInProfOctets>
<droppedOutProfOctets>70450698</droppedOutProfOctets>
<timeCaptured>1521072355051</timeCaptured>
<periodicTime>199796</periodicTime>
<displayedName>to_eNODOB Tarapoto Sur-S1-MME</displayedName>
<monitoredObjectSiteName>SMT-TRS-AN01</monitoredObjectSiteName>
</service.SapEgrQosQueueStatsLogRecord>
</result>
</findResponse>
</SOAP:Body>
</SOAP:Envelope>
The code I am using is:
data_stats = data.xpath('/SOAP:Envelope/SOAP:Body')
The result is:
=> #<Nokogiri::XML::Element:0x3fee745c1c94 name="Body" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1e60 prefix="SOAP" href="http://schemas.xmlsoap.org/soap/envelope/"> children=[#<Nokogiri::XML::Element:0x3fee745c16b8 name="findResponse" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c126c name="result" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c0e84 name="service.SapEgrQosQueueStatsLogRecord" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c0a60 name="queueId" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745c0664 "1">]>, #<Nokogiri::XML::Element:0x3fee745c0498 name="droppedInProfOctets" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745c00b0 "0">]>, #<Nokogiri::XML::Element:0x3fee745adec4 name="droppedOutProfOctets" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745adaa0 "0">]>, #<Nokogiri::XML::Element:0x3fee745ad8d4 name="timeCaptured" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ad4c4 "1521158716279">]>, #<Nokogiri::XML::Element:0x3fee745ad2f8 name="periodicTime" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745aceac "284992">]>, #<Nokogiri::XML::Element:0x3fee745acce0 name="displayedName" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ac8bc "RTN VillaSalvador3 Tdp-VillaBaja">]>, #<Nokogiri::XML::Element:0x3fee745ac6dc name="monitoredObjectSiteName" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ac2b8 "LIM-SPO-AN02">]>]>, #<Nokogiri::XML::Element:0x3fee74593f9c name="service.SapEgrQosQueueStatsLogRecord" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0">
I want it to appear only from service.SapEgrQosQueueStatsLogRecord. The code I use is the following:
data_stats = qos7705egressdiscard_summary.xpath('/SOAP:Envelope/SOAP:Body/findResponse/result/service.SapEgrQosQueueStatsLogRecord')
But the result is an empty arrangement => []
You can use data.remove_namespaces! ( see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Document:remove_namespaces! ). Then this query works:
data.xpath('/Envelope/Body/findResponse/result/service.SapEgrQosQueueStatsLogRecord')

How to create multiple sheets using RSSheet in iOS?

I am trying to create an XLS sheet programmatically. I am able to create single sheet in the XLS file, but when I try to create two sheets, I get the error. The file is created but I am unable to open the file. I can only open the file when it is created with single sheet.
Here is what I tried:
RSworkBook * folder = [ [RSworkBook alloc] init];
folder.author = #"andrea cappellotto";
folder.version = 1.2;
RSworkSheet * sheet = [[RSworkSheet alloc] initWithName:#"prova"];
RSworkSheet * sheet2 = [[RSworkSheet alloc] initWithName:#"222"];
RSworkSheetRow * row = [[RSworkSheetRow alloc] initWithHeight:20];
[row addCellString:#"prova"];
[row addCellString:#"prova2"];
[sheet addWorkSheetRow:row];
[sheet2 addWorkSheetRow:row];
RSworkSheetRow * row2 = [[RSworkSheetRow alloc] initWithHeight:25];
[row2 addCellNumber:100];
[row2 addCellData:[NSDate date] ];
[sheet addWorkSheetRow:row2];
[sheet2 addWorkSheetRow:row];
[folder addWorkSheet:sheet];
[folder addWorkSheet:sheet2];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
[folder writeWithName:#"prova" toPath:documentsDir];
HEre is the xml code that is generated:
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>andrea cappellotto</Author>
<LastAuthor>andrea cappellotto</LastAuthor>
<Created>2015-07-09</Created>
<Version>1.20</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>20000</WindowHeight>
<WindowWidth>20000</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>0</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook><Styles><Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center" ss:Horizontal="Center"/>
<Borders/>
<Font ss:FontName=".HelveticaNeueInterface-Regular" ss:Size="14.00" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s60">
<NumberFormat ss:Format="Short Date"/>
</Style>
</Styles>
<Worksheet ss:Name="prova">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="0.00" ss:DefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="25.00" >
<Cell>
<Data ss:Type="Number">100.00</Data>
</Cell>
<Cell ss:StyleID="s60">
<Data ss:Type="DateTime">2015-07-09</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
<Worksheet ss:Name="222">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="0.00" ss:DefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
</Workbook>
I found another library to create multiple sheets in a xls file. It is libxl.I can add as many sheets as I can by using the following line:
SheetHandle sheet = xlBookAddSheet(book, [sheetNAme UTF8String], NULL);

QBOv3 XML Validation Fault 2500 (Invalid Reference Id )

I'm trying to create a test invoice at quickbooks using quickbooks-ruby gem. Note I have a test account at QB which doesn't have anything: invoice, customer, etc. It's a new account created only for testing purpose. So here is my code:
service = Quickbooks::Service::Invoice.new
service.company_id = current_user.company_id
service.access_token = create_consumer
qb_invoice = Quickbooks::Model::Invoice.new
qb_invoice.customer_id = 123
line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = 100
line_item.sales_item! do |detail|
detail.unit_price = 100
detail.quantity = 1
detail.item_id = 1
end
qb_invoice.line_items << line_item
res = service.create qb_invoice
p res.id #exception!
def create_consumer
OAuth::AccessToken.new(.....)
end
Request:
METHOD = post
RESOURCE = https://qb.sbfinance.intuit.com/v3/company/fdsfdsfdsfds123/invoice
<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns="http://schema.intuit.com/finance/v3" sparse="false">
<Line>
<Amount>100.0</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef>1</ItemRef>
<UnitPrice>100.0</UnitPrice>
<RatePercent>0.0</RatePercent>
<Qty>1.0</Qty>
</SalesItemLineDetail>
</Line>
<CustomerRef>123</CustomerRef>
<TotalAmt>0.0</TotalAmt>
<Balance>0.0</Balance>
<Deposit>0.0</Deposit>
</Invoice>
and response with the error:
RESPONSE CODE = 400
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-06T19:30:49.168-08:00">
<Fault type="ValidationFault">
<Error code="2500" element="">
<Message>Invalid Reference Id</Message>
<Detail>Invalid Reference Id : Something you're trying to use has been deleted. Check the fields with accounts, customers, items, vendors or employees.
</Detail>
</Error>
</Fault>
</IntuitResponse>
Could it be because a customer with id = 123 doesn't exist? If not, what's the cause then?
Please check if you have a customer(ID-123) and Item(Id-1) exist in your account.
If not then create these two entries using apiexplorer/code and use the corresponding object IDs.
ApiExplorer - https://developer.intuit.com/apiexplorer?apiname=V3QBO
EntityRef - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference
ApiExplorer -
Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0015_firstrequest
Thanks

Resources