We're Hiring!

Removing link from file as well as deleting the file

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Removing link from file as well as deleting the file

Postby icaoberg » Thu Apr 21, 2011 5:31 pm

I am linking features tables to images using the API. There exists the possibility of updating these tables. In OMERO if I update a table with the same name I just get a second linked file. Even by linking the same file I get two links as well as two files. So before updating I need to remove the old link and delete the file from repository. Is there a way to this from the API?

Ivan
icaoberg
 
Posts: 145
Joined: Fri Sep 17, 2010 9:05 pm
Location: Pittsburgh, PA

Re: Removing link from file as well as deleting the file

Postby cxallan » Thu Apr 21, 2011 8:08 pm

Yes there is. The over arching ticket describing the advanced delete functionality as introduced in Beta 4.2.1 is here:

http://trac.openmicroscopy.org.uk/ome/ticket/2615

You can see delete examples here:

http://trac.openmicroscopy.org.uk/ome/b ... les/Delete
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: Removing link from file as well as deleting the file

Postby icaoberg » Thu Apr 21, 2011 8:44 pm

thank you the example was useful in showing how to use the delete service. but where can i find information regarding the different options for the delete command. i am looking for removing a specific file link from an image, not removing the image itself. thanks.

ivan
icaoberg
 
Posts: 145
Joined: Fri Sep 17, 2010 9:05 pm
Location: Pittsburgh, PA

Re: Removing link from file as well as deleting the file

Postby cxallan » Tue Apr 26, 2011 7:54 am

If you just want to delete an object, you're probably best saving yourself the delete complexity then and just use the deleteObject() method on the IUpdate service:

http://hudson.openmicroscopy.org.uk/job ... IObject%29
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: Removing link from file as well as deleting the file

Postby bhcho » Thu May 26, 2011 3:25 pm

Hi,

I don't understand how to use deleteObject(ome.model.IObject row).
here's my follow-up questions.

0. Assume that I have an attachment file to an image. I want to delete the attachement file (as well as unlink it) without deleting the image.

1. you said I can use deleteObject function. Does this function delete the attachment file and unlink it simultaneously?

2. if yes, what is the input argument of the deleteObject function? I guess it should be something like the File ID for the attachment file (but the input argument does not look like a file ID).

Thanks in advance,
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: Removing link from file as well as deleting the file

Postby wmoore » Fri May 27, 2011 6:13 am

To delete the file annotation and the link you'll need to delete both separately using deleteObject, with the links being deleted first (deleting the file without deleting links will cause an exception).

In fact there are 3 entities associated with a file annotation which should be deleted in this order.

- ImageAnnotationLink
- Annotation
- OriginalFile

E.g. pseudo code
Code: Select all
query = "select ial from ImageAnnotationLink as ial join fetch ial.child as ann join fetch ann.file as file where ial.parent = imageId"
link = queryService.findByQuery(query, None)
ann = link.child
file = ann.file

deleteService.deleteObject(link)
deleteService.deleteObject(ann)
deleteService.deleteObject(file)
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Removing link from file as well as deleting the file

Postby wmoore » Fri May 27, 2011 6:33 am

In fact, it seems like the deleteService may be your best bet.
I just tried this code in Python to remove a File Annotation and it seems to do the same as the code I posted above, removing the link, annotation and originalfile (as well as the binary file on disk).

Code: Select all
dcs = list()
dcs.append(omero.api.delete.DeleteCommand("/Annotation", long(annId), None))
handle = deleteService().queueDelete(dcs)


Will
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Removing link from file as well as deleting the file

Postby bhcho » Fri May 27, 2011 6:49 am

thanks,

isn't the deleteService from getdeleteService() ?
Code: Select all
deleteService = session.getDeleteService()


I got the following error.
Code: Select all
In [93]: handle = deleteService().queueDelete(dcs)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

<ipython console> in <module>()

TypeError: 'IDeletePrx' object is not callable


BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: Removing link from file as well as deleting the file

Postby jmoore » Fri May 27, 2011 6:53 am

That's a typo in Will's code, but otherwise he's correct that "DeleteCommand('/Annotation', ...)" will do what you want: deleting the annotation, the original file, as well as any links, event to multiple object types like Images, Datasets, etc. I've posted examples named "FileAnnotationDelete" under our examples directory:
http://git.openmicroscopy.org/src/develop/examples/Delete/

Hope that helps.
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Removing link from file as well as deleting the file

Postby bhcho » Fri May 27, 2011 7:16 am

then, what is fa from here?

Code: Select all
  26     deleteServicePrx = s.getDeleteService();
  27     dc = omero.api.delete.DeleteCommand("/Annotation", fa.id.val, None)
  28     deleteHandlePrx = deleteServicePrx .queueDelete([dc])
  29     cb = omero.callbacks.DeleteCallbackI(c, deleteHandlePrx)


from my code, I got 'fa' like this...
Code: Select all
query = session.getQueryService()

#create and populate parameter
params = omero.sys.ParametersI()
params.addLong( "iid", iid );
params.addString( "filename", filename );

#hql string query
string = "select iml from ImageAnnotationLink as iml join fetch iml.child as fileAnn join fetch fileAnn.file join iml.parent as img where img.id = :iid and fileAnn.file.name = :filename"

#database query
fa =  query.findAllByQuery(string, params) 
fa = fa[0]


but still I could not delete it with this 'fa'. Please correct me if I'm wrong
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Next

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests