def experimenter(): o = ExperimenterI() o.id = rlong(1L) o.email = rstring('the_email') o.firstName = rstring('the_firstName') o.institution = rstring('the_institution') o.lastName = rstring('the_lastName') o.middleName = rstring('the_middleName') o.omeName = rstring('the_omeName') return o
def wrapped_image(): experimenter = ExperimenterI() experimenter.firstName = rstring('first_name') experimenter.lastName = rstring('last_name') image = ImageI() image.id = rlong(1L) image.description = rstring('description') image.name = rstring('name') image.acquisitionDate = rtime(1000) # In milliseconds image.details.owner = ExperimenterI(1L, False) creation_event = EventI() creation_event.time = rtime(2000) # In milliseconds image.details.creationEvent = creation_event return ImageWrapper(conn=MockConnection(experimenter), obj=image)
def test_experimenter(self): """ Tests methods handled by BlitzObjectWrapper.__getattr__ These will return unicode strings """ first_name = u'fîrst_nąmę' last_name = u'làst_NÅMÉ' experimenter = ExperimenterI() experimenter.firstName = rstring(first_name) experimenter.lastName = rstring(last_name) exp = MockConnection(experimenter).getObject("Experimenter", 1) assert exp.getFirstName() == first_name assert exp.getLastName() == last_name assert exp.getFullName() == "%s %s" % (first_name, last_name)
def experimenter(): o = ExperimenterI() o.id = rlong(1L) o.email = rstring("the_email") o.firstName = rstring("the_firstName") o.institution = rstring("the_institution") o.lastName = rstring("the_lastName") o.middleName = rstring("the_middleName") o.omeName = rstring("the_omeName") return o
def link_tags(conn, datasetname, image_tag_links, image_ratings): for i in range(1, 51): username = "******" % i print(username) exp = conn.getAdminService().lookupExperimenter(username) exp_id = exp.id.val dataset = conn.getObject("Dataset", attributes={'name': datasetname}, opts={'owner': exp_id}) if dataset is None: print("Dataset not found") continue links = [] for image in dataset.listChildren(): name = image.name if name in image_tag_links: for tag_id in image_tag_links[name]: link = ImageAnnotationLinkI() link.parent = ImageI(image.id, False) link.child = TagAnnotationI(tag_id, False) link.details.owner = ExperimenterI(exp_id, False) links.append(link) if name in image_ratings: link = ImageAnnotationLinkI() link.parent = ImageI(image.id, False) r = LongAnnotationI() r.ns = rstring(RATING_NS) r.longValue = rlong(image_ratings[name]) link.child = r link.details.owner = ExperimenterI(exp_id, False) links.append(link) print('links', len(links)) group_id = dataset.getDetails().getGroup().id conn.SERVICE_OPTS.setOmeroGroup(group_id) try: conn.getUpdateService().saveArray(links, conn.SERVICE_OPTS) except ValidationException: print("Failed to link for %s" % username)
def testChgrpDatasetToTargetProject(self, credentials): """ Tests that an Admin can move a user's Dataset to a private group and link it to an existing user's Project there. Also tests that the user can do the same chgrp themselves. """ # One user in two groups client, user = self.new_client_and_user(perms=PRIVATE) target_grp = self.new_group([user], perms=PRIVATE) eCtx = client.sf.getAdminService().getEventContext() # Reset session userId = eCtx.userId target_gid = target_grp.id.val # User creates Dataset in current group... update = client.sf.getUpdateService() ds = self.make_dataset(client=client) # ...and Project in target group ctx = {'omero.group': str(target_gid)} pr = self.new_project() pr = update.saveAndReturnObject(pr, ctx) requests = [] saves = [] chgrp = Chgrp2(targetObjects={"Dataset": [ds.id.val]}, groupId=target_gid) requests.append(chgrp) link = ProjectDatasetLinkI() link.details.owner = ExperimenterI(userId, False) link.child = DatasetI(ds.id.val, False) link.parent = ProjectI(pr.id.val, False) save = Save() save.obj = link saves.append(save) requests.extend(saves) if credentials == "user": c = client else: c = self.root self.doSubmit(requests, c, omero_group=target_gid) queryService = client.sf.getQueryService() ctx = {'omero.group': '-1'} # query across groups dataset = queryService.get('Dataset', ds.id.val, ctx) ds_gid = dataset.details.group.id.val assert target_gid == ds_gid,\ "Dataset should be in group: %s, NOT %s" % (target_gid, ds_gid)
def new_user(self, group=None, perms=None, owner=False, system=False, uname=None, email=None): """ :owner: If user is to be an owner of the created group :system: If user is to be a system admin """ if not self.root: raise Exception("No root client. Cannot create user") adminService = self.root.getSession().getAdminService() if uname is None: uname = self.uuid() # Create group if necessary if not group: g = self.new_group(perms=perms) group = g.name.val else: g, group = self.group_and_name(group) # Create user e = ExperimenterI() e.omeName = rstring(uname) e.firstName = rstring(uname) e.lastName = rstring(uname) e.ldap = rbool(False) e.email = rstring(email) listOfGroups = list() listOfGroups.append(adminService.lookupGroup('user')) uid = adminService.createExperimenterWithPassword( e, rstring(uname), g, listOfGroups) e = adminService.lookupExperimenter(uname) if owner: adminService.setGroupOwner(g, e) if system: adminService.addGroups(e, [ExperimenterGroupI(0, False)]) return adminService.getExperimenter(uid)
def createExperimenter(self, omeName, firstName, lastName, email, admin, active, dGroup, otherGroups, password, middleName=None, institution=None): new_exp = ExperimenterI() new_exp.omeName = rstring(str(omeName)) new_exp.firstName = rstring(str(firstName)) new_exp.middleName = middleName is not None and rstring(str(middleName)) or None new_exp.lastName = rstring(str(lastName)) new_exp.email = rstring(str(email)) new_exp.institution = (institution!="" and institution is not None) and rstring(str(institution)) or None listOfGroups = set() # default group for g in self.groups: if long(dGroup) == g.id: defaultGroup = g._obj break # system group if admin: for g in self.groups: if g.name == "system": sysGroup = g._obj break listOfGroups.add(sysGroup) # user group if active: for g in self.groups: if g.name == "user": userGroup = g._obj break listOfGroups.add(userGroup) # rest of groups for g in self.groups: for og in otherGroups: # remove defaultGroup from otherGroups if contains if long(og) == long(defaultGroup.id.val): pass elif long(og) == g.id: listOfGroups.add(g._obj) return self.conn.createExperimenter(new_exp, defaultGroup, list(listOfGroups), password)
def findByQuery(self, query, params, _ctx=None): experimenter = ExperimenterI() experimenter.firstName = rstring('first_name') experimenter.lastName = rstring('last_name') return experimenter
# list users with the 'IDs' parameter #exp_id = script_params["Experimenter"] experimenters = conn.getObjects("Experimenter") exp_ids = [] for e in experimenters: print e.id, e.firstName, e.lastName if e.id > 1: exp_ids.append(e.id) print "list ids", exp_ids # move users to a single object, in this case public domain public_group_id = 5 adminService = conn.getAdminService() for eid in exp_ids: adminService.addGroups(ExperimenterI(eid, False), [ExperimenterGroupI(public_group_id, False)]) # Return some value(s). # Here, we return anything useful the script has produced. # NB: The Insight and web clients will display the "Message" output. msg = "Script ran OK" client.setOutput("Message", rstring(msg)) client.closeSession()
def move_well_annotations(conn, well, ann_type, remove_anns, ns): """Move annotations from Images in this Well onto the Well itself.""" log("Processing Well: %s %s" % (well.id, well.getWellPos())) iids = [wellSample.getImage().id for wellSample in well.listChildren()] log(" Image IDs: %s" % iids) if len(iids) == 0: return 0 # Params to query links. If not Admin, only work with our own links params = ParametersI() if not conn.isAdmin(): params.theFilter = Filter() params.theFilter.ownerId = rlong(conn.getUserId()) old_links = list(conn.getAnnotationLinks('Image', iids, ns=ns, params=params)) # Filter by type old_links = [l for l in old_links if (ann_type is None or (l.child.__class__.__name__ == ann_type))] link_ids = [l.id for l in old_links] def get_key(ann_link, with_owner=False): # We use ann's 'key' to avoid adding duplicate annotations # Key includes link owner (allows multiple links with different owners) ann = ann_link.child return "%s_%s" % (ann_link.details.owner.id.val, ann.id.val) links_dict = {} # Remove duplicate annotations according to get_key(l) for l in old_links: links_dict[get_key(l, conn.isAdmin())] = l old_links = links_dict.values() # Find existing links on Well so we don't try to duplicate them existing_well_links = list(conn.getAnnotationLinks('Well', [well.id], ns=ns, params=params)) existing_well_keys = [get_key(l) for l in existing_well_links] new_links = [] for l in old_links: if get_key(l) in existing_well_keys: continue log(" Annotation: %s %s" % (l.child.id.val, l.child.__class__.__name__)) link = WellAnnotationLinkI() link.parent = WellI(well.id, False) link.child = l.child # If Admin, the new link Owner is same as old link Owner if conn.isAdmin(): owner_id = l.details.owner.id.val link.details.owner = ExperimenterI(owner_id, False) new_links.append(link) try: conn.getUpdateService().saveArray(new_links) except Exception, ex: log("Failed to create links: %s" % ex.message) return 0
def roi_with_unloaded_details_children(roi): roi.details.owner = ExperimenterI(1, False) roi.details.group = ExperimenterGroupI(1, False) return roi