Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Contributor
Posts: 47
Registered: ‎10-27-2015
Accepted Solution

How to search and delete a query by name

Hi All,

 

is it possible to search and delete a query by name in Geospatial Portal?

There is a $GP.queries.find but it is no good.

 

Thank you

Denis

Technical Evangelist
Posts: 113
Registered: ‎08-05-2015

Re: How to search and delete a query by name

Hi Denis,

 

I browsed the sources of the API and currently the query object can be found only with analysisId. But you can use the following snippet to find analysisId having its name:

 

// helper to find analysis id having its name
function getAnalysisId(name) {
    var a = $analysisManager.findAnalysisByName(name);
    return a && a.get_id();
}

$GP.queries.find({
    analysisId: getAnalysisId("IN operator test")
}, function(q) {
    q.analysis.remove();
}, function(e) {
    console.log("Unable to find analysis")
})

 

In the future version of the API we will just handle finding analysis by name. You could also patch your API.js and change gp.queries.find implementation to:

 

/**
 * Finds Analysis
 * @method find
 * @param {String/RegExp/Object} config
 * @param {String} config.analysisId
 * @param {Function} [callback] callback executed if operation succeeds
 * @param {Function} [errback] callback executed if operation fails
 */
find: function(config, callback, errback) {
    config = config || {};
    var analysis = getPortalObj(P_ANALYSIS_MANAGER).findAnalysis(config.analysisId) /* begin patch */ || getPortalObj(P_ANALYSIS_MANAGER).findAnalysisByName(config.name) /* end patch */ ,
        ret = new Analysis({
            config: config,
            portalAnalysis: analysis
        });
    if (analysis)
        fire(F_SUCCESS, callback, {
            success: true,
            analysis: ret
        });
    else {
        //@TODO failure config
        fire(F_FAILURE, errback, {
            success: false,
            msg: "Analysis not found."
        });
    }
    return ret;
}

Best regards,

Piotr

Contributor
Posts: 47
Registered: ‎10-27-2015

Re: How to search and delete a query by name

Thank you Piotr.

 

Is it possible to get an array of all queries or find queries using wild cards?

Technical Evangelist
Posts: 113
Registered: ‎08-05-2015

Re: How to search and delete a query by name

Unfortunately no Smiley Sad

 

The currently available API relies on analysisId. I would like to change it so that it would work as in the new implementation of $GP.user.workspaces.find from 16 EP02:

 

$GP.user.workspaces.find({
    name: /works/
}, function (ret) {
    $GP.ui.info("Workspaces found " + ret.workspaces.length);
})

Nevertheless, I will note the idea and try to add it in some next version in case there are other works on $GP.queries. Actually I created a sample implementation (you would need to paste it next to the original find method):

 

https://bitbucket.org/snippets/pszrajbe/aeq5x

 

But please mind that it has never been tested

Contributor
Posts: 47
Registered: ‎10-27-2015

Re: How to search and delete a query by name

Hi Piotr,

 

I get this error when I try to access the analysis returned by find2 function:

 

TypeError: access to strict mode caller function is censored

 

Thanks

Denis

Technical Evangelist
Posts: 113
Registered: ‎08-05-2015

Re: How to search and delete a query by name

Hi Denis,

 

1) what browser are you using? Does this error occur also in the other browsers?

2) on what version of Portal it happens?

 

Do you possibly have some stack trace for this error?

 

I've been reading that "TypeError: access to strict mode caller function is censored" may happen when using "strict" mode in ASP.NET apps in Firefox, but that's just a guess.

Regular Contributor
Posts: 221
Registered: ‎05-01-2016

Re: How to search and delete a query by name

[ Edited ]

That snippet is just what i need! 

It does remove the displayed query from the map.  Is it possible to get it to remove the Data View tab with the query result (attribute display)  as well?

 

// helper to find analysis id having its name
function getAnalysisId(name) {
    var a = $analysisManager.findAnalysisByName(name);
    $GP.ui.info(a);
    return a && a.get_id();
}
 
$GP.queries.find({
    analysisId: getAnalysisId("DataView query")
}, function(q) {
    q.analysis.remove();
}, function(e) {
    console.log("Unable to find analysis")
})

 

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.