I want to add a comment log in db.system.profile of mongodb, and it works in a constant variable, such as following.
#Query(value="{'field1':?0, 'field2': ?1}")
#Meta(comment="staticComment")
Mono<Quota> findByField1AndField2(String value1, String value2, Sort sort);
My question is if there's any way to assign comment in running time? or such as #Query to carry parameter in? I tried following, but it show up "{?2}" in comment of db.system.profile.
#Query(value="{'field1':?0, 'field2': ?1}")
#Meta(comment="{?2}")
Mono<Quota> findByField1AndField2(String value1, String value2, String dynamicalComment, Sort sort);
Related
I would need some help to handle configuration files in golang.
I renamed every fields and values for privacy (just saying)
I have this yaml configuration file :
Label1:
field1: value1
field2: value2
field3: value3
field4: value4
Label2:
field1: value1
field2: value2
field3: value3
field4: value4
Label3:
field1: value1
field2: value2
field3: value3
field4: value4
I'm using https://github.com/kylelemons/go-gypsy/tree/master/yaml to manually decode this yaml file into the structure below (manually walking the list of nodes). I don't have control over how many "Label" items will be on that file so I need a generic way of parsing it (and it is generic using the library mentioned above)
type Obj struct {
Field1 string `yaml:"field1"`
Field2 string `yaml:"field2"`
Field3 string `yaml:"field3"`
Field4 bool `yaml:"field4"`
}
type ObjConfig struct {
Objs map[string]Obj
}
I have several other configuration files, much simpler, which I'm able to decode using annotations such as :
type conf1 struct {
Field1 int `yaml:"field1"`
Field2 string `yaml:"field2"`
}
I'm using the automatic yaml Unmarshal (through Viper framework) for these and it's working fine.
It wasn't a big deal mixing these 2 ways of handling configuration files until now. But now I need to retrieve the file from a spring config server that I did set up instead of having the files locally. I'm using this library to do so :
https://github.com/Piszmog/cloudconfigclient
It's working well for structures annotated with the yaml:"fieldX", I'm able to deserialize it directly.
But for the first structure of course it's not working and I need a workaround. The library (cloudconfigclient) is using the classic yaml decoder so I can't write my own custom decoder. Looking at the library code it uses this code to deserialize the configuration file (with resp.Body being the yaml configuration file content) :
var dest interface{}
yaml.NewDecoder(resp.Body).Decode(dest)
I'm able to change the configuraton file structure though, as long as I can get the same data in it. Maybe I could use something like
Labels:
- Label1:
field1: value1
field2:value2
....
- Label2:
field1:value1
....
and use the yaml map handling from unmarshal ?
I'm obviously not experienced with golang, I'd love to get some help here.
To sum up, the question is how to decode the first yaml file using yaml.Unmarshal with the classic decoder (by either specific annotations that I don't know of, or changing the yaml structure itself).
I got it working by mapping it to a generic map[string]interface{} type
var configResponse map[string]interface{}
err = configClient.GetFileFromBranch(BRANCH, CONF_DIR, CONF_FILE, &configResponse )
and then handling the cast myself into the structure
type ObjConfig struct {
Objs map[string]Obj
}
Not the most easy to read nor resilient to error solution but it's working
Normally one can query in the following way:
.query({
key1: value1,
...
keyN: valueN
})
But can I use instead of "hard" key values variables?
like following:
.query({
varKey1: value1,
...
varKeyN: valueN
})
Yes, it is possible.
Assuming varKey1, ... varKeyN are some variables:
.query({
[varKey1]: value1,
...
[varKeyN]: valueN
})
I'd like to get an array of values between delimiters. How would I do this? Like if I was using TN as delimiters and BBCode-type delimiting:
Like:
a="things [TN]are like[/TN] this [TN]for you[/TN]"
b=a.xxxx
b=["are like","for you"]
As long as you're certain that there won't be any nested [TN]...[/TN] tags, then you can use a simple regex for this:
a.scan(/(?<=\[TN\]).*?(?=\[\/TN\])/)
I am trying to add a variable to an xpath but to no avail
This works below for java
assertTrue("Failed", verifyElementPresent("//*[#class='StdLJText' and contains(.,'2 Employees selected')]"));
but when I add a variable , like below it does not
String CountEmp1="2";
assertTrue("Failed", verifyElementPresent("//*[#class='StdLJText' and contains(.,CountEmp1+'Employees selected')]"));
You need to put CountEmp1 as a string addition in the main verifyElePresent func i.e verifyElementPresent("//*[#class='StdLJText' and contains(.,"+CountEmp1+"Employees selected')]"));
Note the replacement of "+CountEmp1+" at contains(.,CountEmp1+'
With your xpath the verifyElementPresent method basically looks for //*[#class='StdLJText' and contains(.,CountEmp1+'Employees selected')] where countEmp1 is taken as string value and not something that needs to be concatenadated.
Say I have two variables (value1 and value2) and either could be nil, how can I create an element using XmlMarkup and only add the attributes that are not nil?
If I do this
xm = Builder::XmlMarkup.new
xm.item(:attribute1=>value1, :attribute2=>value2)
and both value1 and value2 are nil, I still get
<item attribute1="", attribute2=""/>
I have also tried to add the attributes after creating the element but had no success and I cannot figure out if this is even supported.
If it is not already apparent, I am a complete ruby beginner so any input would be appreciated.
I think something like this could work:
xm = Builder::XmlMarkup.new
attributes = {}
attributes[:attribute1] = value1 if value1
attributes[:attribute2] = value2 if value2
xm.item(attributes)
If you have more than a couple of attributes I can show you a way to minimize duplication with a similar method too.