Commit 6b2aee9f authored by Moises Sacal's avatar Moises Sacal
Browse files

added OMERO API

parent 1a954dce
......@@ -44,3 +44,6 @@ e2e/*.map
Thumbs.db
test/angular
redbox-portal
app/gitlab/dist
......@@ -10,20 +10,254 @@ var __extends = (this && this.__extends) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var url = require('url');
var controller = require("../core/CoreController");
var Rx_1 = require("rxjs/Rx");
require("rxjs/add/operator/map");
var controller = require("../core/CoreController.js");
var Controllers;
(function (Controllers) {
var OMEROController = (function (_super) {
__extends(OMEROController, _super);
function OMEROController() {
var _this = _super.call(this) || this;
_this._exportedMethods = [];
_this._config = {};
_this._exportedMethods = [
'login',
'projects',
'create',
'link'
];
_this.config = new Config();
var OMEROConfig = sails.config.local.workspaces.omero;
var workspaceConfig = sails.config.local.workspaces;
_this.config = {
host: OMEROConfig.host,
recordType: OMEROConfig.recordType,
workflowStage: OMEROConfig.workflowStage,
formName: OMEROConfig.formName,
appName: OMEROConfig.appName,
domain: OMEROConfig.domain,
parentRecord: workspaceConfig.parentRecord,
provisionerUser: workspaceConfig.provisionerUser,
serverId: OMEROConfig.serverId,
appId: OMEROConfig.appId,
brandingAndPortalUrl: '',
redboxHeaders: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': '',
}
};
return _this;
}
OMEROController.prototype.login = function (req, res) {
var _this = this;
if (!req.isAuthenticated()) {
this.ajaxFail(req, res, "User not authenticated");
}
else {
var user_1 = {
username: req.param('username') || '',
password: req.param('password') || ''
};
var csrf_1 = {};
var info_1 = {};
var userId_1 = req.user.id;
OMEROService.csrf(this.config)
.flatMap(function (response) {
csrf_1 = JSON.parse(response);
return OMEROService.login(_this.config, csrf_1.data, user_1);
})
.flatMap(function (response) {
var cookies = response.headers['set-cookie'];
var body = JSON.parse(response.body);
var login = body.eventContext;
var sessionUuid = login.sessionUuid;
var cookieJar = WorkspaceService.getCookies(cookies);
info_1 = {
csrf: csrf_1.data,
sessionid: WorkspaceService.getCookieValue(cookieJar, 'sessionid'),
sessionUuid: sessionUuid,
memberOfGroups: login.memberOfGroups,
groupId: login.groupId
};
return WorkspaceService.createWorkspaceInfo(userId_1, _this.config.appName, info_1);
})
.flatMap(function (response) {
if (response.id && response.info !== info_1) {
return WorkspaceService.updateWorkspaceInfo(response.id, info_1);
}
else {
return Rx_1.Observable.of('');
}
})
.subscribe(function (response) {
sails.log.debug('login');
var data = { status: true, login: true };
_this.ajaxOk(req, res, null, data);
}, function (error) {
var errorMessage = "Failed to login for user " + user_1.username;
sails.log.error(errorMessage);
_this.ajaxFail(req, res, errorMessage, error);
});
}
};
OMEROController.prototype.projects = function (req, res) {
var _this = this;
if (!req.isAuthenticated()) {
this.ajaxFail(req, res, "User not authenticated");
}
else {
var userId = req.user.id;
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName)
.flatMap(function (response) {
sails.log.debug('userInfo');
var app = response.info;
return OMEROService.projects(_this.config, app.csrf, app.sessionid, app.sessionUuid);
})
.subscribe(function (response) {
sails.log.debug('projects');
var data = { status: true, projects: JSON.parse(response) };
_this.ajaxOk(req, res, null, data);
}, function (error) {
var errorMessage = "Failed to get projects for user " + req.user.username;
sails.log.error(errorMessage);
_this.ajaxFail(req, res, errorMessage, error);
});
}
};
OMEROController.prototype.create = function (req, res) {
var _this = this;
if (!req.isAuthenticated()) {
this.ajaxFail(req, res, "User not authenticated");
}
else {
var userId = req.user.id;
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName)
.flatMap(function (response) {
sails.log.debug('userInfo');
var appId = _this.config.appId;
var app = response.info;
var project = req.param('creation');
project.type = 'project';
return OMEROService.createContainer(_this.config, app, project);
})
.subscribe(function (response) {
sails.log.debug('createProject');
sails.log.debug(response);
var status = true;
if (response.bad === 'true') {
status = false;
}
var data = { status: status, create: JSON.parse(response) };
_this.ajaxOk(req, res, null, data);
}, function (error) {
var errorMessage = "Failed to create project for user " + req.user.username;
sails.log.error(errorMessage);
_this.ajaxFail(req, res, errorMessage, error);
});
}
};
OMEROController.prototype.link = function (req, res) {
var _this = this;
if (!req.isAuthenticated()) {
this.ajaxFail(req, res, "User not authenticated");
}
else {
this.config.brandingAndPortalUrl = sails.getBaseUrl() + BrandingService.getBrandAndPortalPath(req);
var userId = req.user.id;
var username_1 = req.user.username;
var project = req.param('project');
var rdmp_1 = req.param('rdmp');
var recordMap = req.param('recordMap');
var annId = null;
var mapAnnotation_1 = [];
var record_1 = WorkspaceService.mapToRecord(project, recordMap);
record_1 = _.merge(record_1, { type: this.config.recordType });
sails.log.debug('OMERO::LINK::');
sails.log.debug(record_1.id);
var app_1 = {};
var annotations_1 = [];
var rowAnnotation_1;
var idAnnotation_1;
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName)
.flatMap(function (response) {
sails.log.debug('userInfo');
var appId = _this.config.appId;
app_1 = response.info;
return OMEROService.annotations({ config: _this.config, app: app_1, id: record_1.id });
}).flatMap(function (response) {
sails.log.debug('annotations');
annotations_1 = (JSON.parse(response)).annotations;
mapAnnotation_1 = annotations_1;
var ann = _.first(_this.findAnnotation('stash', mapAnnotation_1));
if (!ann) {
rowAnnotation_1 = undefined;
idAnnotation_1 = undefined;
return _this.createAnnotation({
app: app_1, record: record_1, rowAnnotation: rowAnnotation_1, idAnnotation: idAnnotation_1, annotations: annotations_1, username: username_1, rdmp: rdmp_1
});
}
else
return Rx_1.Observable.of('');
}).subscribe(function (response) {
sails.log.debug('linkWorkspace');
var data = { status: true, response: response };
_this.ajaxOk(req, res, null, data);
}, function (error) {
var errorMessage = "Failed to link project for user " + req.user.username;
sails.log.error(errorMessage);
_this.ajaxFail(req, res, errorMessage, error);
});
}
};
OMEROController.prototype.createAnnotation = function (_a) {
var _this = this;
var app = _a.app, record = _a.record, rowAnnotation = _a.rowAnnotation, idAnnotation = _a.idAnnotation, annotations = _a.annotations, username = _a.username, rdmp = _a.rdmp;
sails.log.debug('createWorkspaceRecord');
return WorkspaceService.provisionerUser(this.config.provisionerUser)
.flatMap(function (response) {
sails.log.debug('provisionerUser:createWorkspaceRecord');
_this.config.redboxHeaders['Authorization'] = 'Bearer ' + response.token;
return WorkspaceService.createWorkspaceRecord(_this.config, username, record, _this.config.recordType, _this.config.workflowStage);
}).flatMap(function (response) {
var create = _this.mapAnnotation(rowAnnotation, _this.getAnnotation(idAnnotation, annotations), 'stash', rdmp + "." + response.oid);
var annId = idAnnotation || null;
var mapAnnotation = create.values;
return OMEROService.annotateMap({
config: _this.config, app: app, id: record.id,
annId: annId, mapAnnotation: mapAnnotation
});
});
};
OMEROController.prototype.getAnnotation = function (id, annotations) {
return annotations.find(function (an) { return an.id === id; });
};
OMEROController.prototype.mapAnnotation = function (row, annotation, key, newValue) {
if (annotation) {
annotation.values[row.toString()][1] = newValue;
return annotation;
}
else {
var annotation_1 = {
values: [[key, newValue.toString()]]
};
return annotation_1;
}
};
OMEROController.prototype.findAnnotation = function (annotation, annotations) {
return annotations.map(function (anns, index) {
var row = anns.values.findIndex(function (an) { return an[0] === annotation; });
return { index: index, id: anns.id, row: row != -1 ? row : null };
}).filter(function (cur) {
return cur.row != null;
});
};
return OMEROController;
}(controller.Controllers.Core.Controller));
Controllers.OMEROController = OMEROController;
var Config = (function () {
function Config() {
}
return Config;
}());
})(Controllers = exports.Controllers || (exports.Controllers = {}));
module.exports = new Controllers.OMEROController().exports();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require('lodash');
var pathExists = require("path-exists");
var Controllers;
(function (Controllers) {
......
......@@ -10,16 +10,125 @@ var __extends = (this && this.__extends) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var services = require("../core/CoreService");
var Rx_1 = require("rxjs/Rx");
var request = require("request-promise");
var services = require("../core/CoreService.js");
var Services;
(function (Services) {
var OMEROService = (function (_super) {
__extends(OMEROService, _super);
function OMEROService() {
var _this_1 = _super !== null && _super.apply(this, arguments) || this;
_this_1._exportedMethods = [];
var _this_1 = _super.call(this) || this;
_this_1._exportedMethods = [
'csrf',
'login',
'projects',
'createContainer',
'annotateMap',
'annotations'
];
return _this_1;
}
OMEROService.prototype.csrf = function (config) {
var get = request({
uri: config.host + "/api/v0/token/"
});
return Rx_1.Observable.fromPromise(get);
};
OMEROService.prototype.login = function (config, csrf, user) {
var jar = request.jar();
jar = WorkspaceService.cookieJar(jar, config, 'csrftoken', csrf);
var post = request({
uri: config.host + "/api/v0/login/",
method: 'POST',
formData: {
username: user.username,
password: user.password,
server: config.serverId
},
resolveWithFullResponse: true,
jar: jar,
headers: {
'X-CSRFToken': csrf
}
});
return Rx_1.Observable.fromPromise(post);
};
OMEROService.prototype.projects = function (config, csrf, sessionid, sessionUuid) {
var jar = request.jar();
jar = WorkspaceService.cookieJar(jar, config, 'csrftoken', csrf);
jar = WorkspaceService.cookieJar(jar, config, 'sessionid', sessionid);
var get = request({
uri: config.host + "/api/v0/m/projects/",
jar: jar,
headers: {
'X-CSRFToken': csrf,
'sessionUuid': sessionUuid
}
});
return Rx_1.Observable.fromPromise(get);
};
OMEROService.prototype.createContainer = function (config, app, project) {
var jar = request.jar();
jar = WorkspaceService.cookieJar(jar, config, 'csrftoken', app.csrf);
jar = WorkspaceService.cookieJar(jar, config, 'sessionid', app.sessionid);
var post = request({
uri: config.host + "/webclient/action/addnewcontainer/",
method: 'POST',
jar: jar,
formData: {
name: project.name,
folder_type: project.type,
description: project.description,
owner: project.owner || ''
},
headers: {
'X-CSRFToken': app.csrf,
'sessionUuid': app.sessionUuid
}
});
return Rx_1.Observable.fromPromise(post);
};
OMEROService.prototype.annotateMap = function (_a) {
var config = _a.config, app = _a.app, id = _a.id, annId = _a.annId, mapAnnotation = _a.mapAnnotation;
var jar = request.jar();
jar = WorkspaceService.cookieJar(jar, config, 'csrftoken', app.csrf);
jar = WorkspaceService.cookieJar(jar, config, 'sessionid', app.sessionid);
var formData = {
project: id,
mapAnnotation: JSON.stringify(mapAnnotation)
};
if (annId) {
formData['annId'] = annId;
}
var post = request({
uri: config.host + "/webclient/annotate_map/",
method: 'POST',
jar: jar,
formData: formData,
headers: {
'X-CSRFToken': app.csrf,
'sessionUuid': app.sessionUuid
},
resolveWithFullResponse: true
});
return Rx_1.Observable.fromPromise(post);
};
OMEROService.prototype.annotations = function (_a) {
var config = _a.config, app = _a.app, id = _a.id;
var jar = request.jar();
jar = WorkspaceService.cookieJar(jar, config, 'csrftoken', app.csrf);
jar = WorkspaceService.cookieJar(jar, config, 'sessionid', app.sessionid);
var get = request({
uri: config.host + "/webclient/api/annotations/?type=map&project=" + id,
jar: jar,
headers: {
'X-CSRFToken': app.csrf,
'sessionUuid': app.sessionUuid
}
});
return Rx_1.Observable.fromPromise(get);
};
return OMEROService;
}(services.Services.Core.Service));
Services.OMEROService = OMEROService;
......
/**
* omero form
* OMERO form
*/
module.exports = {
name: 'omero-1.0-draft',
type: 'omero',
customAngularApp: {
appName: 'omero',
appSelector: 'omero-form'
},
skipValidationOnSave: true,
editCssClasses: 'row col-md-12',
viewCssClasses: 'row col-md-offset-1 col-md-10',
messages: {
'saving': ['@dmpt-form-saving'],
'validationFail': ['@dmpt-form-validation-fail-prefix', '@dmpt-form-validation-fail-suffix'],
'saveSuccess': ['@dmpt-form-save-success'],
'saveError': ['@dmpt-form-save-error']
"saving": ["@dmpt-form-saving"],
"validationFail": ["@dmpt-form-validation-fail-prefix", "@dmpt-form-validation-fail-suffix"],
"saveSuccess": ["@dmpt-form-save-success"],
"saveError": ["@dmpt-form-save-error"]
},
fields: [
{
......@@ -19,10 +23,131 @@ module.exports = {
compClass: 'TextBlockComponent',
viewOnly: false,
definition: {
name: 'title',
value: 'OMERO',
type: 'h2'
}
},
{
class: 'Container',
compClass: 'TextBlockComponent',
viewOnly: false,
definition: {
value: 'Workspaces',
type: 'h3'
}
},
{
class: 'ListWorkspaceDataField',
showHeader: true,
definition: {
name: 'ListWorkspaces',
columns: [
{'label': 'Name', 'property': 'Name'},
{'label': 'Description', 'property': 'Description'},
{'label': 'Location', 'property': '@id', 'link': 'true',
'classes': 'btn btn-primary', 'label': 'Open'}
],
rdmpLinkLabel: 'Plan',
syncLabel: 'Sync',
workspaceLink: 'https://omero-dev.research.uts.edu.au/webclient/?show=project-'
// subscribe: {
// 'LoginWorkspaceApp': {
// listWorkspaces: [{
// action: 'listWorkspaces'
// }]
// }
// },
}
},
{
class: 'LinkModalWorkspaceField',
showHeader: true,
definition: {
name: 'LinkModal',
workspaceDefinition: [
{label: 'Name', name: 'name_with_namespace'},
{label: 'URL', name: 'web_url'}
],
recordMap: [
{record: 'title', ele: 'title'},
{record: 'id', ele: '@id'},
{record: 'description', ele: 'description'},
{record: 'location', ele: 'url:project'},
{record: 'dataset', ele: 'url:dataset'}
],
checkField: 'name_with_namespace',
checkBranch: 'master',
linkModalTitle: 'Workspace Linking',
workspaceDetailsTitle: 'Workspace Details',
processingLabel: 'Processing Link',
processingMessage: 'Checking your master workspace link ...',
comparingLabel: 'Checking current links ...',
statusLabel: 'No links, Linking to workspace ...',
processingSuccess: 'Your workspace was linked succesfully',
processingFail: 'Your workspace is linked with another RDMP',
closeLabel: 'Ok'
}
},
{
class: 'CreateWorkspaceField',
showHeader: true,
definition: {
name: 'CreateWorkspace',
recordMap: [
{record: 'title', ele: 'title'},
{record: 'id', ele: '@id'},
{record: 'description', ele: 'description'},
{record: 'location', ele: 'url:project'},
{record: 'dataset', ele: 'url:dataset'}
],
branch: 'master',
createLabel: 'Create',
dismissLabel: 'Ok',
createWorkspaceLabel: 'Create Workspace',
workspaceDetailsLabel: 'Workspace Details',
selectSpace: 'Select Space',
nameWorkspace: 'Name your workspace',
nameHasSpacesValidation: 'Name should not include spaces',
addDescription: 'Add a description',
selectTemplate: 'Select Template',
nameWorkspaceValidation: 'Name of the workspace is required',
descriptionWorkspaceValidation: 'Description of the workspace is required',
creatingWorkspace: 'Creating Workspace',
linkingWorkspace: 'Linking Workspace',
workspaceCreated: 'Workspace Created'
}
},
{
class: 'LoginWorkspaceAppField',
showHeader: true,
definition: {
name: 'LoginWorkspaceApp',
permissionStep: 'The provisioner requires permission to create a workspace on your behalf',
usernameLabel: 'username',
passwordLabel: 'password',
loginLabel: 'Login',
permissionStep: 'Stash is requesting from OMERO the following permissions:',
permissionList: [
'Create Repositories',
'Write information into your repositories'
],
allowLabel: 'Allow',
closeLabel: 'Close',
loginErrorMessage: 'Please include username and password'
}
},
{
class: "AnchorOrButton",
viewOnly: false,
definition: {
name: "BackToPlan",
label: 'Back to your Plan',
value: '/@branding/@portal/record/view/',
cssClasses: 'btn btn-large btn-info',
showPencil: false,
controlType: 'anchor'
},
variableSubstitutionFields: ['value']
}
]
};
}
This diff is collapsed.
......@@ -23,20 +23,24 @@
"author": "Moises Sacal",
"license": "GPL-3.0",
"devDependencies": {
"@angular/cli": "^6.0.7",
"@types/mocha": "^5.2.1",
"@types/node": "^10.1.3",
"mocha": "^5.1.1",
"sails": "^1.0.2",
"supertest": "^3.0.0"
"supertest": "^3.0.0",
"ts-node": "^6.1.0",
"typings": "^2.1.1"
},
"dependencies": {