#!/usr/bin/env python import cherrypy from dm.common.service.dmSessionController import DmSessionController from dm.common.exceptions.invalidRequest import InvalidRequest from dm.common.utility.encoder import Encoder from dm.ds_web_service.service.impl.experimentSessionControllerImpl import ExperimentSessionControllerImpl class ExperimentSessionController(DmSessionController): def __init__(self): DmSessionController.__init__(self) self.experimentSessionControllerImpl = ExperimentSessionControllerImpl() @cherrypy.expose @DmSessionController.require(DmSessionController.isLoggedIn()) @DmSessionController.execute def getExperimentTypes(self, **kwargs): return self.listToJson(self.experimentSessionControllerImpl.getExperimentTypes()) @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def getExperiments(self, **kwargs): return self.listToJson(self.experimentSessionControllerImpl.getExperiments()) @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def getExperimentByName(self, name, **kwargs): response = self.experimentSessionControllerImpl.getExperimentByName(name).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def getExperimentById(self, id, **kwargs): response = self.experimentSessionControllerImpl.getExperimentByid(id).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def addExperiment(self, **kwargs): name = kwargs.get('name') if name is None or not len(name): raise InvalidRequest('Missing experiment name.') name = Encoder.decode(name) experimentTypeId = kwargs.get('experimentTypeId') if experimentTypeId is None: raise InvalidRequest('Missing experiment type id.') description = kwargs.get('description') if description is not None: description = Encoder.decode(description) startDate = kwargs.get('startDate') if startDate is not None: startDate = Encoder.decode(startDate) endDate = kwargs.get('endDate') if endDate is not None: endDate = Encoder.decode(endDate) response = self.experimentSessionControllerImpl.addExperiment(name, experimentTypeId, description, startDate, endDate).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def startExperiment(self, **kwargs): name = kwargs.get('name') if name is None or not len(name): raise InvalidRequest('Missing experiment name.') name = Encoder.decode(name) response = self.experimentSessionControllerImpl.startExperiment(name).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def updateExperiment(self, **kwargs): name = kwargs.get('name') if name is None or not len(name): raise InvalidRequest('Missing experiment name.') name = Encoder.decode(name) response = self.experimentSessionControllerImpl.updateExperiment(name).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def stopExperiment(self, **kwargs): name = kwargs.get('name') if name is None or not len(name): raise InvalidRequest('Missing experiment name.') name = Encoder.decode(name) response = self.experimentSessionControllerImpl.stopExperiment(name).getFullJsonRep() self.logger.debug('Returning: %s' % response) return response