def testIterators(self): d = DatasetI() image = ImageI() image.linkDataset(d) it = image.iterateDatasetLinks() count = 0 for i in it: count += 1 self.assert_(count == 1)
def test1184(self): uuid = self.uuid() client = self.new_client(perms="rw----") share = client.sf.getShareService() query = client.sf.getQueryService() update = client.sf.getUpdateService() admin = client.sf.getAdminService() cont = client.sf.getContainerService() ds = DatasetI() ds.setName(rstring('test1184-ds-%s' % (uuid))) for i in range(1, 2001): img = ImageI() img.setName(rstring('img1184-%s' % (uuid))) img.setAcquisitionDate(rtime(time.time())) # Saving in one go #dil = DatasetImageLinkI() #dil.setParent(ds) #dil.setChild(img) #update.saveObject(dil) ds.linkImage(img) ds = update.saveAndReturnObject(ds) c = cont.getCollectionCount(ds.__class__.__name__, ("imageLinks"), [ds.id.val], None) self.assert_(c[ds.id.val] == 2000) page = 1 p = omero.sys.Parameters() p.map = {} p.map["eid"] = rlong(admin.getEventContext().userId) p.map["oid"] = rlong(ds.id.val) if page is not None: f = omero.sys.Filter() f.limit = rint(24) f.offset = rint((int(page) - 1) * 24) p.theFilter = f sql = "select im from Image im join fetch im.details.owner join fetch im.details.group " \ "left outer join fetch im.datasetLinks dil left outer join fetch dil.parent d " \ "where d.id = :oid and im.details.owner.id=:eid order by im.id asc" start = time.time() res = query.findAllByQuery(sql, p) self.assertEquals(24, len(res)) end = time.time() elapsed = end - start self.assertTrue( elapsed < 3.0, "Expected the test to complete in < 3 seconds, took: %f" % elapsed)
def testLinkingAndUnlinking(self): d = DatasetI() i = ImageI() d.linkImage(i) self.assert_(d.sizeOfImageLinks() == 1) d.unlinkImage(i) self.assert_(d.sizeOfImageLinks() == 0) d = DatasetI() i = ImageI() d.linkImage(i) self.assert_(i.sizeOfDatasetLinks() == 1) i.unlinkDataset(d) self.assert_(d.sizeOfImageLinks() == 0) d = DatasetI() i = ImageI() dil = DatasetImageLinkI() dil.link(d, i) d.addDatasetImageLink(dil, False) self.assert_(d.sizeOfImageLinks() == 1) self.assert_(i.sizeOfDatasetLinks() == 0)
def testLinkingAndUnlinking(self): d = DatasetI() i = ImageI() d.linkImage(i) assert d.sizeOfImageLinks() == 1 d.unlinkImage(i) assert d.sizeOfImageLinks() == 0 d = DatasetI() i = ImageI() d.linkImage(i) assert i.sizeOfDatasetLinks() == 1 i.unlinkDataset(d) assert d.sizeOfImageLinks() == 0 d = DatasetI() i = ImageI() dil = DatasetImageLinkI() dil.link(d, i) d.addDatasetImageLink(dil, False) assert d.sizeOfImageLinks() == 1 assert i.sizeOfDatasetLinks() == 0
def testLinkingInPrivateGroup(self): uuid = self.uuid() group = self.new_group(perms="rw----") client, user = self.new_client_and_user(group=group, admin=True) update = client.sf.getUpdateService() project = ProjectI() project.setName(rstring("project1_%s" % uuid)) project = update.saveAndReturnObject(project) dataset = DatasetI() dataset.setName(rstring("dataset1_%s" % uuid)) dataset = update.saveAndReturnObject(dataset) links = [] l = ProjectDatasetLinkI() l.setChild(dataset) l.setParent(project) links.append(l) update.saveAndReturnArray(links)
def test1072(self): #create two users where both are in the same active group admin = self.root.sf.getAdminService() uuid = admin.getEventContext().sessionUuid new_gr = self.new_group(perms="rwr---") c1, test_user = self.new_client_and_user(new_gr) c2, test_user2 = self.new_client_and_user(new_gr) #login as user1 update = c1.sf.getUpdateService() pr1 = ProjectI() pr1.setName(rstring('test1072-pr1-%s' % (uuid))) pr1 = update.saveAndReturnObject(pr1) pr1.unload() #datasets ds1 = DatasetI() ds1.setName(rstring('test1072-ds1-%s' % (uuid))) ds1 = update.saveAndReturnObject(ds1) ds1.unload() pdl1 = ProjectDatasetLinkI() pdl1.setParent(pr1) pdl1.setChild(ds1) update.saveObject(pdl1) #login as user2 pojos = c2.sf.getContainerService() self.assert_(c2.sf.getAdminService().getEventContext()) #print c1.sf.getAdminService().getEventContext() p = omero.sys.ParametersI() p.grp(rlong(c2.sf.getAdminService().getEventContext().groupId)) pojos.loadContainerHierarchy("Project", None, p)
def test1071_1(self): admin = self.root.sf.getAdminService() common_group = self.new_group(perms="rwrw--") c1 = self.new_client(common_group) c2 = self.new_client(common_group) c1_pojos = c1.sf.getContainerService() c1_query = c1.sf.getQueryService() c1_update = c1.sf.getUpdateService() c1_uuid = c1.sf.getAdminService().getEventContext().sessionUuid c2_pojos = c2.sf.getContainerService() c2_query = c2.sf.getQueryService() c2_update = c2.sf.getUpdateService() c2_uuid = c2.sf.getAdminService().getEventContext().sessionUuid #projects pr1 = ProjectI() pr1.setName(rstring('test1071-pr1-%s' % (c1_uuid))) pr1 = c1_update.saveAndReturnObject(pr1) pr1.unload() pr2 = ProjectI() pr2.setName(rstring('test1071-pr2-%s' % (c2_uuid))) pr2 = c2_update.saveAndReturnObject(pr2) pr2.unload() #datasets ds1 = DatasetI() ds1.setName(rstring('test1071-ds1-%s' % (c1_uuid))) ds1 = c1_update.saveAndReturnObject(ds1) ds1.unload() ds2 = DatasetI() ds2.setName(rstring('test1071-ds2-%s' % (c2_uuid))) ds2 = c2_update.saveAndReturnObject(ds2) ds2.unload() #images im2 = ImageI() im2.setName(rstring('test1071-im2-%s' % (c2_uuid))) im2.acquisitionDate = rtime(0) im2 = c2_update.saveAndReturnObject(im2) im2.unload() #links # im2 owned by u2 # # im2 -> ds2 --> pr2 (owned by u2) # | # \-> ds1 --> pr1 (owned by u1) # pdl1 = ProjectDatasetLinkI() pdl1.setParent(pr1) pdl1.setChild(ds1) c1_update.saveObject(pdl1) pdl2 = ProjectDatasetLinkI() pdl2.setParent(pr2) pdl2.setChild(ds2) c2_update.saveObject(pdl2) dil2 = DatasetImageLinkI() dil2.setParent(ds2) dil2.setChild(im2) c2_update.saveObject(dil2) dil1 = DatasetImageLinkI() dil1.setParent(ds1) dil1.setChild(im2) c1_update.saveObject(dil1) #test: hier = c2_pojos.findContainerHierarchies("Project", [long(im2.id.val)], None) self.assertEquals(2, len(hier), "size of hier != 2: %s" % [type(x) for x in hier]) for c in hier: if c.id.val == pr1.id.val and isinstance(c, ProjectI): self.assertEquals(1, c.sizeOfDatasetLinks()) for pdl in c.copyDatasetLinks(): self.assertEquals(1, pdl.child.sizeOfImageLinks()) for dil in pdl.child.copyImageLinks(): self.assert_(dil.child.id.val == im2.id.val) elif c.id.val == pr2.id.val and isinstance(c, ProjectI): self.assertEquals(1, c.sizeOfDatasetLinks()) elif c.id.val == ds3.id.val and isinstance(c, DatasetI): self.assertEquals(1, c.sizeOfImageLinks())
def test1071(self): uuid = self.root.sf.getAdminService().getEventContext().sessionUuid pojos = self.root.sf.getContainerService() query = self.root.sf.getQueryService() update = self.root.sf.getUpdateService() #projects pr1 = ProjectI() pr1.setName(rstring('test1071-pr1-%s' % (uuid))) pr1 = update.saveAndReturnObject(pr1) pr1.unload() pr2 = ProjectI() pr2.setName(rstring('test1071-pr2-%s' % (uuid))) pr2 = update.saveAndReturnObject(pr2) pr2.unload() #datasets ds1 = DatasetI() ds1.setName(rstring('test1071-ds1-%s' % (uuid))) ds1 = update.saveAndReturnObject(ds1) ds1.unload() ds2 = DatasetI() ds2.setName(rstring('test1071-ds2-%s' % (uuid))) ds2 = update.saveAndReturnObject(ds2) ds2.unload() ds3 = DatasetI() ds3.setName(rstring('test1071-ds3-%s' % (uuid))) ds3 = update.saveAndReturnObject(ds3) ds3.unload() #images im2 = ImageI() im2.setName(rstring('test1071-im2-%s' % (uuid))) im2.acquisitionDate = rtime(0) im2 = update.saveAndReturnObject(im2) im2.unload() #links # # im2 -> ds3 # +-> ds2 --> pr2 # | \ # \-> ds1 --> pr1 # pdl1 = ProjectDatasetLinkI() pdl1.setParent(pr1) pdl1.setChild(ds1) update.saveObject(pdl1) pdl2 = ProjectDatasetLinkI() pdl2.setParent(pr1) pdl2.setChild(ds2) update.saveObject(pdl2) pdl3 = ProjectDatasetLinkI() pdl3.setParent(pr2) pdl3.setChild(ds2) update.saveObject(pdl3) dil4 = DatasetImageLinkI() dil4.setParent(ds1) dil4.setChild(im2) update.saveObject(dil4) dil5 = DatasetImageLinkI() dil5.setParent(ds2) dil5.setChild(im2) update.saveObject(dil5) dil6 = DatasetImageLinkI() dil6.setParent(ds3) dil6.setChild(im2) update.saveObject(dil6) #test: hier = pojos.findContainerHierarchies("Project", [long(im2.id.val)], None) self.assertEquals(3, len(hier), "len of hier != 3: %s" % [type(x) for x in hier]) for c in hier: if c.id.val == pr1.id.val and isinstance(c, ProjectI): self.assert_(c.sizeOfDatasetLinks() == 2, "length 2 != " + str(c.sizeOfDatasetLinks())) for pdl in c.copyDatasetLinks(): self.assert_(pdl.child.sizeOfImageLinks() == 1) for dil in pdl.child.copyImageLinks(): self.assert_(dil.child.id.val == im2.id.val) elif c.id.val == pr2.id.val and isinstance(c, ProjectI): self.assert_(c.sizeOfDatasetLinks() == 1) elif c.id.val == ds3.id.val and isinstance(c, DatasetI): self.assert_(c.sizeOfImageLinks() == 1)
#!/usr/bin/env python # -*- coding: utf-8 -*- from omero_model_ImageI import ImageI from omero_model_DatasetI import DatasetI image = ImageI() dataset = DatasetI() link = dataset.linkImage(image) for link in image.iterateDatasetLinks(): link.getChild().getName()