def _upload_metadata(self, xls_filename, scenario, app): # First, create a new metadata entity and POST it. emd_coll = create_staging_collection(IExperimentMetadata) emd = ExperimentMetadata('unit_test_metadata', next(iter(get_root_aggregate(ISubproject))), 1, get_experiment_metadata_type(scenario)) mb_emd = emd_coll.create_member(emd) rpr = as_representer(mb_emd, XmlMime) emd_rpr = rpr.to_string(mb_emd) res = app.post("/%s" % emd_coll.__name__, params=emd_rpr, content_type=XmlMime.mime_type_string, status=HTTPCreated.code) self.__session.commit() mb_url = res.headers['Location'] # Now, PUT the excel meta data file. self.__session.begin_nested() with open(xls_filename, 'rb') as xls_file: res = app.put(mb_url, params=xls_file.read(), content_type=XlsMime.mime_type_string) # If the file had warnings, we have to repeat the PUT. if res.status.endswith(HTTPTemporaryRedirect.title): self.__session.rollback() # 307 Redirect: Repeat with warnings disabled. with open(xls_filename, 'rb') as xls_file: res = app.put(res.headers['Location'], params=xls_file.read(), content_type=XlsMime.mime_type_string, status=HTTPOk.code) self.__session.commit() assert res.status.endswith(HTTPOk.title) return mb_url
def _upload_metadata(self, xls_filename, scenario, app): # First, create a new metadata entity and POST it. emd_coll = create_staging_collection(IExperimentMetadata) emd = ExperimentMetadata('unit_test_metadata', next(iter(get_root_aggregate(ISubproject))), 1, get_experiment_metadata_type(scenario) ) mb_emd = emd_coll.create_member(emd) rpr = as_representer(mb_emd, XmlMime) emd_rpr = rpr.to_string(mb_emd) res = app.post("/%s" % emd_coll.__name__, params=emd_rpr, content_type=XmlMime.mime_type_string, status=HTTPCreated.code) self.__session.commit() mb_url = res.headers['Location'] # Now, PUT the excel meta data file. self.__session.begin_nested() with open(xls_filename, 'rb') as xls_file: res = app.put(mb_url, params=xls_file.read(), content_type=XlsMime.mime_type_string) # If the file had warnings, we have to repeat the PUT. if res.status.endswith(HTTPTemporaryRedirect.title): self.__session.rollback() # 307 Redirect: Repeat with warnings disabled. with open(xls_filename, 'rb') as xls_file: res = app.put(res.headers['Location'], params=xls_file.read(), content_type=XlsMime.mime_type_string, status=HTTPOk.code) self.__session.commit() assert res.status.endswith(HTTPOk.title) return mb_url
def get_all_displaynames(cls): """ Returns the display names of all supported scenarios as list. """ display_names = [] for scenario_name in cls.ALL: entity = get_experiment_metadata_type(scenario_name) display_names.append(entity.display_name) return display_names
def get_all_displaynames(cls): """ Returns the display names of all supported scenarios as list. """ display_names = [] for scenario_name in cls.ALL: entity = get_experiment_metadata_type(scenario_name) display_names.append(entity.display_name) return display_names
def update(self, data): if IDataElement.providedBy(data): # pylint: disable=E1101 # FIXME: This really should be a PATCH operation. prx = DataElementAttributeProxy(data) self_entity = self.get_entity() changed_num_reps = prx.number_replicates != self.number_replicates emt_id = prx.experiment_metadata_type.get('id') changed_em_type = emt_id != self.experiment_metadata_type.id if changed_em_type or changed_num_reps: if changed_num_reps: self_entity.number_replicates = prx.number_replicates if changed_em_type: self_entity.experiment_metadata_type = \ get_experiment_metadata_type(emt_id) if not self_entity.experiment_design is None: # invalidate data to force a fresh upload of the XLS file self_entity.experiment_design.experiment_design_racks = [] self_entity.experiment_design.worklist_series = None if not self_entity.lab_iso_request is None: shape = self_entity.lab_iso_request.rack_layout.shape new_layout = RackLayout(shape=shape) self_entity.lab_iso_request.rack_layout = new_layout self_entity.lab_iso_request.owner = '' changed_sp = self_entity.subproject.id != prx.subproject.get('id') if changed_sp: new_sp = \ url_to_resource(prx.subproject.get('href')).get_entity() self_entity.subproject = new_sp self_entity.label = prx.label # Perform appropriate Trac updates. if not self_entity.lab_iso_request is None: if self.iso_request.owner == STOCKMANAGEMENT_USER: ticket_activator = IsoRequestTicketActivator( experiment_metadata=self_entity) self.__run_trac_tool(ticket_activator, 'Could not update the ticket: %s.') else: if changed_em_type or changed_num_reps: trac_updater = IsoRequestTicketDescriptionRemover( experiment_metadata=self_entity, changed_num_replicates=changed_num_reps, changed_em_type=changed_em_type) else: url = 'http://thelma/public//LOUICe.html#' \ + self.path iso_url = 'http://thelma/public//LOUICe.html#' \ + self.iso_request.path trac_updater = IsoRequestTicketDescriptionUpdater( experiment_metadata=self_entity, experiment_metadata_link=url, iso_request_link=iso_url) self.__run_trac_tool(trac_updater, 'Could not update the ticket: %s.') else: Member.update(self, data)
def update(self, data): if IDataElement.providedBy(data): # pylint: disable=E1101 # FIXME: This really should be a PATCH operation. prx = DataElementAttributeProxy(data) self_entity = self.get_entity() changed_num_reps = prx.number_replicates != self.number_replicates emt_id = prx.experiment_metadata_type.get('id') changed_em_type = emt_id != self.experiment_metadata_type.id if changed_em_type or changed_num_reps: if changed_num_reps: self_entity.number_replicates = prx.number_replicates if changed_em_type: self_entity.experiment_metadata_type = \ get_experiment_metadata_type(emt_id) if not self_entity.experiment_design is None: # invalidate data to force a fresh upload of the XLS file self_entity.experiment_design.experiment_design_racks = [] self_entity.experiment_design.worklist_series = None if not self_entity.lab_iso_request is None: shape = self_entity.lab_iso_request.rack_layout.shape new_layout = RackLayout(shape=shape) self_entity.lab_iso_request.rack_layout = new_layout self_entity.lab_iso_request.owner = '' changed_sp = self_entity.subproject.id != prx.subproject.get('id') if changed_sp: new_sp = \ url_to_resource(prx.subproject.get('href')).get_entity() self_entity.subproject = new_sp self_entity.label = prx.label # Perform appropriate Trac updates. if not self_entity.lab_iso_request is None: if self.iso_request.owner == STOCKMANAGEMENT_USER: ticket_activator = IsoRequestTicketActivator( experiment_metadata=self_entity) self.__run_trac_tool(ticket_activator, 'Could not update the ticket: %s.') else: if changed_em_type or changed_num_reps: trac_updater = IsoRequestTicketDescriptionRemover( experiment_metadata=self_entity, changed_num_replicates=changed_num_reps, changed_em_type=changed_em_type) else: url = 'http://thelma/public//LOUICe.html#' \ + self.path iso_url = 'http://thelma/public//LOUICe.html#' \ + self.iso_request.path trac_updater = IsoRequestTicketDescriptionUpdater( experiment_metadata=self_entity, experiment_metadata_link=url, iso_request_link=iso_url) self.__run_trac_tool(trac_updater, 'Could not update the ticket: %s.') else: Member.update(self, data)