Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cast using NGSIv2 types in updateAction (version 2) #376

Merged
merged 19 commits into from Oct 17, 2019

Conversation

AlvaroVega
Copy link
Member

@AlvaroVega AlvaroVega commented Oct 1, 2019

Currently there are some automatic cast about types:

  • Number
  • Text
  • Booleam
  • None
  • DateTime

What do we want?
Currently updateAction in version 2 is trying to cast (after expandVars) to NGSIv2 types like:

var changes = {};
    action.parameters.attributes.forEach(function(attr) {
        // Direct value for Text, DateTime, and others. Apply expandVar for strings
        let theValue = myutils.expandVar(attr.value, event, true);
        let theType = myutils.expandVar(attr.type, event);
        // Metadata should be null or object
        let theMeta = attr.metadata;
        var date;
        switch (theType) {
             case 'Text':
                 theValue = theValue.toString();
                 break;
             case 'Number':
                 theValue = parseFloat(theValue);
                 break;
             case 'Boolean':
                 if (typeof theValue === 'string') {
                     theValue = theValue.toLowerCase().trim() === 'true';
                 }
                 break;
             case 'DateTime':
                 if (parseInt(theValue).toString() === theValue) {
                     // Parse String with number (timestamp__ts in Perseo events)
                     theValue = parseInt(theValue);
                 }
                 date = new Date(theValue);
                 theValue = isNaN(date.getTime()) ? theValue : date.toISOString();
                 break;
             case 'None':
                 theValue = null;
                 break;
         }
        var key = myutils.expandVar(attr.name, event);
        changes[key] = {
            value: theValue,
            type: theType
        };

@AlvaroVega AlvaroVega changed the title Do not cast using NGSIv2 types [WIP] Do not cast using NGSIv2 types Oct 1, 2019
@AlvaroVega AlvaroVega changed the title [WIP] Do not cast using NGSIv2 types [WIP] Do not cast using NGSIv2 types in updateAction with version 2 Oct 2, 2019
@AlvaroVega AlvaroVega changed the title [WIP] Do not cast using NGSIv2 types in updateAction with version 2 Do not cast using NGSIv2 types in updateAction with version 2 Oct 7, 2019
@AlvaroVega
Copy link
Member Author

@fgalan Which version is used by default (v1 or v2) for that notification?

@AlvaroVega
Copy link
Member Author

AlvaroVega commented Oct 16, 2019

@fgalan Maybe we can add a configuration flag option (and env var) to enable or disable it, instead of remove all ? It would be disabled by default

@AlvaroVega AlvaroVega changed the title Do not cast using NGSIv2 types in updateAction with version 2 Do not cast using NGSIv2 types in updateAction Oct 16, 2019
@AlvaroVega AlvaroVega changed the title Do not cast using NGSIv2 types in updateAction Do not cast using NGSIv2 types in updateAction (version1 and version 2) Oct 17, 2019
CHANGES_NEXT_RELEASE Outdated Show resolved Hide resolved
bin/perseo Show resolved Hide resolved
@AlvaroVega AlvaroVega changed the title Do not cast using NGSIv2 types in updateAction (version1 and version 2) Do not cast using NGSIv2 types in updateAction (version 2) Oct 17, 2019
Co-Authored-By: Fermín Galán Márquez <fgalan@users.noreply.github.com>
Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fgalan fgalan merged commit 875c32d into master Oct 17, 2019
@fgalan fgalan deleted the task/disable_ngsiv2_type_cast_values branch October 17, 2019 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants