use of omero.gateway.facility.TablesFacility in project imagej-omero by imagej.
the class DefaultOMEROService method uploadTable.
@Override
public long uploadTable(final OMEROCredentials credentials, final String name, final Table<?, ?> imageJTable, final long imageID) throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
final TableData omeroTable = convertOMEROTable(imageJTable);
long id = -1;
try (final OMEROSession session = new DefaultOMEROSession(credentials)) {
// Get image
final BrowseFacility browseFacility = session.getGateway().getFacility(BrowseFacility.class);
final ImageData image = browseFacility.getImage(session.getSecurityContext(), imageID);
// attach table to image
final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
final TableData stored = tablesFacility.addTable(session.getSecurityContext(), image, name, omeroTable);
id = stored.getOriginalFileId();
}
return id;
}
use of omero.gateway.facility.TablesFacility in project imagej-omero by imagej.
the class OmeroIT method testUploadTable.
@Test
public void testUploadTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
final byte[][] d = new byte[][] { { 127, 0, -128 }, { -1, -6, -23 }, { 100, 87, 4 } };
final ByteTable table = new DefaultByteTable(3, 3);
for (int c = 0; c < table.getColumnCount(); c++) {
table.setColumnHeader(c, "Heading " + (c + 1));
for (int r = 0; r < table.getRowCount(); r++) table.set(c, r, d[c][r]);
}
final long tableId = omero.uploadTable(cred, "test-table-upload", table, 1);
// When upload table was called it created a session, which cleared out
// the username and password from the credentials. The credentials must
// have a username and password to create security contexts.
final OMEROCredentials tc = new OMEROCredentials();
tc.setServer(OMERO_SERVER);
tc.setPort(OMERO_PORT);
tc.setUser(OMERO_USER);
tc.setPassword(OMERO_PASSWORD);
try (final OMEROSession session = new DefaultOMEROSession(tc)) {
final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
final TableData td = tablesFacility.getTableInfo(session.getSecurityContext(), tableId);
assertEquals(td.getColumns().length, 3);
assertEquals(td.getColumns()[0].getName(), "Heading 1");
assertEquals(td.getColumns()[1].getName(), "Heading 2");
assertEquals(td.getColumns()[2].getName(), "Heading 3");
assertEquals(td.getNumberOfRows(), 3);
}
}
use of omero.gateway.facility.TablesFacility 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.facility.TablesFacility 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));
}
}
}
Aggregations