as I try to switch more Jython Dropboxes to the V3 version of the API, I still have trouble finding the relevant methods.
Now, I have a very basic dropbox with a folder named after a sample code. The Dropbox shall check for the sample and attach the folder as a new dataset.
Additionally, what would be the method to look up the sample by PermId since Codes can exist in other spaces, too, as I understood?
Help is appreciated since I already spent quite some time figuring out the proper Java methods.
The problem in the code is that the data set you are creating is from the V2 API and you are trying to pass it an object from the V3 API. They are incompatible. To make your code work, I would suggest something like this:
I want to extend the example a little bit since it is kind of a prototype for many (dropboxes and people):
Not only do I want to put a DataSet to a sample as before, I also want to create a sample, of a specific type first.
I know how to tackle that with the V2 API but adjusting to V3, I followed the procedure at https://unlimited.ethz.ch/display/openBISDoc2010/openBIS+V3+API, I create a new sample of type SAMPLE_TYPE by
from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create import SampleCreation
from ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id import EntityTypePermId
sample = SampleCreation()
sample.setTypeId(EntityTypePermId("SAMPLE_TYPE"))
sample.setParentIds([machine, identifier]) # identifier is the original sample
sample.setProperty("$NAME", "Some Name")
...
created_sample = service.createSamples(sessionToken, [sample])
That fails since a sampleID is expected to be passed as 2nd argument.
java.lang.RuntimeException: java.lang.RuntimeException: class java.lang.String cannot be cast to class ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id.IObjectId (java.lang.String is in module java.base of loader 'bootstrap'; ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id.IObjectId is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @13d9cbf5) (Context: [])
Does the sample have a SamplePermId​ before it is created by “createSamples”?
Thanks for your help.
I would like to emphasize a very important aspect when programming dropboxes: all modification operations (creations, updates, file transfers) must use the V2 API and all read operations should preferably use the V3 (but this part is not a must). The reason is that the V3 search API is more efficient, however when the V3 API is used for modification operations, it is not invoked in the transactional context of the dropbox; this means that if one operation fails in the middle, the changes will not be rolled back, and you might end up with inconsistent data. For example, if you create multiple samples and one creation fails, the samples, which have been created, will remain in the system, but this behaviour is almost always undesirable.
This is a snipped from a Dropbox of another project. From it, you can get the idea of how to create samples:
thanks for making explicitly the separation between the purposes of both APIs. I wasn’t aware of that. I understood an apparent movement to V3 and tried to use it wherever possible.
Thanks @viktor.kovtun for the explanation indeed. It would be great if the next Dropbox version would use the V3 API transactionally. It is generally a much cleaner API than the V2!