def comments_userA(request, userA, groupA): """ Returns new OMERO Comments """ comments = [] ctx = {'omero.group': str(groupA.id.val)} for text in ["Test Comment", "Another comment userA"]: comment = CommentAnnotationI() comment.textValue = rstring(text) comments.append(comment) comments = get_update_service(userA).saveAndReturnArray(comments, ctx) comments.sort(cmp_id) return comments
def fileset_with_images_and_annotations(request, gatewaywrapper): gatewaywrapper.loginAsAuthor() update_service = gatewaywrapper.gateway.getUpdateService() fileset = create_fileset() comment_annotation = CommentAnnotationI() comment_annotation.ns = rstring("comment_annotation") comment_annotation.textValue = rstring("textValue") long_annotation = LongAnnotationI() long_annotation.ns = rstring("long_annotation") long_annotation.longValue = rlong(1L) fileset.linkAnnotation(comment_annotation) fileset.linkAnnotation(long_annotation) fileset = update_service.saveAndReturnObject(fileset) return gatewaywrapper.gateway.getObject("Fileset", fileset.id.val)
def fileset_with_images_and_annotations(request, gatewaywrapper): gatewaywrapper.loginAsAuthor() update_service = gatewaywrapper.gateway.getUpdateService() fileset = create_fileset() comment_annotation = CommentAnnotationI() comment_annotation.ns = rstring('comment_annotation') comment_annotation.textValue = rstring('textValue') long_annotation = LongAnnotationI() long_annotation.ns = rstring('long_annotation') long_annotation.longValue = rlong(1L) fileset.linkAnnotation(comment_annotation) fileset.linkAnnotation(long_annotation) fileset = update_service.saveAndReturnObject(fileset) return gatewaywrapper.gateway.getObject('Fileset', fileset.id.val)
def rename_fileset(client, mrepo, fileset, new_dir, ctx=None): """ Loads each OriginalFile found under orig_dir and updates its path field to point at new_dir. Files are not yet moved. """ from omero.constants.namespaces import NSFSRENAME from omero.model import CommentAnnotationI from omero.model import FilesetAnnotationLinkI tomove = [] tosave = [] query = client.sf.getQueryService() update = client.sf.getUpdateService() orig_dir = fileset.templatePrefix.val def parse_parent(dir): """ Note that final elements are empty """ parts = dir.split("/") parpath = "/".join(parts[0:-2]+[""]) parname = parts[-2] logname = parts[-2] + ".log" return parpath, parname, logname orig_parpath, orig_parname, orig_logname = parse_parent(orig_dir) new_parpath, new_parname, new_logname = parse_parent(new_dir) for entry in contents(mrepo, orig_dir, ctx): ofile = query.get("OriginalFile", entry.id, ctx) path = ofile.path.val if entry.level == 0: tomove.append((orig_dir, new_dir)) assert orig_parpath in path repl = path.replace(orig_parpath, new_parpath) ofile.name = rstring(new_parname) else: assert orig_dir in path repl = path.replace(orig_dir, new_dir) ofile.path = rstring(repl) tosave.append(ofile) fileset.templatePrefix = rstring(new_dir) # TODO: placing the fileset at the end of this list # causes ONLY the fileset to be updated !! tosave.insert(0, fileset) # Add an annotation to the fileset as well so # we can detect if something's gone wrong. link = FilesetAnnotationLinkI() link.parent = fileset.proxy() link.child = CommentAnnotationI() link.child.ns = rstring(NSFSRENAME) link.child.textValue = rstring("previous=%s" % orig_dir) tosave.insert(1, link) # And now move the log file as well: log = get_logfile(query, fileset.id.val) if log is not None: target = new_parpath + new_logname source = orig_parpath + orig_logname tomove.append((source, target)) log.path = rstring(new_parpath) log.name = rstring(new_logname) tosave.append(log) # Done. Save in one transaction and return tomove update.saveAndReturnArray(tosave, ctx) return tomove
def add_annotations(o): ''' Annotation BasicAnnotation BooleanAnnotation BooleanAnnotationI NumericAnnotation DoubleAnnotation DoubleAnnotationI LongAnnotation LongAnnotationI TermAnnotation TermAnnotationI TimestampAnnotation TimestampAnnotationI ListAnnotation ListAnnotationI MapAnnotation MapAnnotationI TextAnnotation CommentAnnotation CommentAnnotationI TagAnnotation TagAnnotationI XmlAnnotation XmlAnnotationI TypeAnnotation FileAnnotation FileAnnotationI ''' annotation = BooleanAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('boolean_annotation') annotation.boolValue = rbool(True) o.linkAnnotation(annotation) annotation = CommentAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('comment_annotation') annotation.textValue = rstring('text_value') o.linkAnnotation(annotation) annotation = DoubleAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('double_annotation') annotation.doubleValue = rdouble(1.0) o.linkAnnotation(annotation) annotation = LongAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('long_annotation') annotation.longValue = rlong(1L) o.linkAnnotation(annotation) annotation = MapAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('map_annotation') annotation.setMapValue([NamedValue('a', '1'), NamedValue('b', '2')]) o.linkAnnotation(annotation) annotation = TagAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('tag_annotation') annotation.textValue = rstring('tag_value') o.linkAnnotation(annotation) annotation = TermAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('term_annotation') annotation.termValue = rstring('term_value') o.linkAnnotation(annotation) annotation = TimestampAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('timestamp_annotation') annotation.timeValue = rtime(1) o.linkAnnotation(annotation) annotation = XmlAnnotationI() annotation.description = rstring('the_description') annotation.ns = rstring('xml_annotation') annotation.textValue = rstring('<xml_value></xml_value>') o.linkAnnotation(annotation)