STOMP Selector - convert_string_expressions - activemq

I am using the following selector string when creating a durable subscriber.
(PackageCode='' OR PackageCode IS NULL) AND ( WarehouseCode LIKE '%"WHSE1"%')
When the subscriber is created, the selector is prefixed with convert_string_expressions:. Based on the ActiveMQ documentation it is used to automatically convert string properties to numeric ones. But my filter doesn't have a number and there is no need to have this prefix.
convert_string_expressions:(PackageCode='' OR PackageCode IS NULL) AND ( WarehouseCode LIKE '%"WHSE1"%')
I have three questions:
Is the selector with the prefix valid?
Does it hurt to have the prefix even when the condition is just string?
How can I suppress the prefix that is added automatically?

The selector with the prefix is just as valid as it is without the prefix.
It doesn't hurt to have the prefix even when the condition is just strings. If it did hurt then it wouldn't be added automatically.
You cannot suppress the prefix that is added automatically. It is hard-coded.

Related

How to ignore unregistered namespaces in i18next (colons in strings)

We use i18next in a CMS to power its internationalization features. Since developers can build however they want with the CMS there is opportunity for them to add l10n keys that include colons, including as part of HTML, such as Find more info here.
As has been documented, with default namespace separator settings i18next will think the colon is identifying a namespace/key pair. Since the CMS uses its own namespace (so devs won't accidentally overwrite UI strings), we don't have the option to turn off namespacing completely (with nsSeparator: false).
What I'm looking for is a way for i18next to only recognize registered namespaces as namespaces. So if we tell i18next that the valid namespaces are ['ns1', 'ns2'] and it receives Title: Subtitle, that string will be treated as a key, not a namespace/key pair.
I saw the loadNamespaces method, but that looks to simply register them to the ns option on the instance. Is there a way for i18next to essentially disallow any unregistered namespace?
This is definitely a workaround, but it doesn't feel too hackey, so I was comfortable using it indefinitely. It's been several weeks, so I don't remember if I got this from somewhere else, but it's possible, for the sake of not taking the credit if undeserved.
First, I added the appendNamespaceToMissingKey: true option to the init function. This adds the default namespace to any keys that don't already have a namespace. It also includes an unknown namespace (or something it thinks is a NS) with the "missing key" for parsing.
Then I added the parseMissingKeyHandler option assigned to the following function:
function (key) {
if (key.startsWith(`${this.defaultNS[0]}:`)) {
return key.slice(this.defaultNS[0].length + 1);
} else {
return key;
}
}
Since I didn't have to hard-code the namespace I felt okay with that.
So if a "key" comes in here with the default namespace, which will include all unlocalized strings without colons (e.g., 'Some text'), that namespace is removed and the string continues on normally. Since i18next doesn't have a value for that string, the string is printed as-is.
If an unlocalized string comes in containing a colon (e.g., '🏛', i18next thinks the first part before the colon is a namespace, so the default is not applied. Therefore this colon-ized string is returned from the function the same as it entered. Again, since i18next doesn't have a value for this string, the string is printed as-is. In this case, that includes the part before the colon as well as the colon separator. We end up with the full link HTML, for example.
So in addition to the other options in place, it looks like:
i18next.init({
...otherOptions,
appendNamespaceToMissingKey: true,
parseMissingKeyHandler (key) {
// We include namespaces with unrecognized l10n keys using
// `appendNamespaceToMissingKey: true`. This passes strings containing
// colons that were never meant to be localized through to the UI.
//
// Strings that do not include colons ("Content area") are given the
// default namespace by i18next ("translation," by default). Here we
// check if the key starts with that default namespace, meaning it
// belongs to no other registered namespace, then remove that default
// namespace before passing this through to be processed and displayed.
if (key.startsWith(`${this.defaultNS[0]}:`)) {
return key.slice(this.defaultNS[0].length + 1);
} else {
return key;
}
}
});
I'm including my code comment since you may also want to include something like this to remind yourself later why you include this convoluted handler.

Can we have a dynamic string input with as a variable present on the terraform resource block?

Scenario: to have multiple Kubernetes deployments I have a skeleton.tf file that could create an app as per requirement with minimum variable changes and in different namespaces and I do not want to provide a default name so that I will give the input everytime I do a Terraform plan and apply
like
resource "kubernetes_deployment" "${var.deployment-1}" {
...
...
namespace= var.namespace_1
...
}
how do I achieve this? Is this supported, because I face a syntax interpolation error,
or
Invalid string literal: Template sequences are not allowed in this string. To include a literal "$", double it (as "$$") to escape it.
or
Invalid character: This character is not used within the language.
or
Invalid block definition: Either a quoted string block label or an opening brace ("{") is expected here.
I have read about the terraform workspaces but then, it would be a tedious task to be able to get the resource name as a dynamic input. any help or workarounds to this is appreciated.
The name given in the second label of a resource block is used only within the current Terraform module, so there is no need for it to be dynamically customizable. If you don't have a specific name to use then you can use a generic name like "main".
Because this is a Terraform-only name, Terraform will automatically deal with it appearing in possibly several different instances of your module, because the full address of a resource includes the address of the module that contains it. The whole result is therefore unique with in a Terraform configuration, and the resource's local name is unique within the module that declares it.

Just check for existence in ALFA target clause

I want write a target clause that says "If a certain attribute is set (oneAndOnly), then the policy applies". I have seen the [mustbepresent] thing, however, it always requires a comparator (like ==).
This was my approch, but the syntax checker complains...
policy reportPolicies {
target clause stringBagSize(my.company.person.doctor.id)==1
}
I've seen you defining a string attribute "resourceType" but I don't like to define such a meta attribute. I'd rather like to check for existence of certain attributes.
Again, great questions. Yes I often use an artificial attribute e.g. resourceType and compare it to values e.g. medical record or transaction. You do not have to do that because the attribute identifiers themselves convey the fact that you are dealing with one or another. However, I do think that it helps the policy be more readable.
On to the other issue: how to make sure an attribute has at least one value. In a Target element you can use the mustBePresent tag but I do not like it. If the attribute has no value, then the PDP returns Indeterminate and it short-circuits evaluation.
An alternative is to compare an attribute using > (greater than). For instance:
clause user.role > ""
clause user.age>0
That will force the value to be defined.
The cleaner way to do this, though, is to use bag functions inside a condition. For instance
condition stringBagSize(user.role)>0 // True if the user has at least one role

Browse sort criteria

I'm trying to write a upnp/dlna client for videos and I would like to allow the option to sort by title and date.
With Windows7/wmp as the server, I can use "dc:title" or "dc:date" for sorting and it seems to work but testers have told me it doesn't work on other servers. Is there a universal way to know if sorting is allowed and what the sorting criteria should be?
Thanks.
There is a way to query this (but be prepared for broken implementations that lie about their abilities as well). Quoting ContentDirectory service spec (v3):
2.3.3
SortCapabilities
This state variable is a CSV list of property names that the ContentDirectory service can use to sort
Search() or Browse() action results. An empty string indicates that the device does not support any kind of
sorting. A wildcard (“*”) indicates that the device supports sorting using all property names supported by
the ContentDirectory service. The property names returned MUST include the appropriate namespace
prefixes, except for the DIDL-Lite namespace. Properties in the DIDL-Lite namespace MUST always be
returned without the prefix. All property names MUST be fully qualified using the double colon (“::”)
syntax as defined in Section 2.2.20, “property”. For example,
“upnp:foreignMetadata::fmBody::fmURI”

jms message selectors

I am using ActiveMQ 5.5 and JMS. I have created a topic consumer with a message selector of
key<>'aValue'
meaning that the consumer will only receive messages that have a property called "key" that does not have the value 'aValue'.
Then I send a message with no property called "key" (Note that the case is NOT that there is a property with a null value, there is no property.)
What puzzles me is that the message is delivered.
This is not the case if I use the operator NOT LIKE:
key NOT LIKE 'aVal%'.
In this case the consumer does not receive the message. This is inconsistent in my mind.
This is what the JMS spec says:
A message selector matches a message when the selector evaluates to true when the message's header field and property values are substituted for their corresponding identifiers in the selector.
According to the SQL92 spec (which JMS message selectors syntax is based on) comparing anything to NULL results in NULL rather than to a value (TRUE or FALSE in this case). If this is the case the first case should not result in the message being received.
Has anybody come across this? Which result, the <> case or the NOT LIKE case, is the correct one when the producer has not specified the property and the consumer has a selector? Any ideas how this can be worked around?
Based on my limited reading, my understanding is this, first from the JMS spec:
If a property that does not exist in a message is referenced, its
value is NULL.
So in your case the key identifier when substituted for property values will evaluate to NULL
The first expression will essentially be NULL<>'aValue', which is true in my mind
The second expression will be NULL NOT LIKE '%aVal' which the spec says will have an unknown outcome and ActiveMQ seems to have gone with true as the outcome:
If identifier of a LIKE or NOT LIKE operation is NULL, the value of
the operation is unknown.
I think the fix will be to make the selector very explicit:
(key NOT NULL) AND ...