Commit da547cc9 authored by Moises Sacal's avatar Moises Sacal
Browse files

added sync mechanisms for create and link

parent 5955d8c5
......@@ -45,7 +45,6 @@ var Controllers;
OMEROService.csrf(this.config)
.flatMap(function (response) {
csrf_1 = JSON.parse(response);
sails.log.debug(csrf_1.data);
return OMEROService.login(_this.config, csrf_1.data, user_1);
})
.flatMap(function (response) {
......@@ -72,7 +71,6 @@ var Controllers;
}
})
.subscribe(function (response) {
sails.log.debug('login');
var data = { status: true, login: true };
_this.ajaxOk(req, res, null, data);
}, function (error) {
......@@ -161,14 +159,17 @@ var Controllers;
var recordMap = req.param('recordMap');
var annId = null;
var mapAnnotation_1 = [];
sails.log.debug(project);
var record_1 = WorkspaceService.mapToRecord(project, recordMap);
record_1 = _.merge(record_1, { type: this.config.recordType });
sails.log.debug(record_1);
sails.log.debug('OMERO::LINK::');
sails.log.debug(record_1.id);
var app_1 = {};
var annotations_1 = [];
var rowAnnotation_1;
var idAnnotation_1;
var workspaceId_1;
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName)
.flatMap(function (response) {
sails.log.debug('userInfo');
......@@ -188,7 +189,26 @@ var Controllers;
});
}
else
return Rx_1.Observable.of('');
return Rx_1.Observable.of({ body: ann });
}).flatMap(function (response) {
sails.log.debug('mapAnnotation');
sails.log.debug(response.body);
return WorkspaceService.createWorkspaceRecord(_this.config, username_1, record_1, _this.config.recordType, _this.config.workflowStage);
})
.flatMap(function (response) {
workspaceId_1 = response.oid;
sails.log.debug('addParentRecordLink');
return WorkspaceService.getRecordMeta(_this.config, rdmp_1);
})
.flatMap(function (recordMetadata) {
sails.log.debug('recordMetadata');
if (recordMetadata && recordMetadata.workspaces) {
var wss = recordMetadata.workspaces.find(function (id) { return workspaceId_1 === id; });
if (!wss) {
recordMetadata.workspaces.push({ id: workspaceId_1 });
}
}
return WorkspaceService.updateRecordMeta(_this.config, recordMetadata, rdmp_1);
}).subscribe(function (response) {
sails.log.debug('linkWorkspace');
var data = { status: true, response: response };
......@@ -265,7 +285,7 @@ var Controllers;
this.redboxHeaders = {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': '',
'Authorization': workspaceConfig.portal.authorization,
};
};
return Config;
......
......@@ -35,7 +35,6 @@ var Services;
var keyvalue = key + '=' + value;
var cookie = requestPromise.cookie('' + keyvalue);
jar.setCookie(cookie, config.host, function (error, cookie) {
sails.log.debug(cookie);
});
return jar;
};
......@@ -62,7 +61,6 @@ var Services;
return Rx_1.Observable.fromPromise(get);
};
OMEROService.prototype.login = function (config, csrf, user) {
sails.log.debug('login');
var jar = requestPromise.jar();
jar = this.cookieJar(jar, config, 'csrftoken', csrf);
var post = requestPromise({
......
......@@ -37,6 +37,7 @@ export class CreateWorkspaceField extends FieldBase<any> {
workspaceCreated: string;
linkingWorkspace: string;
creatingWorkspace: string;
workspaceLink: string;
validations: any[];
loadingModal: boolean;
......@@ -79,6 +80,7 @@ export class CreateWorkspaceField extends FieldBase<any> {
this.workspaceCreated = options['workspaceCreated'] || '';
this.linkingWorkspace = options['linkingWorkspace'] || '';
this.creatingWorkspace = options['creatingWorkspace'] || '';
this.workspaceLink = options['workspaceLink'] || '';
}
init() {
......@@ -141,9 +143,9 @@ export class CreateWorkspaceField extends FieldBase<any> {
if(this.creation.nameHasSpaces()) {
validateWorkspace.push({message: this.nameHasSpacesValidation});
}
// if(!this.creation.description) {
// validateWorkspace.push({message: this.descriptionWorkspaceValidation});
// }
if(!this.creation.description) {
validateWorkspace.push({message: this.descriptionWorkspaceValidation});
}
return validateWorkspace;
}
......@@ -153,11 +155,11 @@ export class CreateWorkspaceField extends FieldBase<any> {
.then(response => {
if(!response.status) {
//TODO: improve this assignment in case of error.
const name = response.message.error.error.message.name || '';
throw new Error('Name ' + _.first(name));
throw new Error('Error creating workspace');
} else {
this.creationAlert.set({message: this.linkingWorkspace, status: 'working', className: 'warning'});
this.creationAlert.set({message: this.linkingWorkspace, status: 'linking', className: 'warning'});
this.creation.id = response.create['id'];
this.creation.location = this.workspaceLink + this.creation.id;
return this.omeroService.link({
rdmp: this.rdmp, project: this.creation, recordMap: this.recordMap
})
......
......@@ -34,6 +34,7 @@ export class LinkModalWorkspaceField extends FieldBase<any> {
closeLabel: string;
processing: boolean;
processingStatus: string; //Control status code {'done','async','start'}
workspaceLink: string;
omeroService: OMEROService;
currentWorkspace: CurrentWorkspace;
......@@ -63,6 +64,7 @@ export class LinkModalWorkspaceField extends FieldBase<any> {
this.workspaceDefinition = options['workspaceDefinition'] || [];
this.checkField = options['checkField'] || '';
this.recordMap = options['recordMap'] || [];
this.workspaceLink = options['workspaceLink'] || '';
}
registerEvents() {
......@@ -95,6 +97,7 @@ export class LinkModalWorkspaceField extends FieldBase<any> {
linkModal({rdmp, workspace}) {
this.currentWorkspace = workspace;
this.currentWorkspace.location = this.workspaceLink + workspace['@id'];
this.checks.clear();
jQuery('#linkModal').modal('show');
this.processing = true;
......
......@@ -26,8 +26,10 @@ export class Creation {
description: string = '';
group: any;
validateMessage: string;
location: string;
clear() {
this.location = '';
this.description = '';
this.name = '';
this.id = '';
......@@ -58,5 +60,6 @@ export class CreationAlert {
export class CurrentWorkspace {
path_with_namespace: string = '';
web_url: string = ''
web_url: string = '';
location: string;
}
module.exports.asyncworkflow = {
service: 'omeroservice',
workflow: {
createAndLink: [
{start: 'create', next: 'link'},
{start: 'link', next: 'end'}
]
}
};
......@@ -18,6 +18,9 @@ module.exports = {
***************************************************************************/
workspaces: {
portal:{
authorization: 'Bearer 123123'
},
provisionerUser: 'admin',
parentRecord: 'rdmp',
omero: {
......@@ -27,7 +30,9 @@ module.exports = {
appName: 'omero',
appId: 'omero-test',
recordType: 'omero',
host: 'https://omero.com'
host: 'https://omero-dev.research.uts.edu.au',
domain: 'omero-dev.research.uts.edu.au',
serverId: '1'
}
}
};
......@@ -17,7 +17,10 @@ module.exports = {
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/
workspaces: {
workspaces:{
portal:{
authorization: 'Bearer 123123'
},
provisionerUser: 'admin',
parentRecord: 'rdmp',
omero: {
......@@ -27,7 +30,9 @@ module.exports = {
appName: 'omero',
appId: 'omero-test',
recordType: 'omero',
host: 'https://omero.com'
host: 'https://omero-dev.research.uts.edu.au',
domain: 'omero-dev.research.uts.edu.au',
serverId: '1'
}
}
};
......@@ -18,6 +18,9 @@ module.exports = {
***************************************************************************/
workspaces: {
portal:{
authorization: 'Bearer 123123'
},
provisionerUser: 'admin',
parentRecord: 'rdmp',
omero: {
......@@ -27,7 +30,9 @@ module.exports = {
appName: 'omero',
appId: 'omero-test',
recordType: 'omero',
host: 'https://omero.com'
host: 'https://omero-dev.research.uts.edu.au',
domain: 'omero-dev.research.uts.edu.au',
serverId: '1'
}
}
};
......@@ -69,12 +69,13 @@ module.exports = {
{label: 'URL', name: 'web_url'}
],
recordMap: [
{record: 'title', ele: 'title'},
{record: 'title', ele: 'Name'},
{record: 'id', ele: '@id'},
{record: 'description', ele: 'description'},
{record: 'location', ele: 'url:project'},
{record: 'location', ele: 'location'},
{record: 'dataset', ele: 'url:dataset'}
],
workspaceLink: 'https://omero-dev.research.uts.edu.au/webclient/?show=project-',
checkField: 'name_with_namespace',
checkBranch: 'master',
linkModalTitle: 'Workspace Linking',
......@@ -94,12 +95,13 @@ module.exports = {
definition: {
name: 'CreateWorkspace',
recordMap: [
{record: 'title', ele: 'title'},
{record: 'id', ele: '@id'},
{record: 'title', ele: 'name'},
{record: 'id', ele: 'id'},
{record: 'description', ele: 'description'},
{record: 'location', ele: 'url:project'},
{record: 'location', ele: 'location'},
{record: 'dataset', ele: 'url:dataset'}
],
workspaceLink: 'https://omero-dev.research.uts.edu.au/webclient/?show=project-',
branch: 'master',
createLabel: 'Create',
dismissLabel: 'Ok',
......
......@@ -49,7 +49,6 @@ export module Controllers {
OMEROService.csrf(this.config)
.flatMap(response => {
csrf = JSON.parse(response);
sails.log.debug(csrf.data);
return OMEROService.login(this.config, csrf.data, user);
})
.flatMap(response => {
......@@ -75,7 +74,6 @@ export module Controllers {
}
})
.subscribe(response => {
sails.log.debug('login');
const data = {status: true, login: true};
this.ajaxOk(req, res, null, data);
}, error => {
......@@ -159,17 +157,20 @@ export module Controllers {
const rdmp = req.param('rdmp');
const recordMap = req.param('recordMap');
let annId = null;//
let mapAnnotation = [];//
let annId = null;
let mapAnnotation = [];
sails.log.debug(project);
let record = WorkspaceService.mapToRecord(project, recordMap);
record = _.merge(record, {type: this.config.recordType});
sails.log.debug(record);
sails.log.debug('OMERO::LINK::');
sails.log.debug(record.id);
let app = {};
let annotations = [];
let rowAnnotation;
let idAnnotation;
let workspaceId;
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName)
.flatMap(response => {
......@@ -189,7 +190,26 @@ export module Controllers {
return this.createAnnotation({
app, record, rowAnnotation, idAnnotation, annotations, username, rdmp
});
} else return Observable.of('');
} else return Observable.of({body: ann});
}).flatMap(response => {
sails.log.debug('mapAnnotation');
sails.log.debug(response.body);
return WorkspaceService.createWorkspaceRecord(this.config, username, record, this.config.recordType, this.config.workflowStage);
})
.flatMap(response => {
workspaceId = response.oid;
sails.log.debug('addParentRecordLink');
return WorkspaceService.getRecordMeta(this.config, rdmp);
})
.flatMap(recordMetadata => {
sails.log.debug('recordMetadata');
if(recordMetadata && recordMetadata.workspaces) {
const wss = recordMetadata.workspaces.find(id => workspaceId === id);
if(!wss) {
recordMetadata.workspaces.push({id: workspaceId});
}
}
return WorkspaceService.updateRecordMeta(this.config, recordMetadata, rdmp);
}).subscribe(response => {
sails.log.debug('linkWorkspace');
const data = {status: true, response};
......@@ -286,7 +306,7 @@ export module Controllers {
this.redboxHeaders = {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': '',
'Authorization': workspaceConfig.portal.authorization,
};
}
......
......@@ -34,7 +34,7 @@ export module Services {
const keyvalue = key + '=' + value;
const cookie = requestPromise.cookie('' + keyvalue);
jar.setCookie(cookie, config.host, function(error, cookie) {
sails.log.debug(cookie);
//sails.log.debug(cookie);
});
return jar;
}
......@@ -64,7 +64,6 @@ export module Services {
}
login(config: any, csrf: string, user: any) {
sails.log.debug('login');
let jar = requestPromise.jar();
jar = this.cookieJar(jar, config, 'csrftoken', csrf);
const post = requestPromise({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment