def getDataFields(self): """ Retrieve the Data Fields of a Protocol. Returns ------- :class:`~labstep.entities.metadata.model.Metadata` An array of objects representing the Labstep Data Fields on a Protocol. Example ------- :: protocol = user.getProtocol(17000) metadata = protocol.getDataFields() """ self.update() if "metadatas" not in self.last_version["metadata_thread"]: return [] def addId(field): field.protocol_id = self.id return field return list(map(addId, listToClass( self.last_version["metadata_thread"]["metadatas"], ProtocolDataField, self.__user__ )))
def getSignatures(self): """ Retrieve a list of signatures added to the experiment Returns ------- List[:class:`~labstep.entities.experimentSignature.model.ExperimentSignature`] List of the signatures added to the Experiment """ exp = self.__user__.getExperiment(self.id) return listToClass(exp.signatures, ExperimentSignature, self.__user__)
def getPermissions(self, entity): entityName = entity.__entityName__ headers = getHeaders(entity.__user__) url = url_join( configService.getHost(), "api/generic/", "acl", entityName.replace("-", "_"), str(entity.id), ) response = requestService.get(url, headers=headers) resp = json.loads(response.content) return listToClass(resp["group_permissions"], Permission, entity)
def getFiles(self): """ Returns a list of the files in a Protocol. Returns ------- List[:class:`~labstep.file.File`] List of the files in a Protocol. Example ------- :: experiment = user.getExperiment(17000) experiment_protocol = experiment.getProtocols()[0] filess = experiment_protocol.getFiles() """ self.update() files = self.files return listToClass(files, File, self.__user__)
def getEntities(self, user, entityClass, count, filterParams={}): countParameter = min(count, 50) if count is not None else None searchParams = {"search": 1, "cursor": -1, "count": countParameter} params = {**searchParams, **filterParams} headers = getHeaders(user=user) url = url_join(configService.getHost(), "/api/generic/", entityClass.__entityName__) response = requestService.get(url, params=params, headers=headers) resp = json.loads(response.content) items = resp["items"] expectedResults = min(resp["total"], count) if count is not None else resp["total"] while len(items) < expectedResults: params["cursor"] = resp["next_cursor"] response = requestService.get(url, headers=headers, params=params) resp = json.loads(response.content) items.extend(resp["items"]) return listToClass(items, entityClass, user)
def getTimers(self): """ Returns a list of the timers in a Protocol within an Experiment. Returns ------- List[:class:`~labstep.entities.experimentTimer.model.ExperimentTimer`] List of the timers in an Experiment's Protocol. Example ------- :: experiment = user.getExperiment(17000) exp_protocol = experiment.getProtocols()[0] exp_protocol_timers = exp_protocol.getTimers() exp_protocol_timers[0].attributes() """ self.update() timers = self.experiment_timers return listToClass(timers, ExperimentTimer, self.__user__)
def getFiles(self): """ Returns a list of the files in a Protocol. Returns ------- List[:class:`~labstep.file.File`] List of the files in a Protocol. Example ------- :: protocol = user.getProtocol(17000) protocol_files = protocol.getFiles() """ self.update() if 'files' not in self.last_version: return [] files = self.last_version['files'] return listToClass(files, File, self.__user__)
def getMaterials(self, count=100, extraParams={}): """ Returns a list of the materials in a Protocol. Returns ------- List[:class:`~labstep.entities.protocolMaterial.model.ProtocolMaterial`] List of the materials in a Protocol. Example ------- :: protocol = user.getProtocol(17000) protocol_materials = protocol.getMaterials() protocol_materials[0].attributes() """ self.update() if "protocol_values" not in self.last_version: return [] materials = self.last_version["protocol_values"] return listToClass(materials, ProtocolMaterial, self.__user__)
def getSteps(self): """ Returns a list of the steps in a Protocol. Returns ------- List[:class:`~labstep.entities.protocolStep.model.ProtocolStep`] List of the steps in Protocol. Example ------- :: protocol = user.getProtocol(17000) protocol_steps = protocol.getSteps() protocol_steps[0].attributes() """ self.update() if "protocol_steps" not in self.last_version: return [] steps = self.last_version["protocol_steps"] return listToClass(steps, ProtocolStep, self.__user__)
def getTables(self): """ Returns a list of the tables in a Protocol. Returns ------- List[:class:`~labstep.entities.protocolTable.model.ProtocolTable`] List of the tables in a Protocol. Example ------- :: protocol = user.getProtocol(17000) protocol_tables = protocol.getTables() protocol_tables[0].attributes() """ self.update() if "protocol_tables" not in self.last_version: return [] tables = self.last_version["protocol_tables"] return listToClass(tables, ProtocolTable, self.__user__)