def testAllParametersChecked(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rstring(""))
        params.inputs = {"a": param}

        input = rlist(rstring("foo"), rint(1))
        inputs = {"a": input}
        assert not "" == validate_inputs(params, inputs)
    def testRListRList(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rlist())
        params.inputs = {"a": param}

        input = rlist(rlist(rint(1), rstring("a")))
        inputs = {"a": input}
        assert "" == validate_inputs(params, inputs)
    def testRListRList(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rlist())
        params.inputs = {"a": param}

        input = rlist(rlist(rint(1), rstring("a")))
        inputs = {"a": input}
        assert "" == validate_inputs(params, inputs)
    def testAllParametersChecked(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rstring(""))
        params.inputs = {"a": param}

        input = rlist(rstring("foo"), rint(1))
        inputs = {"a": input}
        assert not "" == validate_inputs(params, inputs)
    def testRListRListRString(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rlist(rstring("")))
        params.inputs = {"a": param}

        input = rlist(rlist(rstring("a")))
        inputs = {"a": input}
        assert "" == validate_inputs(params, inputs)

        input.val[0].val.insert(0, rint(1))
        assert not "" == validate_inputs(params, inputs)
    def testRListRListRString(self):
        params = omero.grid.JobParams()
        param = omero.grid.Param()
        param.prototype = rlist(rlist(rstring("")))
        params.inputs = {"a": param}

        input = rlist(rlist(rstring("a")))
        inputs = {"a": input}
        assert "" == validate_inputs(params, inputs)

        input.val[0].val.insert(0, rint(1))
        assert not "" == validate_inputs(params, inputs)
Exemple #7
0
 def testGetAttrWorks(self):
     rbool(True).val
     rdouble(0.0).val
     rfloat(0.0).val
     rint(0).val
     rlong(0).val
     rtime(0).val
     rinternal(None).val
     robject(None).val
     rstring("").val
     rclass("").val
     rarray().val
     rlist().val
     rset().val
     rmap().val
 def testGetAttrWorks(self):
     rbool(True).val
     rdouble(0.0).val
     rfloat(0.0).val
     rint(0).val
     rlong(0).val
     rtime(0).val
     rinternal(None).val
     robject(None).val
     rstring("").val
     rclass("").val
     rarray().val
     rlist().val
     rset().val
     rmap().val
    def testListCreationEqualsHash(self):

        list_notnull1 = rlist(ids)
        list_notnull2 = rlist(ids)
        # Equals based on content
        assert list_notnull1 == list_notnull2
        # But content is copied!
        assert not list_notnull1.getValue() is list_notnull2.getValue()

        list_null1 = rlist()
        list_null2 = rlist(None)
        list_null3 = rlist(*[])

        # All different since the contents are mutable.
        assert list_null1 is not list_notnull1
        assert list_null1 is not list_null2
        assert list_null1 is not list_null3
Exemple #10
0
    def testListCreationEqualsHash(self):

        list_notnull1 = rlist(ids)
        list_notnull2 = rlist(ids)
        # Equals based on content
        assert list_notnull1 == list_notnull2
        # But content is copied!
        assert not list_notnull1.getValue() is list_notnull2.getValue()

        list_null1 = rlist()
        list_null2 = rlist(None)
        list_null3 = rlist(*[])

        # All different since the contents are mutable.
        assert list_null1 is not list_notnull1
        assert list_null1 is not list_null2
        assert list_null1 is not list_null3
def populate_test_data(client, cli, remote_conn):
    image_ids = []
    query_service = client.getSession().getQueryService()
    params = om_sys.Parameters()
    params.map = {}

    for dataset_name in DATASET_NAMES:
        dataset_id = create_dataset(cli, dataset_name, 'Test dataset')
        print(dataset_id)

        # get created dataset object
        dataset_ids = map(
            rtypes.rlong,
            [dataset_id
             ])  # wrap dataset ID in list since it's only one ID to map
        params.map = {'dids': rtypes.rlist(dataset_ids)}
        datasets = query_service.findAllByQuery(DATASETS_BY_ID_QUERY, params)

        for i in range(0, 4):
            tag_label = random.choice(TAG_LABELS)
            tag_desc = random.choice(TAG_DESCRIPTIONS)
            tag_id = create_tag(cli, tag_label, tag_desc)
            update_object_tag(client, datasets, rtypes.rlong(tag_id))

        try:
            image_ids = import_image(IMAGE_PATH, remote_conn, dataset_id,
                                     client.getSessionId())

            # get created image object
            image_ids = map(
                rtypes.rlong, image_ids
            )  # wrap image ID in list since it's only one ID to map
            params.map = {'iids': rtypes.rlist(image_ids)}
            images = query_service.findAllByQuery(IMAGES_BY_ID_QUERY, params)

            for image in images:
                for i in range(0, 4):
                    tag_label = random.choice(TAG_LABELS)
                    tag_desc = random.choice(TAG_DESCRIPTIONS)
                    tag_id = create_tag(cli, tag_label, tag_desc)
                    update_object_tag(client, [image], rtypes.rlong(tag_id))
        except Exception as e:
            print(IMAGE_PATH)
        print(image_ids)
Exemple #12
0
            def getAnnotationsForObjects(obj_type, oids):
                # Get the images that match
                hql = "select distinct link.child.id from %sAnnotationLink link " \
                      "where link.parent.id in (:oids)" % obj_type

                params = Parameters()
                params.map = {}
                params.map["oids"] = rlist([rlong(o) for o in oids])

                qs = conn.getQueryService()
                return [result[0].val for result in qs.projection(hql,params, service_opts)]
Exemple #13
0
def _set_parameters(mapann_ns=[],
                    mapann_names=[],
                    mapann_query=None,
                    mapann_value=None,
                    params=None,
                    experimenter_id=-1,
                    page=1,
                    limit=settings.PAGE):
    if params is None:
        params = omero.sys.ParametersI()

    # Paging
    if page is not None and page > 0:
        params.page((page - 1) * limit, limit)

    where_clause = []

    if mapann_names is not None and len(mapann_names) > 0:
        manlist = [rstring(str(n)) for n in mapann_names]
        params.add("filter", rlist(manlist))
        where_clause.append('mv.name in (:filter)')

    if mapann_ns is not None and len(mapann_ns) > 0:
        mnslist = [rstring(str(n)) for n in mapann_ns]
        params.add("ns", rlist(mnslist))
        where_clause.append('a.ns in (:ns)')

    if experimenter_id is not None and experimenter_id != -1:
        params.addId(experimenter_id)
        where_clause.append('a.details.owner.id = :id')

    if mapann_query:
        # query starts from search terms
        params.addString("query", rstring("%s%%" % str(mapann_query).lower()))
        where_clause.append('lower(mv.value) like :query')

    if mapann_value:
        params.addString("value", mapann_value)
        where_clause.append('mv.value  = :value')

    return params, where_clause
Exemple #14
0
        def getObjectsWithAllAnnotations(obj_type, annids):
            # Get the images that match
            hql = "select link.parent.id from %sAnnotationLink link " \
                  "where link.child.id in (:oids) " \
                  "group by link.parent.id " \
                  "having count (distinct link.child) = %s" % (obj_type, len(annids))
            params = Parameters()
            params.map = {}
            params.map["oids"] = rlist([rlong(o) for o in set(annids)])

            qs = conn.getQueryService()
            return [x[0].getValue() for x in qs.projection(hql,params,service_opts)]
Exemple #15
0
    def test_batch_image_export(self):
        sid = super(TestExportScripts, self).get_script(batch_image_export)
        assert sid > 0

        client, user = self.new_client_and_user()
        # x,y,z,c,t
        image = self.create_test_image(100, 100, 1, 1, 1, client.getSession())
        image_ids = []
        image_ids.append(rlong(image.id.val))
        args = {"Data_Type": rstring("Image"), "IDs": rlist(image_ids)}
        ann = run_script(client, sid, args, "File_Annotation")
        c = self.new_client(user=user)
        check_file_annotation(c, ann)
Exemple #16
0
            def getAnnotationsForObjects(obj_type, oids):
                # Get the images that match
                hql = "select distinct link.child.id from %sAnnotationLink link " \
                      "where link.parent.id in (:oids)" % obj_type

                params = Parameters()
                params.map = {}
                params.map["oids"] = rlist([rlong(o) for o in oids])

                qs = conn.getQueryService()
                return [
                    result[0].val
                    for result in qs.projection(hql, params, service_opts)
                ]
Exemple #17
0
    def test1154(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid

        
        ### create two users in one group
        client_share1, user1 = self.new_client_and_user()
        client_share2, user2 = self.new_client_and_user()

        ## login as user1
        share1 = client_share1.sf.getShareService()
        update1 = client_share1.sf.getUpdateService()
        
        # create image
        img = ImageI()
        img.setName(rstring('test1154-img-%s' % (uuid)))
        img.setAcquisitionDate(rtime(0))
        img = update1.saveAndReturnObject(img)
        img.unload()
        
        # create share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        sid = share1.createShare(description, timeout, objects,experimenters, guests, enabled)
        
        self.assertEquals(1,len(share1.getContents(sid)))
        
        ## login as user2
        share2 = client_share2.sf.getShareService()
        query2 = client_share2.sf.getQueryService()
        
        content = share2.getContents(sid)
        self.assertEquals(1,len(share2.getContents(sid)))
        
        # get shared image when share is activated
        share2.activate(sid)

        p = omero.sys.Parameters()
        p.map = {}
        p.map["ids"] = rlist([rlong(img.id.val)])
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p)
        self.assertEquals(1,len(res))
        for e in res:
            self.assert_(e.id.val == img.id.val)
Exemple #18
0
    def test1154(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid

        ### create two users in one group
        client_share1, user1 = self.new_client_and_user()
        client_share2, user2 = self.new_client_and_user()

        ## login as user1
        share1 = client_share1.sf.getShareService()
        update1 = client_share1.sf.getUpdateService()

        # create image
        img = ImageI()
        img.setName(rstring('test1154-img-%s' % (uuid)))
        img.setAcquisitionDate(rtime(0))
        img = update1.saveAndReturnObject(img)
        img.unload()

        # create share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        sid = share1.createShare(description, timeout, objects, experimenters,
                                 guests, enabled)

        self.assertEquals(1, len(share1.getContents(sid)))

        ## login as user2
        share2 = client_share2.sf.getShareService()
        query2 = client_share2.sf.getQueryService()

        content = share2.getContents(sid)
        self.assertEquals(1, len(share2.getContents(sid)))

        # get shared image when share is activated
        share2.activate(sid)

        p = omero.sys.Parameters()
        p.map = {}
        p.map["ids"] = rlist([rlong(img.id.val)])
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p)
        self.assertEquals(1, len(res))
        for e in res:
            self.assert_(e.id.val == img.id.val)
Exemple #19
0
        def getObjectsWithAllAnnotations(obj_type, annids):
            # Get the images that match
            hql = "select link.parent.id from %sAnnotationLink link " \
                  "where link.child.id in (:oids) " \
                  "group by link.parent.id " \
                  "having count (distinct link.child) = %s" % (obj_type,
                                                               len(annids))
            params = Parameters()
            params.map = {}
            params.map["oids"] = rlist([rlong(o) for o in set(annids)])

            qs = conn.getQueryService()
            return [
                x[0].getValue()
                for x in qs.projection(hql, params, service_opts)
            ]
Exemple #20
0
    def get_tag_annos_for_labels(self, tag_labels=None):
        anno_list = []
        if tag_labels is not None:
            c, cli, remote_conn = self.connect_to_remote(
                self.USERNAME, self.PASSWORD)
            params = om_sys.Parameters()

            for tag_label in tag_labels:
                tag_rstr_label = rtypes.rstring(tag_label)
                params.map = {'anno_text': rtypes.rlist(tag_rstr_label)}
                anno_list.extend(
                    self.find_objects_by_query(c,
                                               TAG_ANNOS_BY_TEXT_VALUES_QUERY,
                                               params))

            self.session_exit_condition = True
            self.close_remote_connection(c, cli, remote_conn)

        return anno_list
    def testCanAnnotate(self):

        # Users in Private and Read-annotate groups
        private_g = self.new_group(perms="rw----")
        readann_g = self.new_group(perms="rwra--")

        # User 1 is only in private group
        client1, user1 = self.new_client_and_user(group=private_g)

        # User2 is in read-ann group (default) AND private group
        user2 = self.new_user(group=readann_g)
        self.add_groups(user2, [private_g])
        client2 = self.new_client(user=user2)

        # User 1 creates image in Private group...
        img = self.make_image(name='ishare_testCanAnnotate', client=client1)
        assert not img.details.permissions.isGroupRead()
        assert not img.details.permissions.isGroupAnnotate()

        # ...Adds it to share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        share1 = client1.sf.getShareService()
        sid = share1.createShare(description, timeout, objects,
                                 experimenters, guests, enabled)

        # User 2 logs in, gets image from share
        query2 = client2.sf.getQueryService()
        p = omero.sys.Parameters()
        p.map = {"ids": rlist([rlong(img.id.val)])}
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p, {'omero.share': str(sid)})
        assert 1 == len(res)

        # User should not be able to annotate private image.
        for e in res:
            canAnn = e.getDetails().getPermissions().canAnnotate()
            assert not canAnn
            assert e.id.val == img.id.val
Exemple #22
0
    def testCanAnnotate(self):

        # Users in Private and Read-annotate groups
        private_g = self.new_group(perms="rw----")
        readann_g = self.new_group(perms="rwra--")

        # User 1 is only in private group
        client1, user1 = self.new_client_and_user(group=private_g)

        # User2 is in read-ann group (default) AND private group
        user2 = self.new_user(group=readann_g)
        self.add_groups(user2, [private_g])
        client2 = self.new_client(user=user2)

        # User 1 creates image in Private group...
        img = self.make_image(name='ishare_testCanAnnotate', client=client1)
        assert not img.details.permissions.isGroupRead()
        assert not img.details.permissions.isGroupAnnotate()

        # ...Adds it to share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        share1 = client1.sf.getShareService()
        sid = share1.createShare(description, timeout, objects, experimenters,
                                 guests, enabled)

        # User 2 logs in, gets image from share
        query2 = client2.sf.getQueryService()
        p = omero.sys.Parameters()
        p.map = {"ids": rlist([rlong(img.id.val)])}
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p, {'omero.share': str(sid)})
        assert 1 == len(res)

        # User should not be able to annotate private image.
        for e in res:
            canAnn = e.getDetails().getPermissions().canAnnotate()
            assert not canAnn
            assert e.id.val == img.id.val
    def test1154(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid

        # create two users in one group
        client_share1, user1 = self.new_client_and_user()
        client_share2, user2 = self.new_client_and_user()

        # login as user1
        share1 = client_share1.sf.getShareService()

        # create image
        img = self.make_image(name='test1154-img-%s' % uuid)

        # create share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        sid = share1.createShare(description, timeout, objects,
                                 experimenters, guests, enabled)

        assert 1 == len(share1.getContents(sid))

        # login as user2
        share2 = client_share2.sf.getShareService()
        query2 = client_share2.sf.getQueryService()

        share2.getContents(sid)
        assert 1 == len(share2.getContents(sid))

        # get shared image when share is activated
        share2.activate(sid)

        p = omero.sys.Parameters()
        p.map = {"ids": rlist([rlong(img.id.val)])}
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p)
        assert 1 == len(res)
        for e in res:
            assert e.id.val == img.id.val
Exemple #24
0
    def test1154(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid

        # create two users in one group
        client_share1, user1 = self.new_client_and_user()
        client_share2, user2 = self.new_client_and_user()

        # login as user1
        share1 = client_share1.sf.getShareService()

        # create image
        img = self.make_image(name='test1154-img-%s' % uuid)

        # create share
        description = "my description"
        timeout = None
        objects = [img]
        experimenters = [user2]
        guests = []
        enabled = True
        sid = share1.createShare(description, timeout, objects, experimenters,
                                 guests, enabled)

        assert 1 == len(share1.getContents(sid))

        # login as user2
        share2 = client_share2.sf.getShareService()
        query2 = client_share2.sf.getQueryService()

        share2.getContents(sid)
        assert 1 == len(share2.getContents(sid))

        # get shared image when share is activated
        share2.activate(sid)

        p = omero.sys.Parameters()
        p.map = {"ids": rlist([rlong(img.id.val)])}
        sql = "select im from Image im where im.id in (:ids) order by im.name"
        res = query2.findAllByQuery(sql, p)
        assert 1 == len(res)
        for e in res:
            assert e.id.val == img.id.val
Exemple #25
0
    def update_tag_links(self,
                         duplicate_tag_ids,
                         client,
                         query,
                         replacement_tag_id,
                         dry_run=False):
        params = om_sys.Parameters()
        params.map = {}

        anno_ids = map(rtypes.rlong, duplicate_tag_ids)
        params.map = {'aids': rtypes.rlist(anno_ids)}
        objects_list = self.find_objects_by_query(client, query, params)

        object_ids = [i.getId().getValue() for i in objects_list]
        logging.info("updating these objects: {}".format(object_ids))

        self.update_object_tag(client,
                               objects_list,
                               replacement_tag_id,
                               dry_run=dry_run)
Exemple #26
0
def attributes_by_attributes(conn,
                             name="Gene Symbol",
                             value="ASH2L",
                             ns="openmicroscopy.org/mapr/gene",
                             ns2="openmicroscopy.org/mapr/phenotype",
                             name2=None,
                             sId=None
                             ):

    """
    Return a list of neighbours attributes
    for given case insensitive attribute value. (Uses the python blitz gateway)
    """
    from omero.rtypes import rstring, rlist, unwrap
    from omero.sys import ParametersI

    params = ParametersI()
    params.addString("value", value.lower())
    q = (
        "select distinct new map( mv.value as value) "
        "from Annotation as a "
        "join a.mapValue as mv "
        "where lower(mv.value) = :value {where_claus}"
    )
    where_claus = []
    if name:
        params.addString("name", name)
        where_claus.append("and mv.name = :name")
    q = q.format(**{'where_claus':" ".join(where_claus)})

    values = [v[0]['value'] for v in unwrap(
        conn.getQueryService().projection(q, params))]

    params = ParametersI()
    valuelist = [rstring(unicode(v)) for v in values]
    params.add('values', rlist(valuelist))
    params.addString("ns", ns)
    params.addString("ns2", ns2)

    q = (
        "select distinct new map("
            "mv.name as name, "
            "mv.value as value, "
            "mv2.name as name2, "
            "mv2.value as value2) "
        "from Image as i "
        "join i.annotationLinks as ial "
        "join i.annotationLinks as ial2 "
        "join ial.child as a "
        "join a.mapValue as mv "
        "join ial2.child as a2 "
        "join a2.mapValue as mv2 "
        "where a.ns = :ns and a2.ns = :ns2 "
        "and mv.value in (:values) {where_claus} "
    )
    
    where_claus = []
    if name:
        params.addString("name", name)
        where_claus.append("and mv.name = :name")
    if name2:
        params.addString("name2", name2)
        where_claus.append("and mv2.name = :name2")

    q = q.format(**{'where_claus':" ".join(where_claus)})
    
    if sId != None:
        q = q + ("and i in (select image from WellSample "
            "where well.plate in "
            "(select child from ScreenPlateLink where parent.id = {sId}))")

        screenidList = []
        screenidList.append(str(sId))
        q = q.format(**{'sId':" ".join(screenidList)})
    
    res = {}
    for r in unwrap(conn.getQueryService().projection(q, params)):
        r = r[0]
        try:
            res[(r['name'], r['value'])].append((r['name2'], r['value2']))
        except KeyError:
            res[(r['name'], r['value'])] = [(r['name2'], r['value2'])]
    return res
Exemple #27
0
    def __init__(self,
                 name,
                 optional=True,
                 out=False,
                 description=None,
                 default=None,
                 **kwargs):

        # Non-Param attributes
        omero.grid.Param.__init__(self)

        # Non-Param attributes
        self._name = name
        self._in = True
        self._out = out

        # Other values will be filled in by the kwargs
        # Mostly leaving these for backwards compatibility
        self.description = description
        self.optional = optional

        # Assign all the kwargs
        for k, v in list(kwargs.items()):
            if not hasattr(self, k):
                TYPE_LOG.warn("Unknown property: %s", k)
            setattr(self, k, v)

        _DEF = self.__get(self.PROTOTYPE_DEFAULT, False)
        _FUN = self.__get(self.PROTOTYPE_FUNCTION)
        _MAX = self.__get(self.PROTOTYPE_MAX)
        _MIN = self.__get(self.PROTOTYPE_MIN)
        _VAL = self.__get(self.PROTOTYPE_VALUES)

        # Someone specifically set the prototype, then
        # we assume that useDefault should be True
        # For whatever reason, inheritance isn't working.
        if default is not None:
            newfunc = _FUN
            newdefault = default
            if isinstance(self, List):
                if isinstance(default, (list, tuple)):
                    newdefault = wrap(default).val
                elif isinstance(default, omero.RCollection):
                    newfunc = lambda x: x
                elif isinstance(default, omero.RType):
                    default = [default]
                else:
                    newfunc = lambda x: x
                    newdefault = rlist([rtype(default)])
            self.useDefault = True
            self.prototype = newfunc(newdefault)
        else:
            if not callable(_FUN):
                raise ValueError("Bad prototype function: %s" % _FUN)

            # To prevent weirdness, if the class default is
            # callable, we'll assume its a constructor and
            # create a new one to prevent modification.
            try:
                _def = _DEF()
            except TypeError:
                _def = _DEF
            self.prototype = _FUN(_def)

        # The following use wrap to guarantee that an rtype is present
        if self.min is not None:
            if _MIN is None:
                self.min = _FUN(self.min)
            else:
                self.min = _MIN(self.min)

        if self.max is not None:
            if _MAX is None:
                self.max = _FUN(self.max)
            else:
                self.max = _MAX(self.max)

        if self.values is not None:
            if _VAL is None:
                self.values = wrap(self.values)
            else:
                self.values = _VAL(self.values)

        # Now if useDefault has been set, either manually, or
        # via setting default="..." we check that the default
        # value matches a value if present
        if self.values is not None and self.values and self.useDefault:
            if isinstance(self.prototype, omero.RCollection):
                test = unwrap(self.prototype.val[0])
            else:
                test = unwrap(self.prototype)
            values = unwrap(self.values)
            if test not in values:
                raise ValueError("%s is not in %s" % (test, values))
Exemple #28
0
    def test1172(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid
        share = self.root.sf.getShareService()
        query = self.root.sf.getQueryService()
        update = self.root.sf.getUpdateService()

        ### create user
        client_share1, user1 = self.new_client_and_user()

        #create dataset with image
        #dataset with image
        ds = omero.model.DatasetI()
        ds.setName(rstring("dataset-%s" % (uuid)))
        ds = update.saveAndReturnObject(ds)
        ds.unload()

        # create image
        img = ImageI()
        img.setName(rstring('test-img in dataset-%s' % (uuid)))
        img.setAcquisitionDate(rtime(0))
        img = update.saveAndReturnObject(img)
        img.unload()

        dil = DatasetImageLinkI()
        dil.setParent(ds)
        dil.setChild(img)
        dil = update.saveAndReturnObject(dil)
        dil.unload()

        # create share by root
        items = list()
        ms = list()

        p = omero.sys.Parameters()
        p.map = {}
        p.map["oid"] = ds.id
        sql = "select ds from Dataset ds join fetch ds.details.owner join fetch ds.details.group " \
              "left outer join fetch ds.imageLinks dil left outer join fetch dil.child i " \
              "where ds.id=:oid"
        items.extend(query.findAllByQuery(sql, p))
        self.assertEquals(1, len(items))

        #members
        p.map["eid"] = rlong(user1.id.val)
        sql = "select e from Experimenter e where e.id =:eid order by e.omeName"
        ms = query.findAllByQuery(sql, p)
        sid = share.createShare(("test-share-%s" % uuid),
                                rtime(long(time.time() * 1000 + 86400)), items,
                                ms, [], True)

        # USER RETRIEVAL
        ## login as user1
        share1 = client_share1.sf.getShareService()
        query1 = client_share1.sf.getQueryService()
        cntar1 = client_share1.sf.getContainerService()

        content = share1.getContents(sid)
        # Content now contains just the dataset with nothing loaded
        self.assertEquals(1, len(content))

        # get shared dataset and image when share is activated
        share1.activate(sid)

        #retrieve dataset
        p = omero.sys.Parameters()
        p.map = {}
        p.map["ids"] = rlist([ds.id])
        sql = "select ds from Dataset ds join fetch ds.details.owner join fetch ds.details.group " \
              "left outer join fetch ds.imageLinks dil left outer join fetch dil.child i " \
              "where ds.id in (:ids) order by ds.name"
        try:
            res1 = query1.findAllByQuery(sql, p)
            self.fail("This should throw an exception")
        except:
            pass

        #
        # Now we add all the other elements to the share to prevent
        # the security violation
        #
        # Not working imgs = cntar.getImages("Dataset",[ds.id.val], None)
        img = query.findByQuery(
            "select i from Image i join fetch i.datasetLinks dil join dil.parent d where d.id = %s "
            % ds.id.val, None)
        self.assert_(img)
        share.addObject(sid, img)
        share.addObjects(sid, img.copyDatasetLinks())
        self.assertEquals(3, len(share.getContents(sid)))

        #
        # And try again to load them
        #
        share1.activate(sid)
        res1 = query1.findAllByQuery(sql, p)
        self.assert_(len(res1) == 1)
        for e in res1:
            self.assert_(e.id.val == ds.id.val)

        # retrieve only image
        p = omero.sys.Parameters()
        p.map = {}
        p.map["oid"] = rlong(img.id)
        sql = "select im from Image im " \
              "where im.id=:oid order by im.name"
        res2 = query1.findByQuery(sql, p)
        self.assert_(res2.id.val == img.id.val)
    def test1172(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid
        share = self.root.sf.getShareService()
        query = self.root.sf.getQueryService()

        # create user
        client_share1, user1 = self.new_client_and_user()

        # create dataset with image
        ds = self.make_dataset(name="dataset-%s" % uuid, client=self.root)
        img = self.new_image(name='test-img in dataset-%s' % uuid)
        self.link(ds, img, client=self.root)

        items = list()
        p = omero.sys.Parameters()
        p.map = {"oid": ds.id}
        sql = (
            "select ds from Dataset ds "
            "join fetch ds.details.owner "
            "join fetch ds.details.group "
            "left outer join fetch ds.imageLinks dil "
            "left outer join fetch dil.child i "
            "where ds.id=:oid")
        items.extend(query.findAllByQuery(sql, p))
        assert 1 == len(items)

        # members
        p.map["eid"] = rlong(user1.id.val)
        sql = ("select e from Experimenter e "
               "where e.id =:eid order by e.omeName")
        ms = query.findAllByQuery(sql, p)
        sid = share.createShare(("test-share-%s" % uuid),
                                rtime(long(time.time() * 1000 + 86400)),
                                items, ms, [], True)

        # USER RETRIEVAL
        # login as user1
        share1 = client_share1.sf.getShareService()
        query1 = client_share1.sf.getQueryService()

        content = share1.getContents(sid)
        # Content now contains just the dataset with nothing loaded
        assert 1 == len(content)

        # get shared dataset and image when share is activated
        share1.activate(sid)

        # retrieve dataset
        p = omero.sys.Parameters()
        p.map = {"ids": rlist([ds.id])}
        sql = (
            "select ds from Dataset ds "
            "join fetch ds.details.owner "
            "join fetch ds.details.group "
            "left outer join fetch ds.imageLinks dil "
            "left outer join fetch dil.child i "
            "where ds.id in (:ids) order by ds.name")
        try:
            res1 = query1.findAllByQuery(sql, p)
            assert False, "This should throw an exception"
        except:
            pass

        # Now we add all the other elements to the share to prevent
        # the security violation
        #
        # Not working imgs = cntar.getImages("Dataset",[ds.id.val], None)
        img = query.findByQuery(
            "select i from Image i join fetch i.datasetLinks dil "
            "join dil.parent d where d.id = %s " % ds.id.val, None)
        assert img
        share.addObject(sid, img)
        share.addObjects(sid, img.copyDatasetLinks())
        assert 3 == len(share.getContents(sid))

        # And try again to load them
        share1.activate(sid)
        res1 = query1.findAllByQuery(sql, p)
        assert len(res1) == 1
        for e in res1:
            assert e.id.val == ds.id.val

        # retrieve only image
        p = omero.sys.Parameters()
        p.map = {"oid": rlong(img.id)}
        sql = "select im from Image im " \
              "where im.id=:oid order by im.name"
        res2 = query1.findByQuery(sql, p)
        assert res2.id.val == img.id.val
 def addLongs(self, name, longs):
     rlongs = rlist([])
     for l in longs:
         rlongs.val.append(rlong(l))
     self.add(name, rlongs)
     return self
Exemple #31
0
    def __init__(self, name, optional=True, out=False, description=None, default=None, **kwargs):

        # Non-Param attributes
        omero.grid.Param.__init__(self)

        # Non-Param attributes
        self._name = name
        self._in = True
        self._out = out

        # Other values will be filled in by the kwargs
        # Mostly leaving these for backwards compatibility
        self.description = description
        self.optional = optional

        # Assign all the kwargs
        for k, v in kwargs.items():
            if not hasattr(self, k):
                TYPE_LOG.warn("Unknown property: %s", k)
            setattr(self, k, v)

        _DEF = self.__get(self.PROTOTYPE_DEFAULT, False)
        _FUN = self.__get(self.PROTOTYPE_FUNCTION)
        _MAX = self.__get(self.PROTOTYPE_MAX)
        _MIN = self.__get(self.PROTOTYPE_MIN)
        _VAL = self.__get(self.PROTOTYPE_VALUES)

        # Someone specifically set the prototype, then
        # we assume that useDefault should be True
        # For whatever reason, inheritance isn't working.
        if default is not None:
            newfunc = _FUN
            newdefault = default
            if isinstance(self, List):
                if isinstance(default, (list, tuple)):
                    newdefault = wrap(default).val
                elif isinstance(default, omero.RCollection):
                    newfunc = lambda x: x
                elif isinstance(default, omero.RType):
                    default = [default]
                else:
                    newfunc = lambda x: x
                    newdefault = rlist([rtype(default)])
            self.useDefault = True
            self.prototype = newfunc(newdefault)
        else:
            if not callable(_FUN):
                raise ValueError("Bad prototype function: %s" % _FUN)

            # To prevent weirdness, if the class default is
            # callable, we'll assume its a constructor and
            # create a new one to prevent modification.
            try:
                _def = _DEF()
            except TypeError:
                _def = _DEF
            self.prototype = _FUN(_def)

        # The following use wrap to guarantee that an rtype is present
        if self.min is not None:
            if _MIN is None:
                self.min = _FUN(self.min)
            else:
                self.min = _MIN(self.min)

        if self.max is not None:
            if _MAX is None:
                self.max = _FUN(self.max)
            else:
                self.max = _MAX(self.max)

        if self.values is not None:
            if _VAL is None:
                self.values = wrap(self.values)
            else:
                self.values = _VAL(self.values)

        # Now if useDefault has been set, either manually, or
        # via setting default="..." we check that the default
        # value matches a value if present
        if self.values is not None and self.values and self.useDefault:
            if isinstance(self.prototype, omero.RCollection):
                test = unwrap(self.prototype.val[0])
            else:
                test = unwrap(self.prototype)
            values = unwrap(self.values)
            if test not in values:
                raise ValueError("%s is not in %s" % (test, values))
Exemple #32
0
    def test3639(self):
        uuid = self.client.sf.getAdminService().getEventContext().sessionUuid
        group = self.client.sf.getAdminService().getGroup(
            self.client.sf.getAdminService().getEventContext().groupId)
        update = self.client.sf.getUpdateService()

        images = list()
        for i in range(0, 5):
            img = self.new_image()
            img = update.saveAndReturnObject(img)
            images.append(img.id.val)

        p = omero.sys.Parameters()
        p.map = {}
        p.map["oids"] = rlist([rlong(s) for s in images])

        # create dataset
        dataset = omero.model.DatasetI()
        dataset.name = rstring('DS-test-2936-%s' % (uuid))
        dataset = update.saveAndReturnObject(dataset)

        # put image in dataset
        for iid in images:
            dlink = omero.model.DatasetImageLinkI()
            dlink.parent = omero.model.DatasetI(dataset.id.val, False)
            dlink.child = omero.model.ImageI(iid, False)
            update.saveAndReturnObject(dlink)

        # log in as group owner:
        client_o, owner = self.new_client_and_user(group=group, admin=True)
        query_o = client_o.sf.getQueryService()

        handlers = list()
        op = dict()
        op["/Image"] = "KEEP"
        dc = omero.cmd.Delete('/Dataset', long(dataset.id.val), op)
        handlers.append(str(client_o.sf.submit(dc)))

        imageToDelete = images[2]
        images.remove(imageToDelete)
        dc2 = omero.cmd.Delete('/Image', long(imageToDelete), {})
        handlers.append(str(client_o.sf.submit(dc2)))

        def _formatReport(delete_handle):
            """
            Added as workaround to the changes made in #3006.
            """
            delete_report = delete_handle.getResponse()
            rv = []
            if isinstance(delete_report, omero.cmd.ERR):
                rv.append(str(delete_report))
            else:
                if delete_report.warning:
                    rv.append(delete_report.warning)
            if len(rv) > 0:
                return "; ".join(rv)
            return None

        failure = list()
        in_progress = 0
        r = None

        while(len(handlers) > 0):
            for cbString in handlers:
                try:
                    with pytest.raises(Ice.ObjectNotExistException):
                        handle = omero.cmd.HandlePrx.checkedCast(
                            client_o.ic.stringToProxy(cbString))
                        cb = omero.callbacks.CmdCallbackI(client_o, handle)
                        if not cb.block(500):  # ms.
                            # No errors possible if in progress(
                            # (since no response)
                            print "in progress", _formatReport(handle)
                            in_progress += 1
                        else:
                            rsp = cb.getResponse()
                            if isinstance(rsp, omero.cmd.ERR):
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                else:
                                    failure.append("No report!!!")
                            else:
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                cb.close(True)  # Close handle
                            handlers.remove(cbString)
                except Exception:
                    if r is not None:
                        failure.append(traceback.format_exc())

        if len(failure) > 0:
            assert False, ";".join(failure)
        assert not query_o.find('Dataset', dataset.id.val)
Exemple #33
0
 def testPassThroughNoneAndRTypes(self):
     """
     To prevent having to check for isintance(int,...) or
     isintance(RInt,...) all over the place, the static methods
     automatically check for acceptable
     types and simply pass them through. Similarly, the primitive types all
     check for None and return a null RType if necessary.
     """
     # Bool
     assert None == rbool(None)
     assert rbool(True) == rbool(rbool(True))
     assert rbool(True) == rbool(1)
     assert rbool(False) == rbool(0)
     # Double
     assert None == rdouble(None)
     assert rdouble(0.0) == rdouble(rdouble(0.0))
     assert rdouble(0.0) == rdouble(rdouble(0))
     assert rdouble(0.0) == rdouble(rdouble("0.0"))
     pytest.raises(ValueError, lambda: rdouble("string"))
     # Float
     assert None == rfloat(None)
     assert rfloat(0.0) == rfloat(rfloat(0.0))
     assert rfloat(0.0) == rfloat(rfloat(0))
     assert rfloat(0.0) == rfloat(rfloat("0.0"))
     pytest.raises(ValueError, lambda: rfloat("string"))
     # Long
     assert None == rlong(None)
     assert rlong(0) == rlong(rlong(0))
     assert rlong(0) == rlong(rlong(0.0))
     assert rlong(0) == rlong(rlong("0"))
     pytest.raises(ValueError, lambda: rlong("string"))
     # Time
     assert None == rtime(None)
     assert rtime(0) == rtime(rtime(0))
     assert rtime(0) == rtime(rtime(0.0))
     assert rtime(0) == rtime(rtime("0"))
     pytest.raises(ValueError, lambda: rtime("string"))
     # Int
     assert None == rint(None)
     assert rint(0) == rint(rint(0))
     assert rint(0) == rint(rint(0.0))
     assert rint(0) == rint(rint("0"))
     pytest.raises(ValueError, lambda: rint("string"))
     #
     # Starting here handling of null is different.
     #
     # String
     assert rstring("") == rstring(None)
     assert rstring("a") == rstring(rstring("a"))
     assert rstring("0") == rstring(0)
     # Class
     assert rclass("") == rclass(None)
     assert rclass("c") == rclass(rclass("c"))
     pytest.raises(ValueError, lambda: rclass(0))
     # Internal
     internal = omero.Internal()
     assert rinternal(None) == rinternal(None)
     assert rinternal(internal) == rinternal(rinternal(internal))
     pytest.raises(ValueError, lambda: rinternal("string"))
     # Object
     obj = omero.model.ImageI()
     assert robject(None) == robject(None)
     assert robject(obj) == robject(robject(obj))
     pytest.raises(ValueError, lambda: robject("string"))
     #
     # Same does not hold for collections
     #
     # Array
     assert rarray([]) == rarray(None)
     # assert rarray(obj) == rarray(rarray(obj))
     # pytest.raises(ValueError, lambda : rarray("string"))
     # List
     assert rlist([]) == rlist(None)
     # assert rlist(obj) == rlist(rlist(obj))
     # pytest.raises(ValueError, lambda : rlist("string"))
     # Set
     assert rset([]) == rset(None)
     # assert rset(obj) == rset(rset(obj))
     # pytest.raises(ValueError, lambda : rset("string"))
     # Map
     assert rmap({}) == rmap(None)
    def testUnwrap(self):
        # NUMS plain
        assert 0 == unwrap(0)
        assert 1 == unwrap(1)
        assert 0.0 == unwrap(0.0)
        assert 1.0 == unwrap(1.0)
        # NUMS rtyped
        assert 0 == unwrap(rint(0))
        assert 0 == unwrap(rlong(0))
        assert 1 == unwrap(rint(1))
        assert 1 == unwrap(rlong(1))
        assert 0.0 == unwrap(rfloat(0.0))
        assert 0.0 == unwrap(rdouble(0.0))
        assert 1.0 == unwrap(rfloat(1.0))
        assert 1.0 == unwrap(rdouble(1.0))

        # STRINGS
        assert "" == unwrap("")
        assert "str" == unwrap("str")

        # BOOL
        assert True == unwrap(True)
        assert False == unwrap(False)
        assert True == unwrap(rbool(True))
        assert False == unwrap(rbool(False))

        # TIME
        # Bit odd, do we want the long for time, or transformed?
        assert 0 == unwrap(rtime(0))
        assert 1 == unwrap(rtime(1))

        # CLASS
        # same for class, should we map it?
        assert "k" == unwrap(rclass("k"))

        # INTERNAL
        color = omero.Color()
        assert color == unwrap(rinternal(color))

        # OBJECT
        image = omero.model.ImageI()
        assert image == unwrap(robject(image))

        # COLLECTIONS
        # empty
        assert [] == unwrap([])
        assert {} == unwrap({})
        assert set() == unwrap(set())
        # plain in collection
        assert [1] == unwrap([1])
        # rtype in collection
        assert [1] == unwrap([rint(1)])
        assert {"a": 1} == unwrap({"a": 1})
        # plain in rcollection ILLEGAL
        # assert [1] == unwrap(rlist([1]))
        # assert {"a":1} == unwrap(rmap({"a":1}))
        # rtype in rcollection
        assert [1] == unwrap(rlist([rint(1)]))
        assert {"a": 1} == unwrap(rmap({"a": rint(1)}))
        # rtype keys ILLEGAL
        # assert {"a":1} == unwrap(rmap({rstring("a"):rint(1)}))
        # recursion, ticket:1977
        m1 = rmap({"a": rint(1)})
        m1.val["m1"] = m1
        m2 = {"a": 1}
        m2["m1"] = m2
        unwrap(m1)
        assert m2["a"] == unwrap(m1)["a"]
        # Can't compare directly "maximum recursion depth exceeded in cmp"
        assert type(m2["m1"]) == type(unwrap(m1)["m1"])
def _set_parameters(mapann_ns=[], mapann_names=[],
                    mapann_value=None, query=False, case_sensitive=True,
                    params=None, experimenter_id=-1,
                    page=None, limit=settings.PAGE):

    ''' Helper to map ParametersI

        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param params Instance of ParametersI
        @type params L{omero.sys.ParametersI}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to None
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''

    if params is None:
        params = omero.sys.ParametersI()

    # Paging
    if page is not None and page > 0:
        params.page((page-1) * limit, limit)

    where_clause = []

    if mapann_names is not None and len(mapann_names) > 0:
        manlist = [rstring(unicode(n)) for n in mapann_names]
        params.add('filter', rlist(manlist))
        where_clause.append("mv.name in (:filter)")

    if mapann_ns is not None and len(mapann_ns) > 0:
        mnslist = [rstring(unicode(n)) for n in mapann_ns]
        params.add("ns", rlist(mnslist))
        where_clause.append("a.ns in (:ns)")

    if experimenter_id is not None and experimenter_id != -1:
        params.addId(experimenter_id)
        where_clause.append("a.details.owner.id = :id")

    if mapann_value:
        mapann_value = mapann_value if case_sensitive else mapann_value.lower()
        _cwc = 'mv.value' if case_sensitive else 'lower(mv.value)'
        if query:
            params.addString(
                "query",
                rstring("%%%s%%" % _escape_chars_like(mapann_value)))
            where_clause.append("%s like :query" % _cwc)
        else:
            params.addString('value', mapann_value)
            where_clause.append("%s  = :value" % _cwc)
    else:
        where_clause.append("mv.value != '' ")

    return params, where_clause
Exemple #36
0
    def discover(self, args):

        import omero
        ldap = self.__import_ldap__()

        c = self.ctx.conn(args)
        iconfig = c.sf.getConfigService()
        iadmin = c.sf.getAdminService()
        iquery = c.sf.getQueryService()

        LDAP_PROPERTIES = """
        omero.ldap.urls
        omero.ldap.username
        omero.ldap.password
        omero.ldap.base
        omero.ldap.user_filter
        omero.ldap.user_mapping
        omero.ldap.group_filter
        omero.ldap.group_mapping
        omero.ldap.new_user_group
        """.split()

        cfg = dict()
        for key in LDAP_PROPERTIES:
            cfg[key.split(".")[-1]] = iconfig.getConfigValue(key)

        urls = args.urls and args.urls or cfg["urls"]
        basedn = args.base and args.base or cfg["base"]

        for url in urls.split(","):

            self.ctx.err("Connecting to %s..." % url)

            ld = ldap.initialize(url)
            ld.simple_bind_s(cfg['username'], cfg['password'])

            user_filter = cfg["user_filter"]
            user_mapping = cfg["user_mapping"]
            user_mapping = user_mapping.split(",")
            omeName_mapping = None
            for um in user_mapping:
                parts = um.split("=")
                if parts[0] == "omeName":
                    omeName_mapping = parts[1]

            from ldap.controls import SimplePagedResultsControl

            cookie = ''
            # This is the limit for Active Directory, 1000. However
            # the LDAP connection has a sizeLimit that overrides
            # this value if the page_size exceeds it so it is safe
            # to enter pretty much anything here when using paged results.
            page_size = 1000

            results = []
            first = True
            page_control = SimplePagedResultsControl(False, page_size, cookie)

            while first or page_control.cookie:
                first = False
                try:
                    msgid = ld.search_ext(
                        basedn, ldap.SCOPE_SUBTREE,
                        user_filter, serverctrls=[page_control]
                    )
                except:
                    self.ctx.die(1, "Failed to execute LDAP search")

                result_type, results, msgid, serverctrls = ld.result3(msgid)
                if serverctrls:
                    page_control.cookie = serverctrls[0].cookie

                user_names = set()
                user_dns = {}
                for dn, entry in results:
                    omeName = entry[omeName_mapping]
                    if isinstance(omeName, (list, tuple)):
                        if len(omeName) == 1:
                            omeName = omeName[0]
                            user_names.add(omeName)
                            user_dns[omeName] = dn
                        else:
                            self.ctx.err("Failed to unwrap omeName: %s" %
                                         omeName)
                            continue

                if not user_names:
                    continue  # Early exit!

                from omero.rtypes import rlist
                from omero.rtypes import rstring
                from omero.rtypes import unwrap
                params = omero.sys.ParametersI()
                params.add("names", rlist([rstring(x) for x in user_names]))
                id_names = unwrap(iquery.projection(
                    "select id, omeName from Experimenter "
                    "where omeName in (:names)", params))

                for eid, omeName in id_names:
                    try:
                        olddn = iadmin.lookupLdapAuthExperimenter(eid)
                        dn = user_dns[omeName]
                    except omero.ApiUsageException:
                        continue  # Unknown user

                    if olddn:
                        if olddn.lower() != dn.lower():
                            self.ctx.err("Found different DN for %s: %s"
                                         % (omeName, olddn))
                        else:
                            self.ctx.dbg("DN already set for %s: %s"
                                         % (omeName, olddn))
                    else:
                        if args.commands:
                            self.ctx.out("%s ldap setdn %s %s"
                                         % (sys.argv[0], omeName, dn))
                        else:
                            self.ctx.out("Experimenter:%s\tomeName=%s\t%s"
                                         % (eid, omeName, dn))
Exemple #37
0
    def test1172(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid
        share = self.root.sf.getShareService()
        query = self.root.sf.getQueryService()

        # create user
        client_share1, user1 = self.new_client_and_user()

        # create dataset with image
        ds = self.make_dataset(name="dataset-%s" % uuid, client=self.root)
        img = self.new_image(name='test-img in dataset-%s' % uuid)
        self.link(ds, img, client=self.root)

        items = list()
        p = omero.sys.Parameters()
        p.map = {"oid": ds.id}
        sql = ("select ds from Dataset ds "
               "join fetch ds.details.owner "
               "join fetch ds.details.group "
               "left outer join fetch ds.imageLinks dil "
               "left outer join fetch dil.child i "
               "where ds.id=:oid")
        items.extend(query.findAllByQuery(sql, p))
        assert 1 == len(items)

        # members
        p.map["eid"] = rlong(user1.id.val)
        sql = ("select e from Experimenter e "
               "where e.id =:eid order by e.omeName")
        ms = query.findAllByQuery(sql, p)
        sid = share.createShare(("test-share-%s" % uuid),
                                rtime(long(time.time() * 1000 + 86400)), items,
                                ms, [], True)

        # USER RETRIEVAL
        # login as user1
        share1 = client_share1.sf.getShareService()
        query1 = client_share1.sf.getQueryService()

        content = share1.getContents(sid)
        # Content now contains just the dataset with nothing loaded
        assert 1 == len(content)

        # get shared dataset and image when share is activated
        share1.activate(sid)

        # retrieve dataset
        p = omero.sys.Parameters()
        p.map = {"ids": rlist([ds.id])}
        sql = ("select ds from Dataset ds "
               "join fetch ds.details.owner "
               "join fetch ds.details.group "
               "left outer join fetch ds.imageLinks dil "
               "left outer join fetch dil.child i "
               "where ds.id in (:ids) order by ds.name")
        try:
            res1 = query1.findAllByQuery(sql, p)
            assert False, "This should throw an exception"
        except:
            pass

        # Now we add all the other elements to the share to prevent
        # the security violation
        #
        # Not working imgs = cntar.getImages("Dataset",[ds.id.val], None)
        img = query.findByQuery(
            "select i from Image i join fetch i.datasetLinks dil "
            "join dil.parent d where d.id = %s " % ds.id.val, None)
        assert img
        share.addObject(sid, img)
        share.addObjects(sid, img.copyDatasetLinks())
        assert 3 == len(share.getContents(sid))

        # And try again to load them
        share1.activate(sid)
        res1 = query1.findAllByQuery(sql, p)
        assert len(res1) == 1
        for e in res1:
            assert e.id.val == ds.id.val

        # retrieve only image
        p = omero.sys.Parameters()
        p.map = {"oid": rlong(img.id)}
        sql = "select im from Image im " \
              "where im.id=:oid order by im.name"
        res2 = query1.findByQuery(sql, p)
        assert res2.id.val == img.id.val
Exemple #38
0
    def discover(self, args):

        import omero
        ldap = self.__import_ldap__()

        c = self.ctx.conn(args)
        iconfig = c.sf.getConfigService()
        iadmin = c.sf.getAdminService()
        iquery = c.sf.getQueryService()

        LDAP_PROPERTIES = """
        omero.ldap.urls
        omero.ldap.username
        omero.ldap.password
        omero.ldap.base
        omero.ldap.user_filter
        omero.ldap.user_mapping
        omero.ldap.group_filter
        omero.ldap.group_mapping
        omero.ldap.new_user_group
        """.split()

        cfg = dict()
        for key in LDAP_PROPERTIES:
            cfg[key.split(".")[-1]] = iconfig.getConfigValue(key)

        urls = args.urls and args.urls or cfg["urls"]
        basedn = args.base and args.base or cfg["base"]

        for url in urls.split(","):

            self.ctx.err("Connecting to %s..." % url)

            ld = ldap.initialize(url)
            ld.simple_bind_s(cfg['username'], cfg['password'])

            user_filter = cfg["user_filter"]
            user_mapping = cfg["user_mapping"]
            user_mapping = user_mapping.split(",")
            omeName_mapping = None
            for um in user_mapping:
                parts = um.split("=")
                if parts[0] == "omeName":
                    omeName_mapping = parts[1]

            from ldap.controls import SimplePagedResultsControl

            cookie = ''
            # This is the limit for Active Directory, 1000. However
            # the LDAP connection has a sizeLimit that overrides
            # this value if the page_size exceeds it so it is safe
            # to enter pretty much anything here when using paged results.
            page_size = 1000

            results = []
            first = True
            page_control = SimplePagedResultsControl(False, page_size, cookie)

            while first or page_control.cookie:
                first = False
                try:
                    msgid = ld.search_ext(basedn,
                                          ldap.SCOPE_SUBTREE,
                                          user_filter,
                                          serverctrls=[page_control])
                except:
                    self.ctx.die(1, "Failed to execute LDAP search")

                result_type, results, msgid, serverctrls = ld.result3(msgid)
                if serverctrls:
                    page_control.cookie = serverctrls[0].cookie

                user_names = set()
                user_dns = {}
                for dn, entry in results:
                    omeName = entry[omeName_mapping]
                    if isinstance(omeName, (list, tuple)):
                        if len(omeName) == 1:
                            omeName = omeName[0]
                            user_names.add(omeName)
                            user_dns[omeName] = dn
                        else:
                            self.ctx.err("Failed to unwrap omeName: %s" %
                                         omeName)
                            continue

                if not user_names:
                    continue  # Early exit!

                from omero.rtypes import rlist
                from omero.rtypes import rstring
                from omero.rtypes import unwrap
                params = omero.sys.ParametersI()
                params.add("names", rlist([rstring(x) for x in user_names]))
                id_names = unwrap(
                    iquery.projection(
                        "select id, omeName from Experimenter "
                        "where omeName in (:names)", params))

                for eid, omeName in id_names:
                    try:
                        olddn = iadmin.lookupLdapAuthExperimenter(eid)
                        dn = user_dns[omeName]
                    except omero.ApiUsageException:
                        continue  # Unknown user

                    if olddn:
                        if olddn.lower() != dn.lower():
                            self.ctx.err("Found different DN for %s: %s" %
                                         (omeName, olddn))
                        else:
                            self.ctx.dbg("DN already set for %s: %s" %
                                         (omeName, olddn))
                    else:
                        if args.commands:
                            self.ctx.out("%s ldap setdn %s %s" %
                                         (sys.argv[0], omeName, dn))
                        else:
                            self.ctx.out("Experimenter:%s\tomeName=%s\t%s" %
                                         (eid, omeName, dn))
Exemple #39
0
    def test1172(self):
        uuid = self.root.sf.getAdminService().getEventContext().sessionUuid
        share = self.root.sf.getShareService()
        query = self.root.sf.getQueryService()
        update = self.root.sf.getUpdateService()
        
        ### create user
        client_share1, user1 = self.new_client_and_user()
        
        #create dataset with image
        #dataset with image
        ds = omero.model.DatasetI()
        ds.setName(rstring("dataset-%s" % (uuid)))
        ds = update.saveAndReturnObject(ds)
        ds.unload()
        
        # create image
        img = ImageI()
        img.setName(rstring('test-img in dataset-%s' % (uuid)))
        img.setAcquisitionDate(rtime(0))
        img = update.saveAndReturnObject(img)
        img.unload()
        
        dil = DatasetImageLinkI()
        dil.setParent(ds)
        dil.setChild(img)
        dil = update.saveAndReturnObject(dil)
        dil.unload()
        
        # create share by root
        items = list()
        ms = list()
        
        p = omero.sys.Parameters()
        p.map = {}
        p.map["oid"] = ds.id
        sql = "select ds from Dataset ds join fetch ds.details.owner join fetch ds.details.group " \
              "left outer join fetch ds.imageLinks dil left outer join fetch dil.child i " \
              "where ds.id=:oid"
        items.extend(query.findAllByQuery(sql, p))
        self.assertEquals(1, len(items))
        
        #members
        p.map["eid"] = rlong(user1.id.val)
        sql = "select e from Experimenter e where e.id =:eid order by e.omeName"
        ms = query.findAllByQuery(sql, p)
        sid = share.createShare(("test-share-%s" % uuid), rtime(long(time.time()*1000 + 86400)) , items, ms, [], True)
        
        # USER RETRIEVAL
        ## login as user1
        share1 = client_share1.sf.getShareService()
        query1 = client_share1.sf.getQueryService()
        cntar1 = client_share1.sf.getContainerService()
        
        content = share1.getContents(sid)
        # Content now contains just the dataset with nothing loaded
        self.assertEquals(1, len(content))

        # get shared dataset and image when share is activated
        share1.activate(sid)

        #retrieve dataset
        p = omero.sys.Parameters()
        p.map = {}
        p.map["ids"] = rlist([ds.id])
        sql = "select ds from Dataset ds join fetch ds.details.owner join fetch ds.details.group " \
              "left outer join fetch ds.imageLinks dil left outer join fetch dil.child i " \
              "where ds.id in (:ids) order by ds.name"
        try:
            res1 = query1.findAllByQuery(sql, p)
            self.fail("This should throw an exception")
        except:
            pass

        #
        # Now we add all the other elements to the share to prevent
        # the security violation
        #
        # Not working imgs = cntar.getImages("Dataset",[ds.id.val], None)
        img = query.findByQuery("select i from Image i join fetch i.datasetLinks dil join dil.parent d where d.id = %s " % ds.id.val, None)
        self.assert_(img)
        share.addObject(sid, img)
        share.addObjects(sid, img.copyDatasetLinks())
        self.assertEquals(3, len(share.getContents(sid)))

        #
        # And try again to load them
        #
        share1.activate(sid)
        res1 = query1.findAllByQuery(sql, p)
        self.assert_(len(res1) == 1)
        for e in res1:
            self.assert_(e.id.val == ds.id.val)

        # retrieve only image
        p = omero.sys.Parameters()
        p.map = {}
        p.map["oid"] = rlong(img.id)
        sql = "select im from Image im " \
              "where im.id=:oid order by im.name"
        res2 = query1.findByQuery(sql, p)
        self.assert_(res2.id.val == img.id.val)
Exemple #40
0
    def test_batch_roi_export(self, all_planes):
        sid = super(TestExportScripts, self).get_script(batch_roi_export)
        assert sid > 0

        client, user = self.new_client_and_user()
        session = client.getSession()
        # x,y,z,c,t
        size_c = 2
        size_z = 3
        size_t = 4
        image_name = "ROI_image"
        label_text = "Shape_Text"
        image = self.create_test_image(100,
                                       100,
                                       size_z,
                                       size_c,
                                       size_t,
                                       session,
                                       name=image_name)
        # Add 2 Shapes... A Rectangle and Polygon covering same area
        polygon = omero.model.PolygonI()
        polygon.points = rstring("10,10, 91,10, 91,91, 10,91")
        polygon.textValue = rstring(label_text)
        rect = omero.model.RectangleI()
        rect.x = rdouble(10)
        rect.y = rdouble(10)
        rect.width = rdouble(81)
        rect.height = rdouble(81)
        rect.theZ = rint(1)
        rect.theT = rint(1)
        # ...to an ROI
        roi = omero.model.RoiI()
        roi.setImage(image)
        roi.addShape(polygon)
        roi.addShape(rect)
        roi = session.getUpdateService().saveAndReturnObject(roi)
        shapes = roi.copyShapes()
        polygon = shapes[0]

        image_ids = []
        file_name = "test_batch_roi_export"
        image_ids.append(rlong(image.id.val))
        channels = [rint(c) for c in range(4)]
        args = {
            "Data_Type": rstring("Image"),
            "IDs": rlist(image_ids),
            # Should ignore Channels out of range. 1-based index
            "Channels": rlist(channels),
            "Export_All_Planes": rbool(all_planes),
            "File_Name": rstring(file_name)
        }
        ann = run_script(client, sid, args, "File_Annotation")
        c = self.new_client(user=user)
        check_file_annotation(c, ann, file_name="%s.csv" % file_name)
        file_id = ann.getValue().getFile().id.val
        csv_text = get_file_contents(self.new_client(user=user), file_id)

        # Check we have expected number of rows
        polygon_planes = size_c
        if all_planes:
            polygon_planes = size_c * size_z * size_t
        # Rows: Header + rect with Z/T set + polygon without Z/T
        row_count = 1 + size_c + polygon_planes
        assert len(csv_text.split("\n")) == row_count

        # Check first 2 rows of csv (except Std dev)
        zt = ","
        points_min_max_sum_mean = ",,,,"
        area = "6561.0"
        if all_planes:
            zt = "1,1"
            points_min_max_sum_mean = "6561,10.0,90.0,328050.0,50.0"
        expected = ("image_id,image_name,roi_id,shape_id,type,text,"
                    "z,t,channel,area (pixels),length (pixels),"
                    "points,min,max,sum,mean,std_dev,"
                    "X,Y,Width,Height,RadiusX,RadiusY,X1,Y1,X2,Y2,Points\n"
                    "%s,\"%s\",%s,%s,polygon,\"%s\",%s,0,%s,,%s,") % (
                        image.id.val, image_name, roi.id.val, polygon.id.val,
                        label_text, zt, area, points_min_max_sum_mean)
        assert csv_text.startswith(expected)
 def testPassThroughNoneAndRTypes(self):
     """
     To prevent having to check for isintance(int,...) or
     isintance(RInt,...) all over the place, the static methods
     automatically check for acceptable
     types and simply pass them through. Similarly, the primitive types all
     check for None and return a null RType if necessary.
     """
     # Bool
     assert None == rbool(None)
     assert rbool(True) == rbool(rbool(True))
     assert rbool(True) == rbool(1)
     assert rbool(False) == rbool(0)
     # Double
     assert None == rdouble(None)
     assert rdouble(0.0) == rdouble(rdouble(0.0))
     assert rdouble(0.0) == rdouble(rdouble(0))
     assert rdouble(0.0) == rdouble(rdouble("0.0"))
     pytest.raises(ValueError, lambda: rdouble("string"))
     # Float
     assert None == rfloat(None)
     assert rfloat(0.0) == rfloat(rfloat(0.0))
     assert rfloat(0.0) == rfloat(rfloat(0))
     assert rfloat(0.0) == rfloat(rfloat("0.0"))
     pytest.raises(ValueError, lambda: rfloat("string"))
     # Long
     assert None == rlong(None)
     assert rlong(0) == rlong(rlong(0))
     assert rlong(0) == rlong(rlong(0.0))
     assert rlong(0) == rlong(rlong("0"))
     pytest.raises(ValueError, lambda: rlong("string"))
     # Time
     assert None == rtime(None)
     assert rtime(0) == rtime(rtime(0))
     assert rtime(0) == rtime(rtime(0.0))
     assert rtime(0) == rtime(rtime("0"))
     pytest.raises(ValueError, lambda: rtime("string"))
     # Int
     assert None == rint(None)
     assert rint(0) == rint(rint(0))
     assert rint(0) == rint(rint(0.0))
     assert rint(0) == rint(rint("0"))
     pytest.raises(ValueError, lambda: rint("string"))
     #
     # Starting here handling of null is different.
     #
     # String
     assert rstring("") == rstring(None)
     assert rstring("a") == rstring(rstring("a"))
     assert rstring("0") == rstring(0)
     # Class
     assert rclass("") == rclass(None)
     assert rclass("c") == rclass(rclass("c"))
     pytest.raises(ValueError, lambda: rclass(0))
     # Internal
     internal = omero.Internal()
     assert rinternal(None) == rinternal(None)
     assert rinternal(internal) == rinternal(rinternal(internal))
     pytest.raises(ValueError, lambda: rinternal("string"))
     # Object
     obj = omero.model.ImageI()
     assert robject(None) == robject(None)
     assert robject(obj) == robject(robject(obj))
     pytest.raises(ValueError, lambda: robject("string"))
     #
     # Same does not hold for collections
     #
     # Array
     assert rarray([]) == rarray(None)
     # assert rarray(obj) == rarray(rarray(obj))
     # pytest.raises(ValueError, lambda : rarray("string"))
     # List
     assert rlist([]) == rlist(None)
     # assert rlist(obj) == rlist(rlist(obj))
     # pytest.raises(ValueError, lambda : rlist("string"))
     # Set
     assert rset([]) == rset(None)
     # assert rset(obj) == rset(rset(obj))
     # pytest.raises(ValueError, lambda : rset("string"))
     # Map
     assert rmap({}) == rmap(None)
 def addLongs(self, name, longs):
     rlongs = rlist([])
     for l in longs:
         rlongs.val.append(rlong(l))
     self.add(name, rlongs)
     return self
Exemple #43
0
    def testUnwrap(self):
        # NUMS plain
        assert 0 == unwrap(0)
        assert 1 == unwrap(1)
        assert 0.0 == unwrap(0.0)
        assert 1.0 == unwrap(1.0)
        # NUMS rtyped
        assert 0 == unwrap(rint(0))
        assert 0 == unwrap(rlong(0))
        assert 1 == unwrap(rint(1))
        assert 1 == unwrap(rlong(1))
        assert 0.0 == unwrap(rfloat(0.0))
        assert 0.0 == unwrap(rdouble(0.0))
        assert 1.0 == unwrap(rfloat(1.0))
        assert 1.0 == unwrap(rdouble(1.0))

        # STRINGS
        assert "" == unwrap("")
        assert "str" == unwrap("str")

        # BOOL
        assert True == unwrap(True)
        assert False == unwrap(False)
        assert True == unwrap(rbool(True))
        assert False == unwrap(rbool(False))

        # TIME
        # Bit odd, do we want the long for time, or transformed?
        assert 0 == unwrap(rtime(0))
        assert 1 == unwrap(rtime(1))

        # CLASS
        # same for class, should we map it?
        assert "k" == unwrap(rclass("k"))

        # INTERNAL
        color = omero.Color()
        assert color == unwrap(rinternal(color))

        # OBJECT
        image = omero.model.ImageI()
        assert image == unwrap(robject(image))

        # COLLECTIONS
        # empty
        assert [] == unwrap([])
        assert {} == unwrap({})
        assert set() == unwrap(set())
        # plain in collection
        assert [1] == unwrap([1])
        # rtype in collection
        assert [1] == unwrap([rint(1)])
        assert {"a": 1} == unwrap({"a": 1})
        # plain in rcollection ILLEGAL
        # assert [1] == unwrap(rlist([1]))
        # assert {"a":1} == unwrap(rmap({"a":1}))
        # rtype in rcollection
        assert [1] == unwrap(rlist([rint(1)]))
        assert {"a": 1} == unwrap(rmap({"a": rint(1)}))
        # rtype keys ILLEGAL
        # assert {"a":1} == unwrap(rmap({rstring("a"):rint(1)}))
        # recursion, ticket:1977
        m1 = rmap({"a": rint(1)})
        m1.val["m1"] = m1
        m2 = {"a": 1}
        m2["m1"] = m2
        unwrap(m1)
        assert m2["a"] == unwrap(m1)["a"]
        # Can't compare directly "maximum recursion depth exceeded in cmp"
        assert type(m2["m1"]) == type(unwrap(m1)["m1"])
Exemple #44
0
    def manage_duplicate_tags(self,
                              client,
                              target_tag_id=None,
                              merge_tag_ids=None,
                              dry_run=False):
        params = om_sys.Parameters()
        params.map = {}
        query_filter = om_sys.Filter()
        #query_filter.limit = rtypes.rint(10) # should limit and enhance performance of query, but does not seem to
        params.theFilter = query_filter
        anno_list = []

        if merge_tag_ids == None or len(merge_tag_ids) == 0:
            anno_list = self.find_objects_by_query(client,
                                                   DUPLICATE_TAGS_S1_QUERY,
                                                   params)
            anno_list.extend(
                self.find_objects_by_query(client, DUPLICATE_TAGS_S2_QUERY,
                                           params))
            anno_list.extend(
                self.find_objects_by_query(client, DUPLICATE_TAGS_S3_QUERY,
                                           params))
            anno_list.extend(
                self.find_objects_by_query(client, DUPLICATE_TAGS_S4_QUERY,
                                           params))
            anno_list.extend(
                self.find_objects_by_query(client, DUPLICATE_TAGS_S5_QUERY,
                                           params))
            anno_list.extend(
                self.find_objects_by_query(client, DUPLICATE_TAGS_S6_QUERY,
                                           params))
        else:
            if len(merge_tag_ids) > 0:
                all_tag_ids = merge_tag_ids
                all_tag_ids.append(target_tag_id)
                anno_ids = map(rtypes.rlong, all_tag_ids)
                params.map = {'aids': rtypes.rlist(anno_ids)}
                anno_list = self.find_objects_by_query(client,
                                                       ANNOS_BY_IDS_QUERY,
                                                       params)

        cur_tag_name, cur_tag_id = None, None
        duplicate_tag_ids = []
        merge_tag_id = None

        if merge_tag_ids == None or len(merge_tag_ids) == 0:
            for anno in anno_list:
                if isinstance(anno, model.TagAnnotationI):
                    tag_name = anno.getTextValue().getValue()
                    tag_id = anno.getId().getValue()

                    if tag_name != cur_tag_name and tag_id != cur_tag_id:
                        # it's a fresh tag; find all datasets for tag and update them
                        # params.map = {'aid': rtypes.rlong(cur_tag_id)}
                        if len(duplicate_tag_ids) > 0:
                            if target_tag_id is None:
                                merge_tag_id = cur_tag_id
                            else:
                                merge_tag_id = target_tag_id

                            self.do_tag_merge(client,
                                              merge_tag_id,
                                              duplicate_tag_ids,
                                              dry_run=dry_run)

                        # reset the parameters
                        cur_tag_name = tag_name
                        cur_tag_id = tag_id
                        duplicate_tag_ids = []
                        merge_tag_id = None
                    elif tag_name == cur_tag_name and tag_id != cur_tag_id:
                        # it's a duplicate tag;
                        if tag_id not in duplicate_tag_ids:
                            duplicate_tag_ids.append(tag_id)
        else:
            duplicate_tag_ids = merge_tag_ids

        # catch the final iteration
        if len(duplicate_tag_ids) > 0:
            if target_tag_id is None:
                merge_tag_id = cur_tag_id
            else:
                merge_tag_id = target_tag_id

            self.do_tag_merge(client,
                              merge_tag_id,
                              duplicate_tag_ids,
                              dry_run=dry_run)
Exemple #45
0
def _set_parameters(mapann_ns=[],
                    mapann_names=[],
                    mapann_value=None,
                    query=False,
                    case_sensitive=True,
                    params=None,
                    experimenter_id=-1,
                    page=None,
                    limit=settings.PAGE):
    ''' Helper to map ParametersI

        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param params Instance of ParametersI
        @type params L{omero.sys.ParametersI}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to None
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''

    if params is None:
        params = omero.sys.ParametersI()

    # Paging
    if page is not None and page > 0:
        params.page((page - 1) * limit, limit)

    where_clause = []

    if mapann_names is not None and len(mapann_names) > 0:
        manlist = [rstring(n) for n in mapann_names]
        params.add('filter', rlist(manlist))
        where_clause.append("mv.name in (:filter)")

    if mapann_ns is not None and len(mapann_ns) > 0:
        mnslist = [rstring(n) for n in mapann_ns]
        params.add("ns", rlist(mnslist))
        where_clause.append("a.ns in (:ns)")

    if experimenter_id is not None and experimenter_id != -1:
        params.addId(experimenter_id)
        where_clause.append("a.details.owner.id = :id")

    if mapann_value:
        mapann_value = mapann_value if case_sensitive else mapann_value.lower()
        _cwc = 'mv.value' if case_sensitive else 'lower(mv.value)'
        if query:
            params.addString(
                "query", rstring("%%%s%%" % _escape_chars_like(mapann_value)))
            where_clause.append("%s like :query" % _cwc)
        else:
            params.addString('value', mapann_value)
            where_clause.append("%s  = :value" % _cwc)
    else:
        where_clause.append("mv.value != '' ")

    return params, where_clause
Exemple #46
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from omero.rtypes import rstring, rint, rset, rlist

# Sets and Lists may be interpreted differently on the server
list = rlist(rstring("a"), rstring("b"))
set = rset(rint(1), rint(2))
    def test3639(self):
        uuid = self.ctx.sessionUuid

        images = list()
        for i in range(0, 5):
            images.append(self.make_image())

        p = omero.sys.Parameters()
        p.map = {}
        p.map["oids"] = rlist([rlong(s.id.val) for s in images])

        # create dataset
        dataset = self.make_dataset('DS-test-2936-%s' % uuid)

        # put image in dataset
        for image in images:
            self.link(dataset, image)

        # log in as group owner:
        client_o, owner = self.new_client_and_user(group=self.group,
                                                   owner=True)
        query_o = client_o.sf.getQueryService()

        handlers = list()
        keep = ChildOption(excludeType=["Image"])
        dc = Delete2(targetObjects={'Dataset': [dataset.id.val]},
                     childOptions=[keep])
        handlers.append(str(client_o.sf.submit(dc)))

        imageToDelete = images[2].id.val
        dc2 = Delete2(targetObjects={'Image': [imageToDelete]})
        handlers.append(str(client_o.sf.submit(dc2)))

        def _formatReport(delete_handle):
            """
            Added as workaround to the changes made in #3006.
            """
            delete_report = delete_handle.getResponse()
            rv = []
            if isinstance(delete_report, omero.cmd.ERR):
                rv.append(str(delete_report))
            if len(rv) > 0:
                return "; ".join(rv)
            return None

        failure = list()
        in_progress = 0
        r = None

        while (len(handlers) > 0):
            for cbString in handlers:
                try:
                    with pytest.raises(Ice.ObjectNotExistException):
                        handle = omero.cmd.HandlePrx.checkedCast(
                            client_o.ic.stringToProxy(cbString))
                        cb = omero.callbacks.CmdCallbackI(client_o, handle)
                        if not cb.block(500):  # ms.
                            # No errors possible if in progress(
                            # (since no response)
                            print "in progress", _formatReport(handle)
                            in_progress += 1
                        else:
                            rsp = cb.getResponse()
                            if isinstance(rsp, omero.cmd.ERR):
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                else:
                                    failure.append("No report!!!")
                            else:
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                cb.close(True)  # Close handle
                            handlers.remove(cbString)
                except Exception:
                    if r is not None:
                        failure.append(traceback.format_exc())

        if len(failure) > 0:
            assert False, ";".join(failure)
        assert not query_o.find('Dataset', dataset.id.val)
    def test3639(self):
        uuid = self.client.sf.getAdminService().getEventContext().sessionUuid
        group = self.client.sf.getAdminService().getGroup(
            self.client.sf.getAdminService().getEventContext().groupId)
        update = self.client.sf.getUpdateService()

        images = list()
        for i in range(0, 5):
            img = self.new_image()
            img = update.saveAndReturnObject(img)
            images.append(img.id.val)

        p = omero.sys.Parameters()
        p.map = {}
        p.map["oids"] = rlist([rlong(s) for s in images])

        # create dataset
        dataset = omero.model.DatasetI()
        dataset.name = rstring('DS-test-2936-%s' % (uuid))
        dataset = update.saveAndReturnObject(dataset)

        # put image in dataset
        for iid in images:
            dlink = omero.model.DatasetImageLinkI()
            dlink.parent = omero.model.DatasetI(dataset.id.val, False)
            dlink.child = omero.model.ImageI(iid, False)
            update.saveAndReturnObject(dlink)

        # log in as group owner:
        client_o, owner = self.new_client_and_user(group=group, admin=True)
        query_o = client_o.sf.getQueryService()

        handlers = list()
        op = dict()
        op["/Image"] = "KEEP"
        dc = omero.cmd.Delete('/Dataset', long(dataset.id.val), op)
        handlers.append(str(client_o.sf.submit(dc)))

        imageToDelete = images[2]
        images.remove(imageToDelete)
        dc2 = omero.cmd.Delete('/Image', long(imageToDelete), {})
        handlers.append(str(client_o.sf.submit(dc2)))

        def _formatReport(delete_handle):
            """
            Added as workaround to the changes made in #3006.
            """
            delete_report = delete_handle.getResponse()
            rv = []
            if isinstance(delete_report, omero.cmd.ERR):
                rv.append(str(delete_report))
            else:
                if delete_report.warning:
                    rv.append(delete_report.warning)
            if len(rv) > 0:
                return "; ".join(rv)
            return None

        failure = list()
        in_progress = 0
        r = None

        while(len(handlers) > 0):
            for cbString in handlers:
                try:
                    with pytest.raises(Ice.ObjectNotExistException):
                        handle = omero.cmd.HandlePrx.checkedCast(
                            client_o.ic.stringToProxy(cbString))
                        cb = omero.callbacks.CmdCallbackI(client_o, handle)
                        if not cb.block(500):  # ms.
                            # No errors possible if in progress(
                            # (since no response)
                            print "in progress", _formatReport(handle)
                            in_progress += 1
                        else:
                            rsp = cb.getResponse()
                            if isinstance(rsp, omero.cmd.ERR):
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                else:
                                    failure.append("No report!!!")
                            else:
                                r = _formatReport(handle)
                                if r is not None:
                                    failure.append(r)
                                cb.close(True)  # Close handle
                            handlers.remove(cbString)
                except Exception:
                    if r is not None:
                        failure.append(traceback.format_exc())

        if len(failure) > 0:
            assert False, ";".join(failure)
        assert not query_o.find('Dataset', dataset.id.val)