Dynamic Date to be passed in getListItemChanges method - soap

I am using the below code. It works perfectly.
<GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>States At A Glance</listName>
<viewFields></viewFields>
<since>2013-08-29T 19:52:52Z</since>
<contains></contains>
</GetListItemChanges>
I wanted the datetime in the since tag to be dynamic. So, I used the below xquery functions to calculate it:
declare variable $Y := fn:concat(fn:substring(fn:string(fn:current-dateTime() - xs:dayTimeDuration('P30D')),1,11), ' ', fn:substring(fn:string(fn:current-dateTime() - xs:dayTimeDuration('P30D')),12,8), 'Z');
I tested the value of $Y, it is exactly - what I want.
But, when I substituted the date value with $Y, the code started erroring out:
let $soap-payload := ('<GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>States At A Glance</listName>
<since>{fn:data($Y)}</since>
</GetListItemChanges>')
error message:
axis2_svc_client_send_receive failed. Web Service returned a soap fault.
Error type: XQuery Engine error. soap:ReceiverException of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown..

Your code as shown will not perform the substitution. The variable $soap-payload doesn't contain XML, but a string. XQuery expressions inside of a string will not be evaluated. If you remove the single quotes from $soap-payload, the XQuery expression will be evaluated.
If you need $soap-payload to be a string, you could build it through string concatenation, or you could serialize the XML. The mechanism for that depends on your XQuery processor (and version).
XQuery 3.0: fn:serialize()
MarkLogic Server: xdmp:quote()
Saxon: saxon:serialize()
Concatenation Examples
XQuery 1.0
let $soap-payload :=
fn:concat(
'<GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>States At A Glance</listName>
<since>',
fn:concat(
$Y,
'</since>
</GetListItemChanges>'))
XQuery 3.0
let $soap-payload :=
'<GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>States At A Glance</listName>
<since>' || $Y || '</since>
</GetListItemChanges>'
Serialization Example
let $soap-payload-xml :=
<GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>States At A Glance</listName>
<since>{ $Y }</since>
</GetListItemChanges>
let $soap-payload := fn:serialize($soap-payload-xml)

Related

Unicode encoding / decoding error in Free Pascal 3.2.0

This test passed with Free Pascal 3.0.4. (source file encoding is UTF8, OS is Windows 10 64 Bit)
{$MODE DELPHI}
...
var
Raw: RawByteString;
Actual: string;
begin
Raw := UTF8Encode('关于汉语');
Actual := string (UTF8Decode(Raw));
CheckEquals('关于汉语', Actual);
end
With Free Pascal 3.2.0 it fails:
expected: <关于汉语> but was: <å³äºæ±è¯­>
RawByteString is declared as type AnsiString(CP_NONE) in system.h
The conversion works if I cast (or declare) the characters as UnicodeString. The following test succeeds with Free Pascal 3.2.0:
procedure TFreePascalTests.TestUTF8Encode;
const
THE_CHARACTERS: UnicodeString = '关于汉语';
var
Raw: UTF8String;
Actual: UnicodeString;
begin
Raw := UTF8Encode(THE_CHARACTERS);
Actual := UTF8Decode(Raw);
CheckEquals(THE_CHARACTERS, Actual);
end;
The Raw variable may be defined as RawByteString or Utf8String.

Is white space relevant when casting from the 'any' type in Apama EPL?

I am on Apama 10.3 (Community Edition):
any emptyString := "";
any emptyDictionary := new dictionary<string,any>;
string myString := <string> emptyString;
dictionary<string,any> := <dictionary<string,any>> emptyDictionary;
The cast in line 3 works, but in line 4 Designer complains about unexpected token: <. Only if I use white spaces does it work:
dictionary<string,any> := <dictionary< string,any> > emptyDictionary;
In the documentation Developing Apama Applications this is not mentioned but on page 296 when casting with optional<>, the correct syntax with the white spaces is used.
Does this work as expected or is it a bug?
The problem here isn't about casting to an any type. This is due to the EPL parser always interpreting expression >> as a right-shift operator. If you need to close two angle brackets, you always need to use a space between them. It’s only the closing brackets that are affected (as you’d never need to write << in EPL).
The form I always use is:
dictionary<string,any> x := <dictionary<string,any> > emptyDictionary;
sequence<sequence<string> > jaggedArray := new sequence<sequence<string> >;

How to receive xml nodes inside a time range by using xquery

I have an xml with something like that inside
<SFEvents>
<EventList>
<Event>
<ID>1111</ID>
<Type>Measurement</Type>
<TimeStamp>2015-09-28T09:50:27.514</TimeStamp>
<Space>Main_area</Space>
<SourceID>Thermometer_3</SourceID>
<Content>
<Measurement>
<!-- From B2MML standard (OpSegmentDataType) -->
<ID/>
<Description>Temperature of a power resistance</Description>
<Value>
<ValueString>100</ValueString>
<UnitOfMeasure>oC</UnitOfMeasure>
</Value>
</Measurement>
</Content>
</Event>
<Event>..</Event>
...
</EventList>
with many events and I currently try to receive with xquery all the Event nodes that have their Timestamp inside a time range
I use this code
all_xmls_String=session.execute("xquery for $b in doc('CIDEMdb/CIDEM.xml')
let $date_string as xs:string :=$b/SFEvents/EventList/Event/TimeStamp/data()
let $date as xs:dateTime := xs:dateTime($date_string)
where $date ge xs:dateTime('"+startdate+"') and $date le
xs:dateTime('"+enddate+"') return $b/SFEvents/EventList");
but I receive this error
Cannot cast xs:untypedAtomic+ to xs:string: ("2015-09-28T09:50:27.514", ...).
Any idea?
The problem is that you are iterating over the EventList document, which has a cardinality of 1, while selecting $b/SFEvents/EventList/Event/TimeStamp/data(), a sequence of TimeStamp values, and assigning it to a variable that expects a single value. Your query also returns an EventList, but you say you want to return Events.
There are several ways to do this, but the easiest way given your existing query it to simply iterate over the Event elements instead, select the single TimeStamp value, and then return the selected Events.
for $b in doc('CIDEMdb/CIDEM.xml')//SFEvents/EventList/Event
let $date_string as xs:string :=$b/TimeStamp/data()
let $date as xs:dateTime := xs:dateTime($date_string)
where $date ge xs:dateTime('"+startdate+"') and $date le xs:dateTime('"+enddate+"')
return $b

XText cross referencing

I have written following grammar
Model:
package = PackageDec?
greetings+=Greeting*
usage+=Usage* ;
PackageDec:
'package' name=QualifiedName ;
Greeting:
'greet' name=ID '{' ops += Operation* '}' ;
Operation:
'op' name=ID ('(' ')' '{' '}')? ;
QualifiedName:
ID ('.' ID)*;
Usage:
'use';
With above i can write following script.
package p1.p2
greet G1 {op f1 op f2 }
Now i need to write something like this:
package p1.p2
greet G1 {op f1 op f2 op f3}
use p1.p2.G1.f1
use p1.p2.G1
use p1.p2.G1.f3
To support that i changed Usage RULE like this
Usage:
'use' head=[Greet|QualifiedName] =>('.' tail=[Operation])?
However when i generate xtext artifacts it is complaining about multiple alternatives.
Please let me know how to write correct grammar rule for this.
This is because QualifiedName consumes dots (.). Adding ('.' ...)? makes two alternatives. Consider input
a.b.c
This could be parsed as
head="a" tail = "b.c"
head="a.b" tail = "c"
If I understand your intention of using predicate => right, than you just have to replace
head=[Greet|QualifiedName]
with
head=[Greet]
In this case however you will not be able to parse references with dots.
As a solution I would recommend to substitute your dot with some other character. For example with colon:
Usage:
'use' head=[Greet|QualifiedName] (':' tail=[Operation])?

How do you concatenate strings in a Puppet .pp file?

Here is my naive approach:
# puppet/init.pp
$x = 'hello ' +
'goodbye'
This does not work. How does one concatenate strings in Puppet?
Keyword variable interpolation:
$value = "${one}${two}"
Source: http://docs.puppetlabs.com/puppet/4.3/reference/lang_variables.html#interpolation
Note that although it might work without the curly braces, you should always use them.
I use the construct where I put the values into an array an then 'join' them.
In this example my input is an array and after those have been joined with the ':2181,' the resulting value is again put into an array that is joined with an empty string as separator.
$zookeeperservers = [ 'node1.example.com', 'node2.example.com', 'node3.example.com' ]
$mesosZK = join([ "zk://" , join($zookeeperservers,':2181,') ,":2181/mesos" ],'')
resulting value of $mesosZK
zk://node1.example.com:2181,node2.example.com:2181,node3.example.com:2181/mesos
Another option not mentioned in other answers is using Puppet's sprintf() function, which functions identically to the Ruby function behind it. An example:
$x = sprintf('hello user %s', 'CoolUser')
Verified to work perfectly with puppet. As mentioned by chutz, this approach can also help you concatenate the output of functions.
The following worked for me.
puppet apply -e ' $y = "Hello" $z = "world" $x = "$y $z" notify { "$x": } '
notice: Hello world
notice: /Stage[main]//Notify[Hello world]/message: defined 'message' as 'Hello world'
notice: Finished catalog run in 0.04 seconds
The following works as well:
$abc = "def"
file { "/tmp/$abc":
You could use the join() function from puppetlabs-stdlib. I was thinking there should be a string concat function there, but I don't see it. It'd be easy to write one.
As stated in docs, you can just use ${varname} interpolation. And that works with function calls as well:
$mesosZK = "zk://${join($zookeeperservers,':2181,')}:2181/mesos"
$x = "${dirname($file)}/anotherfile"
Could not use {} with function arguments though: got Syntax error at '}'.