Skip to content

Commit d2f8480

Browse files
authored
Merge pull request #453 from will-moore/externalInfo
getObject() and getExternalInfo() load externalInfo
2 parents e485be4 + 41a85bd commit d2f8480

2 files changed

Lines changed: 103 additions & 2 deletions

File tree

src/omero/gateway/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def _getQueryString(cls, opts=None):
339339
"""
340340
query = ("select obj from %s obj "
341341
"join fetch obj.details.owner as owner "
342+
"left outer join fetch obj.details.externalInfo "
342343
"join fetch obj.details.creationEvent" % cls.OMERO_CLASS)
343344

344345
params = omero.sys.ParametersI()
@@ -1345,6 +1346,26 @@ def getName(self):
13451346
else:
13461347
return None
13471348

1349+
def getExternalInfo(self):
1350+
"""
1351+
Gets the object's details.externalInfo
1352+
1353+
:return: omero.model.ExternalInfo object
1354+
"""
1355+
extinfo = self.getDetails()._externalInfo
1356+
if extinfo is not None and not extinfo._loaded:
1357+
params = omero.sys.ParametersI()
1358+
params.addId(extinfo.id)
1359+
query = """
1360+
select e from ExternalInfo as e
1361+
where e.id = :id
1362+
"""
1363+
queryService = self._conn.getQueryService()
1364+
extinfo = queryService.findByQuery(query, params, {"omero.group": "-1"})
1365+
# cache the result
1366+
self._obj._details._externalInfo = extinfo
1367+
return extinfo
1368+
13481369
def getDescription(self):
13491370
"""
13501371
Gets this object description

src/omero/plugins/obj.py

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from omero_ext.argparse import SUPPRESS
3636
from omero.cli import BaseControl, CLI, ExceptionHandler
37-
from omero.rtypes import rlong
37+
from omero.rtypes import rlong, unwrap
3838

3939

4040
class TxField(object):
@@ -278,6 +278,76 @@ def save_and_return(self, ctx):
278278
self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)
279279

280280

281+
class ExtInfoSetTxAction(NonFieldTxAction):
282+
283+
def on_go(self, ctx, args):
284+
# ['ext-info-set', 'Project:302', 'lsid', 'entityType', 'entityId']
285+
argc = len(self.tx_cmd.arg_list)
286+
if argc not in [4, 5, 6]:
287+
ctx.die(345,
288+
"usage: ext-info-set OBJ entityId entityType [lsid] [uuid]")
289+
try:
290+
entity_id = int(self.tx_cmd.arg_list[2])
291+
except ValueError:
292+
ctx.die(347, "entityId must be an integer, got: %s" %
293+
self.tx_cmd.arg_list[2])
294+
entity_type = self.tx_cmd.arg_list[3]
295+
296+
details = self.obj.getDetails()
297+
extinfo_id = None
298+
# if externalInfo exists, delete affer replacing below...
299+
if details and details._externalInfo:
300+
extinfo_id = details._externalInfo._id.val
301+
302+
from omero.model import ExternalInfoI
303+
from omero.rtypes import rstring, rlong
304+
305+
extinfo = ExternalInfoI()
306+
# non-nullable properties
307+
setattr(extinfo, "entityId", rlong(entity_id))
308+
setattr(extinfo, "entityType", rstring(entity_type))
309+
# nullable properties
310+
if argc > 4:
311+
lsid = self.tx_cmd.arg_list[4]
312+
setattr(extinfo, "lsid", rstring(lsid))
313+
if argc == 6:
314+
uuid = self.tx_cmd.arg_list[5]
315+
setattr(extinfo, "uuid", rstring(uuid))
316+
317+
self.obj.details.externalInfo = extinfo
318+
self.save_and_return(ctx)
319+
320+
if extinfo_id is not None:
321+
self.update.deleteObject(ExternalInfoI(extinfo_id, False))
322+
323+
324+
class ExtInfoGetTxAction(NonFieldTxAction):
325+
326+
def on_go(self, ctx, args):
327+
details = self.obj.getDetails()
328+
extinfo = None
329+
if details and details._externalInfo:
330+
extinfo = self.query.get("ExternalInfo",
331+
details._externalInfo._id.val, {"omero.group": "-1"})
332+
333+
if extinfo is None:
334+
obj, kls = self.instance(ctx)
335+
ctx.die(346, f"No ExternalInfo found: {kls}:{obj.id.val}")
336+
337+
attr_list = ["id", "entityId", "entityType", "lsid", "uuid"]
338+
proxy = ""
339+
if len(self.tx_cmd.arg_list) == 3:
340+
field = self.tx_cmd.arg_list[2]
341+
if field not in attr_list:
342+
ctx.die(335, f"usage: ext-info-get OBJ [{'|'.join(attr_list)}]")
343+
value = getattr(extinfo, field) or ""
344+
proxy += f"{unwrap(value)}"
345+
else:
346+
for field in attr_list:
347+
value = getattr(extinfo, field) or ""
348+
proxy += f"{field}={unwrap(value)}\n"
349+
self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)
350+
281351
class MapSetTxAction(NonFieldTxAction):
282352

283353
def on_go(self, ctx, args):
@@ -526,6 +596,11 @@ class ObjControl(BaseControl):
526596
$ omero obj list-get MapAnnotation:456 mapValue 0
527597
(foo,bar)
528598
599+
$ omero obj ext-info-set Image:12 3 myEntityType myLsid
600+
$ omero obj ext-info-set Image:12 3 myEntityType myLsid myUuid
601+
$ omero obj ext-info-get Image:12
602+
$ omero obj ext-info-get Image:12 entityType
603+
529604
Bash examples:
530605
531606
$ project=$(omero obj new Project name='my Project')
@@ -546,7 +621,8 @@ def _configure(self, parser):
546621
"command", nargs="?",
547622
choices=("new", "update", "null",
548623
"map-get", "map-set",
549-
"get", "list-get"),
624+
"get", "list-get",
625+
"ext-info-get", "ext-info-set"),
550626
help="operation to be performed")
551627
parser.add_argument(
552628
"Class", nargs="?",
@@ -603,6 +679,10 @@ def parse(self, tx_state, arg_list=None, line=None):
603679
return MapSetTxAction(tx_state, tx_cmd)
604680
elif tx_cmd.action == "map-get":
605681
return MapGetTxAction(tx_state, tx_cmd)
682+
elif tx_cmd.action == "ext-info-set":
683+
return ExtInfoSetTxAction(tx_state, tx_cmd)
684+
elif tx_cmd.action == "ext-info-get":
685+
return ExtInfoGetTxAction(tx_state, tx_cmd)
606686
elif tx_cmd.action == "null":
607687
return NullTxAction(tx_state, tx_cmd)
608688
elif tx_cmd.action == "get":

0 commit comments

Comments
 (0)