I am trying to create a function within my rule sets that will check that a particular document's field is null. Unfortunately one of the variables I pass in has a leading slash. For example: /mycollection/xyz123
rules_version = '1';
function hasNullStartDate(teamGuid, path) {
return get(/databases/$(database)/documents/team/$(teamGuid)/$(path)).data.startDate == null
}
match /teams/{teamid}/{subpath=**} {
allow delete: if hasNullStartDate(teamid, subpath)
}
I have tried removing the slash between my two variables $(teamGuid)$(path) but that causes a syntax error in the rules.
I have tried to do .replace() on the path, but that has ended up in a run time error. Maybe I didn't format it right or maybe it has to do with the rules version.
https://firebase.google.com/docs/reference/rules/rules.String#replace
How can I get rid of that leading slash /?
So I think you don't want to use replace at all in this specific case, since a Path object (what you're passing to get()) isn't actually a string. I think you'll be better off with a string split to get "mycollection" and "xyz123" into separate elements so you can build the path using their values individually.
Either that, or you can build the entire string the way you would expect for a normal string, and pass that string to path() to then pass to get(). Again, see the Path documentation for more on that.
Related
I'm writing a Gatling simulation, and I want to verify both that a certain element exists, and that the content of one of its attributes starts with a certain substring. E.g.:
val scn: ScenarioBuilder = scenario("BasicSimulation")
.exec(http("request_1")
.get("/path/to/resource")
.check(
status.is(200),
css("form#name", "action").ofType[String].startsWith(BASE_URL).saveAs("next_url")))
Now, when I add the startsWith above, the compiler reports an error that says startsWith is not a member of io.gatling.http.check.body.HttpBodyCssCheckBuilder[String]. If I leave the startsWith out, then everything works just fine. I know that the expected form element is there, but I cant confirm that its #action attribute starts with the correct base.
How can I confirm that the attribute start with a certain substring?
Refer this https://gatling.io/docs/2.3/general/scenario/
I have copied the below from there but it is a session function and will work like below :-
doIf(session => session("myKey").as[String].startsWith("admin")) { // executed if the session value stored in "myKey" starts with "admin" exec(http("if true").get("..."))}
I just had the same problem. I guess one option is to use a validator, but I'm not sure how if you can declare one on the fly to validate against your BASE_URL (the documentation doesn't really give any examples). You can use transform and is.
Could look like this:
css("form#name", "action").transform(_.startsWith(BASE_URL)).is(true)
If you also want to include the saveAs call in one go you could probably also do something like this:
css("form#name", "action").transform(_.substring(0, BASE_URL.length)).is(BASE_URL).saveAs
But that's harder to read. Also I'm not sure what happens when substring throws an exception (like IndexOutOfBounds).
Can someone explain to me what the difference is between these two Cloud Functions declarations!?
exports.boxScoresUpdate = functions.database.ref('/Games/{gid}/BoxScores').onWrite(event => {
and
exports.emailEmployeeReport = functions.database.ref('/Employee/${eid}/reports').onWrite(event => {
Other then they reference different Nodes... the first function just has {gid} while the second function has ${eid}
What is the $ used for!? and does it actually matter (can you use them interchangeably) since my function works without the $ as seen in the first database reference using only {gid}
The first line is the correct expression for a wildcard variable in a database path.
The second line doesn't seem to be correct at all. If it was using string variable interpolation with backticks (which it is not), it would include the current value of eid in the string, assuming it has been defined globally ahead of time. Right now it is literally including the $ in the string path, which is most likely not what was intended.
If you got that line from this video, notice in the comments that we acknowledged that is was a mistake in the typing and should not have included the dollar sign.
I am trying to find entities (Tags) in the database via their Name property, where it is important to ignore the case (When database is searched and the Database contains a Tag with the name Database, that one should be returned). Right now, my code looks like this:
public IEnumerable<db.Tag> FindByNames(IEnumerable<string> tagNames)
{
return this.DatabaseContext.Tags
.Where(tag => tagNames.Contains(tag.Name));
}
Obviously, this one is case sensitive. I have tried to provide StringComparer.OrdinalIgnoreCase as comparer to the Contains method, but got a warning during execution that the expression could not be translated and would be executed in code rather than in the database (I don't remember the exact message, I will edit as soon as I am back on my development machine). I can live with that if I have to, but it would be nice to know how to let the database do the work in this case. Is it possible?
No change should be necessary. SQLite's "LIKE" is already case-insensitive.
The default behavior of the LIKE operator is to ignore case for ASCII characters.
(cref https://www.sqlite.org/pragma.html#pragma_case_sensitive_like and Case sensitive and insensitive like in SQLite)
Of course, you can always use .FromSql() to get the exact query you want. Example:
context.Tags.FromSql("SELECT * FROM tags WHERE name LIKE '%{0}%'", tagName)
I need to find a solution for the following problem:
After basic url (say "domain.org/elements") I need to have a hierarchical structure of elements following this basic url, and user if free, possibly infinitely, add another elements at any level, including element-containers, e.g. url for the example some containers and 1 element at the end of this hierarchy could look like these ones:
domain.org/elements/container-top/container-deeper/container-deeper2/element
domain.org/elements/container-top/container-deeper/container-deeper3/..../container-deeperN/element
The problem is: how to identify such routes in the Symfony2 controller, not using solutions like a Dynamic Controller (I don't want e.g. to save routes to DB)?
Well, you could easily do something like this by tweaking the regular expression to use:
/**
* #Route("/{parameters}", requirements={"parameters"="[^/]+(/[^/]+)*"})
*/
public function myAction($parameters)
{
$parameters = explode('/', $parameters);
// ...
}
The regular expression above reads like:
one or more non-forward slash character FOLLOWED BY zero or more (forward slash FOLLOWED BY one or more non-forward slash character)
I'm working on a webapp, one function of which was to list all the files under given path. I tried to map several segments of URL to one PathVariable like this :
#RequestMapping("/list/{path}")
public String listFilesUnderPath(#PathVariable String path, Model model) {
//.... add the file list to the model
return "list"; //the model name
}
It didn't work. When the request url was like /list/folder_a/folder_aa, RequestMappingHandlerMapping complained : "Did not find handler method for ..."
Since the given path could contains any number of segments, it's not practical to write a method for every possible situation.
In REST each URL is a separate resource, so I don't think you can have a generic solution. I can think of two options
One option is to change the mapping to #RequestMapping("/list/**") (path parameter no longer needed) and extract the whole path from request
Second option is to create several methods, with mappings like #RequestMapping("/list/{level1}"), #RequestMapping("/list/{level1}/{level2}"), #RequestMapping("/list/{level1}/{level2}/{level3}")... concatenate the path in method bodies and call one method that does the job. This, of course, has a downside that you can only support a limited folder depth (you can make a dozen methods with these mappings if it's not too ugly for you)
You can capture zero or more path segments by appending an asterisk to the path pattern.
From the Spring documentation on PathPattern:
{*spring} matches zero or more path segments until the end of the path and captures it as a variable named "spring"
Note that the leading slash is part of the captured path as mentioned in the example on the same page:
/resources/{*path} — matches all files underneath the /resources/, as well as /resources, and captures their relative path in a variable named "path"; /resources/image.png will match with "path" → "/image.png", and /resources/css/spring.css will match with "path" → "/css/spring.css"
For your particular problem the solution would be:
#RequestMapping("/list/{*path}") // Use *path instead of path
public String listFilesUnderPath(#PathVariable String path, Model model) {
//.... add the file list to the model
return "list"; //the model name
}