def tagset_tag(self): """ Returns a new OMERO TagAnnotation, with the OMERO.insight tagset namespace set, and linked TagAnnotation with required fields set. """ tagset = TagAnnotationI() tagset.ns = rstring(omero.constants.metadata.NSINSIGHTTAGSET) tagset.textValue = rstring(self.uuid()) tag = TagAnnotationI() tag.textValue = rstring(self.uuid()) tagset.linkAnnotation(tag) return self.update.saveAndReturnObject(tagset)
def tagset_tag(request, itest, update_service): """ Returns a new OMERO TagAnnotation, with the OMERO.insight tagset namespace set, and linked TagAnnotation with required fields set. """ tagset = TagAnnotationI() tagset.ns = rstring(omero.constants.metadata.NSINSIGHTTAGSET) tagset.textValue = rstring(itest.uuid()) tag = TagAnnotationI() tag.textValue = rstring(itest.uuid()) tagset.linkAnnotation(tag) return update_service.saveAndReturnObject(tagset)
def test_container_tags_update(self, user1, dtype): """ Test updating a Object without losing linked Tags. If we load a Object without loading Annotations, then update and save the Object, we don't want to lose Annotation links """ conn = get_connection(user1) user_name = conn.getUser().getName() django_client = self.new_django_client(user_name, user_name) container = dtype[1]() container.name = rstring('test_container_tags_update') tag = TagAnnotationI() tag.textValue = rstring('tag') container.linkAnnotation(tag) container = get_update_service(user1).saveAndReturnObject(container) version = api_settings.API_VERSIONS[-1] object_url = reverse('api_%s' % dtype[0], kwargs={ 'api_version': version, 'object_id': container.id.val }) save_url = reverse('api_save', kwargs={'api_version': version}) # Get container, update and save back rsp = get_json(django_client, object_url) object_json = rsp['data'] object_json['Name'] = 'renamed container' put_json(django_client, save_url, object_json) # Check container has been updated and still has annotation links proj = conn.getObject(dtype[0], container.id.val) assert proj.getName() == 'renamed container' assert len(list(proj.listAnnotations())) == 1
def createTag(name, description=None): print "Create Tag:", name tag = TagAnnotationI() tag.textValue = rstring(name) if description is not None: tag.description = rstring(description) return tag
def test_validation_exception(self, user_A): """Test handling when we try to save something invalid.""" conn = get_connection(user_A) group = conn.getEventContext().groupId userName = conn.getUser().getName() django_client = self.new_django_client(userName, userName) version = api_settings.API_VERSIONS[-1] save_url = reverse('api_save', kwargs={'api_version': version}) save_url += '?group=' + native_str(group) # Create Tag tag = TagAnnotationI() tag.textValue = rstring('test_tag') tag = conn.getUpdateService().saveAndReturnObject(tag) tag_json = {'Value': 'test_tag', '@id': tag.id.val, '@type': OME_SCHEMA_URL + '#TagAnnotation'} # Add Tag twice to Project to get Validation Exception payload = {'Name': 'test_validation', '@type': OME_SCHEMA_URL + '#Project', 'Annotations': [tag_json, tag_json]} rsp = post_json(django_client, save_url, payload, status_code=400) # NB: message contains whole stack trace assert "ValidationException" in rsp['message'] assert rsp['stacktrace'].startswith( 'Traceback (most recent call last):')
def create_tag(self, name, description, text="tag"): """ Creates a new tag object. Returns the new tag object. If either the name or description parameters are None, the user will be prompted to input them. The "text" parameter should be the text description to use upon user input. For example, if we were creating a tag, this would be "tag" (the default). If we were creating a tagset, this could be "tag set". """ if name is None: name = raw_input("Please enter a name for this %s: " % text) if description is None: description = raw_input("Please enter a description for this %s: " % text) if name is not None and description is not None and name != '': tag = TagAnnotationI() tag.textValue = rstring(name) if description is not None and len(description) > 0: tag.description = rstring(description) return tag else: self.ctx.err("Tag/tagset name cannot be 'None' or empty.") sys.exit(1)
def create_tag(self, name, description, text="tag"): """ Creates a new tag object. Returns the new tag object. If either the name or description parameters are None, the user will be prompted to input them. The "text" parameter should be the text description to use upon user input. For example, if we were creating a tag, this would be "tag" (the default). If we were creating a tagset, this could be "tag set". """ if name is None: name = raw_input("Please enter a name for this %s: " % text) if description is None: description = raw_input( "Please enter a description for this %s: " % text) if name is not None and description is not None and name != '': tag = TagAnnotationI() tag.textValue = rstring(name) if description is not None and len(description) > 0: tag.description = rstring(description) return tag else: self.ctx.err("Tag/tagset name cannot be 'None' or empty.") sys.exit(1)
def tag(self, request): """Returns a new OMERO TagAnnotation with required fields set.""" name = rstring(self.uuid()) for index in range(request.param): tag = TagAnnotationI() tag.textValue = name tag = self.update.saveAndReturnObject(tag) return tag
def tag(request, itest, update_service): """Returns a new OMERO TagAnnotation with required fields set.""" name = rstring(itest.uuid()) for index in range(request.param): tag = TagAnnotationI() tag.textValue = name tag = update_service.saveAndReturnObject(tag) return tag
def tags_userA_userB(request, userA, userB, groupA): """ Returns new OMERO Tags """ tags = [] ctx = {'omero.group': str(groupA.id.val)} for name, user in zip(["userAtag", "userBtag"], [userA, userB]): tag = TagAnnotationI() tag.textValue = rstring(name) tag = get_update_service(user).saveAndReturnObject(tag, ctx) tags.append(tag) tags.sort(cmp_id) return tags
def tags_userA_userB(request, userA, userB, groupA): """ Returns new OMERO Tags """ tags = [] ctx = {'omero.group': str(groupA.id.val)} for name, user in zip(["userAtag", "userBtag"], [userA, userB]): tag = TagAnnotationI() tag.textValue = rstring(name) tag = get_update_service(user).saveAndReturnObject(tag, ctx) tags.append(tag) tags.sort(cmp_id) return tags
def test_tag_annotation(self): """Tests AnnotationWrapper methods return strings""" ns = u'πλζ.test.ζ' text_value = u'Tαg - ℗' obj = TagAnnotationI() obj.textValue = rstring(text_value) obj.ns = rstring(ns) tag = MockConnection(obj).getObject("Annotation", 1) assert tag.getValue() == text_value.encode('utf8') assert tag.textValue == text_value assert tag.getNs() == ns.encode('utf8') assert tag.ns == ns
def tags_userA_userB(request, userA, userB, groupA): """ Returns new OMERO Tags with descriptions """ tags = [] ctx = {'omero.group': native_str(groupA.id.val)} for name, user in zip(["userAtag", "userBtag"], [userA, userB]): tag = TagAnnotationI() tag.textValue = rstring(name) # Only add description to first tag if name == "userAtag": tag.description = rstring('tag description') tag = get_update_service(user).saveAndReturnObject(tag, ctx) tags.append(tag) tags.sort(key=lambda x: unwrap(x.id)) return tags
def projects_dataset_image_tag(self): """ Returns 2 new OMERO Projects, linked Dataset and linked Image populated by an L{test.integration.library.ITest} instance with required fields set. Also a Tag linked to both Projects. """ project1 = ProjectI() project1.name = rstring(f'P1_{self.uuid()}') project2 = ProjectI() project2.name = rstring(f'P2_{self.uuid()}') dataset = DatasetI() dataset.name = rstring(f'D{self.uuid()}') image = self.new_image(f'I{self.uuid()}') dataset.linkImage(image) project1.linkDataset(dataset) project2.linkDataset(dataset) tag = TagAnnotationI() tag.textValue = rstring("ChgrpTag") project1.linkAnnotation(tag) project2.linkAnnotation(tag) return self.update.saveAndReturnArray([project1, project2])
def projects_dataset_image_tag(self): """ Returns 2 new OMERO Projects, linked Dataset and linked Image populated by an L{test.integration.library.ITest} instance with required fields set. Also a Tag linked to both Projects. """ project1 = ProjectI() project1.name = rstring(self.uuid()) project2 = ProjectI() project2.name = rstring(self.uuid()) dataset = DatasetI() dataset.name = rstring(self.uuid()) image = self.new_image(name=self.uuid()) dataset.linkImage(image) project1.linkDataset(dataset) project2.linkDataset(dataset) tag = TagAnnotationI() tag.textValue = rstring("ChgrpTag") project1.linkAnnotation(tag) project2.linkAnnotation(tag) return self.update.saveAndReturnArray([project1, project2])
def testQueryTaggedUnique(self): # get group we're working on... ctx = self.client.sf.getAdminService().getEventContext() groupId = ctx.groupId print 'groupId', groupId # Admin sets permissions to read-ann admin = self.root.sf.getAdminService() rootUpdate = self.root.sf.getUpdateService() gr = admin.getGroup(groupId) p = PermissionsI() p.setUserRead(True) p.setUserWrite(True) p.setGroupRead(True) p.setGroupAnnotate(True) p.setGroupWrite(False) p.setWorldRead(False) p.setWorldAnnotate(False) p.setWorldWrite(False) gr.details.permissions = p admin.updateGroup(gr) # Update context for user ctx = self.client.sf.getAdminService().getEventContext() update = self.client.sf.getUpdateService() queryService = self.client.sf.getQueryService() tagCount = 5 # User creates tag linked to images tag = TagAnnotationI() tag.textValue = wrap("test_iQuerySpeed") links = [] for i in range(tagCount): iid = createImageWithPixels(self.client, self.uuid()) link = ImageAnnotationLinkI() link.parent = ImageI(iid, False) link.child = tag links.append(link) links = update.saveAndReturnArray(links) tag = links[0].child # check permissions p = tag.getDetails().getPermissions() assert p.isGroupRead() assert p.isGroupAnnotate() # Root also links user's tag to images rootLinks = [] for l in links: link = ImageAnnotationLinkI() link.parent = ImageI(l.parent.id, False) link.child = TagAnnotationI(l.child.id, False) rootLinks.append(link) rootUpdate.saveAndReturnArray(rootLinks, {'omero.group': str(groupId)}) q = """select distinct new map(obj.id as id, obj.name as name, obj.details.owner.id as ownerId, obj as image_details_permissions, obj.fileset.id as filesetId, lower(obj.name) as n , pix.sizeX as sizeX, pix.sizeY as sizeY, pix.sizeZ as sizeZ ) from Image obj left outer join obj.pixels pix join obj.annotationLinks alink where %s order by lower(obj.name), obj.id """ params = ParametersI() params.add('tid', tag.id) # We can get all the tagged images like this. # We use an additional select statement to give 'unique' results uniqueClause = """alink.id = (select max(alink.id) from ImageAnnotationLink alink where alink.child.id=:tid and alink.parent.id=obj.id)""" query = q % uniqueClause result1 = queryService.projection(query, params, {'omero.group': str(groupId)}) assert len(result1) == tagCount # Without the select statement, we get the same image returned # multiple times if there is no 'distinct' clause = "alink.child.id=:tid" query = q % clause result2 = queryService.projection(query, params, {'omero.group': str(groupId)}) assert len(result2) == tagCount for idx in range(len(result1)-1): # Omit final since == isn't defined for Ice objects. assert result1[idx] == result2[idx]
def testQueryTaggedUnique(self): # get group we're working on... ctx = self.client.sf.getAdminService().getEventContext() groupId = ctx.groupId print 'groupId', groupId # Admin sets permissions to read-ann admin = self.root.sf.getAdminService() rootUpdate = self.root.sf.getUpdateService() gr = admin.getGroup(groupId) p = PermissionsI() p.setUserRead(True) p.setUserWrite(True) p.setGroupRead(True) p.setGroupAnnotate(True) p.setGroupWrite(False) p.setWorldRead(False) p.setWorldAnnotate(False) p.setWorldWrite(False) gr.details.permissions = p admin.updateGroup(gr) # Update context for user ctx = self.client.sf.getAdminService().getEventContext() update = self.client.sf.getUpdateService() queryService = self.client.sf.getQueryService() tagCount = 5 # User creates tag linked to images tag = TagAnnotationI() tag.textValue = wrap("test_iQuerySpeed") links = [] for i in range(tagCount): iid = createImageWithPixels(self.client, self.uuid()) link = ImageAnnotationLinkI() link.parent = ImageI(iid, False) link.child = tag links.append(link) links = update.saveAndReturnArray(links) tag = links[0].child # check permissions p = tag.getDetails().getPermissions() assert p.isGroupRead() assert p.isGroupAnnotate() # Root also links user's tag to images rootLinks = [] for l in links: link = ImageAnnotationLinkI() link.parent = ImageI(l.parent.id, False) link.child = TagAnnotationI(l.child.id, False) rootLinks.append(link) rootUpdate.saveAndReturnArray(rootLinks, {'omero.group': str(groupId)}) q = """select distinct new map(obj.id as id, obj.name as name, obj.details.owner.id as ownerId, obj as image_details_permissions, obj.fileset.id as filesetId, lower(obj.name) as n , pix.sizeX as sizeX, pix.sizeY as sizeY, pix.sizeZ as sizeZ ) from Image obj left outer join obj.pixels pix join obj.annotationLinks alink where %s order by lower(obj.name), obj.id """ params = ParametersI() params.add('tid', tag.id) # We can get all the tagged images like this. # We use an additional select statement to give 'unique' results uniqueClause = """alink.id = (select max(alink.id) from ImageAnnotationLink alink where alink.child.id=:tid and alink.parent.id=obj.id)""" query = q % uniqueClause result1 = queryService.projection(query, params, {'omero.group': str(groupId)}) assert len(result1) == tagCount # Without the select statement, we get the same image returned # multiple times if there is no 'distinct' clause = "alink.child.id=:tid" query = q % clause result2 = queryService.projection(query, params, {'omero.group': str(groupId)}) assert len(result2) == tagCount for idx in range(len(result1)-1): # Omit final since == isn't defined for Ice objects. assert result1[idx] == result2[idx]
userConn = BlitzGateway(username, "ome") userConn.connect() for g in userConn.getGroupsMemberOf(): if g.getName() == "user": continue print " ", g.getName() userConn.SERVICE_OPTS.setOmeroGroup(g.getId()) params = omero.sys.Parameters() params.theFilter = omero.sys.Filter() params.theFilter.ownerId = rlong(exp.getId()) tags = list(userConn.getObjects("TagAnnotation", params=params)) for i in range(TAG_COUNT - len(tags)): t = TagAnnotationI() newTagVal = "%s_%s_TEST" % (username, g.getName()) print "creating TAG:", newTagVal t.textValue = wrap(str(newTagVal)) userConn.getUpdateService().saveObject(t, userConn.SERVICE_OPTS) # for t in tags: # print " TAG", t.getId(), t.getTextValue() userConn.c.closeSession() print "\n---- DOING ANNOTATING... ----\n" # We want to Tag loads of stuff with OUR tags and Others' tags for exp in allUsers: username = exp.getOmeName() if username not in USER_NAMES: continue print "\n\n------------ USER:"******"------------" userConn = BlitzGateway(username, "ome") userConn.connect() updateService = userConn.getUpdateService()
userConn = BlitzGateway(username, "ome") userConn.connect() for g in userConn.getGroupsMemberOf(): if g.getName() == "user": continue print " ", g.getName() userConn.SERVICE_OPTS.setOmeroGroup(g.getId()) params = omero.sys.Parameters() params.theFilter = omero.sys.Filter() params.theFilter.ownerId = rlong(exp.getId()) tags = list( userConn.getObjects("TagAnnotation", params=params) ) for i in range( TAG_COUNT-len(tags) ): t = TagAnnotationI() newTagVal = "%s_%s_TEST" % (username, g.getName()) print "creating TAG:", newTagVal t.textValue = wrap(str(newTagVal)) userConn.getUpdateService().saveObject(t, userConn.SERVICE_OPTS) # for t in tags: # print " TAG", t.getId(), t.getTextValue() userConn.c.closeSession() print "\n---- DOING ANNOTATING... ----\n" # We want to Tag loads of stuff with OUR tags and Others' tags for exp in allUsers: username = exp.getOmeName() if username not in USER_NAMES: continue print "\n\n------------ USER:"******"------------" userConn = BlitzGateway(username, "ome")