Page 1 of 2

Removing link from file as well as deleting the file

PostPosted: Thu Apr 21, 2011 5:31 pm
by icaoberg
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

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

PostPosted: Thu Apr 21, 2011 8:08 pm
by cxallan
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

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

PostPosted: Thu Apr 21, 2011 8:44 pm
by icaoberg
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

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

PostPosted: Tue Apr 26, 2011 7:54 am
by cxallan
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

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

PostPosted: Thu May 26, 2011 3:25 pm
by bhcho
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

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

PostPosted: Fri May 27, 2011 6:13 am
by wmoore
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)

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

PostPosted: Fri May 27, 2011 6:33 am
by wmoore
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

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

PostPosted: Fri May 27, 2011 6:49 am
by bhcho
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

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

PostPosted: Fri May 27, 2011 6:53 am
by jmoore
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.

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

PostPosted: Fri May 27, 2011 7:16 am
by bhcho
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