Skip to content
Snippets Groups Projects
Commit a17695d2 authored by cramakri's avatar cramakri
Browse files

MINOR Use the official openbis.js

SVN: 25167
parent 56591eab
No related branches found
No related tags found
No related merge requests found
/*! // Comments follow the yuidoc convenions: http://developer.yahoo.com/yui/yuidoc/
* OpenBIS API (public/resources) /**
* The openBIS module provides objects for communicating with openBIS.
* *
* An API for accessing openBIS. Depends on jQuery. * @module openbis
* @requires jquery
*/ */
var jsonRequestData = function(params) { var jsonRequestData = function(params) {
...@@ -19,11 +21,9 @@ var ajaxRequest = function(settings) { ...@@ -19,11 +21,9 @@ var ajaxRequest = function(settings) {
$.ajax(settings) $.ajax(settings)
} }
/* // Functions for working with cookies.
* Functions for working with cookies. //
* // These are from http://www.quirksmode.org/js/cookies.html
* These are from http://www.quirksmode.org/js/cookies.html
*/
function createCookie(name,value,days) { function createCookie(name,value,days) {
if (days) { if (days) {
var date = new Date(); var date = new Date();
...@@ -49,18 +49,33 @@ function eraseCookie(name) { ...@@ -49,18 +49,33 @@ function eraseCookie(name) {
createCookie(name,"",-1); createCookie(name,"",-1);
} }
function openbis(openbisHost, openbisContext) { /**
this.openbisHost = openbisHost; * A lightweight facade for interacting with openBIS. It provides access
this.openbisContext = openbisContext; * to the following openBIS APIs:
*
// these services always use 'openbis' context * ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService
this.generalInfoServiceUrl = openbisHost + "/openbis/openbis/rmi-general-information-v1.json"; * ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer
* ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric
*
* The Javascript API is not yet exhaustive in its coverage of the above APIs;
* there are methods in the API that do not have Javascript equivelants.
*
*
* @class
*/
function openbis(url, dssUrl) {
this.generalInfoServiceUrl = url + "/rmi-general-information-v1.json";
this.queryServiceUrl = url + "/rmi-query-v1.json";
this.dssUrl = dssUrl + "/rmi-dss-api-v1.json"; this.dssUrl = dssUrl + "/rmi-dss-api-v1.json";
this.queryServiceUrl = openbisHost + "/openbis/openbis/rmi-query-v1.json"; this.webInfoServiceUrl = url + "/openbis/openbis/rmi-web-information-v1.json"
this.webInfoServiceUrl = openbisHost + "/openbis/openbis/rmi-web-information-v1.json"
} }
/**
* Log into openBIS.
*
* @method
*/
openbis.prototype.login = function(username, password, action) { openbis.prototype.login = function(username, password, action) {
openbisObj = this openbisObj = this
ajaxRequest({ ajaxRequest({
...@@ -89,7 +104,7 @@ openbis.prototype.restoreSession = function() { ...@@ -89,7 +104,7 @@ openbis.prototype.restoreSession = function() {
this.sessionToken = readCookie('openbis'); this.sessionToken = readCookie('openbis');
} }
openbis.prototype.isSessionActive = function(action) { openbis.prototype.isSessionActive = function(action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "isSessionActive", data: { "method" : "isSessionActive",
...@@ -99,96 +114,151 @@ openbis.prototype.isSessionActive = function(action) { ...@@ -99,96 +114,151 @@ openbis.prototype.isSessionActive = function(action) {
}); });
} }
openbis.prototype.logout = function(action) { /**
* Restore the session from a cookie and check that it is still valid.
*
* @method
*/
openbis.prototype.ifRestoredSessionActive = function(action) {
this.restoreSession();
this.isSessionActive(function(data) { if (data.result) action(data) });
}
openbis.prototype.getSessionTokenFromServer = function(action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.webInfoServiceUrl,
data: { "method" : "logout", data: { "method" : "getSessionToken" },
"params" : [ this.sessionToken ]
},
success: action success: action
}); });
} }
openbis.prototype.getSessionToken = function(action){ /**
* Log out of openBIS
*
* @method
*/
openbis.prototype.logout = function(action) {
ajaxRequest({ ajaxRequest({
url: this.webInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "getSessionToken" }, data: { "method" : "logout",
"params" : [ this.sessionToken ]
},
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.listSpacesWithProjectsAndRoleAssignments(String, String)
*
* @method
*/
openbis.prototype.listSpacesWithProjectsAndRoleAssignments = function(databaseInstanceCodeOrNull, action) { openbis.prototype.listSpacesWithProjectsAndRoleAssignments = function(databaseInstanceCodeOrNull, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "listSpacesWithProjectsAndRoleAssignments", data: { "method" : "listSpacesWithProjectsAndRoleAssignments",
"params" : [ this.sessionToken, databaseInstanceCodeOrNull ] "params" : [ this.sessionToken, databaseInstanceCodeOrNull ]
}, },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.listProjects(String)
*
* @method
*/
openbis.prototype.listProjects = function(action) { openbis.prototype.listProjects = function(action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "listProjects", data: { "method" : "listProjects",
"params" : [ this.sessionToken ] "params" : [ this.sessionToken ]
}, },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.listExperiments(String, List<Project>, String)
*
* @method
*/
openbis.prototype.listExperiments = function(projects, experimentType, action) { openbis.prototype.listExperiments = function(projects, experimentType, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "listExperiments", data: { "method" : "listExperiments",
"params" : [ this.sessionToken, projects, experimentType ] "params" : [ this.sessionToken, projects, experimentType ]
}, },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.listSamplesForExperiment(String, String)
*
* @method
*/
openbis.prototype.listSamplesForExperiment = function(experimentIdentifier, action) { openbis.prototype.listSamplesForExperiment = function(experimentIdentifier, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "listSamplesForExperiment", data: { "method" : "listSamplesForExperiment",
"params" : [ this.sessionToken, experimentIdentifier ] "params" : [ this.sessionToken, experimentIdentifier ]
}, },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.searchForSamples(String, SearchCriteria)
*
* @method
*/
openbis.prototype.searchForSamples = function(searchCriteria, action) { openbis.prototype.searchForSamples = function(searchCriteria, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "searchForSamples", data: { "method" : "searchForSamples",
"params" : [ this.sessionToken, "params" : [ this.sessionToken,
searchCriteria ] }, searchCriteria ] },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.searchForDataSets(String, SearchCriteria)
*
* @method
*/
openbis.prototype.searchForDataSets = function(searchCriteria, action) { openbis.prototype.searchForDataSets = function(searchCriteria, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "searchForDataSets", data: { "method" : "searchForDataSets",
"params" : [ this.sessionToken, "params" : [ this.sessionToken,
searchCriteria ] }, searchCriteria ] },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService.listDataSetsForSample(String, Sample, boolean)
*
* @method
*/
openbis.prototype.listDataSetsForSample = function(sample, restrictToDirectlyConnected, action) { openbis.prototype.listDataSetsForSample = function(sample, restrictToDirectlyConnected, action) {
ajaxRequest({ ajaxRequest({
url: this.generalInfoServiceUrl, url: this.generalInfoServiceUrl,
data: { "method" : "listDataSetsForSample", data: { "method" : "listDataSetsForSample",
"params" : [ this.sessionToken, sample, restrictToDirectlyConnected ] "params" : [ this.sessionToken, sample, restrictToDirectlyConnected ]
}, },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric.listFilesForDataSet(String, String, String, boolean)
*
* @method
*/
openbis.prototype.listFilesForDataSet = function(dataSetCode, path, recursive, action) { openbis.prototype.listFilesForDataSet = function(dataSetCode, path, recursive, action) {
ajaxRequest({ ajaxRequest({
url: this.dssUrl, url: this.dssUrl,
data: { "method" : "listFilesForDataSet", data: { "method" : "listFilesForDataSet",
"params" : [ this.sessionToken, dataSetCode, path, recursive ] "params" : [ this.sessionToken, dataSetCode, path, recursive ]
...@@ -197,6 +267,11 @@ openbis.prototype.listFilesForDataSet = function(dataSetCode, path, recursive, a ...@@ -197,6 +267,11 @@ openbis.prototype.listFilesForDataSet = function(dataSetCode, path, recursive, a
}); });
} }
/**
* See ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric.getDownloadUrlForFileForDataSet(String, String, String)
*
* @method
*/
openbis.prototype.getDownloadUrlForFileForDataSet = function(dataSetCode, filePath, action) { openbis.prototype.getDownloadUrlForFileForDataSet = function(dataSetCode, filePath, action) {
ajaxRequest({ ajaxRequest({
url: this.dssUrl, url: this.dssUrl,
...@@ -207,20 +282,62 @@ openbis.prototype.getDownloadUrlForFileForDataSet = function(dataSetCode, filePa ...@@ -207,20 +282,62 @@ openbis.prototype.getDownloadUrlForFileForDataSet = function(dataSetCode, filePa
}); });
} }
/**
* See ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer.listQueries(String)
*
* @method
*/
openbis.prototype.listQueries = function(action) { openbis.prototype.listQueries = function(action) {
ajaxRequest({ ajaxRequest({
url: this.queryServiceUrl, url: this.queryServiceUrl,
data: { "method" : "listQueries", data: { "method" : "listQueries",
"params" : [ this.sessionToken ] }, "params" : [ this.sessionToken ] },
success: action success: action
}); });
} }
/**
* See ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer.executeQuery(String, long, Map<String, String>)
*
* @method
*/
openbis.prototype.executeQuery = function(queryId, parameterBindings, action) { openbis.prototype.executeQuery = function(queryId, parameterBindings, action) {
ajaxRequest({ ajaxRequest({
url: this.queryServiceUrl, url: this.queryServiceUrl,
data: { "method" : "executeQuery", data: { "method" : "executeQuery",
"params" : [ this.sessionToken, queryId, parameterBindings ] }, "params" : [ this.sessionToken, queryId, parameterBindings ] },
success: action success: action
}); });
}
/**
* A utility class for deferring an action until all of some kind of action has completed
*
* @argument dependencies An array of the keys for the dependencies.
*/
function actionDeferrer(pendingAction, dependencies) {
this.pendingAction = pendingAction;
this.dependencies = {};
var newme = this;
dependencies.forEach(function(key) {
newme.dependencies[key] = false;
});
}
/**
* Note that a dependency completed. Execute the pending action if appropriate.
*/
actionDeferrer.prototype.dependencyCompleted = function(key) {
this.dependencies[key] = true;
var shouldExecute = true;
for (prop in this.dependencies) {
if (false == this.dependencies[prop]) {
shouldExecute = false;
break;
}
}
if (shouldExecute) {
this.pendingAction();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment