Exemplo n.º 1
0
    def testChgrpImage(self):
        """
        Tests chgrp for a dummny image object (no Pixels)
        """
        # One user in two groups
        client, exp = self.new_client_and_user()
        grp = self.new_group([exp])
        gid = grp.id.val
        client.sf.getAdminService().getEventContext()  # Reset session
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()
        admin = client.sf.getAdminService()
        first_gid = admin.getEventContext().groupId

        # Create a dataset in the 'first group'
        ds = self.make_dataset(name="testChgrpImage_target", client=client)
        ds_id = ds.id.val

        # Change our context to new group and create image
        admin.setDefaultGroup(exp, ExperimenterGroupI(gid, False))
        self.set_context(client, gid)
        update = client.sf.getUpdateService()   # do we need to get this again?
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # Move image to new group
        chgrp = Chgrp2(
            targetObjects={'Image': [img.id.val]}, groupId=first_gid)

        # Link to Save
        link = DatasetImageLinkI()
        link.child = ImageI(img.id.val, False)
        link.parent = DatasetI(ds_id, False)
        save = Save()
        save.obj = link
        requests = [chgrp, save]        # we're going to chgrp THEN save DIlink

        # Change our context to original group...
        admin.setDefaultGroup(exp, ExperimenterGroupI(first_gid, False))
        self.set_context(client, first_gid)

        # We have to be in destination group for link Save to work
        self.doSubmit(requests, client)

        # ...check image
        img = client.sf.getQueryService().get("Image", img.id.val)
        assert img.details.group.id.val == first_gid
        # check Dataset
        query = "select link from DatasetImageLink link\
            where link.child.id=%s" % img.id.val
        l = client.sf.getQueryService().findByQuery(query, None)
        assert l is not None, "New DatasetImageLink on image not found"
        assert l.details.group.id.val == first_gid,\
            "Link Created in same group as Image target"
Exemplo n.º 2
0
    def testChgrpImage(self):
        """
        Tests chgrp for a dummny image object (no Pixels)
        """
        # One user in two groups
        client, exp = self.new_client_and_user()
        grp = self.new_group([exp])
        gid = grp.id.val
        client.sf.getAdminService().getEventContext()  # Reset session
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()
        admin = client.sf.getAdminService()
        first_gid = admin.getEventContext().groupId

        # Create a dataset in the 'first group'
        ds = self.make_dataset(name="testChgrpImage_target", client=client)
        ds_id = ds.id.val

        # Change our context to new group and create image
        admin.setDefaultGroup(exp, ExperimenterGroupI(gid, False))
        self.set_context(client, gid)
        update = client.sf.getUpdateService()  # do we need to get this again?
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # Move image to new group
        chgrp = Chgrp2(targetObjects={'Image': [img.id.val]},
                       groupId=first_gid)

        # Link to Save
        link = DatasetImageLinkI()
        link.child = ImageI(img.id.val, False)
        link.parent = DatasetI(ds_id, False)
        save = Save()
        save.obj = link
        requests = [chgrp, save]  # we're going to chgrp THEN save DIlink

        # Change our context to original group...
        admin.setDefaultGroup(exp, ExperimenterGroupI(first_gid, False))
        self.set_context(client, first_gid)

        # We have to be in destination group for link Save to work
        self.doSubmit(requests, client)

        # ...check image
        img = client.sf.getQueryService().get("Image", img.id.val)
        assert img.details.group.id.val == first_gid
        # check Dataset
        query = "select link from DatasetImageLink link\
            where link.child.id=%s" % img.id.val
        l = client.sf.getQueryService().findByQuery(query, None)
        assert l is not None, "New DatasetImageLink on image not found"
        assert l.details.group.id.val == first_gid,\
            "Link Created in same group as Image target"
Exemplo n.º 3
0
def images_to_dataset(conn, params):
    figure_ids = params["Figure_IDs"]
    dataset_id = params["IDs"][0]

    dataset = conn.getObject("Dataset", dataset_id)
    if dataset is None:
        return "Dataset %s not found" % dataset_id, dataset

    gid = dataset.getDetails().group.id.val
    print("Dataset: %s, Group: %s" % (dataset.name, gid))

    update = conn.getUpdateService()
    conn.SERVICE_OPTS.setOmeroGroup(-1)

    if len(figure_ids) == 0:
        return "Enter Figure IDs separated with a comma: '1,2'", dataset
    image_ids = []
    for figure_id in figure_ids:
        file_ann = conn.getObject("FileAnnotation", figure_id)
        if file_ann is None:
            print("Figure File-Annotation %s not found" % figure_id)
        figure_json = b"".join(list(file_ann.getFileInChunks()))
        figure_json = figure_json.decode('utf8')
        json_data = json.loads(figure_json)

        image_ids.extend([p["imageId"] for p in json_data.get("panels")])

    image_ids = list(set(image_ids))
    if len(image_ids) == 0:
        return "No Images found. Check Info log", dataset
    print("Image IDs: %s" % image_ids)

    conn.SERVICE_OPTS.setOmeroGroup(gid)

    added_count = 0
    for image_id in image_ids:
        link = DatasetImageLinkI()
        link.parent = DatasetI(dataset_id, False)
        link.child = ImageI(image_id, False)
        try:
            update.saveObject(link, conn.SERVICE_OPTS)
            added_count += 1
        except Exception:
            print("Image %s not linked to Dataset. "
                  "Link exists or permissions failed" % image_id)
    return "Added %s images to Dataset" % added_count, dataset
Exemplo n.º 4
0
    def chgrpImagesToTargetDataset(self, imgCount):
        """
        Helper method to test chgrp of image(s) to target Dataset
        """
        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        admin = client.sf.getAdminService()
        target_grp = self.new_group([user], perms=PRIVATE)
        target_gid = target_grp.id.val

        images = self.importMIF(imgCount, client=client)
        ds = self.createDSInGroup(target_gid, client=client)

        # each chgrp includes a 'save' link to target dataset
        saves = []
        ids = []
        for i in images:
            ids.append(i.id.val)
            link = DatasetImageLinkI()
            link.child = ImageI(i.id.val, False)
            link.parent = DatasetI(ds.id.val, False)
            save = Save()
            save.obj = link
            saves.append(save)
        chgrp = Chgrp2(
            targetObjects={"Image": ids}, groupId=target_gid)
        requests = [chgrp]
        requests.extend(saves)
        self.doSubmit(requests, client, omero_group=target_gid)

        # Check Images moved to correct group
        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        for i in images:
            image = queryService.get('Image', i.id.val, ctx)
            img_gid = image.details.group.id.val
            assert target_gid == img_gid,\
                "Image should be in group: %s, NOT %s" % (target_gid,  img_gid)
        # Check Dataset has images linked
        dsImgs = client.sf.getContainerService().getImages(
            'Dataset', [ds.id.val], None, ctx)
        assert len(dsImgs) == len(images),\
            "All Images should be in target Dataset"

        previous_gid = admin.getEventContext().groupId
        return (ds, images, client, user, previous_gid, target_gid)
Exemplo n.º 5
0
    def chgrpImagesToTargetDataset(self, imgCount):
        """
        Helper method to test chgrp of image(s) to target Dataset
        """
        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        admin = client.sf.getAdminService()
        target_grp = self.new_group([user], perms=PRIVATE)
        target_gid = target_grp.id.val

        images = self.importMIF(imgCount, client=client)
        ds = self.createDSInGroup(target_gid, client=client)

        # each chgrp includes a 'save' link to target dataset
        saves = []
        ids = []
        for i in images:
            ids.append(i.id.val)
            link = DatasetImageLinkI()
            link.child = ImageI(i.id.val, False)
            link.parent = DatasetI(ds.id.val, False)
            save = Save()
            save.obj = link
            saves.append(save)
        chgrp = Chgrp2(targetObjects={"Image": ids}, groupId=target_gid)
        requests = [chgrp]
        requests.extend(saves)
        self.doSubmit(requests, client, omero_group=target_gid)

        # Check Images moved to correct group
        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        for i in images:
            image = queryService.get('Image', i.id.val, ctx)
            img_gid = image.details.group.id.val
            assert target_gid == img_gid,\
                "Image should be in group: %s, NOT %s" % (target_gid,  img_gid)
        # Check Dataset has images linked
        dsImgs = client.sf.getContainerService().getImages(
            'Dataset', [ds.id.val], None, ctx)
        assert len(dsImgs) == len(images),\
            "All Images should be in target Dataset"

        previous_gid = admin.getEventContext().groupId
        return (ds, images, client, user, previous_gid, target_gid)
Exemplo n.º 6
0
    def testChgrpImageToTargetDatasetAndBackDS(self):
        """
        Chgrp a single Image to target Dataset and then back
        see ticket:11118
        """
        new_ds, images, client, user, old_gid, new_gid =\
            self.chgrpImagesToTargetDataset(1)

        # create Dataset in original group
        old_ds = self.createDSInGroup(old_gid, client=client)
        link = DatasetImageLinkI()
        link.parent = old_ds.proxy()
        link.child = images[0].proxy()

        chgrp = Chgrp2(
            targetObjects={"Image": [images[0].id.val]}, groupId=old_gid)
        save = Save(link)
        self.doSubmit([chgrp, save], client, omero_group=old_gid)

        dils = client.sf.getQueryService().findAllByQuery(
            "select dil from DatasetImageLink dil where dil.child.id = :id",
            omero.sys.ParametersI().addId(images[0].id.val),
            {"omero.group": "-1"})
        assert 1 == len(dils)
Exemplo n.º 7
0
    def testChgrpImageToTargetDatasetAndBackDS(self):
        """
        Chgrp a single Image to target Dataset and then back
        see ticket:11118
        """
        new_ds, images, client, user, old_gid, new_gid =\
            self.chgrpImagesToTargetDataset(1)

        # create Dataset in original group
        old_ds = self.createDSInGroup(old_gid, client=client)
        link = DatasetImageLinkI()
        link.parent = old_ds.proxy()
        link.child = images[0].proxy()

        chgrp = Chgrp2(targetObjects={"Image": [images[0].id.val]},
                       groupId=old_gid)
        save = Save(link)
        self.doSubmit([chgrp, save], client, omero_group=old_gid)

        dils = client.sf.getQueryService().findAllByQuery(
            "select dil from DatasetImageLink dil where dil.child.id = :id",
            omero.sys.ParametersI().addId(images[0].id.val),
            {"omero.group": "-1"})
        assert 1 == len(dils)