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
Related
I consider myself that 0 is not a good thing to do when returning information from an API
e.g.
{
userId: int|null
}
I have a colleague that insists in that userId should be 0 or -1, but that forces a system to know that the 0 means "not set", instead of null which is universally known as not set.
The same happens with string params, like logoUrl. However, in this case I think it is acceptable to have an empty string instead of null if the variable is not set or was unset.
Is there bibliography, standards, etc, that I can refer to?
I'm not aware of any standard around that, but the way I take those kind of decisions is by thinking about the way consumer services would read this response, the goal being to provide a very smooth and clean consuming workflow. This exercise can even be transformed into a documentation for your API consumers.
In your case, instead of returning a null/0 field, I would simply remove that field altogether when it's empty and let the consumers explicitly mark that field as optional in the model they use to deserialize this response.
In that way, they'll explicitly have to deal with those optional fields, than relying on the API to always provide a value for them.
I am trying to create a custom inspection in IntelliJ using structural search. The idea is to find all methods that have one or more parameters, of which at least one is not annotated. Bonus: Only hit non-primitive types of parameters.
So far, I have created the following Search Template:
$MethodType$ $Method$(#$ParamAnnotation$ $ParameterType$ $Parameter$);
using these filters and the search target "complete match":
$Parameters$: count[1,∞]
$ParamAnnotation$: count[0,0]
However, this only hits methods without any parameters annotated. I want it to also match methods where only some parameters have an annotation but others don't.
Is it possible to reference the count of one variable in the filter of another, e.g. by using script filters? If so, how?
You can do this by creating a Search Template like this:
$MethodType$ $Method$($TypeBefore$ $before$,
#$ParamAnnotation$ $ParameterType$ $Parameter$,
$TypeAfter$ $after$);
Filters:
$Parameters$: count=[1,1] // i.e. no filter
$ParamAnnotation$: count=[0,0]
$before$: count=[0,∞]
$after$: count=[0,∞]
This will find all method with at least one parameter without annotation.
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”
I'm trying to come up with a good naming convention for boolean variables that indicate something is "allowed".
E.g.,
WarningAllowed or WarningEnabled (means that we have turned on the option to give a warning).
CodeComplete has some suggestion for booleans (Has<> Is<>) but those aren't applicable.
My ideas:
<>Enabled
<>Allowed
Should<>
Allow<>
I've seen the prefix Can used in this context. For example:
StackPanel.CanHorizontallyScroll
ReceiveActivity.CanCreateInstance
CanExecuteToolEventArgs.CanExecute
I like this naming convention quite a bit because it abstracts away the reason for the value, be it true or false: The user of the API usually does not have to know whether a command is not eligible because it is forbidden or because it is impossible to execute. The result is the same: a greyed-out menu item/button/whatever.
This also allows the reason to change in future versions (e.g. if a Can* property returns false only when something is actually impossible at first, but in future versions, an access rights model is added, and from then on, the value of said Can* property also depends on the current access rights).
I have an EntityA which has an optional attribute int32 result. When I create EntityA I do not set the result attribute. Then later on when I fetch it I expect it to have nil value but for some reason it's set to 3 even though I have not set this attribute.
What's going on here?
1st possible issue:
You have set a default value in the model editor. Select the attribute and check the inspector.
2nd possible issue:
You are retrieving or showing the wrong value. Show the code you are using to find out that result is '3'.
3rd possible issue:
You are setting the value later inadvertently, perhaps in a loop or something similar. Do a text search for the attribute to find a possible occurrence in your code.
Your int32 will be stored wrapped into a NSNumber object. If you don't provide a value, no NSNumber object will be created - sql will treat it as NULL.
The iOS Core Data Programming Guide says:
You can specify that an attribute is optional—that is, it is not
required to have a value. In general, however, you are discouraged
from doing so—especially for numeric values (typically you can get
better results using a mandatory attribute with a default value—in the
model—of 0). The reason for this is that SQL has special comparison
behavior for NULL that is unlike Objective-C's nil. NULL in a database
is not the same as 0, and searches for 0 will not match columns with
NULL.
So, it may be better to either make the attribute mandatory and set it to a distinct value, or to pass in NSNumber from the start.