current-dateTime() value is not updating on page-refresh event - xslt

I set the value of an instance to current-dateTime(). I want to update this value on page-refresh event. So I have the following code:
<xf:action ev:event="page-refresh">
<xf:setvalue ref="instance('noCache')/val"><xsl:value-of select="current-dateTime()" /></xf:setvalue>
<!-- call to resource with new value-->
</xf:action>
This above code sets the instance value (dateTime) as the same which was at page-load !
Later I use this instance value to make GET request calls to a resource and pass this updated instance value as a parameter.
Note: Using current-dateTime() to pass a parameter to the resource to avoid using cached resources (since couldn't find a way to generate random numbers
Seems like the problem I feel is that the xsl variable current-dateTime() is evaluated only on page-load and the same value is used for page-refresh. Is there some other way I can get the updated dateTime on page-refresh event ?

With XSLTForms you can call Javascript functions on XPath expressions on client side, this way:
<xf:setvalue ref="instance('noCache')/val" value="getXMLDate()" ></xf:setvalue>
And write the getXMLDate() function in your HTML:
<script>
function gwtXMLDate(){
var d = new Date();
return d.toISOString();
}
</script>

Related

Google Cloud Data flow : CloudBigtableScanConfiguration.withScan(), how to pass dynamic filter values?

SourceLocation is prefix for my Bigtable, which is fetched from application.properties. Is there a way to fetch it dynamically while running the data flow template?
My Pipeline:
pipeline.apply("ReadTable", Read.from(CloudBigtableIO.read(configSetUp(options))))
CloudBigtableScanConfiguration
private static CloudBigtableScanConfiguration configSetUp(LocationSetupOptions options) {
ValueProvider<Integer> pageFilter = options.getPageFilter();
Scan scan = new Scan(Bytes.toBytes(options.getSourceLocation().get()));
FilterList filterList = new FilterList();
PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes(options.getSourceLocation().get()));
filterList.addFilter(new PageFilter(Long.valueOf(pageFilter.get())));
filterList.addFilter(prefixFilter);
scan.setFilter(filterList);
return new CloudBigtableScanConfiguration.Builder()
.withProjectId(options.getProjectId())
.withInstanceId(options.getInstanceId())
.withTableId(options.getTableId())
.withScan(scan)
.build();}
There are two clients for Bigtable CloudBigtableIO and BigtableIO. The CloudBigtableIO parameters are not updated to be modified by templates via a ValueProvider but BigtableIO is compatible with ValueProviders.
In your particular case if you are looking for ValueProvider to be used along with template then I would recommend that you move to using BigtableIO. A sample can be found here AvroToBigtable.
UPDATE
The #Default.InstanceFactory can be used to specify a user-provided factory method to generate default values for a parameter. With this, you could read the default value from a resource file inside of your DefaultValueFactory implementation.
As an example, you can check how WindowedWordCount defines DefaultToCurrentSystemTime to annotate the minTimestampMillis parameter:

What is best method to get property for the content type with the closest match using client context (CSOM)?

I’m converting Event receiver codes into Remote event receiver using SharePoint 2013 Client context.
var documentList = clientContext.Web.GetList(Constants.DocumentsListUrl);
var classifiedContentTypeId = documentList.ContentTypes.BestMatch(new
SPContentTypeId("0x0120D52000155C54BB8DF04DE78D5F78461B236DEF"));
var classifiedContentType =
documentList.ContentTypes[classifiedContentTypeId];
Note that if the search finds two matches, the shorter ID is returned. For example, if 0x0101 is the argument, and the collection contains both 0x010109 and 0x01010901, the method returns 0x010109.
List.ContentTypes.BestMatch method is available to get closest match in SSOM. What is the right method in CSOM ?
Thanks in advance
One idea is to make use of the
ContentType.Id.IsChildOf()
method and then use string methods to choose the shortest Guid ?

Grails: pass a List from GSP to controller with remote link

So, in my method A in the controller ServicioComunitario I send this to the GSP:
tg = ServicioComunitario.findAll("from ServicioComunitario as b where "+query)
[servicioComunitarioInstanceList: tg, params: params]
Then in the GSP I call another method (generarDocDeReporte) of ServicioComunitarioController:
<g:set var="b" value="${'xls'}"/>
<g:set var="a" value="${'excel'}"/>
<g:set var="servicioLista" value="${servicioComunitarioInstanceList}"/>
<g:link controller="ServicioComunitario" action="generarDocDeReporte"
params="${[exportFormat:a, extesion:b, tg: servicioLista] }"
update="mainContent">Excel</g:link><br/>
Then, in the new method "generarDocDeReporte" I have:
println params.exportFormat+"-"+params.extesion
if(params.tg)
println "Not empty"
exportFormat and extension work as expected, but the params.tg doesn't seem to behave normal.
I am trying to use this new params.tg where it was a ServicioComunitario.list(params):
exportService.export(params.exportFormat, response.outputStream, ServicioComunitario.list(params), fields, labels, formatters, parameters)
And here is where I get the error:
exportService.export(params.exportFormat, response.outputStream, params.tg, fields, labels, formatters, parameters)
When I receive the params.tg, do I need to cast it? or what do you think is the error?
Thank you very much in advance
You can't just pass a list of instances like that in a link. You can however collect the ids into a list as a parameter and then use it to populate it later. For example:
<g:link controller="ServicioComunitario" action="generarDocDeReporte"
params="${[exportFormat:a, extesion:b, tgids: servicioLista.collect{it.id}.join(',')] }"
update="mainContent">Excel</g:link><br/>
And then in your controller where you need to get the list again:
def tg = ServicioComunitario.getAll(params?.tgids?.tokenize(","))
Also, you don't need to assign params to params when returning your model. parameters are already exposed in the GSP by convention.
[servicioComunitarioInstanceList: tg]

Writing a custom condition in WSO2 CEP with left and right argument

I want to extend the Wso2 CEP product in our needs and try to write a custom condition as indicated in this official wso2 cep link.
I am able to write an extension class that extends "org.wso2.siddhi.core.executor.conditon.AbstractGenericConditionExecutor" and implement its abstract method as indicated below:
#SiddhiExtension(namespace = "myext", function = "startswithA")
public class StringUtils extends
org.wso2.siddhi.core.executor.conditon.AbstractGenericConditionExecutor {
static Log log = LogFactory.getLog(StringUtils.class);
#Override
public boolean execute(AtomicEvent atomicEvent) {
log.error("Entered the execute method");
log.error("Atomic event to string: " + atomicEvent.toString());
return true;
}
}
when i use this extensioned method as:
from allEventsStream[myext:startswithA(name)]
insert into selectedEventsStream *;
In this situation, i want that startswithA method returns true if the name field has 'A' at the begining of it. However when i run this query in CEP the whole event drops into my execute function i.e. there is no sign to show that i send "name" field is sent to startswithA method as argument.
How can i understand which field of the stream is sent to my extended method as argument?
Also i want to write conditions like
from allEventsStream[myext:startswith('A', name)]
insert into selectedEventsStream *;
How can i achive this?
In 'AbstractGenericConditionExecutor' there's another method that gives you the set of expression executors that are included in the parameters when executor instantiates:
public void setExpressionExecutors(List<ExpressionExecutor> expressionExecutors)
You don't necessarily have to override this method and store the list, it is already stored there in the 'AbastractGenericConditionExecutor' as a list named expressionExecutors. You can pass the event to these executors to retrieve the relevant values from the event in order.
For an example, if you include a variable (like 'name') in the query (as a parameter at index 0), you'll get a 'VariableExpressionExecutor' in the list at index 0 that will fetch you the value of the variable from the event. Similarly for a constant like 'A', you'll get a different executor that will give you the value 'A' when called.
To add to Rajeev's answer, if you want to filter all the names that starts with 'A', you can override the execute method of your custom Siddhi extension similar to the following segment.
#Override
public boolean execute(AtomicEvent atomicEvent) {
if(!this.expressionExecutors.isEmpty()) {
String name = (String)this.expressionExecutors.get(0).execute(atomicEvent);
if(name.startsWith("A")) {
return true;
}
}
return false;
}
When writing the query, it would be similar to
from allEventStream[myext:startsWithA(name)]
insert into filteredStream *;
You can extend this behaviour to achieve an extension that supports
from allEventsStream[myext:startswith('A', name)]
type queries as well.
HTH,
Lasantha

Adding SignedDataObjects (and consequently add proofOfApproval property) to an enveloped signature

I'm creating an Enveloped signature with xades4j following this statements:
Element elemToSign = doc.getDocumentElement();
XadesSigner signer = new XadesTSigningProfile(...).newSigner();
new Enveloped(signer).sign(elemToSign);
But I need to put in the signature also other properties like ProofOfApprova etc...
I see that in xades4j examples the proofOfApprovalProperties are addedto enveloped signature using different statements of signature, for example:
AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
CommitmentTypeProperty commitment = CommitmentTypeProperty.proofOfCreation();
DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id"))
.withTransform(new EnvelopedSignatureTransform())
.withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding")
.withDescription("Isto é uma descrição do elemento raiz")
.withDocumentationUri("http://doc1.txt")
.withDocumentationUri("http://doc2.txt"))
.withIdentifier("http://elem.root"))
.withCommitmentType(commitment)
.withDataObjectTimeStamp(dataObjsTimeStamp)
SignedDataObjects dataObjs = new SignedDataObjects(obj1)
.withCommitmentType(globalCommitment);
signer.sign(dataObjs, elemToSign);
I see here that another procedure of signature is used, more specificately the statement in which I create a DataObjectreference saying that I use "Id" attibute fo root tag is unusable for me because in input I can have any kind of xml document and I cannot know what kind of attribute (if present) I can use foe define root tag.
Briefly, can I have some examp'le code where I create an Enveloped signature and put a proofOfApproval property using "new Enveloped(signer).sign(elemToSign);", or anyway whitout knowing the xml source structure?
Thanks
M.
The proofOfApproval property has to be applied to data objects being signed, hence the need to use the SignedDataObjects class.
The Enveloped class is just a helper for straightforward scenarios. If I understood correctly you want to sign the whole XML document. The XML-Signatures spec defines that an empty URI on a reference (URI="") means exactly that. If you check the code on the Enveloped class you'll see that it adds a DataObjectReference with an empty uri.
To sum up, you'll need something like:
DataObjectDesc obj1 = new DataObjectReference("")
.withTransform(new EnvelopedSignatureTransform())
.withCommitmentType(CommitmentTypeProperty.proofOfApproval());
signer.sign(new SignedDataObjects(obj1), elemToSign);