Search in sources :

Example 1 with TableData

use of omero.gateway.model.TableData 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;
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) ImageData(omero.gateway.model.ImageData) TableData(omero.gateway.model.TableData) BrowseFacility(omero.gateway.facility.BrowseFacility)

Example 2 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class ModuleAdapter method launch.

/**
 * Executes the associated ImageJ module as an OMERO script.
 *
 * @throws IOException
 * @throws ServerError
 * @throws ExecutionException
 * @throws CannotCreateSessionException
 * @throws PermissionDeniedException
 * @throws DSAccessException
 * @throws DSOutOfServiceException
 */
public void launch() throws ServerError, IOException, ExecutionException, PermissionDeniedException, CannotCreateSessionException, DSOutOfServiceException, DSAccessException {
    // populate inputs
    log.debug(info.getTitle() + ": populating inputs");
    final HashMap<String, Object> inputMap = new HashMap<>();
    for (final String name : client.getInputKeys()) {
        final ModuleItem<?> input = getInput(name);
        final Class<?> type = input.getType();
        final Object value = omeroService.toImageJ(client, client.getInput(name), type);
        inputMap.put(input.getName(), value);
    }
    // execute ImageJ module
    log.debug(info.getTitle() + ": executing module");
    final Future<Module> future = moduleService.run(info, true, inputMap);
    final Module module = moduleService.waitFor(future);
    final HashMap<String, TableData> tables = new HashMap<>();
    // populate outputs, except tables
    log.debug(info.getTitle() + ": populating outputs");
    for (final ModuleItem<?> item : module.getInfo().outputs()) {
        final Object value = omeroService.toOMERO(client, item.getValue(module));
        final String name = getOutputName(item);
        if (value == null) {
            log.warn(info.getTitle() + ": output '" + name + "' is null");
        }
        if (value instanceof omero.RType)
            client.setOutput(name, (omero.RType) value);
        if (value instanceof TableData)
            tables.put(name, (TableData) value);
    }
    createOutputLinks(inputMap, tables);
    gateway.disconnect();
    log.debug(info.getTitle() + ": completed execution");
}
Also used : HashMap(java.util.HashMap) Module(org.scijava.module.Module) TableData(omero.gateway.model.TableData)

Example 3 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method testFloatTable.

@Test
public void testFloatTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final FloatTable table = new DefaultFloatTable(4, 2);
    table.get(0).fill(new float[] { -380129.125f, 0.25f });
    table.get(1).fill(new float[] { 9871234.0f, -12.5f });
    table.get(2).fill(new float[] { 0.0625f, 13208.03125f });
    table.get(3).fill(new float[] { -0.0625f, 1908471790.5f });
    final String[] headers = new String[] { "H1", "H2", "H3", "H4" };
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.get(i).setHeader(headers[i]);
    }
    // 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, Double.class);
        }
    };
}
Also used : FloatTable(net.imagej.table.FloatTable) DefaultFloatTable(net.imagej.table.DefaultFloatTable) DefaultFloatTable(net.imagej.table.DefaultFloatTable) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Example 4 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method testByteArrayTable.

@Test
public void testByteArrayTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final GenericTable table = new DefaultGenericTable();
    final DefaultColumn<ByteArray> ij0 = new DefaultColumn<>(ByteArray.class);
    final DefaultColumn<ByteArray> ij1 = new DefaultColumn<>(ByteArray.class);
    ij0.add(new ByteArray(new byte[] { -128, 127 }));
    ij0.add(new ByteArray(new byte[] { 0, 10 }));
    ij1.add(new ByteArray(new byte[] { 112, 42 }));
    ij1.add(new ByteArray(new byte[] { -13, -84 }));
    table.add(ij0);
    table.add(ij1);
    // 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, Long[].class);
        }
    };
}
Also used : DefaultGenericTable(net.imagej.table.DefaultGenericTable) DefaultColumn(net.imagej.table.DefaultColumn) GenericTable(net.imagej.table.GenericTable) DefaultGenericTable(net.imagej.table.DefaultGenericTable) ByteArray(org.scijava.util.ByteArray) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Example 5 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method testCharTable.

@Test
public void testCharTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final CharTable table = new DefaultCharTable(5, 2);
    table.get(0).fill(new char[] { 'q', 'V' });
    table.get(1).fill(new char[] { '2', '$' });
    table.get(2).fill(new char[] { 'b', 'a' });
    table.get(3).fill(new char[] { '\t', '\n' });
    table.get(4).fill(new char[] { '.', ' ' });
    // 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, String.class);
        }
    };
}
Also used : DefaultCharTable(net.imagej.table.DefaultCharTable) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) DefaultCharTable(net.imagej.table.DefaultCharTable) CharTable(net.imagej.table.CharTable) Test(org.junit.Test)

Aggregations

TableData (omero.gateway.model.TableData)23 Test (org.junit.Test)17 Verifications (mockit.Verifications)9 GenericTable (net.imagej.table.GenericTable)9 TableDataColumn (omero.gateway.model.TableDataColumn)9 DefaultColumn (net.imagej.table.DefaultColumn)6 DefaultGenericTable (net.imagej.table.DefaultGenericTable)4 TablesFacility (omero.gateway.facility.TablesFacility)4 ImageData (omero.gateway.model.ImageData)3 BoolColumn (net.imagej.table.BoolColumn)2 BoolTable (net.imagej.table.BoolTable)2 LongTable (net.imagej.table.LongTable)2 DataObject (omero.gateway.model.DataObject)2 DoubleArray (org.scijava.util.DoubleArray)2 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 DefaultOMEROSession (net.imagej.omero.DefaultOMEROSession)1 OMEROCredentials (net.imagej.omero.OMEROCredentials)1 OMEROSession (net.imagej.omero.OMEROSession)1 ByteTable (net.imagej.table.ByteTable)1