Skip to content

Commit

Permalink
Add source from URL operator gets the server URL and resource from th…
Browse files Browse the repository at this point in the history
…e url parameters
  • Loading branch information
Alejandro Rodriguez committed Nov 30, 2016
1 parent 8a46f36 commit 608cc18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
14 changes: 11 additions & 3 deletions shared/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
//FUNCTIONS CALLED WHEN THE HTTP REQUEST ENDS//
///////////////////////////////////////////////

var pushResourceData = function pushResourceData(response) {
var pushResourceData = function pushResourceData(server, response) {

var limit = parseInt(MP.prefs.get('limit_rows'), 10);
if (isNaN(limit) || limit < 0) {
Expand All @@ -95,6 +95,11 @@
}
}

finalData.metadata = {
id: resource.result.resource_id,
ckan_server: server,
};

// Push the data through the wiring
MashupPlatform.wiring.pushEvent('resource', JSON.stringify(finalData));

Expand Down Expand Up @@ -122,7 +127,7 @@
//GET THE RESOURCE//
////////////////////

window.get_resource = function get_resource(resource) {
window.get_resource = function get_resource(ckanServer, resource) {
var parameters = {
resource_id: resource
};
Expand All @@ -131,7 +136,10 @@
if (!isNaN(limit) && limit > 0) {
parameters.limit = limit;
}
make_request('GET', MP.prefs.get('ckan_server') + '/api/action/datastore_search', parameters, pushResourceData, failureCb);

make_request('GET', ckanServer + '/api/action/datastore_search', parameters, function (response) {
pushResourceData(ckanServer, response);
}, failureCb);
};

})();
1 change: 0 additions & 1 deletion src-fromurl/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<changelog>doc/changelog.md</changelog>
</details>
<preferences>
<preference name="ckan_server" type="text" description="CKAN Server URL" label="CKAN Server URL" default="https://data.lab.fiware.org"/>
<preference name="auth_token" type="text" label="CKAN Authorization Token" description="CKAN Authorization Token. If empty, this operator will use the IdM credentials of the current user (only available for users logged through the IdM server, so will not work for anoymous users/public workspaces)"/>
<preference name="limit_rows" type="text" description="Maximum number of rows/results to retrieve. 0 or empty to use the default configuration from the CKAN server" label="Row limit" default="100"/>
</preferences>
Expand Down
3 changes: 2 additions & 1 deletion src-fromurl/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@

var init = function init() {
var mashupUrl = window.frameElement.parentNode.ownerDocument.location;
var ckanserver = getURLParameter('ckanserver', mashupUrl);
var resourceid = getURLParameter('resourceid', mashupUrl);
get_resource(resourceid);
get_resource(ckanserver, resourceid);
};

init();
Expand Down
1 change: 1 addition & 0 deletions src/doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added some missing type mappings (`int`, `float` and `float8`)
- Use the same source for building the `ckan-source-from-url` operator.
- Data sent by this operators now has metadata with server URL and resource ID.

## v0.4.4 (2016-10-26)

Expand Down
6 changes: 4 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

var MP = MashupPlatform;

MashupPlatform.prefs.registerCallback(get_resource);
MashupPlatform.prefs.registerCallback(function () {
get_resource(MP.prefs.get('ckan_server'), MP.prefs.get('resource'));
});

// Start the execution
get_resource(MP.prefs.get('resource'));
get_resource(MP.prefs.get('ckan_server'), MP.prefs.get('resource'));

})();

0 comments on commit 608cc18

Please sign in to comment.