Fixing serverId issues

This commit is contained in:
Bruno Alves de Faria committed 2017-06-16 16:36:34 -03:00
1 parent 95533c785b
commit b4bb44625c
62 files changed
+685 -556

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
import './publications.js';
import './methods.js';
import './startup.js';
import './lib';
@@ -0,0 +1,68 @@
import { Meteor } from 'meteor/meteor';
import { OHIF } from 'meteor/ohif:core';
import { Servers, CurrentServer } from 'meteor/ohif:servers/both/collections';
OHIF.servers.control = {
writeCallback(error, affected) {
if (error) {
throw new Meteor.Error('data-write', error);
}
},
resetCurrentServer() {
const currentServer = CurrentServer.findOne();
if (currentServer && Servers.find({ _id: currentServer.serverId }).count()) {
return;
}
const newServer = Servers.findOne({
origin: 'json',
type: Meteor.settings.defaultServiceType || 'dicomWeb'
});
if (newServer) {
CurrentServer.remove({});
CurrentServer.insert({
serverId: newServer._id
});
}
},
find(query) {
return Servers.find(query).fetch();
},
save(serverSettings) {
const query = {
_id: serverSettings._id
};
const options = {
upsert: true
};
if (!serverSettings._id) {
delete serverSettings._id;
}
return Servers.update(query, serverSettings, options, this.writeCallback);
},
setActive(serverId) {
CurrentServer.remove({});
CurrentServer.insert({
serverId: serverId
});
},
remove(serverId) {
const query = {
_id: serverId
};
const removeStatus = Servers.remove(query, this.writeCallback);
OHIF.servers.control.resetCurrentServer();
return removeStatus;
}
};
@@ -0,0 +1 @@
import './control.js';
+9
View File
@@ -0,0 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { OHIF } from 'meteor/ohif:core';
Meteor.methods({
serverFind: query => OHIF.servers.control.find(query),
serverSave: serverSettings => OHIF.servers.control.save(serverSettings),
serverSetActive: serverId => OHIF.servers.control.setActive(serverId),
serverRemove: serverId => OHIF.servers.control.remove(serverId)
});
@@ -0,0 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { Servers, CurrentServer } from 'meteor/ohif:servers/both/collections';
// When publishing Servers Collection, do not publish the requestOptions.headers
// field in case any authentication information is being passed
Meteor.publish('servers', () => Servers.find({}, {
fields: { 'requestOptions.headers': 0 }
}));
Meteor.publish('currentServer', () => CurrentServer.find());
+61
View File
@@ -0,0 +1,61 @@
import { Meteor } from 'meteor/meteor';
import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core';
import { Servers } from 'meteor/ohif:servers/both/collections';
import { ServerConfiguration } from 'meteor/ohif:servers/both/schema/servers.js';
// Check the servers on meteor startup
Meteor.startup(function() {
OHIF.log.info('Updating servers information from JSON configuration');
_.each(Meteor.settings.servers, function(endpoints, serverType) {
_.each(endpoints, function(endpoint) {
const server = _.clone(endpoint);
server.origin = 'json';
server.type = serverType;
// Try to find a server with the same name/type/origin combination
const existingServer = Servers.findOne({
name: server.name,
type: server.type,
origin: server.origin
});
// Check if server was already added. Update it if so and insert if not
if (existingServer) {
const newServerData = _.clone(existingServer);
delete newServerData._id;
Servers.update(existingServer._id, { $set: newServerData });
} else {
Servers.insert(server);
}
});
});
OHIF.servers.control.resetCurrentServer();
});
// Validate the servers configuration
Meteor.startup(() => {
// Save custom properties (if any)...
// "Meteor.settings" and "Meteor.settings.public" are set by default...
let custom = {
private: Meteor.settings.custom,
public: Meteor.settings.public.custom
};
// ... and remove them to prevent clean up
delete Meteor.settings.custom;
delete Meteor.settings.public.custom;
ServerConfiguration.clean(Meteor.settings);
// TODO: Make the error messages more clear
// Taking this out for now to prevent confusion.
// check(Meteor.settings, ServerConfiguration);
Meteor.settings.custom = custom.private;
Meteor.settings.public.custom = custom.public;
OHIF.log.info(JSON.stringify(Meteor.settings, null, 2));
});