How to remove / filter parameter in Typewriter - typewriter

I have the below script in Typewriter
$Methods()[
$name($Parameters[$name$IsNullable: $WriteType][, ]) {}
]
...which works fine.
Now I want to check whether my method in c# has a parameter named commandId and if so not add it to type script (removing it from $Parameters)
This is my method for checking if the parameter's name is commandId;
bool IsCommandIdParameter(Parameter p)
{
return (p.Name == "commandId" && p.Type.Name == "string");
}

I found answer and I put it here in case somebody else has same issue, you can filter parameters by lambda expressions
$Methods()[
$name($Parameters(p => !IsCommandIdParameter(p))[$name$IsNullable: $WriteType][, ]) {}
]

Related

JSONPath expression for an array of multiple arrays

I have a json payload that looks like this
{
"data":{
"methods":[
[
{
"p_id":"01",
"description":"Test01",
"offline":true
}
],
[
{
"p_id":"02",
"description":"Test02",
"offline":false
}
],
[
{
"p_id":"03",
"description":"Test03",
"offline":true
}
]
]
}
}
How can I write a JSONPath expression to get the "p_id" where "offline"= false?
You can use a filter expression which selects all elements in an object or array that match the specified filter. For example, [?(#.offline === false)] will match any object if its offline property is strictly false.
So, if the object is always in the same place, you could do:
$.data.methods.*[?(#.offline === false)].p_id
Or, if you want to look for any object where offline is false and fetch p_id, you could use a recursive descent with the filter expression:
$..[?(#.offline === false)].p_id
Note: I used strict equality in my examples so it will only match with a boolean false. If you don't need/want that you could instead simply use a ! to negate the filter. E.g. [?(!#.offline)]

How do I pass a parameter with Expression as value in ADFv2?

In Azure Data Factory v2 (ADFv2) I am having trouble passing a parameter whose value is an expression that needs evaluated at runtime.
For example, I have a set of extracts I want to download daily from the same LinkedService/Connection. I want a pipeline with a Foreach to be able to input a JSON pipeline parameter with a list of configuration for each report type (this I can do). "but" when I have one of those configuration KVPairs with value that is an expression, the expression does not seem to be evaluated.
here is an example of a Foreach parameter set that works for an SFTP LinkedService :
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_works_fine_20180307*.txt" } ]
here is an example of a Foreach parameter set that does not match the files I need to get.
(assume utcnow('yyyyMMdd') returns 20180307
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_does_NOT_work_#{utcnow('yyyyMMdd')}*.txt" } ]
This assumes that in the underlying Copy activity I am passing the dataset parameter fileFilter as
#item().fileFilter
...and in the dataset, the value of the fileFilter is an expression with value
#dataset().fileFilter
...I have also tried to wrap the argument completely as:
[ { "dirPath" : "/dirPath" ,"fileFilter" : "#toLower(concat(string('this_does_NOT_work_'),string(utcnow('yyyyMMdd')),string('*.txt') )))" } ]
...If you have suggestions/guidance, please let me know.
Thanks,
J
Try to put the fileFilter parameter directly in pipeline parameter.
Something like this will work:
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_works_fine_#{formatDateTime(utcnow(), 'yyyy')}#{formatDateTime(utcnow(), 'MM')}#{formatDateTime(utcnow(), 'dd')}*.txt" } ]

Elasticsearch groovy script to check parameter inclusion in array

I'm using elasticsearch (v2.0.0) for search in Rails and want to add to our custom script for scoring, but I'm either messing up the syntax or just missing something else entirely. It all works without the check in the script for the array, so that's the only part that's not working.
So for the index, recipe_user_ids is an array of integers:
indexes :recipe_user_ids, type: 'integer'
Then in the search query I specify the parameter for the script file and which script file:
functions: [{
script_score: {
params: { current_user_id: user.id },
script_file: 'ownership_script'
}
}]
And the ownership-script.groovy file:
if (current_user_id == doc['user_id'].value) { owner_modifier = 1.0 } else { owner_modifier = 0.0 }
if (doc['recipe_user_ids'].values.contains(current_user_id)) { recipe_user_modifier = 50.0 } else { recipe_user_modifier = 0.0 }
(_score + (doc['score_for_sort'].value + owner_modifier + recipe_user_modifier)*5)/_score
I'm not getting any errors, but the results don't seem to match what I'd expect when the recipe_user_ids array does contain current_user_id, so everything is falling into the else statement. Is it a type issue, syntax? Any tips greatly appreciated.
This seems to occur due to mismatch in type caused by autoboxing.
The doc['field_name].values for field mapping short, integer, long types seems to be returning a collection always of type 'Long' and the argument to contains is autoboxed to Integercausing contains to fail.
You could probably explictly cast current_user_id to the type of Long:
Example:
doc['recipe_user_ids'].values.contains(new Long(current_user_id))
Or better to use the 'find' method
doc['recipe_user_ids'].values.find {it == current_user_id}

Getter in a Behavior cakephp 3

I've just created a tag behavior to manage tags in an input text field (all keywords are separate by a comma). To do that I name my input "tag_string".
So I need to use a getter to handle the string.
I didn't understand how implement a _getTagString() method directly in the behavior.
If I use my getter (getTagString) in each entities file that use my behavior all my code works fine.
So to avoid write the same getter in each file I want to put it in my behavior file. But it doesn't work.
Here is my method:
public function _getTagString() {
if (isset($this->_properties['tag_string'])) {
return $this->_properties['tag_string'];
}
if (empty($entity->tags)) {
return '';
}
$tags = new Collection($entity->tags);
$str = $tags->reduce(function ($string, $tag) {
return $string . $tag->name . ', ';
}, '');
return trim($str, ', ');
}
Thanks for your help
After several searches I didn't find anything to implement accessors directly in the behavior.
I use trait, and It works fine.

How to alter field value drupal 7

I am working with drupal 7, and wanted to change the output of "number_float" value when it is "0.00". I have digged into field.api but has no clue what function to do.
To say it in plain English:
if the field type "number_float" and value is "0.00", print "empty value".
This is also to consider before views output.
Any hint or guidance would be very much appreciated.
Thanks
UPDATE:
I used hook_field_attach_view_alter. It does as expected, however I wonder if this is the right thing.
function mymodule_field_attach_view_alter(&$output, $context) {
foreach (element_children($output) as $field_name) {
$element = &$output[$field_name];
if ($element['#field_type'] == 'number_float' && $element['#formatter'] == 'number_decimal') {
foreach ($element['#items'] as $delta => $item) {
if ($element[$delta]['#markup'] == '0.00' || $element[$delta]['#markup'] == '0,00') {
$element[$delta]['#markup'] = t('Empty value message');
}
}
}
}
}
Any suggestion or betterment will be the answer.
thanks
A more standard Drupal way would be to manipulate the value in a preprocessor function. You can use hook_preprocess_HOOK for a theme function or template that's defined by another module. Inside of it, test for the 0.00 value and replace.
The update with hook_field_attach_view_alter is the way to go since nobody provides any other suggestion.

Resources