Created
July 29, 2014 09:34
-
-
Save dpwrussell/efb6d48612d794084d30 to your computer and use it in GitHub Desktop.
Broken Multiple Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.fixture(scope='function') | |
def project_broken_multi(conn, request, itest, update_service): | |
# Create a project and dataset and link them | |
project1 = ProjectI() | |
project1.name = rstring(itest.uuid()) | |
dataset1 = DatasetI() | |
dataset1.name = rstring(itest.uuid()) | |
project1.linkDataset(dataset1) | |
# Add an image to the dataset as well | |
image1 = itest.new_image(name=itest.uuid()) | |
dataset1.linkImage(image1) | |
# Add a second dataset | |
dataset2 = DatasetI() | |
dataset2.name = rstring(itest.uuid()) | |
dataset2.linkImage(image1) | |
project1.linkDataset(dataset2) | |
# Save project and all its children | |
project1 = update_service.saveAndReturnObject(project1) | |
# Create another project and attempt to link the same project | |
project2 = ProjectI() | |
project2.name = rstring(itest.uuid()) | |
# If using dataset1 as originally created, this has no id and will create | |
# a completely new dataset | |
# dataset1 = dataset1 | |
# Get the dataset1 from the saved project item | |
dataset1, dataset2 = project1.linkedDatasetList() | |
project2.linkDataset(dataset1) | |
project2 = update_service.saveAndReturnObject(project2) | |
# Create an orphan dataset | |
dataset3 = DatasetI() | |
dataset3.name = rstring(itest.uuid()) | |
# As image1 has already been saved, need to use that version | |
image1, = dataset1.linkedImageList() | |
print 'image1', image1.id.val | |
dataset3.linkImage(image1) | |
dataset3 = update_service.saveAndReturnObject(dataset3) | |
# Print project1 | |
qs = conn.getQueryService() | |
params = omero.sys.ParametersI() | |
params.add('pid', rlong(project1.id.val)) | |
q = ''' | |
select project.id, | |
pdlink.child.id, | |
dilink.child.id | |
from Project project | |
left outer join project.datasetLinks pdlink | |
left outer join pdlink.child.imageLinks dilink | |
where project.id = :pid | |
''' | |
print 'project1: project, dataset, image' | |
for e in qs.projection(q, params, conn.SERVICE_OPTS): | |
print e[0].val, e[1].val, e[2].val | |
# Print project2 | |
qs = conn.getQueryService() | |
params = omero.sys.ParametersI() | |
params.add('pid', rlong(project2.id.val)) | |
q = ''' | |
select project.id, | |
pdlink.child.id, | |
dilink.child.id | |
from Project project | |
left outer join project.datasetLinks pdlink | |
left outer join pdlink.child.imageLinks dilink | |
where project.id = :pid | |
''' | |
print 'project2: project, dataset, image' | |
for e in qs.projection(q, params, conn.SERVICE_OPTS): | |
print e[0].val, e[1].val, e[2].val | |
# Print dataset3 | |
qs = conn.getQueryService() | |
params = omero.sys.ParametersI() | |
params.add('did', rlong(dataset3.id.val)) | |
q = ''' | |
select dataset.id, | |
dilink.child.id | |
from Dataset dataset | |
left outer join dataset.imageLinks dilink | |
where dataset.id = :did | |
''' | |
print 'dataset3: dataset, image' | |
for e in qs.projection(q, params, conn.SERVICE_OPTS): | |
print e[0].val, e[1].val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment