Skip to content

Commit 6ce1c1a

Browse files
committed
Refactors ome#555 to allow for backward compatibility
There were certain downstream omero-web plugins which were using `_marshal_image()`. This refactors the changes of ome#555 such that the prototype of `_marshal_image()` is maintained and a new `_marshal_image_map()` is added to give us options going forward for scalability.
1 parent f347f53 commit 6ce1c1a

File tree

1 file changed

+75
-46
lines changed

1 file changed

+75
-46
lines changed

Diff for: omeroweb/webclient/tree.py

+75-46
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ def _marshal_image(
531531
"""Given an Image row (list) marshals it into a dictionary. Order
532532
and type of columns in row is:
533533
* id (rlong)
534-
* archived (boolean)
535534
* name (rstring)
536535
* details.owner.id (rlong)
537536
* details.permissions (dict)
@@ -550,22 +549,74 @@ def _marshal_image(
550549
@param row_pixels The Image row pixels data to marshal
551550
@type row_pixels L{list}
552551
"""
553-
image_id, archived, name, owner_id, permissions, fileset_id = row
552+
image_id, name, owner_id, permissions, fileset_id = row
553+
data = {
554+
"id": image_id,
555+
"name": name,
556+
"ownerId": owner_id,
557+
"image_details_permissions": permissions,
558+
"filesetId": fileset_id,
559+
}
560+
if row_pixels:
561+
sizeX, sizeY, sizeZ, sizeT = row_pixels
562+
data["sizeX"] = sizeX
563+
data["sizeY"] = sizeY
564+
data["sizeZ"] = sizeZ
565+
data["sizeT"] = sizeT
566+
return _marshal_image_map(
567+
conn,
568+
data,
569+
share_id=share_id,
570+
date=date,
571+
acqDate=acqDate,
572+
thumbVersion=thumbVersion,
573+
)
574+
575+
576+
def _marshal_image_map(
577+
conn,
578+
data,
579+
share_id=None,
580+
date=None,
581+
acqDate=None,
582+
thumbVersion=None,
583+
):
584+
"""Given an Image data dictionary marshals it into a dictionary. Suppored keys are:
585+
* id (rlong)
586+
* archived (boolean; optional)
587+
* name (rstring)
588+
* ownerId (rlong)
589+
* image_details_permissions (dict)
590+
* filesetId (rlong)
591+
* sizeX (rlong; optional)
592+
* sizeY (rlong; optional)
593+
* sizeZ (rlong; optional)
594+
* sizeT (rlong; optional)
595+
596+
@param conn OMERO gateway.
597+
@type conn L{omero.gateway.BlitzGateway}
598+
@param data The data to marshal
599+
@type row L{dict}
600+
"""
554601
image = dict()
555-
image["id"] = unwrap(image_id)
556-
image["archived"] = unwrap(archived) is True
557-
image["name"] = unwrap_to_str(name)
558-
image["ownerId"] = unwrap(owner_id)
559-
image["permsCss"] = parse_permissions_css(permissions, unwrap(owner_id), conn)
560-
fileset_id_val = unwrap(fileset_id)
602+
image["id"] = unwrap(data["imageId"])
603+
image["archived"] = unwrap(data.get("archived")) is True
604+
image["name"] = unwrap_to_str(data["name"])
605+
image["ownerId"] = unwrap(data["ownerId"])
606+
image["permsCss"] = parse_permissions_css(
607+
data["image_details_permissions"], unwrap(data["ownerId"]), conn
608+
)
609+
fileset_id_val = unwrap(data["filesetId"])
561610
if fileset_id_val is not None:
562611
image["filesetId"] = fileset_id_val
563-
if row_pixels:
564-
sizeX, sizeY, sizeZ, sizeT = row_pixels
565-
image["sizeX"] = unwrap(sizeX)
566-
image["sizeY"] = unwrap(sizeY)
567-
image["sizeZ"] = unwrap(sizeZ)
568-
image["sizeT"] = unwrap(sizeT)
612+
if "sizeX" in data:
613+
image["sizeX"] = unwrap(data["sizeX"])
614+
if "sizeY" in data:
615+
image["sizeY"] = unwrap(data["sizeY"])
616+
if "sizeZ" in data:
617+
image["sizeZ"] = unwrap(data["sizeZ"])
618+
if "sizeT" in data:
619+
image["sizeT"] = unwrap(data["sizeT"])
569620
if share_id is not None:
570621
image["shareId"] = share_id
571622
if date is not None:
@@ -753,31 +804,20 @@ def marshal_images(
753804
)
754805

755806
for e in qs.projection(q, params, service_opts):
756-
e = unwrap(e)[0]
757-
d = [
758-
e["id"],
759-
e["archived"],
760-
e["name"],
761-
e["ownerId"],
762-
e["image_details_permissions"],
763-
e["filesetId"],
764-
]
765-
kwargs = {"conn": conn, "row": d[0:6]}
766-
if load_pixels:
767-
d = [e["sizeX"], e["sizeY"], e["sizeZ"], e["sizeT"]]
768-
kwargs["row_pixels"] = d
807+
data = unwrap(e)[0]
808+
kwargs = {}
769809
if date:
770-
kwargs["acqDate"] = e["acqDate"]
771-
kwargs["date"] = e["date"]
810+
kwargs["acqDate"] = data["acqDate"]
811+
kwargs["date"] = data["date"]
772812

773813
# While marshalling the images, determine if there are any
774814
# images mentioned in shares that are not in the results
775815
# because they have been deleted
776-
if share_id is not None and image_rids and e["id"] in image_rids:
816+
if share_id is not None and image_rids and data["id"] in image_rids:
777817
image_rids.remove(e["id"])
778818
kwargs["share_id"] = share_id
779819

780-
images.append(_marshal_image(**kwargs))
820+
images.append(_marshal_image_map(conn, data, **kwargs))
781821

782822
# Load thumbnails separately
783823
# We want version of most recent thumbnail (max thumbId) owned by user
@@ -1536,23 +1576,12 @@ def marshal_tagged(
15361576

15371577
images = []
15381578
for e in qs.projection(q, params, service_opts):
1539-
e = unwrap(e)
1540-
row = [
1541-
e[0]["id"],
1542-
e[0]["archived"],
1543-
e[0]["name"],
1544-
e[0]["ownerId"],
1545-
e[0]["image_details_permissions"],
1546-
e[0]["filesetId"],
1547-
]
1579+
data = unwrap(e)[0]
15481580
kwargs = {}
1549-
if load_pixels:
1550-
d = [e[0]["sizeX"], e[0]["sizeY"], e[0]["sizeZ"], e[0]["sizeT"]]
1551-
kwargs["row_pixels"] = d
15521581
if date:
1553-
kwargs["acqDate"] = e[0]["acqDate"]
1554-
kwargs["date"] = e[0]["date"]
1555-
images.append(_marshal_image(conn, row, **kwargs))
1582+
kwargs["acqDate"] = data["acqDate"]
1583+
kwargs["date"] = data["date"]
1584+
images.append(_marshal_image_map(conn, data, **kwargs))
15561585
tagged["images"] = images
15571586

15581587
# Screens

0 commit comments

Comments
 (0)