use of omero.gateway.model.TableData in project imagej-omero by imagej.
the class DefaultOMEROService method convertOMEROTable.
@Override
public TableData convertOMEROTable(final Table<?, ?> imageJTable) {
final TableDataColumn[] omeroColumns = new TableDataColumn[imageJTable.getColumnCount()];
final Object[][] data = new Object[imageJTable.getColumnCount()][];
for (int c = 0; c < imageJTable.getColumnCount(); c++) {
omeroColumns[c] = TableUtils.createOMEROColumn(imageJTable.get(c), c);
data[c] = TableUtils.populateOMEROColumn(imageJTable.get(c), convertService);
}
// Create table and attach to image
final TableData omeroTable = new TableData(omeroColumns, data);
omeroTable.setNumberOfRows(imageJTable.getRowCount());
return omeroTable;
}
use of omero.gateway.model.TableData in project imagej-omero by imagej.
the class DefaultOMEROService method downloadTable.
@Override
public Table<?, ?> downloadTable(final OMEROCredentials credentials, final long tableID) throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
try (final OMEROSession session = new DefaultOMEROSession(credentials)) {
final TablesFacility tableService = session.getGateway().getFacility(TablesFacility.class);
final TableData table = tableService.getTable(session.getSecurityContext(), tableID, 0, Integer.MAX_VALUE - 1);
final TableDataColumn[] omeroColumns = table.getColumns();
final Object[][] data = table.getData();
final Table<?, ?> imageJTable = TableUtils.createImageJTable(omeroColumns);
imageJTable.setRowCount((int) table.getNumberOfRows());
boolean colsCreated = false;
if (!(imageJTable instanceof GenericTable)) {
imageJTable.appendColumns(omeroColumns.length);
colsCreated = true;
}
for (int i = 0; i < omeroColumns.length; i++) {
if (!colsCreated) {
final Column<?> imageJCol = TableUtils.createImageJColumn(omeroColumns[i]);
TableUtils.populateImageJColumn(omeroColumns[i].getType(), data[omeroColumns[i].getIndex()], imageJCol);
((GenericTable) imageJTable).add(omeroColumns[i].getIndex(), imageJCol);
} else {
TableUtils.populateImageJColumn(omeroColumns[i].getType(), data[omeroColumns[i].getIndex()], imageJTable.get(i));
imageJTable.get(i).setHeader(omeroColumns[i].getName());
}
}
return imageJTable;
}
}
use of omero.gateway.model.TableData in project imagej-omero by imagej.
the class ModuleAdapter method attachTablesToImages.
/**
* Attaches the tables to the input images. This also adds the Table ids to
* the omero client.
*/
private void attachTablesToImages(final List<ImageData> images, final HashMap<String, TableData> tables, final SecurityContext ctx, final DataManagerFacility dm) throws DSOutOfServiceException, DSAccessException, ExecutionException, ServerError {
final TablesFacility tablesFacility = gateway.getFacility(TablesFacility.class);
for (final String name : tables.keySet()) {
final TableData t = tablesFacility.addTable(ctx, images.get(0), name, tables.get(name));
client.setOutput(name, omero.rtypes.rlong(t.getOriginalFileId()));
}
// Adding tables again would create new tables on the server
for (int i = 1; i < images.size(); i++) {
for (final String name : tables.keySet()) {
final OriginalFile file = new OriginalFileI(tables.get(name).getOriginalFileId(), false);
final FileAnnotation anno = new FileAnnotationI();
anno.setFile(file);
FileAnnotationData annotation = new FileAnnotationData(anno);
annotation.setDescription(name);
annotation = (FileAnnotationData) dm.saveAndReturnObject(ctx, annotation);
dm.attachAnnotation(ctx, annotation, images.get(i));
}
}
}
use of omero.gateway.model.TableData in project imagej-omero by imagej.
the class UploadTableTest method setUpMethodCalls.
// -- Helper methods --
private void setUpMethodCalls() throws ServerError, PermissionDeniedException, CannotCreateSessionException, DSOutOfServiceException, ExecutionException, DSAccessException {
new Expectations() {
{
new DefaultOMEROSession(credentials);
gateway.getFacility(BrowseFacility.class);
result = browseFacility;
browseFacility.getImage((SecurityContext) any, anyLong);
result = new ImageData();
gateway.getFacility(TablesFacility.class);
result = tablesFacility;
tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, (TableData) any);
result = new TableData((TableDataColumn[]) any, (Object[][]) any);
}
};
}
use of omero.gateway.model.TableData in project imagej-omero by imagej.
the class UploadTableTest method testBoolTable.
@Test
public void testBoolTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
final BoolTable table = new DefaultBoolTable(2, 4);
table.get(0).fill(new boolean[] { true, true, false, false });
table.get(1).fill(new boolean[] { true, false, true, false });
// Create expectations
setUpMethodCalls();
final long id = service.uploadTable(credentials, "table", table, 0);
assertEquals(id, -1);
// NB: Can only capture in a Verifications block
new Verifications() {
{
TableData td;
tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
tableEquals(table, td, Boolean.class);
}
};
}
Aggregations