What's the correct way of converting values? - groovy

I was trying to make my model strings to be always uppercase, so I tried to use converter and reverseConverter to do this job. Using the mutual option I got hitted by this topic.
Witch leads to my question. Is this the right use case to converter? Without the mutual the value was converted only in the model, and didn't update the view.
Can I use the DocumentFilter approach?
Example
textField(columns: 3, text: bind("score", target: m,
converter: { it.isEmpty()? 0: Integer.parseInt(it) },
reverseConverter: { String.valueOf(it) },
mutual: true))

I'm afraid converter: and reverseConverter: only work with unidirectional bindings at the moment.

Related

How to get protobuf.js to output enum strings instead of integers

I'm using the latest protobuf.js with Node.js 4.4.5.
I currently struggle to get protobuf.js to output the string definitions of enums instead of integers. I tried several suggestions, but none of them worked:
https://github.com/dcodeIO/ProtoBuf.js/issues/97
https://github.com/dcodeIO/protobuf.js/issues/349
I guess it's because of API changes in protobuf.js for the first one. For the second one, I can use the suggested solution partially, but if the message is nested within other messages, the builder seems to fall back to using the integer values, although the string values have been explicitly set.
Ideally, I'd like to overwrite the function which is used for producing the enum values, but I have a hard time finding the correct one with the debugger. Or is there a better way to achieve this for deeply nested objects?
The generated JS code from protoc has a map in one direction only e.g.
proto.foo.Bar.Myenum = {
HEY: 0,
HO: 1
};
Rationale for this is here but you have to the reverse lookup in your own JS code. There are lots of easy solutions for this. I used the one at https://stackoverflow.com/a/59360329/449347 i.e.
Generic reverse mapper function ...
export function getKey(map, val) {
return Object.keys(map).find(key => map[key] === val);
}
UT ...
import { Bar } from "js/proto/bar_pb";
expect(getKey(proto.foo.Bar.Myenum, 0)).toEqual("HEY");
expect(getKey(proto.foo.Bar.Myenum, 1)).toEqual("HO");
expect(getKey(proto.foo.Bar.Myenum, 99)).toBeUndefined();

Is it possible to do a Lookup use Kiba

Is it possible to do a "Lookup" with Kiba.
Since it's quite a normal process in a etl.
Could you show a demo if yes, thanks.
Yes, a lookup can be done with Kiba!
For a tutorial, see this live coding session I recorded, I create a lookup transform to lookup extra fields using a given fields by tapping in the MovieDB database.
Leveraging this example, you could for instance implement a simple ActiveRecord lookup using a block transform:
# assuming you have a 'country_iso_2' field in the row above
transform do |row|
country = Country.where(iso_2: row['country_iso_2']).first
row['country_name'] = country.try(:name) || 'Unknown'
row
end
or you could extract a more reusable class transform that you would call like this:
transform ActiveRecordLookup, model: Country,
lookup_on: 'country_iso_2',
fetch_fields: { 'name' => 'country_name' }
transform DefaultValue, 'name' => 'Unknown'
Obviously, if you have the need for large volumes, you will have to implement some improvements (e.g. caching, bulk reading).
Hope this helps!

Array access not allowed on OpenFL movieclips

UDATED
How do I go about this?
I got this from Main.hx:
function onMouseOver(e:MouseEvent){
if(Std.is(e.currentTarget, MovieClip)){
initializer (cast e.currentTarget,["scaleX",1.5,"scaleY",1.5])
}
}
Then this is the pointed function in my Animation Class
//here if i set mc:Dynamic everything goes great! but when this one
function initializer(mc:MovieClip, vars:Array<Dynamic>){
var varsLength:Int = Math.round(vars.length/2);
for(m in 0...varsLength){
ini[m] = mc[vars[2*m]];
}
}
then when i compile it, an error appears:
Error: Array access is not allowed in flash.display.MovieClip
How do I resolve this?
EDIT:
vars: are properties of the MovieClip, for example when I pass these parameters:
initializer (mcClip1,["scaleX",1.5,"scaleY",1.5])
so:
vars = ["scaleX",1.5,"scaleY",1.5]
and:
ini[m] will store "scaleX" and "scaleY"`
X-Ref: https://groups.google.com/forum/#!topic/haxelang/_hkyt__Rrzw
In AS3, you can access fields of an object via their String name using [] (array access). This is called Reflection.
In Haxe, Reflection works differently - you need to make use of the Reflect API.
It's considered bad practice - it's not type-safe, which means the compiler can do very little to help you with error messages, and it's quite slow as well. This is why the usage makes it very explicit that Reflection is actually going on (while in AS3, this fact is somewhat hidden). Consider if there are other ways of solving this problem that don't require Reflection.
Now, to get back to your example, here's what it would look like in Haxe:
function onMouseOver(e:MouseEvent){
if (Std.is(e.currentTarget, MovieClip)) {
initializer(cast e.currentTarget, ["scaleX", 1.5, "scaleY", 1.5])
}
}
function initializer(mc:MovieClip, vars:Array<Dynamic>) {
for (m in 0...Std.int(vars.length / 2)) {
ini[m] = Reflect.getProperty(mc, vars[2*m]);
}
}
Btw, your loop was running for too long since you only use half of the values in the array - if you don't divide it by two like I did, you'll end up with [scaleX, scaleY, null, null] instead of the desired [scaleX, scaleY].

xpages #IsMember function in dialog list item values

Based on this XPages adding #Formulas in dialogList, my dialogList1 takes values from two concatenated views: a and b.
There is another dialogList2, which is rendered depending if the dialogList1 value is null or not, whose values should be like this:
dialogList1.value is from a => dialogList2.choices should be only from b
dialogList1.value is from b => dialogList2.choices should be only from a
I tried:
// Contr.txt_particontractcv_1 - is the value binded by dialogList1
var dbname = session.getServerName() + "!!" + "mynsf.nsf";
//var a = #Unique(#DbColumn(dbname, "vwNumeCompanii", 0)).sort();
//var b = #Unique(#DbColumn(#DbName(),"vwA",0));
//return a.concat(b);
if ( #IsMember(Contr.txt_particontractcv_1,#Unique(#DbColumn(#DbName(),"vwA",0))))
{ return #Unique(#DbColumn(dbname, "vwNumeCompanii", 0)) }
else
{ return #Unique(#DbColumn(#DbName(),"vwA",0)) }
but the dialogList2 is taking values only from vwA ( from b ) ... I think I'm missing something. Thanks for your time.
Contr.txt_particontractcv_1 cannot be used in SSJS. Dot notation works in LotusScript but not SSJS or Java because Java's runtime is not proprietary and has not been extended that way. That is why Contr.getItemValueString("txt_particontractcv_1") is required.
Some SSJS global variables allow dot notation to be used, e.g. sessionScope. But that is because it is based on a Map, so sessionScope.myProperty can only map to sessionScope.get("myProperty"). The Domino Document class does not extend the Map interface (that's one of the enhancements of the OpenNTF Domino API), so dot notation doesn't know whether to use getItemValue(), getItemValueString(), getItemValueDateTimeArray() etc.
This is also why best practice for scoped variables is also to use e.g. sessionScope.get("myVar"). When it comes to moving to Java, you will not be able to use dot notation, you will have to use the relevant method. So working that way in SSJS fosters good habits for the future.
Yep, I just modified Contr.txt_particontractcv_1 to Contr.getItemValueString("txt_particontractcv_1") and, now, it works.`

Sails.js Waterline Model Storage

I'm trying to store a large chunk of text as part of a model in Sails.js. However, it seems that the text is getting cut off after some length. Is there a limit set on how long the 'string' type can hold in a model? If so, what's the best way around it? For reference, I'm using sails-mysql as an adapter.
Yes, String is only 255 chars long on default (because thats the default length in the most databases).
Try to use
myfield: {
type: "text"
}
As attribute - this should work.
(See: http://beta.sailsjs.org/#/documentation/reference/Models/Attributes.html)
Try to use
field: {
type: 'ref'
}
this creates longtext in mysql .

Resources